-
Notifications
You must be signed in to change notification settings - Fork 10
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
1 parent
7bf0bbf
commit 500e50b
Showing
29 changed files
with
952 additions
and
1,126 deletions.
There are no files selected for viewing
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
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,17 @@ | ||
import baseConfig from "eslint-config-eslint"; | ||
import eslintPlugin from "eslint-plugin-eslint-plugin"; | ||
import autofixPlugin from "eslint-plugin-autofix"; | ||
import noAutofixPlugin from "eslint-plugin-no-autofix"; | ||
import nPlugin from "eslint-plugin-n"; // eslint-disable-line n/no-extraneous-import | ||
import globals from "globals"; | ||
|
||
export default [ | ||
...baseConfig, | ||
eslintPlugin.configs["flat/recommended"], | ||
{ files: ["packages/*/tests/**/*"], languageOptions: { globals: globals.mocha } }, | ||
{ | ||
plugins: { autofix: autofixPlugin, "no-autofix": noAutofixPlugin }, | ||
rules: { "eslint-comments/require-description": 0, "no-autofix/eslint-plugin/test-case-shorthand-strings": "error" } | ||
}, | ||
...nPlugin.configs["flat/mixed-esm-and-cjs"] | ||
]; |
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 |
---|---|---|
|
@@ -5,11 +5,12 @@ | |
"author": "薛定谔的猫 <[email protected]>", | ||
"description": "some eslint plugins", | ||
"devDependencies": { | ||
"eslint": "^8.1.0", | ||
"eslint-config-eslint": "^7.0.0", | ||
"eslint-plugin-eslint-plugin": "^4.0.1", | ||
"eslint-plugin-jsdoc": "^37.0.3", | ||
"eslint-plugin-node": "^11.1.0" | ||
"eslint": "^9.1.1", | ||
"eslint-config-eslint": "^9.0.0", | ||
"eslint-plugin-autofix": "file:./packages/autofix", | ||
"eslint-plugin-eslint-plugin": "^6.0.0", | ||
"eslint-plugin-no-autofix": "file:./packages/no-autofix", | ||
"globals": "^15.0.0" | ||
}, | ||
"scripts": { | ||
"lint": "eslint packages/", | ||
|
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,24 +1,25 @@ | ||
/** | ||
* @fileoverview configs:all for the plugin | ||
* @author 唯然<[email protected]> | ||
*/ | ||
"use strict"; | ||
|
||
const packageMetadata = require("../../package"); | ||
const PLUGIN_NAME = packageMetadata.name.replace(/^eslint-plugin-/u, ""); | ||
const allRules = require("../rules"); | ||
|
||
const all = { | ||
plugins: [PLUGIN_NAME], | ||
rules: {} | ||
}; | ||
|
||
// turn off core rules | ||
Object.keys(allRules) | ||
.reduce((rules, ruleName) => Object.assign(rules, { [ruleName]: "off" }), all.rules); | ||
|
||
// turn on plugin rules | ||
Object.keys(allRules) | ||
.reduce((rules, ruleName) => Object.assign(rules, { [`${PLUGIN_NAME}/${ruleName}`]: "error" }), all.rules); | ||
|
||
module.exports = all; | ||
/** | ||
* @fileoverview configs:all for the plugin | ||
* @author 唯然<[email protected]> | ||
*/ | ||
"use strict"; | ||
|
||
const packageMetadata = require("../../package"); | ||
const PLUGIN_NAME = packageMetadata.name.replace(/^eslint-plugin-/u, ""); | ||
const allRules = require("../rules"); | ||
|
||
const all = { | ||
plugins: [PLUGIN_NAME], | ||
rules: {} | ||
}; | ||
|
||
// turn off core rules | ||
Object.keys(allRules) | ||
.reduce((rules, ruleName) => Object.assign(rules, { [ruleName]: "off" }), all.rules); | ||
|
||
// turn on plugin rules | ||
Object.keys(allRules) | ||
.reduce((rules, ruleName) => Object.assign(rules, { [`${PLUGIN_NAME}/${ruleName}`]: "error" }), all.rules); | ||
|
||
module.exports = all; | ||
|
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,19 +1,27 @@ | ||
/** | ||
* @fileoverview An ESLint plugin provides autofix for some core rules. | ||
* @author 唯然<[email protected]> | ||
*/ | ||
"use strict"; | ||
|
||
const all = require("./configs/all"); | ||
const recommended = require("./configs/recommended"); | ||
const unsafe = require("./configs/unsafe"); | ||
const rules = require("./rules"); | ||
|
||
module.exports = { | ||
configs: { | ||
all, | ||
recommended, | ||
unsafe | ||
}, | ||
rules | ||
}; | ||
/** | ||
* @fileoverview An ESLint plugin provides autofix for some core rules. | ||
* @author 唯然<[email protected]> | ||
*/ | ||
"use strict"; | ||
|
||
const all = require("./configs/all"); | ||
const recommended = require("./configs/recommended"); | ||
const unsafe = require("./configs/unsafe"); | ||
const rules = require("./rules"); | ||
|
||
const pkg = { | ||
configs: { | ||
all, | ||
recommended, | ||
unsafe | ||
}, | ||
rules | ||
}; | ||
|
||
Object.assign(pkg.configs, { | ||
"flat/all": { ...pkg.configs.all, plugins: { autofix: pkg }, rules: pkg.configs.all.rules }, | ||
"flat/recommended": { ...pkg.configs.recommended, plugins: { autofix: pkg }, rules: pkg.configs.recommended.rules }, | ||
"flat/unsafe": { ...pkg.configs.unsafe, plugins: { autofix: pkg }, rules: pkg.configs.unsafe.rules } | ||
}); | ||
|
||
module.exports = pkg; |
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 |
---|---|---|
@@ -1,15 +1,28 @@ | ||
/** | ||
* @fileoverview utils used by the rule fixers. | ||
* @author 唯然<[email protected]> | ||
*/ | ||
"use strict"; | ||
const eslint = require("eslint"); | ||
const linter = new eslint.Linter(); | ||
|
||
exports.getFixableRule = function(ruleName, recommended = false, fixable = "code") { | ||
const rule = linter.getRules().get(ruleName); | ||
|
||
rule.meta.recommended = recommended; | ||
rule.meta.fixable = fixable; | ||
return rule; | ||
}; | ||
/** | ||
* @fileoverview utils used by the rule fixers. | ||
* @author 唯然<[email protected]> | ||
*/ | ||
"use strict"; | ||
|
||
exports.eslintVersion = Number.parseInt(require("eslint/package.json").version, 10); | ||
|
||
// eslint v6 restructured its codebase | ||
// TODO: this might be unreliable | ||
if (exports.eslintVersion >= 8) { | ||
const { builtinRules } = require("eslint/use-at-your-own-risk"); | ||
exports.builtinRules = builtinRules; | ||
} else if (exports.eslintVersion >= 6) { | ||
const builtin = require("eslint/lib/rules"); | ||
exports.builtinRules = builtin; | ||
} else { | ||
const builtin = require("eslint/lib/built-in-rules-index"); // eslint-disable-line n/no-missing-require | ||
exports.builtinRules = builtin; | ||
} | ||
|
||
exports.getFixableRule = function(ruleName, recommended = false, fixable = "code") { | ||
const rule = exports.builtinRules[ruleName] || exports.builtinRules.get(ruleName); | ||
|
||
rule.meta.recommended = recommended; | ||
rule.meta.fixable = fixable; | ||
return 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
Oops, something went wrong.