-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
247 additions
and
298 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
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,13 @@ | ||
import { camelCaseToKebabCase } from '@code-pushup/utils'; | ||
import { TS_ERROR_CODES } from './ts-error-codes.js'; | ||
import type { CompilerOptionName } from './types.js'; | ||
|
||
/** Build Reverse Lookup Map. It will a map with key as the error code and value as the audit slug. */ | ||
export const AUDIT_LOOKUP = Object.values(TS_ERROR_CODES) | ||
.flatMap(v => Object.entries(v)) | ||
.reduce<Map<number, CompilerOptionName>>((lookup, [name, codes]) => { | ||
codes.forEach((code: number) => | ||
lookup.set(code, camelCaseToKebabCase(name) as CompilerOptionName), | ||
); | ||
return lookup; | ||
}, new Map<number, CompilerOptionName>()); |
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
21 changes: 0 additions & 21 deletions
21
packages/plugin-typescript/src/lib/runner/ts-error-codes.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
11 changes: 5 additions & 6 deletions
11
...ner/typescript-runner.integration.test.ts → .../lib/runner/ts-runner.integration.test.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
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,41 @@ | ||
import { | ||
type CompilerOptions, | ||
type Diagnostic, | ||
createProgram, | ||
getPreEmitDiagnostics, | ||
} from 'typescript'; | ||
import { AUDIT_LOOKUP } from './constants.js'; | ||
import { loadTargetConfig } from './utils.js'; | ||
|
||
export type DiagnosticsOptions = { | ||
fileNames: string[]; | ||
compilerOptions: CompilerOptions; | ||
}; | ||
|
||
export async function getTypeScriptDiagnostics( | ||
tsConfigPath: string, | ||
): Promise<readonly Diagnostic[]> { | ||
try { | ||
const { fileNames, options } = await loadTargetConfig(tsConfigPath); | ||
const program = createProgram(fileNames, options); | ||
|
||
const diagnostics = getPreEmitDiagnostics(program); | ||
validateDiagnostics(diagnostics); | ||
|
||
return diagnostics; | ||
} catch (error) { | ||
throw new Error( | ||
`Can't create TS program in getDiagnostics. \n ${(error as Error).message}`, | ||
); | ||
} | ||
} | ||
|
||
export function validateDiagnostics(diagnostics: readonly Diagnostic[]) { | ||
diagnostics | ||
.filter(({ code }) => !AUDIT_LOOKUP.has(code)) | ||
.forEach(({ code, messageText }) => { | ||
console.warn( | ||
`Diagnostic Warning: The code ${code} is not supported. ${messageText}`, | ||
); | ||
}); | ||
} |
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,9 @@ | ||
import { TS_ERROR_CODES } from './ts-error-codes.js'; | ||
|
||
export type ErrorCodes = typeof TS_ERROR_CODES; | ||
|
||
export type CompilerOptionName = { | ||
[K in keyof ErrorCodes]: keyof ErrorCodes[K]; | ||
}[keyof ErrorCodes]; | ||
|
||
export type SemVerString = `${number}.${number}.${number}`; |
64 changes: 0 additions & 64 deletions
64
packages/plugin-typescript/src/lib/runner/typescript-runner.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
Oops, something went wrong.