-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Replace eslint rulesdir with eslint-plugin-local, convert eslint rules to JS #50380
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
Changes from all commits
2713bb0
d966f0e
31f450e
8c9cb3f
bac2bf1
4820a13
3cab97f
b2e1d2f
a306fb9
a85303a
2bad00a
16ab943
2a16fbf
0a978d8
0197704
f19b256
85c7cd7
0b8464f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| const fs = require("fs"); | ||
| const path = require("path"); | ||
|
|
||
| const rulesDir = path.join(__dirname, "scripts", "eslint", "rules"); | ||
| const ext = ".js"; | ||
| const ruleFiles = fs.readdirSync(rulesDir).filter((p) => p.endsWith(ext)); | ||
|
|
||
| module.exports = { | ||
| rules: Object.fromEntries(ruleFiles.map((p) => { | ||
| return [p.slice(0, -ext.length), require(path.join(rulesDir, p))]; | ||
| })), | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,3 +37,5 @@ Dockerfile | |
| .eslintrc.json | ||
| .yarnrc | ||
| tmp | ||
| .eslintplugin.js | ||
| .eslintcache | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,6 @@ | ||
| // Rename this file 'settings.json' or merge its | ||
| // contents into your existing settings. | ||
| { | ||
| "eslint.validate": [ | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this gone, the template consists solely of suggestions for |
||
| "typescript" | ||
| ], | ||
| "eslint.options": { | ||
| "rulePaths": ["./scripts/eslint/built/rules/"], | ||
| }, | ||
| // To use the last-known-good (LKG) compiler version: | ||
| // "typescript.tsdk": "lib" | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/utils"; | ||
| import { createRule } from "./utils"; | ||
| const { AST_NODE_TYPES, TSESTree } = require("@typescript-eslint/utils"); | ||
| const { createRule } = require("./utils"); | ||
|
|
||
| export = createRule({ | ||
| module.exports = createRule({ | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are all now CJS (well, they were before after compilation, but now we're hand-writing that); a future version of ESLint is poised to completely revamp the way that configuration works and will likely enable ESM rules. |
||
| name: "boolean-trivia", | ||
| meta: { | ||
| docs: { | ||
|
|
@@ -21,8 +21,10 @@ export = createRule({ | |
| const sourceCode = context.getSourceCode(); | ||
| const sourceCodeText = sourceCode.getText(); | ||
|
|
||
| const isSetOrAssert = (name: string): boolean => name.startsWith("set") || name.startsWith("assert"); | ||
| const isTrivia = (node: TSESTree.Node): boolean => { | ||
| /** @type {(name: string) => boolean} */ | ||
| const isSetOrAssert = (name) => name.startsWith("set") || name.startsWith("assert"); | ||
| /** @type {(node: TSESTree.Node) => boolean} */ | ||
| const isTrivia = (node) => { | ||
| if (node.type === AST_NODE_TYPES.Identifier) { | ||
| return node.name === "undefined"; | ||
| } | ||
|
|
@@ -35,7 +37,8 @@ export = createRule({ | |
| return false; | ||
| }; | ||
|
|
||
| const shouldIgnoreCalledExpression = (node: TSESTree.CallExpression): boolean => { | ||
| /** @type {(node: TSESTree.CallExpression) => boolean} */ | ||
| const shouldIgnoreCalledExpression = (node) => { | ||
| if (node.callee && node.callee.type === AST_NODE_TYPES.MemberExpression) { | ||
| const methodName = node.callee.property.type === AST_NODE_TYPES.Identifier | ||
| ? node.callee.property.name | ||
|
|
@@ -68,7 +71,8 @@ export = createRule({ | |
| return false; | ||
| }; | ||
|
|
||
| const checkArg = (node: TSESTree.Node): void => { | ||
| /** @type {(node: TSESTree.Node) => void} */ | ||
| const checkArg = (node) => { | ||
| if (!isTrivia(node)) { | ||
| return; | ||
| } | ||
|
|
@@ -88,7 +92,8 @@ export = createRule({ | |
| } | ||
| }; | ||
|
|
||
| const checkBooleanTrivia = (node: TSESTree.CallExpression) => { | ||
| /** @type {(node: TSESTree.CallExpression) => void} */ | ||
| const checkBooleanTrivia = (node) => { | ||
| if (shouldIgnoreCalledExpression(node)) { | ||
| return; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have included this on my eslint-at-root PR; I really dislike npmignore for this reason. Maybe I'll sit down and change our package to use
"files"instead.