forked from typescript-eslint/typescript-eslint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(website): rewrite WebLinter to typescript and fix support for t…
…s 4.7 (typescript-eslint#5034)
- Loading branch information
Showing
22 changed files
with
221 additions
and
296 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 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 |
---|---|---|
@@ -1,74 +1,16 @@ | ||
import 'vs/language/typescript/tsWorker'; | ||
import { parseForESLint } from './parser'; | ||
import { Linter } from 'eslint'; | ||
import rules from '@typescript-eslint/eslint-plugin/dist/rules'; | ||
|
||
const PARSER_NAME = '@typescript-eslint/parser'; | ||
|
||
export function loadLinter(libs, options) { | ||
export function createLinter() { | ||
const linter = new Linter(); | ||
let storedAST; | ||
let storedTsAST; | ||
let storedScope; | ||
|
||
let compilerOptions = options; | ||
|
||
linter.defineParser(PARSER_NAME, { | ||
parseForESLint(code, eslintOptions) { | ||
const toParse = parseForESLint( | ||
code, | ||
eslintOptions, | ||
compilerOptions, | ||
libs, | ||
); | ||
storedAST = toParse.ast; | ||
storedTsAST = toParse.tsAst; | ||
storedScope = toParse.scopeManager; | ||
return toParse; | ||
}, | ||
// parse(code: string, options: ParserOptions): ParseForESLintResult['ast'] { | ||
// const toParse = parseForESLint(code, options); | ||
// storedAST = toParse.ast; | ||
// return toParse.ast; | ||
// }, | ||
}); | ||
|
||
for (const name of Object.keys(rules)) { | ||
for (const name in rules) { | ||
linter.defineRule(`@typescript-eslint/${name}`, rules[name]); | ||
} | ||
|
||
const ruleNames = Array.from(linter.getRules()).map(value => { | ||
return { | ||
name: value[0], | ||
description: value[1]?.meta?.docs?.description, | ||
}; | ||
}); | ||
|
||
return { | ||
ruleNames: ruleNames, | ||
|
||
updateOptions(options) { | ||
compilerOptions = options || {}; | ||
}, | ||
|
||
getScope() { | ||
return storedScope; | ||
}, | ||
|
||
getAst() { | ||
return storedAST; | ||
}, | ||
|
||
getTsAst() { | ||
return storedTsAST; | ||
}, | ||
|
||
lint(code, parserOptions, rules) { | ||
return linter.verify(code, { | ||
parser: PARSER_NAME, | ||
parserOptions, | ||
rules, | ||
}); | ||
}, | ||
}; | ||
return linter; | ||
} | ||
|
||
export { analyze } from '@typescript-eslint/scope-manager/dist/analyze'; | ||
export { visitorKeys } from '@typescript-eslint/visitor-keys/dist/visitor-keys'; | ||
export { astConverter } from '@typescript-eslint/typescript-estree/dist/ast-converter'; | ||
export { getScriptKind } from '@typescript-eslint/typescript-estree/dist/create-program/getScriptKind'; |
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 |
---|---|---|
@@ -1,38 +1,13 @@ | ||
import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; | ||
import type { ParserOptions } from '@typescript-eslint/types'; | ||
import type { SourceFile, CompilerOptions } from 'typescript'; | ||
|
||
export type LintMessage = TSESLint.Linter.LintMessage; | ||
export type RuleFix = TSESLint.RuleFix; | ||
export type RulesRecord = TSESLint.Linter.RulesRecord; | ||
export type RuleEntry = TSESLint.Linter.RuleEntry; | ||
|
||
export interface WebLinter { | ||
ruleNames: { name: string; description?: string }[]; | ||
|
||
getAst(): TSESTree.Program; | ||
getTsAst(): SourceFile; | ||
getScope(): Record<string, unknown>; | ||
updateOptions(options?: Record<string, unknown>): void; | ||
|
||
lint( | ||
code: string, | ||
parserOptions: ParserOptions, | ||
rules?: RulesRecord, | ||
): LintMessage[]; | ||
import type { TSESLint } from '@typescript-eslint/utils'; | ||
|
||
import { analyze } from '@typescript-eslint/scope-manager/dist/analyze'; | ||
import { astConverter } from '@typescript-eslint/typescript-estree/dist/ast-converter'; | ||
import { getScriptKind } from '@typescript-eslint/typescript-estree/dist/create-program/getScriptKind'; | ||
|
||
export interface LintUtils { | ||
createLinter: () => TSESLint.Linter; | ||
analyze: typeof analyze; | ||
visitorKeys: TSESLint.SourceCode.VisitorKeys; | ||
astConverter: typeof astConverter; | ||
getScriptKind: typeof getScriptKind; | ||
} | ||
|
||
export interface LinterLoader { | ||
loadLinter( | ||
libMap: Map<string, string>, | ||
compilerOptions: CompilerOptions, | ||
): WebLinter; | ||
} | ||
|
||
export type { | ||
DebugLevel, | ||
EcmaVersion, | ||
ParserOptions, | ||
SourceType, | ||
TSESTree, | ||
} from '@typescript-eslint/types'; |
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
2 changes: 1 addition & 1 deletion
2
packages/website/src/components/ast/serializer/serializerESTree.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
2 changes: 1 addition & 1 deletion
2
packages/website/src/components/ast/serializer/serializerScope.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
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
Oops, something went wrong.