Skip to content

Commit

Permalink
New: export all fixable builtin rules (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed Feb 28, 2019
1 parent 803c818 commit 1761307
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 3 deletions.
12 changes: 10 additions & 2 deletions lib/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

const fs = require("fs");
const path = require("path");
const builtin = require("eslint/lib/built-in-rules-index");


/**
* Loads a given rule from the filesystem and generates its documentation URL
Expand All @@ -26,11 +28,17 @@ function loadRule(ruleName) {
return rule;
}

const builtinFixable = Object.keys(builtin)
.filter(rule => builtin[rule].meta.fixable)
.reduce((acc, cur) => {
acc[cur] = builtin[cur];
return acc;
}, {});

// import all rules in lib/rules
const allRules = fs.readdirSync(`${__dirname}/rules`)
.filter(fileName => fileName.endsWith(".js") && /^[^._]/.test(fileName))
.map(fileName => fileName.replace(/\.js$/, ""))
.reduce((rules, ruleName) => Object.assign(rules, { [ruleName]: loadRule(ruleName) }), {});

.reduce((rules, ruleName) => Object.assign(rules, { [ruleName]: loadRule(ruleName) }), builtinFixable);

module.exports = allRules;
101 changes: 101 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,121 @@ add prefix "autofix" to the rulename in eslintrc:
<!-- __BEGIN AUTOGENERATED TABLE__ -->
Name | βœ”οΈ | πŸ›  | Description
----- | ----- | ----- | -----
[array-bracket-newline](https://eslint.org/docs/rules/array-bracket-newline) | | πŸ›  | enforce linebreaks after opening and before closing array brackets
[array-bracket-spacing](https://eslint.org/docs/rules/array-bracket-spacing) | | πŸ›  | enforce consistent spacing inside array brackets
[array-element-newline](https://eslint.org/docs/rules/array-element-newline) | | πŸ›  | enforce line breaks after each array element
[arrow-body-style](https://eslint.org/docs/rules/arrow-body-style) | | πŸ›  | require braces around arrow function bodies
[arrow-parens](https://eslint.org/docs/rules/arrow-parens) | | πŸ›  | require parentheses around arrow function arguments
[arrow-spacing](https://eslint.org/docs/rules/arrow-spacing) | | πŸ›  | enforce consistent spacing before and after the arrow in arrow functions
[block-spacing](https://eslint.org/docs/rules/block-spacing) | | πŸ›  | disallow or enforce spaces inside of blocks after opening block and before closing block
[brace-style](https://eslint.org/docs/rules/brace-style) | | πŸ›  | enforce consistent brace style for blocks
[capitalized-comments](https://eslint.org/docs/rules/capitalized-comments) | | πŸ›  | enforce or disallow capitalization of the first letter of a comment
[comma-dangle](https://eslint.org/docs/rules/comma-dangle) | | πŸ›  | require or disallow trailing commas
[comma-spacing](https://eslint.org/docs/rules/comma-spacing) | | πŸ›  | enforce consistent spacing before and after commas
[comma-style](https://eslint.org/docs/rules/comma-style) | | πŸ›  | enforce consistent comma style
[computed-property-spacing](https://eslint.org/docs/rules/computed-property-spacing) | | πŸ›  | enforce consistent spacing inside computed property brackets
[curly](https://eslint.org/docs/rules/curly) | | πŸ›  | enforce consistent brace style for all control statements
[dot-location](https://eslint.org/docs/rules/dot-location) | | πŸ›  | enforce consistent newlines before and after dots
[dot-notation](https://eslint.org/docs/rules/dot-notation) | | πŸ›  | enforce dot notation whenever possible
[eol-last](https://eslint.org/docs/rules/eol-last) | | πŸ›  | require or disallow newline at the end of files
[eqeqeq](https://eslint.org/docs/rules/eqeqeq) | | πŸ›  | require the use of `===` and `!==`
[func-call-spacing](https://eslint.org/docs/rules/func-call-spacing) | | πŸ›  | require or disallow spacing between function identifiers and their invocations
[function-paren-newline](https://eslint.org/docs/rules/function-paren-newline) | | πŸ›  | enforce consistent line breaks inside function parentheses
[generator-star-spacing](https://eslint.org/docs/rules/generator-star-spacing) | | πŸ›  | enforce consistent spacing around `*` operators in generator functions
[implicit-arrow-linebreak](https://eslint.org/docs/rules/implicit-arrow-linebreak) | | πŸ›  | enforce the location of arrow function bodies
[indent](https://eslint.org/docs/rules/indent) | | πŸ›  | enforce consistent indentation
[indent-legacy](https://eslint.org/docs/rules/indent-legacy) | | πŸ›  | enforce consistent indentation
[jsx-quotes](https://eslint.org/docs/rules/jsx-quotes) | | πŸ›  | enforce the consistent use of either double or single quotes in JSX attributes
[key-spacing](https://eslint.org/docs/rules/key-spacing) | | πŸ›  | enforce consistent spacing between keys and values in object literal properties
[keyword-spacing](https://eslint.org/docs/rules/keyword-spacing) | | πŸ›  | enforce consistent spacing before and after keywords
[linebreak-style](https://eslint.org/docs/rules/linebreak-style) | | πŸ›  | enforce consistent linebreak style
[lines-around-comment](https://eslint.org/docs/rules/lines-around-comment) | | πŸ›  | require empty lines around comments
[lines-around-directive](https://eslint.org/docs/rules/lines-around-directive) | | πŸ›  | require or disallow newlines around directives
[lines-between-class-members](https://eslint.org/docs/rules/lines-between-class-members) | | πŸ›  | require or disallow an empty line between class members
[multiline-comment-style](https://eslint.org/docs/rules/multiline-comment-style) | | πŸ›  | enforce a particular style for multiline comments
[new-parens](https://eslint.org/docs/rules/new-parens) | | πŸ›  | require parentheses when invoking a constructor with no arguments
[newline-after-var](https://eslint.org/docs/rules/newline-after-var) | | πŸ›  | require or disallow an empty line after variable declarations
[newline-before-return](https://eslint.org/docs/rules/newline-before-return) | | πŸ›  | require an empty line before `return` statements
[newline-per-chained-call](https://eslint.org/docs/rules/newline-per-chained-call) | | πŸ›  | require a newline after each call in a method chain
[no-alert](https://eslint.org/docs/rules/no-alert) | | πŸ›  | disallow the use of `alert`, `confirm`, and `prompt`
[no-caller](https://eslint.org/docs/rules/no-caller) | | πŸ›  | disallow the use of `arguments.caller` or `arguments.callee`
[no-confusing-arrow](https://eslint.org/docs/rules/no-confusing-arrow) | | πŸ›  | disallow arrow functions where they could be confused with comparisons
[no-console](https://eslint.org/docs/rules/no-console) | βœ”οΈ | πŸ›  | disallow the use of `console`
[no-debugger](https://eslint.org/docs/rules/no-debugger) | βœ”οΈ | πŸ›  | disallow the use of `debugger`
[no-else-return](https://eslint.org/docs/rules/no-else-return) | | πŸ›  | disallow `else` blocks after `return` statements in `if` statements
[no-eq-null](https://eslint.org/docs/rules/no-eq-null) | | πŸ›  | disallow `null` comparisons without type-checking operators
[no-extra-bind](https://eslint.org/docs/rules/no-extra-bind) | | πŸ›  | disallow unnecessary calls to `.bind()`
[no-extra-boolean-cast](https://eslint.org/docs/rules/no-extra-boolean-cast) | | πŸ›  | disallow unnecessary boolean casts
[no-extra-label](https://eslint.org/docs/rules/no-extra-label) | | πŸ›  | disallow unnecessary labels
[no-extra-parens](https://eslint.org/docs/rules/no-extra-parens) | | πŸ›  | disallow unnecessary parentheses
[no-extra-semi](https://eslint.org/docs/rules/no-extra-semi) | | πŸ›  | disallow unnecessary semicolons
[no-floating-decimal](https://eslint.org/docs/rules/no-floating-decimal) | | πŸ›  | disallow leading or trailing decimal points in numeric literals
[no-implicit-coercion](https://eslint.org/docs/rules/no-implicit-coercion) | | πŸ›  | disallow shorthand type conversions
[no-lonely-if](https://eslint.org/docs/rules/no-lonely-if) | | πŸ›  | disallow `if` statements as the only statement in `else` blocks
[no-multi-spaces](https://eslint.org/docs/rules/no-multi-spaces) | | πŸ›  | disallow multiple spaces
[no-multiple-empty-lines](https://eslint.org/docs/rules/no-multiple-empty-lines) | | πŸ›  | disallow multiple empty lines
[no-new-symbol](https://eslint.org/docs/rules/no-new-symbol) | | πŸ›  | disallow `new` operators with the `Symbol` object
[no-plusplus](https://eslint.org/docs/rules/no-plusplus) | βœ”οΈ | πŸ›  | disallow the unary operators `++` and `--`
[no-proto](https://eslint.org/docs/rules/no-proto) | | πŸ›  | disallow the use of the `__proto__` property
[no-prototype-builtins](https://eslint.org/docs/rules/no-prototype-builtins) | | πŸ›  | disallow calling some `Object.prototype` methods directly on objects
[no-regex-spaces](https://eslint.org/docs/rules/no-regex-spaces) | | πŸ›  | disallow multiple spaces in regular expressions
[no-spaced-func](https://eslint.org/docs/rules/no-spaced-func) | | πŸ›  | disallow spacing between function identifiers and their applications (deprecated)
[no-throw-literal](https://eslint.org/docs/rules/no-throw-literal) | | πŸ›  | disallow throwing literals as exceptions
[no-trailing-spaces](https://eslint.org/docs/rules/no-trailing-spaces) | | πŸ›  | disallow trailing whitespace at the end of lines
[no-undef-init](https://eslint.org/docs/rules/no-undef-init) | | πŸ›  | disallow initializing variables to `undefined`
[no-unneeded-ternary](https://eslint.org/docs/rules/no-unneeded-ternary) | | πŸ›  | disallow ternary operators when simpler alternatives exist
[no-unsafe-negation](https://eslint.org/docs/rules/no-unsafe-negation) | | πŸ›  | disallow negating the left operand of relational operators
[no-unused-labels](https://eslint.org/docs/rules/no-unused-labels) | | πŸ›  | disallow unused labels
[no-useless-computed-key](https://eslint.org/docs/rules/no-useless-computed-key) | | πŸ›  | disallow unnecessary computed property keys in object literals
[no-useless-concat](https://eslint.org/docs/rules/no-useless-concat) | | πŸ›  | disallow unnecessary concatenation of literals or template literals
[no-useless-rename](https://eslint.org/docs/rules/no-useless-rename) | | πŸ›  | disallow renaming import, export, and destructured assignments to the same name
[no-useless-return](https://eslint.org/docs/rules/no-useless-return) | | πŸ›  | disallow redundant return statements
[no-var](https://eslint.org/docs/rules/no-var) | | πŸ›  | require `let` or `const` instead of `var`
[no-whitespace-before-property](https://eslint.org/docs/rules/no-whitespace-before-property) | | πŸ›  | disallow whitespace before properties
[nonblock-statement-body-position](https://eslint.org/docs/rules/nonblock-statement-body-position) | | πŸ›  | enforce the location of single-line statements
[object-curly-newline](https://eslint.org/docs/rules/object-curly-newline) | | πŸ›  | enforce consistent line breaks inside braces
[object-curly-spacing](https://eslint.org/docs/rules/object-curly-spacing) | | πŸ›  | enforce consistent spacing inside braces
[object-property-newline](https://eslint.org/docs/rules/object-property-newline) | | πŸ›  | enforce placing object properties on separate lines
[object-shorthand](https://eslint.org/docs/rules/object-shorthand) | | πŸ›  | require or disallow method and property shorthand syntax for object literals
[one-var](https://eslint.org/docs/rules/one-var) | | πŸ›  | enforce variables to be declared either together or separately in functions
[one-var-declaration-per-line](https://eslint.org/docs/rules/one-var-declaration-per-line) | | πŸ›  | require or disallow newlines around variable declarations
[operator-assignment](https://eslint.org/docs/rules/operator-assignment) | | πŸ›  | require or disallow assignment operator shorthand where possible
[operator-linebreak](https://eslint.org/docs/rules/operator-linebreak) | | πŸ›  | enforce consistent linebreak style for operators
[padded-blocks](https://eslint.org/docs/rules/padded-blocks) | | πŸ›  | require or disallow padding within blocks
[padding-line-between-statements](https://eslint.org/docs/rules/padding-line-between-statements) | | πŸ›  | require or disallow padding lines between statements
[prefer-arrow-callback](https://eslint.org/docs/rules/prefer-arrow-callback) | | πŸ›  | require using arrow functions for callbacks
[prefer-const](https://eslint.org/docs/rules/prefer-const) | | πŸ›  | require `const` declarations for variables that are never reassigned after declared
[prefer-destructuring](https://eslint.org/docs/rules/prefer-destructuring) | | πŸ›  | require destructuring from arrays and/or objects
[prefer-numeric-literals](https://eslint.org/docs/rules/prefer-numeric-literals) | | πŸ›  | disallow `parseInt()` and `Number.parseInt()` in favor of binary, octal, and hexadecimal literals
[prefer-object-spread](https://eslint.org/docs/rules/prefer-object-spread) | | πŸ›  | disallow using Object.assign with an object literal as the first argument and prefer the use of object spread instead.
[prefer-spread](https://eslint.org/docs/rules/prefer-spread) | | πŸ›  | require spread operators instead of `.apply()`
[prefer-template](https://eslint.org/docs/rules/prefer-template) | | πŸ›  | require template literals instead of string concatenation
[quote-props](https://eslint.org/docs/rules/quote-props) | | πŸ›  | require quotes around object literal property names
[quotes](https://eslint.org/docs/rules/quotes) | | πŸ›  | enforce the consistent use of either backticks, double, or single quotes
[radix](https://eslint.org/docs/rules/radix) | | πŸ›  | enforce the consistent use of the radix argument when using `parseInt()`
[rest-spread-spacing](https://eslint.org/docs/rules/rest-spread-spacing) | | πŸ›  | enforce spacing between rest and spread operators and their expressions
[semi](https://eslint.org/docs/rules/semi) | | πŸ›  | require or disallow semicolons instead of ASI
[semi-spacing](https://eslint.org/docs/rules/semi-spacing) | | πŸ›  | enforce consistent spacing before and after semicolons
[semi-style](https://eslint.org/docs/rules/semi-style) | | πŸ›  | enforce location of semicolons
[sort-imports](https://eslint.org/docs/rules/sort-imports) | | πŸ›  | enforce sorted import declarations within modules
[sort-vars](https://eslint.org/docs/rules/sort-vars) | | πŸ›  | require variables within the same declaration block to be sorted
[space-before-blocks](https://eslint.org/docs/rules/space-before-blocks) | | πŸ›  | enforce consistent spacing before blocks
[space-before-function-paren](https://eslint.org/docs/rules/space-before-function-paren) | | πŸ›  | enforce consistent spacing before `function` definition opening parenthesis
[space-in-parens](https://eslint.org/docs/rules/space-in-parens) | | πŸ›  | enforce consistent spacing inside parentheses
[space-infix-ops](https://eslint.org/docs/rules/space-infix-ops) | | πŸ›  | require spacing around infix operators
[space-unary-ops](https://eslint.org/docs/rules/space-unary-ops) | | πŸ›  | enforce consistent spacing before or after unary operators
[spaced-comment](https://eslint.org/docs/rules/spaced-comment) | | πŸ›  | enforce consistent spacing after the `//` or `/*` in a comment
[strict](https://eslint.org/docs/rules/strict) | | πŸ›  | require or disallow strict mode directives
[switch-colon-spacing](https://eslint.org/docs/rules/switch-colon-spacing) | | πŸ›  | enforce spacing around colons of switch statements
[template-curly-spacing](https://eslint.org/docs/rules/template-curly-spacing) | | πŸ›  | require or disallow spacing around embedded expressions of template strings
[template-tag-spacing](https://eslint.org/docs/rules/template-tag-spacing) | | πŸ›  | require or disallow spacing between template tags and their literals
[unicode-bom](https://eslint.org/docs/rules/unicode-bom) | | πŸ›  | require or disallow Unicode byte order mark (BOM)
[valid-jsdoc](https://eslint.org/docs/rules/valid-jsdoc) | | πŸ›  | enforce valid JSDoc comments
[valid-typeof](https://eslint.org/docs/rules/valid-typeof) | | πŸ›  | enforce comparing `typeof` expressions against valid strings
[wrap-iife](https://eslint.org/docs/rules/wrap-iife) | | πŸ›  | require parentheses around immediate `function` invocations
[wrap-regex](https://eslint.org/docs/rules/wrap-regex) | | πŸ›  | require parenthesis around regex literals
[yield-star-spacing](https://eslint.org/docs/rules/yield-star-spacing) | | πŸ›  | require or disallow spacing around the `*` in `yield*` expressions
[yoda](https://eslint.org/docs/rules/yoda) | | πŸ›  | require or disallow "Yoda" conditions
<!-- __END AUTOGENERATED TABLE__ -->

## Contributing
Expand Down
5 changes: 4 additions & 1 deletion tests/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

const entry = require("../../lib/index");
const assert = require("assert");
let rule;

describe("should have the corrent entry", () => {
it("should export config: all", () => {
Expand All @@ -15,8 +16,10 @@ describe("should have the corrent entry", () => {
assert(entry.configs.all.rules["autofix/no-debugger"], "error");
});
it("should export all rules", () => {
const rule = entry.rules["no-debugger"];
rule = entry.rules["no-debugger"];
assert(rule && rule.meta && rule.create);

rule = entry.rules.semi;
assert(rule && rule.meta && rule.create);
});
});

0 comments on commit 1761307

Please sign in to comment.