-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NEW: @W-15652656@: Add public interfaces before adding any business l…
…ogic (#10)
- Loading branch information
1 parent
56f81b9
commit af2dc05
Showing
18 changed files
with
405 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,8 @@ | |
"/dist/" | ||
], | ||
"collectCoverageFrom": [ | ||
"./src/**" | ||
"src/**/*.ts", | ||
"!src/index.ts" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { EnginePlugin } from "@salesforce/code-analyzer-engine-api" | ||
import { RuleSelection } from "./rules" | ||
import { RunResults } from "./results" | ||
import { Event } from "./events" | ||
|
||
export type RunOptions = { | ||
filesToInclude: string[] | ||
entryPoints?: string[] | ||
} | ||
|
||
// Temporarily making this an interface | ||
export interface CodeAnalyzer { | ||
addEnginePlugin(enginePlugin: EnginePlugin): void | ||
|
||
selectRules(ruleSelectors: string[]): RuleSelection | ||
|
||
run(ruleSelection: RuleSelection, runOptions: RunOptions): RunResults | ||
|
||
onEvent<T extends Event>(eventType: T["type"], callback: (event: T) => void): void | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { EngineRunResults } from "./results" | ||
|
||
export enum EventType { | ||
LogEvent = "LogEvent", | ||
EngineProgressEvent = "EngineProgressEvent", | ||
EngineResultsEvent = "EngineResultsEvent" | ||
} | ||
|
||
export enum LogLevel { | ||
Error = 1, | ||
Warn = 2, | ||
Info = 3, | ||
Debug = 4, | ||
Fine = 5 | ||
} | ||
|
||
export type LogEvent = { | ||
type: EventType.LogEvent, | ||
timestamp: Date, | ||
logLevel: LogLevel, | ||
message: string | ||
} | ||
|
||
export type EngineProgressEvent = { | ||
type: EventType.EngineProgressEvent, | ||
timestamp: Date, | ||
engineName: string, | ||
percentComplete: number | ||
} | ||
|
||
export type EngineResultsEvent = { | ||
type: EventType.EngineResultsEvent | ||
timestamp: Date, | ||
results: EngineRunResults | ||
} | ||
|
||
export type Event = LogEvent | EngineProgressEvent | EngineResultsEvent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export { | ||
CodeAnalyzer, | ||
RunOptions | ||
} from "./code-analyzer" | ||
|
||
export { | ||
EngineProgressEvent, | ||
EngineResultsEvent, | ||
Event, | ||
EventType, | ||
LogEvent, | ||
LogLevel | ||
} from "./events" | ||
|
||
export { | ||
CodeLocation, | ||
EngineRunResults, | ||
OutputFormatter, | ||
RunResults, | ||
Violation | ||
} from "./results" | ||
|
||
export { | ||
Rule, | ||
RuleSelection, | ||
RuleType, | ||
SeverityLevel | ||
} from "./rules" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Rule, SeverityLevel } from "./rules" | ||
|
||
export interface CodeLocation { | ||
getFile(): string | ||
getStartLine(): number | ||
getStartColumn(): number | ||
getEndLine(): number | ||
getEndColumn(): number | ||
} | ||
|
||
export interface Violation { | ||
getRule(): Rule, | ||
getMessage(): string, | ||
getCodeLocations(): CodeLocation[] | ||
getPrimaryLocationIndex(): number | ||
} | ||
|
||
export interface EngineRunResults { | ||
getEngineName(): string | ||
getViolationCountOfSeverity(severity: SeverityLevel): number | ||
getViolations(): Violation[] | ||
} | ||
|
||
export interface OutputFormatter { | ||
format(results: RunResults): string | ||
} | ||
|
||
export interface RunResults { | ||
getTotalViolationCount(): number | ||
getViolationCountOfSeverity(severity: SeverityLevel): number | ||
getAllViolations(): Violation[] | ||
getViolationsFromEngine(engineName: string): EngineRunResults | ||
toFormattedOutput(formatter: OutputFormatter): string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export enum SeverityLevel { | ||
High = 1, | ||
Moderate = 2, | ||
Low = 3 | ||
} | ||
|
||
export enum RuleType { | ||
Standard= "Standard", | ||
PathBased = "PathBased", | ||
UnexpectedError = "UnexpectedError" | ||
} | ||
|
||
export interface Rule { | ||
getName(): string | ||
getEngineName(): string | ||
getSeverityLevel(): SeverityLevel | ||
getType(): string | ||
getTags(): string | ||
getDescription(): string | ||
getResourceUrls(): string[] | ||
} | ||
|
||
export interface RuleSelection { | ||
getCount(): number | ||
getEngineNames(): string[] | ||
getRulesFor(engineName: string): Rule[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
// This is just a temporary file and will go away soon. Just using it to make sure things are wired up correctly. | ||
|
||
import { Temp } from '@salesforce/code-analyzer-engine-api' | ||
import {EventType} from "../src"; | ||
|
||
describe('Sample Test', () => { | ||
it('abc', () => { | ||
const t: Temp = new Temp(); | ||
expect(t.hello()).toEqual("world"); | ||
it('Temporary test to satisfy code coverage', () => { | ||
expect(EventType.LogEvent).toEqual(EventType.LogEvent); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,7 @@ | |
], | ||
"collectCoverageFrom": [ | ||
"src/**/*.ts", | ||
"!src/**/index.ts" | ||
"!src/index.ts" | ||
] | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Engine } from "./engines" | ||
|
||
export type ConfigObject = { | ||
[key: string]: ConfigValue | ||
} | ||
export type ConfigValue = | ||
| string | ||
| number | ||
| boolean | ||
| null | ||
| ConfigValue[] | ||
| ConfigObject; | ||
|
||
export interface EnginePlugin { | ||
getPluginVersion(): number | ||
} | ||
|
||
export abstract class EnginePluginV1 implements EnginePlugin { | ||
public getPluginVersion(): number { | ||
return 1.0; | ||
} | ||
|
||
abstract getAvailableEngineNames(): string[] | ||
|
||
abstract createEngine(engineName: string, config: ConfigObject): Engine | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { RuleDescription } from "./rules"; | ||
import { EngineRunResults } from "./results"; | ||
import { Event } from "./events"; | ||
import { EventEmitter } from "node:events"; | ||
|
||
export type EntryPoint = { | ||
file: string | ||
methodName?: string | ||
} | ||
|
||
export type RunOptions = { | ||
filesToInclude: string[] | ||
entryPoints?: EntryPoint[] | ||
} | ||
|
||
export abstract class Engine { | ||
private readonly eventEmitter: EventEmitter = new EventEmitter(); | ||
|
||
public validate(): void {} | ||
|
||
abstract getName(): string | ||
|
||
abstract describeRules(): RuleDescription[] | ||
|
||
abstract runRules(ruleNames: string[], runOptions: RunOptions): EngineRunResults | ||
|
||
public onEvent<T extends Event>(eventType: T["type"], callback: (event: T) => void): void { | ||
this.eventEmitter.on(eventType, callback); | ||
} | ||
|
||
protected emitEvent<T extends Event>(event: T): void { | ||
this.eventEmitter.emit(event.type, event); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export enum EventType { | ||
LogEvent = "LogEvent", | ||
ProgressEvent = "ProgressEvent" | ||
} | ||
|
||
export enum LogLevel { | ||
Error = 1, | ||
Warn = 2, | ||
Info = 3, | ||
Debug = 4, | ||
Fine = 5 | ||
} | ||
|
||
export type LogEvent = { | ||
type: EventType.LogEvent, | ||
logLevel: LogLevel, | ||
message: string | ||
} | ||
|
||
export type ProgressEvent = { | ||
type: EventType.ProgressEvent, | ||
percentComplete: number | ||
} | ||
|
||
export type Event = LogEvent | ProgressEvent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,32 @@ | ||
// This is just a temporary implementation of how a module can export classes to other packages. | ||
// Note that the corresponding dist/index.js file is designated as the main file for package as shown in the package.json file. | ||
export { | ||
ConfigObject, | ||
ConfigValue, | ||
EnginePlugin, | ||
EnginePluginV1 | ||
} from "./engine-plugins" | ||
|
||
import { Temp } from "./Temp" | ||
export { | ||
Engine, | ||
EntryPoint, | ||
RunOptions | ||
} from "./engines" | ||
|
||
export { Temp } | ||
export { | ||
Event, | ||
EventType, | ||
LogEvent, | ||
LogLevel, | ||
ProgressEvent | ||
} from "./events" | ||
|
||
export { | ||
CodeLocation, | ||
EngineRunResults, | ||
Violation | ||
} from "./results" | ||
|
||
export { | ||
RuleDescription, | ||
RuleType, | ||
SeverityLevel | ||
} from "./rules" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export type CodeLocation = { | ||
file: string | ||
startLine: number | ||
startColumn: number | ||
endLine?: number | ||
endColumn?: number | ||
} | ||
|
||
export type Violation = { | ||
ruleName: string | ||
message: string | ||
codeLocations: CodeLocation[] | ||
primaryLocationIndex: number | ||
} | ||
|
||
export type EngineRunResults = { | ||
violations: Violation[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export enum SeverityLevel { | ||
High = 1, | ||
Moderate = 2, | ||
Low = 3 | ||
} | ||
|
||
export enum RuleType { | ||
Standard= "Standard", | ||
PathBased = "PathBased", | ||
UnexpectedError = "UnexpectedError" | ||
} | ||
|
||
export type RuleDescription = { | ||
name: string, | ||
severityLevel: SeverityLevel, | ||
type: RuleType, | ||
tags: string[], | ||
description: string, | ||
resourceUrls: string[] | ||
} |
Oops, something went wrong.