-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
chore(website): rewrite WebLinter to typescript and fix support for ts 4.7 #5034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
652376f
chore(website): rewrite web linter to typescript
armano2 f7d33b4
chore(website): correct issues with ts ^4.7-beta
armano2 298347d
chore(website): linting issues
armano2 dc6f23b
Merge branch 'main' into feat/refactor-and-convert-sandbox-to-ts
armano2 df7e947
Merge remote-tracking branch 'origin/main' into feat/refactor-and-con…
armano2 863b054
chore(website): reuse getScriptKind from typescript-estree
armano2 7a90148
Merge remote-tracking branch 'origin/main' into feat/refactor-and-con…
armano2 a46048a
chore(website): update link to getScriptKind base on changes from #5027
armano2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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'; | ||
armano2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
export { visitorKeys } from '@typescript-eslint/visitor-keys/dist/visitor-keys'; | ||
armano2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
export { astConverter } from '@typescript-eslint/typescript-estree/dist/ast-converter'; | ||
armano2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
export { getScriptKind } from '@typescript-eslint/typescript-estree/dist/create-program/getScriptKind'; |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.