From 7ad86dea02feceb7631943a7e1423cc8a113fcfe Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Tue, 6 Nov 2018 09:26:31 -0800 Subject: [PATCH] New: Add --fix-type option to CLI (fixes #10855) (#10912) * New: Add --fix-type option to CLI (fixes #10855) * Chore: Update rule types * Docs: Update Nodejs API docs with new CLIEngine option * Chore: Fix lint errors * Chore: Update options message for --fix-type * CLIEngine validates fixType values * Check for rule.meta when filtering fixes * Call getRules() just once when filtering fixes * Set no-multiline-str to suggestion * Add check for missing rule info in rule-types.json * Account for late definition of rules in CLIEngine * Add ruleType data to doc page for rules * Remove duplicate test * Update spacing rules to be of type style * Fix lint issues in update-rule-types.js * Change ruleType to rule_type in doc page front matter * Update rule type mappings based on feedback * Update rules to use 'layout' instead of 'style' * Fix update-rule-types script and prefer-arrow-callback * Fix lint error * Update rule types based on latest feedback * Fix bug CLIEngine * Update new rule issue template with category info * Final update of rule types * Refactor CLIEngine piece based on feedback --- .github/ISSUE_TEMPLATE/NEW_RULE.md | 6 +- Makefile.js | 24 +- docs/developer-guide/nodejs-api.md | 3 +- docs/developer-guide/working-with-rules.md | 7 + docs/user-guide/command-line-interface.md | 19 ++ lib/cli-engine.js | 57 +++- lib/cli.js | 7 +- lib/options.js | 5 + lib/rules/accessor-pairs.js | 4 + lib/rules/array-bracket-newline.js | 5 + lib/rules/array-bracket-spacing.js | 5 + lib/rules/array-callback-return.js | 2 + lib/rules/array-element-newline.js | 4 + lib/rules/arrow-body-style.js | 2 + lib/rules/arrow-parens.js | 2 + lib/rules/arrow-spacing.js | 2 + lib/rules/block-scoped-var.js | 2 + lib/rules/block-spacing.js | 2 + lib/rules/brace-style.js | 2 + lib/rules/callback-return.js | 2 + lib/rules/camelcase.js | 2 + lib/rules/capitalized-comments.js | 4 + lib/rules/class-methods-use-this.js | 3 + lib/rules/comma-dangle.js | 4 + lib/rules/comma-spacing.js | 2 + lib/rules/comma-style.js | 5 + lib/rules/complexity.js | 2 + lib/rules/computed-property-spacing.js | 2 + lib/rules/consistent-return.js | 2 + lib/rules/consistent-this.js | 2 + lib/rules/constructor-super.js | 2 + lib/rules/curly.js | 2 + lib/rules/default-case.js | 2 + lib/rules/dot-location.js | 2 + lib/rules/dot-notation.js | 2 + lib/rules/eol-last.js | 5 + lib/rules/eqeqeq.js | 2 + lib/rules/for-direction.js | 4 + lib/rules/func-call-spacing.js | 4 + lib/rules/func-name-matching.js | 3 + lib/rules/func-names.js | 3 + lib/rules/func-style.js | 3 + lib/rules/function-paren-newline.js | 5 + lib/rules/generator-star-spacing.js | 3 + lib/rules/getter-return.js | 5 + lib/rules/global-require.js | 2 + lib/rules/guard-for-in.js | 2 + lib/rules/handle-callback-err.js | 2 + lib/rules/id-blacklist.js | 2 + lib/rules/id-length.js | 2 + lib/rules/id-match.js | 2 + lib/rules/implicit-arrow-linebreak.js | 4 + lib/rules/indent-legacy.js | 2 + lib/rules/indent.js | 2 + lib/rules/init-declarations.js | 2 + lib/rules/jsx-quotes.js | 2 + lib/rules/key-spacing.js | 7 +- lib/rules/keyword-spacing.js | 2 + lib/rules/line-comment-position.js | 2 + lib/rules/linebreak-style.js | 2 + lib/rules/lines-around-comment.js | 2 + lib/rules/lines-around-directive.js | 4 + lib/rules/lines-between-class-members.js | 2 + lib/rules/max-classes-per-file.js | 4 + lib/rules/max-depth.js | 2 + lib/rules/max-len.js | 2 + lib/rules/max-lines-per-function.js | 2 + lib/rules/max-lines.js | 2 + lib/rules/max-nested-callbacks.js | 2 + lib/rules/max-params.js | 2 + lib/rules/max-statements-per-line.js | 2 + lib/rules/max-statements.js | 2 + lib/rules/multiline-comment-style.js | 3 + lib/rules/multiline-ternary.js | 3 + lib/rules/new-cap.js | 2 + lib/rules/new-parens.js | 3 +- lib/rules/newline-after-var.js | 2 + lib/rules/newline-before-return.js | 3 + lib/rules/newline-per-chained-call.js | 4 + lib/rules/no-alert.js | 2 + lib/rules/no-array-constructor.js | 2 + lib/rules/no-async-promise-executor.js | 3 + lib/rules/no-await-in-loop.js | 4 + lib/rules/no-bitwise.js | 2 + lib/rules/no-buffer-constructor.js | 4 + lib/rules/no-caller.js | 2 + lib/rules/no-case-declarations.js | 2 + lib/rules/no-catch-shadow.js | 4 +- lib/rules/no-class-assign.js | 2 + lib/rules/no-compare-neg-zero.js | 4 + lib/rules/no-cond-assign.js | 2 + lib/rules/no-confusing-arrow.js | 2 + lib/rules/no-console.js | 2 + lib/rules/no-const-assign.js | 2 + lib/rules/no-constant-condition.js | 2 + lib/rules/no-continue.js | 2 + lib/rules/no-control-regex.js | 6 +- lib/rules/no-debugger.js | 4 + lib/rules/no-delete-var.js | 2 + lib/rules/no-div-regex.js | 2 + lib/rules/no-dupe-args.js | 2 + lib/rules/no-dupe-class-members.js | 2 + lib/rules/no-dupe-keys.js | 2 + lib/rules/no-duplicate-case.js | 2 + lib/rules/no-duplicate-imports.js | 2 + lib/rules/no-else-return.js | 2 + lib/rules/no-empty-character-class.js | 2 + lib/rules/no-empty-function.js | 2 + lib/rules/no-empty-pattern.js | 2 + lib/rules/no-empty.js | 2 + lib/rules/no-eq-null.js | 2 + lib/rules/no-eval.js | 2 + lib/rules/no-ex-assign.js | 2 + lib/rules/no-extend-native.js | 2 + lib/rules/no-extra-bind.js | 3 +- lib/rules/no-extra-boolean-cast.js | 3 +- lib/rules/no-extra-label.js | 3 +- lib/rules/no-extra-parens.js | 11 +- lib/rules/no-extra-semi.js | 2 + lib/rules/no-fallthrough.js | 2 + lib/rules/no-floating-decimal.js | 3 +- lib/rules/no-func-assign.js | 2 + lib/rules/no-global-assign.js | 2 + lib/rules/no-implicit-coercion.js | 3 + lib/rules/no-implicit-globals.js | 2 + lib/rules/no-implied-eval.js | 2 + lib/rules/no-inline-comments.js | 2 + lib/rules/no-inner-declarations.js | 2 + lib/rules/no-invalid-regexp.js | 2 + lib/rules/no-invalid-this.js | 2 + lib/rules/no-irregular-whitespace.js | 2 + lib/rules/no-iterator.js | 2 + lib/rules/no-label-var.js | 2 + lib/rules/no-labels.js | 2 + lib/rules/no-lone-blocks.js | 2 + lib/rules/no-lonely-if.js | 3 +- lib/rules/no-loop-func.js | 2 + lib/rules/no-magic-numbers.js | 3 + lib/rules/no-misleading-character-class.js | 4 + lib/rules/no-mixed-operators.js | 3 + lib/rules/no-mixed-requires.js | 2 + lib/rules/no-mixed-spaces-and-tabs.js | 2 + lib/rules/no-multi-assign.js | 3 + lib/rules/no-multi-spaces.js | 2 + lib/rules/no-multi-str.js | 2 + lib/rules/no-multiple-empty-lines.js | 2 + lib/rules/no-native-reassign.js | 2 + lib/rules/no-negated-condition.js | 2 + lib/rules/no-negated-in-lhs.js | 4 +- lib/rules/no-nested-ternary.js | 2 + lib/rules/no-new-func.js | 2 + lib/rules/no-new-object.js | 2 + lib/rules/no-new-require.js | 2 + lib/rules/no-new-symbol.js | 2 + lib/rules/no-new-wrappers.js | 2 + lib/rules/no-new.js | 2 + lib/rules/no-obj-calls.js | 2 + lib/rules/no-octal-escape.js | 2 + lib/rules/no-octal.js | 2 + lib/rules/no-param-reassign.js | 2 + lib/rules/no-path-concat.js | 2 + lib/rules/no-plusplus.js | 2 + lib/rules/no-process-env.js | 2 + lib/rules/no-process-exit.js | 2 + lib/rules/no-proto.js | 2 + lib/rules/no-prototype-builtins.js | 2 + lib/rules/no-redeclare.js | 2 + lib/rules/no-regex-spaces.js | 3 +- lib/rules/no-restricted-globals.js | 2 + lib/rules/no-restricted-imports.js | 2 + lib/rules/no-restricted-modules.js | 2 + lib/rules/no-restricted-properties.js | 2 + lib/rules/no-restricted-syntax.js | 2 + lib/rules/no-return-assign.js | 2 + lib/rules/no-return-await.js | 4 + lib/rules/no-script-url.js | 2 + lib/rules/no-self-assign.js | 2 + lib/rules/no-self-compare.js | 2 + lib/rules/no-sequences.js | 2 + lib/rules/no-shadow-restricted-names.js | 2 + lib/rules/no-shadow.js | 2 + lib/rules/no-spaced-func.js | 2 + lib/rules/no-sparse-arrays.js | 2 + lib/rules/no-sync.js | 2 + lib/rules/no-tabs.js | 2 + lib/rules/no-template-curly-in-string.js | 2 + lib/rules/no-ternary.js | 2 + lib/rules/no-this-before-super.js | 2 + lib/rules/no-throw-literal.js | 2 + lib/rules/no-trailing-spaces.js | 2 + lib/rules/no-undef-init.js | 3 +- lib/rules/no-undef.js | 2 + lib/rules/no-undefined.js | 2 + lib/rules/no-underscore-dangle.js | 2 + lib/rules/no-unexpected-multiline.js | 2 + lib/rules/no-unmodified-loop-condition.js | 2 + lib/rules/no-unneeded-ternary.js | 2 + lib/rules/no-unreachable.js | 2 + lib/rules/no-unsafe-finally.js | 2 + lib/rules/no-unsafe-negation.js | 3 + lib/rules/no-unused-expressions.js | 2 + lib/rules/no-unused-labels.js | 3 +- lib/rules/no-unused-vars.js | 20 +- lib/rules/no-use-before-define.js | 2 + lib/rules/no-useless-call.js | 2 + lib/rules/no-useless-computed-key.js | 3 +- lib/rules/no-useless-concat.js | 2 + lib/rules/no-useless-constructor.js | 2 + lib/rules/no-useless-escape.js | 2 + lib/rules/no-useless-rename.js | 4 + lib/rules/no-useless-return.js | 3 + lib/rules/no-var.js | 2 + lib/rules/no-void.js | 2 + lib/rules/no-warning-comments.js | 2 + lib/rules/no-whitespace-before-property.js | 2 + lib/rules/no-with.js | 2 + lib/rules/nonblock-statement-body-position.js | 4 + lib/rules/object-curly-newline.js | 4 + lib/rules/object-curly-spacing.js | 2 + lib/rules/object-property-newline.js | 5 +- lib/rules/object-shorthand.js | 2 + lib/rules/one-var-declaration-per-line.js | 2 + lib/rules/one-var.js | 2 + lib/rules/operator-assignment.js | 2 + lib/rules/operator-linebreak.js | 2 + lib/rules/padded-blocks.js | 2 + lib/rules/padding-line-between-statements.js | 4 + lib/rules/prefer-arrow-callback.js | 2 + lib/rules/prefer-const.js | 2 + lib/rules/prefer-destructuring.js | 3 + lib/rules/prefer-numeric-literals.js | 3 +- lib/rules/prefer-object-spread.js | 4 + lib/rules/prefer-promise-reject-errors.js | 4 + lib/rules/prefer-reflect.js | 2 + lib/rules/prefer-rest-params.js | 2 + lib/rules/prefer-spread.js | 3 +- lib/rules/prefer-template.js | 3 +- lib/rules/quote-props.js | 2 + lib/rules/quotes.js | 2 + lib/rules/radix.js | 2 + lib/rules/require-atomic-updates.js | 4 + lib/rules/require-await.js | 3 + lib/rules/require-jsdoc.js | 2 + lib/rules/require-unicode-regexp.js | 4 + lib/rules/require-yield.js | 2 + lib/rules/rest-spread-spacing.js | 4 + lib/rules/semi-spacing.js | 2 + lib/rules/semi-style.js | 3 + lib/rules/semi.js | 2 + lib/rules/sort-imports.js | 2 + lib/rules/sort-keys.js | 3 + lib/rules/sort-vars.js | 2 + lib/rules/space-before-blocks.js | 2 + lib/rules/space-before-function-paren.js | 2 + lib/rules/space-in-parens.js | 2 + lib/rules/space-infix-ops.js | 2 + lib/rules/space-unary-ops.js | 2 + lib/rules/spaced-comment.js | 2 + lib/rules/strict.js | 2 + lib/rules/switch-colon-spacing.js | 4 + lib/rules/symbol-description.js | 2 + lib/rules/template-curly-spacing.js | 2 + lib/rules/template-tag-spacing.js | 2 + lib/rules/unicode-bom.js | 2 + lib/rules/use-isnan.js | 2 + lib/rules/valid-jsdoc.js | 2 + lib/rules/valid-typeof.js | 2 + lib/rules/vars-on-top.js | 2 + lib/rules/wrap-iife.js | 2 + lib/rules/wrap-regex.js | 4 +- lib/rules/yield-star-spacing.js | 2 + lib/rules/yoda.js | 2 + ...semi-and-prefer-arrow-callback.expected.js | 7 + ...fix-both-semi-and-prefer-arrow-callback.js | 7 + ...fix-only-prefer-arrow-callback.expected.js | 7 + .../fix-only-prefer-arrow-callback.js | 7 + .../fix-types/fix-only-semi.expected.js | 7 + tests/fixtures/fix-types/fix-only-semi.js | 7 + .../fix-types/ignore-missing-meta.expected.js | 8 + .../fixtures/fix-types/ignore-missing-meta.js | 8 + .../rules/fix-types-test/no-program.js | 22 ++ tests/lib/cli-engine.js | 128 ++++++++- tests/lib/cli.js | 41 +++ tests/lib/options.js | 25 ++ tools/rule-types.json | 266 ++++++++++++++++++ tools/update-rule-types.js | 77 +++++ 286 files changed, 1370 insertions(+), 50 deletions(-) create mode 100644 tests/fixtures/fix-types/fix-both-semi-and-prefer-arrow-callback.expected.js create mode 100644 tests/fixtures/fix-types/fix-both-semi-and-prefer-arrow-callback.js create mode 100644 tests/fixtures/fix-types/fix-only-prefer-arrow-callback.expected.js create mode 100644 tests/fixtures/fix-types/fix-only-prefer-arrow-callback.js create mode 100644 tests/fixtures/fix-types/fix-only-semi.expected.js create mode 100644 tests/fixtures/fix-types/fix-only-semi.js create mode 100644 tests/fixtures/fix-types/ignore-missing-meta.expected.js create mode 100644 tests/fixtures/fix-types/ignore-missing-meta.js create mode 100644 tests/fixtures/rules/fix-types-test/no-program.js create mode 100644 tools/rule-types.json create mode 100644 tools/update-rule-types.js diff --git a/.github/ISSUE_TEMPLATE/NEW_RULE.md b/.github/ISSUE_TEMPLATE/NEW_RULE.md index 8dfb93ba281..5a50001b0e6 100644 --- a/.github/ISSUE_TEMPLATE/NEW_RULE.md +++ b/.github/ISSUE_TEMPLATE/NEW_RULE.md @@ -21,9 +21,9 @@ about: Propose a new rule to be added to ESLint **What category of rule is this? (place an "X" next to just one item)** -[ ] Enforces code style -[ ] Warns about a potential error -[ ] Suggests an alternate way of doing something +[ ] Warns about a potential error (problem) +[ ] Suggests an alternate way of doing something (suggestion) +[ ] Enforces code style (layout) [ ] Other (please specify:) **Provide 2-3 code examples that this rule will warn about:** diff --git a/Makefile.js b/Makefile.js index 2a5c7ab8d69..e468d0a16bc 100644 --- a/Makefile.js +++ b/Makefile.js @@ -708,6 +708,7 @@ target.gensite = function(prereleaseVersion) { ruleName = path.basename(filename, ".md"), filePath = path.join("docs", path.relative("tmp", filename)); let text = cat(filename), + ruleType = "", title; process.stdout.write(`> Updating files (Steps 4-9): ${i}/${length} - ${filePath + " ".repeat(30)}\r`); @@ -726,8 +727,11 @@ target.gensite = function(prereleaseVersion) { const ruleDocsContent = textSplit.slice(1).join("\n"); text = `${ruleHeading}${isRecommended ? RECOMMENDED_TEXT : ""}${isFixable ? FIXABLE_TEXT : ""}\n${ruleDocsContent}`; - title = `${ruleName} - Rules`; + + if (rule && rule.meta) { + ruleType = `rule_type: ${rule.meta.type}`; + } } else { // extract the title from the file itself @@ -744,6 +748,7 @@ target.gensite = function(prereleaseVersion) { `title: ${title}`, "layout: doc", `edit_link: https://github.com/eslint/eslint/edit/master/${filePath}`, + ruleType, "---", "", "", @@ -863,7 +868,7 @@ target.checkRuleFiles = function() { echo("Validating rules"); const eslintRecommended = require("./conf/eslint-recommended").rules; - + const ruleTypes = require("./tools/rule-types.json"); const ruleFiles = find("lib/rules/").filter(fileType("js")); let errors = 0; @@ -880,6 +885,15 @@ target.checkRuleFiles = function() { return Object.prototype.hasOwnProperty.call(eslintRecommended, basename); } + /** + * Check if basename is present in rule-types.json file. + * @returns {boolean} true if present + * @private + */ + function isInRuleTypes() { + return Object.prototype.hasOwnProperty.call(ruleTypes, basename); + } + /** * Check if id is present in title * @param {string} id id to check for @@ -918,6 +932,12 @@ target.checkRuleFiles = function() { errors++; } + // check for recommended configuration + if (!isInRuleTypes()) { + console.error("Missing setting for %s in tools/rule-types.json", basename); + errors++; + } + // check for tests if (!test("-f", `tests/lib/rules/${basename}.js`)) { console.error("Missing tests for rule %s", basename); diff --git a/docs/developer-guide/nodejs-api.md b/docs/developer-guide/nodejs-api.md index 0ff1e04ef2c..834fecefda9 100644 --- a/docs/developer-guide/nodejs-api.md +++ b/docs/developer-guide/nodejs-api.md @@ -347,7 +347,8 @@ The `CLIEngine` is a constructor, and you can create a new instance by passing i * `cwd` - Path to a directory that should be considered as the current working directory. * `envs` - An array of environments to load (default: empty array). Corresponds to `--env`. * `extensions` - An array of filename extensions that should be checked for code. The default is an array containing just `".js"`. Corresponds to `--ext`. It is only used in conjunction with directories, not with filenames or glob patterns. -* `fix` - This can be a boolean or a function which will be provided each linting message and should return a boolean. True indicates that fixes should be included with the output report, and that errors and warnings should not be listed if they can be fixed. However, the files on disk will not be changed. To persist changes to disk, call [`outputFixes()`](#cliengineoutputfixes). +* `fix` - A boolean or a function (default: `false`). If a function, it will be passed each linting message and should return a boolean indicating whether the fix should be included with the output report (errors and warnings will not be listed if fixed). Files on disk are never changed regardless of the value of `fix`. To persist changes to disk, call [`outputFixes()`](#cliengineoutputfixes). +* `fixTypes` - An array of rule types for which fixes should be applied (default: `null`). This array acts like a filter, only allowing rules of the given types to apply fixes. Possible array values are `"problem"`, `"suggestion"`, and `"layout"`. * `globals` - An array of global variables to declare (default: empty array). Corresponds to `--global`. * `ignore` - False disables use of `.eslintignore`, `ignorePath` and `ignorePattern` (default: true). Corresponds to `--no-ignore`. * `ignorePath` - The ignore file to use instead of `.eslintignore` (default: null). Corresponds to `--ignore-path`. diff --git a/docs/developer-guide/working-with-rules.md b/docs/developer-guide/working-with-rules.md index 85b8c25ea38..a0524ea5b64 100644 --- a/docs/developer-guide/working-with-rules.md +++ b/docs/developer-guide/working-with-rules.md @@ -26,6 +26,8 @@ Here is the basic format of the source file for a rule: module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow unnecessary semicolons", category: "Possible Errors", @@ -49,6 +51,11 @@ The source file for a rule exports an object with the following properties. `meta` (object) contains metadata for the rule: +* `type` (string) indicates the type of rule, which is one of `"problem"`, `"suggestion"`, or `"layout"`: + * `"problem"` means the rule is identifying code that either will cause an error or may cause a confusing behavior. Developers should consider this a high priority to resolve. + * `"suggestion"` means the rule is identifying something that could be done in a better way but no errors will occur if the code isn't changed. + * `"layout"` means the rule cares primarily about whitespace, semicolons, commas, and parentheses, all the parts of the program that determine how the code looks rather than how it executes. These rules work on parts of the code that aren't specified in the AST. + * `docs` (object) is required for core rules of ESLint: * `description` (string) provides the short description of the rule in the [rules index](../rules/) diff --git a/docs/user-guide/command-line-interface.md b/docs/user-guide/command-line-interface.md index 62ecd3c2021..7fee37cf418 100644 --- a/docs/user-guide/command-line-interface.md +++ b/docs/user-guide/command-line-interface.md @@ -46,6 +46,7 @@ Specifying rules and plugins: Fixing problems: --fix Automatically fix problems --fix-dry-run Automatically fix problems without saving the changes to the file system + --fix-type Array Specify the types of fixes to apply (problem, suggestion, layout) Ignoring files: --ignore-path path::String Specify path of ignore file @@ -233,6 +234,24 @@ getSomeText | eslint --stdin --fix-dry-run --format=json This flag can be useful for integrations (e.g. editor plugins) which need to autofix text from the command line without saving it to the filesystem. +#### `--fix-type` + +This option allows you to specify the type of fixes to apply when using either `--fix` or `--fix-dry-run`. The three types of fixes are: + +1. `problem` - fix potential errors in the code +1. `suggestion` - apply fixes to the code that improve it +1. `layout` - apply fixes that do not change the program structure (AST) + +You can specify one or more fix type on the command line. Here are some examples: + +``` +eslint --fix --fix-type suggestion . +eslint --fix --fix-type suggestion --fix-type problem . +eslint --fix --fix-type suggestion,layout . +``` + +This option is helpful if you are using another program to format your code but you would still like ESLint to apply other types of fixes. + ### Ignoring files #### `--ignore-path` diff --git a/lib/cli-engine.js b/lib/cli-engine.js index f801aee48ca..652d68b59b4 100644 --- a/lib/cli-engine.js +++ b/lib/cli-engine.js @@ -33,6 +33,7 @@ const fs = require("fs"), const debug = require("debug")("eslint:cli-engine"); const resolver = new ModuleResolver(); +const validFixTypes = new Set(["problem", "suggestion", "layout"]); //------------------------------------------------------------------------------ // Typedefs @@ -50,6 +51,7 @@ const resolver = new ModuleResolver(); * @property {string[]} envs An array of environments to load. * @property {string[]} extensions An array of file extensions to check. * @property {boolean|Function} fix Execute in autofix mode. If a function, should return a boolean. + * @property {string[]} fixTypes Array of rule types to apply fixes for. * @property {string[]} globals An array of global variables to declare. * @property {boolean} ignore False disables use of .eslintignore. * @property {string} ignorePath The ignore file to use instead of .eslintignore. @@ -86,6 +88,21 @@ const resolver = new ModuleResolver(); // Helpers //------------------------------------------------------------------------------ +/** + * Determines if each fix type in an array is supported by ESLint and throws + * an error if not. + * @param {string[]} fixTypes An array of fix types to check. + * @returns {void} + * @throws {Error} If an invalid fix type is found. + */ +function validateFixTypes(fixTypes) { + for (const fixType of fixTypes) { + if (!validFixTypes.has(fixType)) { + throw new Error(`Invalid fix type "${fixType}" found.`); + } + } +} + /** * It will calculate the error and warning count for collection of messages per file * @param {Object[]} messages - Collection of messages @@ -176,7 +193,6 @@ function processText(text, configHelper, filename, fix, allowInlineConfig, repor } const autofixingEnabled = typeof fix !== "undefined" && (!processor || processor.supportsAutofix); - const fixedResult = linter.verifyAndFix(text, config, { filename: effectiveFilename, allowInlineConfig, @@ -185,7 +201,6 @@ function processText(text, configHelper, filename, fix, allowInlineConfig, repor preprocess: processor && (rawText => processor.preprocess(rawText, effectiveFilename)), postprocess: processor && (problemLists => processor.postprocess(problemLists, effectiveFilename)) }); - const stats = calculateStatsPerFile(fixedResult.messages); const result = { @@ -456,6 +471,33 @@ class CLIEngine { */ this._lintResultCache = new LintResultCache(cacheFile, this.config); } + + // setup special filter for fixes + if (this.options.fix && this.options.fixTypes && this.options.fixTypes.length > 0) { + + debug(`Using fix types ${this.options.fixTypes}`); + + // throw an error if any invalid fix types are found + validateFixTypes(this.options.fixTypes); + + // convert to Set for faster lookup + const fixTypes = new Set(this.options.fixTypes); + + // save original value of options.fix in case it's a function + const originalFix = (typeof this.options.fix === "function") + ? this.options.fix : () => this.options.fix; + + // create a cache of rules (but don't populate until needed) + this._rulesCache = null; + + this.options.fix = lintResult => { + const rule = this._rulesCache.get(lintResult.ruleId); + const matches = rule.meta && fixTypes.has(rule.meta.type); + + return matches && originalFix(lintResult); + }; + } + } getRules() { @@ -560,6 +602,11 @@ class CLIEngine { } } + // if there's a cache, populate it + if ("_rulesCache" in this) { + this._rulesCache = this.getRules(); + } + debug(`Processing ${fileInfo.filename}`); const { result, config } = processFile(fileInfo.filename, configHelper, options, this.linter); @@ -630,6 +677,12 @@ class CLIEngine { } usedDeprecatedRules = []; } else { + + // if there's a cache, populate it + if ("_rulesCache" in this) { + this._rulesCache = this.getRules(); + } + const { result, config } = processText( text, configHelper, diff --git a/lib/cli.js b/lib/cli.js index f854015fe9c..f67eb7274ff 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -64,6 +64,7 @@ function translateOptions(cliOptions) { cacheFile: cliOptions.cacheFile, cacheLocation: cliOptions.cacheLocation, fix: (cliOptions.fix || cliOptions.fixDryRun) && (cliOptions.quiet ? quietFixPredicate : true), + fixTypes: cliOptions.fixType, allowInlineConfig: cliOptions.inlineConfig, reportUnusedDisableDirectives: cliOptions.reportUnusedDisableDirectives }; @@ -187,8 +188,12 @@ const cli = { return 2; } - const engine = new CLIEngine(translateOptions(currentOptions)); + if (currentOptions.fixType && !currentOptions.fix && !currentOptions.fixDryRun) { + log.error("The --fix-type option requires either --fix or --fix-dry-run."); + return 2; + } + const engine = new CLIEngine(translateOptions(currentOptions)); const report = useStdin ? engine.executeOnText(text, currentOptions.stdinFilename, true) : engine.executeOnFiles(files); if (currentOptions.fix) { diff --git a/lib/options.js b/lib/options.js index 9265d151d5c..ee7357a296a 100644 --- a/lib/options.js +++ b/lib/options.js @@ -97,6 +97,11 @@ module.exports = optionator({ default: false, description: "Automatically fix problems without saving the changes to the file system" }, + { + option: "fix-type", + type: "Array", + description: "Specify the types of fixes to apply (problem, suggestion, layout)" + }, { heading: "Ignoring files" }, diff --git a/lib/rules/accessor-pairs.js b/lib/rules/accessor-pairs.js index 68607295438..032e8943057 100644 --- a/lib/rules/accessor-pairs.js +++ b/lib/rules/accessor-pairs.js @@ -72,12 +72,15 @@ function isPropertyDescriptor(node) { module.exports = { meta: { + type: "suggestion", + docs: { description: "enforce getter and setter pairs in objects", category: "Best Practices", recommended: false, url: "https://eslint.org/docs/rules/accessor-pairs" }, + schema: [{ type: "object", properties: { @@ -90,6 +93,7 @@ module.exports = { }, additionalProperties: false }], + messages: { getter: "Getter is not present.", setter: "Setter is not present." diff --git a/lib/rules/array-bracket-newline.js b/lib/rules/array-bracket-newline.js index e8f7c502ef4..a458e69f761 100644 --- a/lib/rules/array-bracket-newline.js +++ b/lib/rules/array-bracket-newline.js @@ -13,13 +13,17 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "enforce linebreaks after opening and before closing array brackets", category: "Stylistic Issues", recommended: false, url: "https://eslint.org/docs/rules/array-bracket-newline" }, + fixable: "whitespace", + schema: [ { oneOf: [ @@ -42,6 +46,7 @@ module.exports = { ] } ], + messages: { unexpectedOpeningLinebreak: "There should be no linebreak after '['.", unexpectedClosingLinebreak: "There should be no linebreak before ']'.", diff --git a/lib/rules/array-bracket-spacing.js b/lib/rules/array-bracket-spacing.js index f46c3978dfa..4bead37a12f 100644 --- a/lib/rules/array-bracket-spacing.js +++ b/lib/rules/array-bracket-spacing.js @@ -12,13 +12,17 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "enforce consistent spacing inside array brackets", category: "Stylistic Issues", recommended: false, url: "https://eslint.org/docs/rules/array-bracket-spacing" }, + fixable: "whitespace", + schema: [ { enum: ["always", "never"] @@ -39,6 +43,7 @@ module.exports = { additionalProperties: false } ], + messages: { unexpectedSpaceAfter: "There should be no space after '{{tokenValue}}'.", unexpectedSpaceBefore: "There should be no space before '{{tokenValue}}'.", diff --git a/lib/rules/array-callback-return.js b/lib/rules/array-callback-return.js index 4d374cf2240..bfee39b037b 100644 --- a/lib/rules/array-callback-return.js +++ b/lib/rules/array-callback-return.js @@ -141,6 +141,8 @@ function isCallbackOfArrayMethod(node) { module.exports = { meta: { + type: "problem", + docs: { description: "enforce `return` statements in callbacks of array methods", category: "Best Practices", diff --git a/lib/rules/array-element-newline.js b/lib/rules/array-element-newline.js index c4caf8c71c0..440290917d3 100644 --- a/lib/rules/array-element-newline.js +++ b/lib/rules/array-element-newline.js @@ -13,13 +13,17 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "enforce line breaks after each array element", category: "Stylistic Issues", recommended: false, url: "https://eslint.org/docs/rules/array-element-newline" }, + fixable: "whitespace", + schema: [ { oneOf: [ diff --git a/lib/rules/arrow-body-style.js b/lib/rules/arrow-body-style.js index 92068c75c42..c2ce3b59e4f 100644 --- a/lib/rules/arrow-body-style.js +++ b/lib/rules/arrow-body-style.js @@ -16,6 +16,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "require braces around arrow function bodies", category: "ECMAScript 6", diff --git a/lib/rules/arrow-parens.js b/lib/rules/arrow-parens.js index 7a6ef6f8bed..637a0c1f1f1 100644 --- a/lib/rules/arrow-parens.js +++ b/lib/rules/arrow-parens.js @@ -16,6 +16,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "require parentheses around arrow function arguments", category: "ECMAScript 6", diff --git a/lib/rules/arrow-spacing.js b/lib/rules/arrow-spacing.js index a1db18fc910..87d381840a9 100644 --- a/lib/rules/arrow-spacing.js +++ b/lib/rules/arrow-spacing.js @@ -16,6 +16,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "enforce consistent spacing before and after the arrow in arrow functions", category: "ECMAScript 6", diff --git a/lib/rules/block-scoped-var.js b/lib/rules/block-scoped-var.js index 1000fbc83c6..053cfc334cd 100644 --- a/lib/rules/block-scoped-var.js +++ b/lib/rules/block-scoped-var.js @@ -10,6 +10,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "enforce the use of variables within the scope they are defined", category: "Best Practices", diff --git a/lib/rules/block-spacing.js b/lib/rules/block-spacing.js index 838c2c7016b..6496f8596d3 100644 --- a/lib/rules/block-spacing.js +++ b/lib/rules/block-spacing.js @@ -13,6 +13,8 @@ const util = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "disallow or enforce spaces inside of blocks after opening block and before closing block", category: "Stylistic Issues", diff --git a/lib/rules/brace-style.js b/lib/rules/brace-style.js index 236a01096ab..d172124d2f4 100644 --- a/lib/rules/brace-style.js +++ b/lib/rules/brace-style.js @@ -13,6 +13,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "enforce consistent brace style for blocks", category: "Stylistic Issues", diff --git a/lib/rules/callback-return.js b/lib/rules/callback-return.js index f55fed87db0..c5263cde46b 100644 --- a/lib/rules/callback-return.js +++ b/lib/rules/callback-return.js @@ -10,6 +10,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "require `return` statements after callbacks", category: "Node.js and CommonJS", diff --git a/lib/rules/camelcase.js b/lib/rules/camelcase.js index 41040450f94..8aeb4b5bd0d 100644 --- a/lib/rules/camelcase.js +++ b/lib/rules/camelcase.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "enforce camelcase naming convention", category: "Stylistic Issues", diff --git a/lib/rules/capitalized-comments.js b/lib/rules/capitalized-comments.js index 8fabde287cc..86427ba7acc 100644 --- a/lib/rules/capitalized-comments.js +++ b/lib/rules/capitalized-comments.js @@ -108,13 +108,17 @@ function createRegExpForIgnorePatterns(normalizedOptions) { module.exports = { meta: { + type: "suggestion", + docs: { description: "enforce or disallow capitalization of the first letter of a comment", category: "Stylistic Issues", recommended: false, url: "https://eslint.org/docs/rules/capitalized-comments" }, + fixable: "code", + schema: [ { enum: ["always", "never"] }, { diff --git a/lib/rules/class-methods-use-this.js b/lib/rules/class-methods-use-this.js index b7d94135bb7..a15ab6b89e4 100644 --- a/lib/rules/class-methods-use-this.js +++ b/lib/rules/class-methods-use-this.js @@ -11,12 +11,15 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "enforce that class methods utilize `this`", category: "Best Practices", recommended: false, url: "https://eslint.org/docs/rules/class-methods-use-this" }, + schema: [{ type: "object", properties: { diff --git a/lib/rules/comma-dangle.js b/lib/rules/comma-dangle.js index 9bc6c3fa8cc..96799b30796 100644 --- a/lib/rules/comma-dangle.js +++ b/lib/rules/comma-dangle.js @@ -76,13 +76,17 @@ function normalizeOptions(optionValue) { module.exports = { meta: { + type: "layout", + docs: { description: "require or disallow trailing commas", category: "Stylistic Issues", recommended: false, url: "https://eslint.org/docs/rules/comma-dangle" }, + fixable: "code", + schema: { definitions: { value: { diff --git a/lib/rules/comma-spacing.js b/lib/rules/comma-spacing.js index d3f82b3a4b9..2db0035b545 100644 --- a/lib/rules/comma-spacing.js +++ b/lib/rules/comma-spacing.js @@ -12,6 +12,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "enforce consistent spacing before and after commas", category: "Stylistic Issues", diff --git a/lib/rules/comma-style.js b/lib/rules/comma-style.js index 7f996b344d4..2586cf66e92 100644 --- a/lib/rules/comma-style.js +++ b/lib/rules/comma-style.js @@ -13,13 +13,17 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "enforce consistent comma style", category: "Stylistic Issues", recommended: false, url: "https://eslint.org/docs/rules/comma-style" }, + fixable: "code", + schema: [ { enum: ["first", "last"] @@ -37,6 +41,7 @@ module.exports = { additionalProperties: false } ], + messages: { unexpectedLineBeforeAndAfterComma: "Bad line breaking before and after ','.", expectedCommaFirst: "',' should be placed first.", diff --git a/lib/rules/complexity.js b/lib/rules/complexity.js index bc66d303b63..af583c02791 100644 --- a/lib/rules/complexity.js +++ b/lib/rules/complexity.js @@ -20,6 +20,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "enforce a maximum cyclomatic complexity allowed in a program", category: "Best Practices", diff --git a/lib/rules/computed-property-spacing.js b/lib/rules/computed-property-spacing.js index 060b2c5b40d..188d863d0d0 100644 --- a/lib/rules/computed-property-spacing.js +++ b/lib/rules/computed-property-spacing.js @@ -12,6 +12,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "enforce consistent spacing inside computed property brackets", category: "Stylistic Issues", diff --git a/lib/rules/consistent-return.js b/lib/rules/consistent-return.js index 6185d094fb5..ffd7ef20589 100644 --- a/lib/rules/consistent-return.js +++ b/lib/rules/consistent-return.js @@ -53,6 +53,8 @@ function isClassConstructor(node) { module.exports = { meta: { + type: "suggestion", + docs: { description: "require `return` statements to either always or never specify values", category: "Best Practices", diff --git a/lib/rules/consistent-this.js b/lib/rules/consistent-this.js index 5cc3a647dab..4bdcdfdc10e 100644 --- a/lib/rules/consistent-this.js +++ b/lib/rules/consistent-this.js @@ -10,6 +10,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "enforce consistent naming when capturing the current execution context", category: "Stylistic Issues", diff --git a/lib/rules/constructor-super.js b/lib/rules/constructor-super.js index 3cbc2f59f89..e4cdb099b3b 100644 --- a/lib/rules/constructor-super.js +++ b/lib/rules/constructor-super.js @@ -92,6 +92,8 @@ function isPossibleConstructor(node) { module.exports = { meta: { + type: "problem", + docs: { description: "require `super()` calls in constructors", category: "ECMAScript 6", diff --git a/lib/rules/curly.js b/lib/rules/curly.js index ad8da821c1c..ee12da71352 100644 --- a/lib/rules/curly.js +++ b/lib/rules/curly.js @@ -16,6 +16,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "enforce consistent brace style for all control statements", category: "Best Practices", diff --git a/lib/rules/default-case.js b/lib/rules/default-case.js index cf123198f4a..3061265ed8e 100644 --- a/lib/rules/default-case.js +++ b/lib/rules/default-case.js @@ -12,6 +12,8 @@ const DEFAULT_COMMENT_PATTERN = /^no default$/i; module.exports = { meta: { + type: "suggestion", + docs: { description: "require `default` cases in `switch` statements", category: "Best Practices", diff --git a/lib/rules/dot-location.js b/lib/rules/dot-location.js index 34d2d4eaab8..0eefec2eaff 100644 --- a/lib/rules/dot-location.js +++ b/lib/rules/dot-location.js @@ -13,6 +13,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "enforce consistent newlines before and after dots", category: "Best Practices", diff --git a/lib/rules/dot-notation.js b/lib/rules/dot-notation.js index a7062df8a5b..55ccea4ce38 100644 --- a/lib/rules/dot-notation.js +++ b/lib/rules/dot-notation.js @@ -19,6 +19,8 @@ const keywords = require("../util/keywords"); module.exports = { meta: { + type: "suggestion", + docs: { description: "enforce dot notation whenever possible", category: "Best Practices", diff --git a/lib/rules/eol-last.js b/lib/rules/eol-last.js index 3ecf4227399..84f4d45f176 100644 --- a/lib/rules/eol-last.js +++ b/lib/rules/eol-last.js @@ -16,18 +16,23 @@ const lodash = require("lodash"); module.exports = { meta: { + type: "layout", + docs: { description: "require or disallow newline at the end of files", category: "Stylistic Issues", recommended: false, url: "https://eslint.org/docs/rules/eol-last" }, + fixable: "whitespace", + schema: [ { enum: ["always", "never", "unix", "windows"] } ], + messages: { missing: "Newline required at end of file but not found.", unexpected: "Newline not allowed at end of file." diff --git a/lib/rules/eqeqeq.js b/lib/rules/eqeqeq.js index 2c5e9ae9e4f..715c5ce7c02 100644 --- a/lib/rules/eqeqeq.js +++ b/lib/rules/eqeqeq.js @@ -17,6 +17,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "require the use of `===` and `!==`", category: "Best Practices", diff --git a/lib/rules/for-direction.js b/lib/rules/for-direction.js index b93c4c2caa4..db079b26793 100644 --- a/lib/rules/for-direction.js +++ b/lib/rules/for-direction.js @@ -11,14 +11,18 @@ module.exports = { meta: { + type: "problem", + docs: { description: "enforce \"for\" loop update clause moving the counter in the right direction.", category: "Possible Errors", recommended: true, url: "https://eslint.org/docs/rules/for-direction" }, + fixable: null, schema: [], + messages: { incorrectDirection: "The update clause in this loop moves the variable in the wrong direction." } diff --git a/lib/rules/func-call-spacing.js b/lib/rules/func-call-spacing.js index 9aae3e2517e..c49aa9e59f7 100644 --- a/lib/rules/func-call-spacing.js +++ b/lib/rules/func-call-spacing.js @@ -17,6 +17,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "require or disallow spacing between function identifiers and their invocations", category: "Stylistic Issues", @@ -25,6 +27,7 @@ module.exports = { }, fixable: "whitespace", + schema: { anyOf: [ { @@ -58,6 +61,7 @@ module.exports = { } ] }, + messages: { unexpected: "Unexpected newline between function name and paren.", missing: "Missing space between function name and paren." diff --git a/lib/rules/func-name-matching.js b/lib/rules/func-name-matching.js index 89c07c3514c..f14c998dc7f 100644 --- a/lib/rules/func-name-matching.js +++ b/lib/rules/func-name-matching.js @@ -70,6 +70,8 @@ const optionsObject = { module.exports = { meta: { + type: "suggestion", + docs: { description: "require function names to match the name of the variable or property to which they are assigned", category: "Stylistic Issues", @@ -88,6 +90,7 @@ module.exports = { items: [optionsObject] }] }, + messages: { matchProperty: "Function name `{{funcName}}` should match property name `{{name}}`", matchVariable: "Function name `{{funcName}}` should match variable name `{{name}}`", diff --git a/lib/rules/func-names.js b/lib/rules/func-names.js index 31f30291811..4ccbae0f0cb 100644 --- a/lib/rules/func-names.js +++ b/lib/rules/func-names.js @@ -26,6 +26,8 @@ function isFunctionName(variable) { module.exports = { meta: { + type: "suggestion", + docs: { description: "require or disallow named `function` expressions", category: "Stylistic Issues", @@ -58,6 +60,7 @@ module.exports = { } ] }, + messages: { unnamed: "Unexpected unnamed {{name}}.", named: "Unexpected named {{name}}." diff --git a/lib/rules/func-style.js b/lib/rules/func-style.js index ff48792d29a..b7e368cbd2e 100644 --- a/lib/rules/func-style.js +++ b/lib/rules/func-style.js @@ -10,6 +10,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "enforce the consistent use of either `function` declarations or expressions", category: "Stylistic Issues", @@ -31,6 +33,7 @@ module.exports = { additionalProperties: false } ], + messages: { expression: "Expected a function expression.", declaration: "Expected a function declaration." diff --git a/lib/rules/function-paren-newline.js b/lib/rules/function-paren-newline.js index d78e88038e2..37256484f4a 100644 --- a/lib/rules/function-paren-newline.js +++ b/lib/rules/function-paren-newline.js @@ -16,13 +16,17 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "enforce consistent line breaks inside function parentheses", category: "Stylistic Issues", recommended: false, url: "https://eslint.org/docs/rules/function-paren-newline" }, + fixable: "whitespace", + schema: [ { oneOf: [ @@ -42,6 +46,7 @@ module.exports = { ] } ], + messages: { expectedBefore: "Expected newline before ')'.", expectedAfter: "Expected newline after '('.", diff --git a/lib/rules/generator-star-spacing.js b/lib/rules/generator-star-spacing.js index 97868dd3fa9..6f860290cec 100644 --- a/lib/rules/generator-star-spacing.js +++ b/lib/rules/generator-star-spacing.js @@ -27,6 +27,8 @@ const OVERRIDE_SCHEMA = { module.exports = { meta: { + type: "layout", + docs: { description: "enforce consistent spacing around `*` operators in generator functions", category: "ECMAScript 6", @@ -56,6 +58,7 @@ module.exports = { ] } ], + messages: { missingBefore: "Missing space before *.", missingAfter: "Missing space after *.", diff --git a/lib/rules/getter-return.js b/lib/rules/getter-return.js index 452ba49f595..dc3d9d6b627 100644 --- a/lib/rules/getter-return.js +++ b/lib/rules/getter-return.js @@ -44,13 +44,17 @@ function getId(node) { module.exports = { meta: { + type: "problem", + docs: { description: "enforce `return` statements in getters", category: "Possible Errors", recommended: true, url: "https://eslint.org/docs/rules/getter-return" }, + fixable: null, + schema: [ { type: "object", @@ -62,6 +66,7 @@ module.exports = { additionalProperties: false } ], + messages: { expected: "Expected to return a value in {{name}}.", expectedAlways: "Expected {{name}} to always return a value." diff --git a/lib/rules/global-require.js b/lib/rules/global-require.js index a5f5335d01d..6576cfb6a1f 100644 --- a/lib/rules/global-require.js +++ b/lib/rules/global-require.js @@ -48,6 +48,8 @@ function isShadowed(scope, node) { module.exports = { meta: { + type: "suggestion", + docs: { description: "require `require()` calls to be placed at top-level module scope", category: "Node.js and CommonJS", diff --git a/lib/rules/guard-for-in.js b/lib/rules/guard-for-in.js index 0f85e4984aa..6e8452a4844 100644 --- a/lib/rules/guard-for-in.js +++ b/lib/rules/guard-for-in.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "require `for-in` loops to include an `if` statement", category: "Best Practices", diff --git a/lib/rules/handle-callback-err.js b/lib/rules/handle-callback-err.js index f6e6c108ce1..c62016d5895 100644 --- a/lib/rules/handle-callback-err.js +++ b/lib/rules/handle-callback-err.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "require error handling in callbacks", category: "Node.js and CommonJS", diff --git a/lib/rules/id-blacklist.js b/lib/rules/id-blacklist.js index ba9b5d4b398..7b8facbabe0 100644 --- a/lib/rules/id-blacklist.js +++ b/lib/rules/id-blacklist.js @@ -12,6 +12,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow specified identifiers", category: "Stylistic Issues", diff --git a/lib/rules/id-length.js b/lib/rules/id-length.js index eaed26217dd..d72eb08876a 100644 --- a/lib/rules/id-length.js +++ b/lib/rules/id-length.js @@ -12,6 +12,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "enforce minimum and maximum identifier lengths", category: "Stylistic Issues", diff --git a/lib/rules/id-match.js b/lib/rules/id-match.js index 608ef17d114..17dfbc05bd2 100644 --- a/lib/rules/id-match.js +++ b/lib/rules/id-match.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "require identifiers to match a specified regular expression", category: "Stylistic Issues", diff --git a/lib/rules/implicit-arrow-linebreak.js b/lib/rules/implicit-arrow-linebreak.js index a7ad1122b50..cd729f8ad93 100644 --- a/lib/rules/implicit-arrow-linebreak.js +++ b/lib/rules/implicit-arrow-linebreak.js @@ -9,13 +9,17 @@ //------------------------------------------------------------------------------ module.exports = { meta: { + type: "layout", + docs: { description: "enforce the location of arrow function bodies", category: "Stylistic Issues", recommended: false, url: "https://eslint.org/docs/rules/implicit-arrow-linebreak" }, + fixable: "whitespace", + schema: [ { enum: ["beside", "below"] diff --git a/lib/rules/indent-legacy.js b/lib/rules/indent-legacy.js index c3858ba753f..16687b521ed 100644 --- a/lib/rules/indent-legacy.js +++ b/lib/rules/indent-legacy.js @@ -21,6 +21,8 @@ const astUtils = require("../util/ast-utils"); /* istanbul ignore next: this rule has known coverage issues, but it's deprecated and shouldn't be updated in the future anyway. */ module.exports = { meta: { + type: "layout", + docs: { description: "enforce consistent indentation", category: "Stylistic Issues", diff --git a/lib/rules/indent.js b/lib/rules/indent.js index 940c080a037..dc9fbaf908b 100644 --- a/lib/rules/indent.js +++ b/lib/rules/indent.js @@ -490,6 +490,8 @@ const ELEMENT_LIST_SCHEMA = { module.exports = { meta: { + type: "layout", + docs: { description: "enforce consistent indentation", category: "Stylistic Issues", diff --git a/lib/rules/init-declarations.js b/lib/rules/init-declarations.js index 412b96dc0ab..755090917f9 100644 --- a/lib/rules/init-declarations.js +++ b/lib/rules/init-declarations.js @@ -44,6 +44,8 @@ function isInitialized(node) { module.exports = { meta: { + type: "suggestion", + docs: { description: "require or disallow initialization in variable declarations", category: "Variables", diff --git a/lib/rules/jsx-quotes.js b/lib/rules/jsx-quotes.js index 3dd9567d737..603d55330b5 100644 --- a/lib/rules/jsx-quotes.js +++ b/lib/rules/jsx-quotes.js @@ -38,6 +38,8 @@ const QUOTE_SETTINGS = { module.exports = { meta: { + type: "layout", + docs: { description: "enforce the consistent use of either double or single quotes in JSX attributes", category: "Stylistic Issues", diff --git a/lib/rules/key-spacing.js b/lib/rules/key-spacing.js index 75578b2c747..2d1315fde09 100644 --- a/lib/rules/key-spacing.js +++ b/lib/rules/key-spacing.js @@ -128,6 +128,8 @@ const messages = { module.exports = { meta: { + type: "layout", + docs: { description: "enforce consistent spacing between keys and values in object literal properties", category: "Stylistic Issues", @@ -360,10 +362,9 @@ module.exports = { */ function isKeyValueProperty(property) { return !( - property.method || + (property.method || property.shorthand || - property.kind !== "init" || - property.type !== "Property" // Could be "ExperimentalSpreadProperty" or "SpreadElement" + property.kind !== "init" || property.type !== "Property") // Could be "ExperimentalSpreadProperty" or "SpreadElement" ); } diff --git a/lib/rules/keyword-spacing.js b/lib/rules/keyword-spacing.js index 2a66779e7aa..66ce2cb34c0 100644 --- a/lib/rules/keyword-spacing.js +++ b/lib/rules/keyword-spacing.js @@ -65,6 +65,8 @@ function isCloseParenOfTemplate(token) { module.exports = { meta: { + type: "layout", + docs: { description: "enforce consistent spacing before and after keywords", category: "Stylistic Issues", diff --git a/lib/rules/line-comment-position.js b/lib/rules/line-comment-position.js index 7f45a94b6b5..7c791d5f277 100644 --- a/lib/rules/line-comment-position.js +++ b/lib/rules/line-comment-position.js @@ -12,6 +12,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "enforce position of line comments", category: "Stylistic Issues", diff --git a/lib/rules/linebreak-style.js b/lib/rules/linebreak-style.js index cd432dbcca1..5345d53f288 100644 --- a/lib/rules/linebreak-style.js +++ b/lib/rules/linebreak-style.js @@ -17,6 +17,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "enforce consistent linebreak style", category: "Stylistic Issues", diff --git a/lib/rules/lines-around-comment.js b/lib/rules/lines-around-comment.js index 67fd2032b3e..30175cd3663 100644 --- a/lib/rules/lines-around-comment.js +++ b/lib/rules/lines-around-comment.js @@ -52,6 +52,8 @@ function getCommentLineNums(comments) { module.exports = { meta: { + type: "layout", + docs: { description: "require empty lines around comments", category: "Stylistic Issues", diff --git a/lib/rules/lines-around-directive.js b/lib/rules/lines-around-directive.js index 2ed72942d46..02bbe13b4fc 100644 --- a/lib/rules/lines-around-directive.js +++ b/lib/rules/lines-around-directive.js @@ -14,12 +14,15 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "require or disallow newlines around directives", category: "Stylistic Issues", recommended: false, url: "https://eslint.org/docs/rules/lines-around-directive" }, + schema: [{ oneOf: [ { @@ -40,6 +43,7 @@ module.exports = { } ] }], + fixable: "whitespace", deprecated: true, replacedBy: ["padding-line-between-statements"] diff --git a/lib/rules/lines-between-class-members.js b/lib/rules/lines-between-class-members.js index 8d4e6dd8c18..5c1e69277a5 100644 --- a/lib/rules/lines-between-class-members.js +++ b/lib/rules/lines-between-class-members.js @@ -12,6 +12,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "require or disallow an empty line between class members", category: "Stylistic Issues", diff --git a/lib/rules/max-classes-per-file.js b/lib/rules/max-classes-per-file.js index bf6b4ba31c6..3193a731c94 100644 --- a/lib/rules/max-classes-per-file.js +++ b/lib/rules/max-classes-per-file.js @@ -15,18 +15,22 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "enforce a maximum number of classes per file", category: "Best Practices", recommended: false, url: "https://eslint.org/docs/rules/max-classes-per-file" }, + schema: [ { type: "integer", minimum: 1 } ], + messages: { maximumExceeded: "Number of classes per file must not exceed {{ max }}" } diff --git a/lib/rules/max-depth.js b/lib/rules/max-depth.js index 368dcfa6681..34d58b0d31e 100644 --- a/lib/rules/max-depth.js +++ b/lib/rules/max-depth.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "enforce a maximum depth that blocks can be nested", category: "Stylistic Issues", diff --git a/lib/rules/max-len.js b/lib/rules/max-len.js index 88a388309b2..13dd72160cc 100644 --- a/lib/rules/max-len.js +++ b/lib/rules/max-len.js @@ -65,6 +65,8 @@ const OPTIONS_OR_INTEGER_SCHEMA = { module.exports = { meta: { + type: "layout", + docs: { description: "enforce a maximum line length", category: "Stylistic Issues", diff --git a/lib/rules/max-lines-per-function.js b/lib/rules/max-lines-per-function.js index ccf6304e4b2..8c64a20bcc3 100644 --- a/lib/rules/max-lines-per-function.js +++ b/lib/rules/max-lines-per-function.js @@ -69,6 +69,8 @@ function getCommentLineNumbers(comments) { module.exports = { meta: { + type: "suggestion", + docs: { description: "enforce a maximum number of line of code in a function", category: "Stylistic Issues", diff --git a/lib/rules/max-lines.js b/lib/rules/max-lines.js index 7eb959795ab..730e05ab41c 100644 --- a/lib/rules/max-lines.js +++ b/lib/rules/max-lines.js @@ -17,6 +17,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "enforce a maximum number of lines per file", category: "Stylistic Issues", diff --git a/lib/rules/max-nested-callbacks.js b/lib/rules/max-nested-callbacks.js index 8cc80ae7aab..d4ecb4e2a5c 100644 --- a/lib/rules/max-nested-callbacks.js +++ b/lib/rules/max-nested-callbacks.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "enforce a maximum depth that callbacks can be nested", category: "Stylistic Issues", diff --git a/lib/rules/max-params.js b/lib/rules/max-params.js index 4089e8ae899..f678974acf3 100644 --- a/lib/rules/max-params.js +++ b/lib/rules/max-params.js @@ -19,6 +19,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "enforce a maximum number of parameters in function definitions", category: "Stylistic Issues", diff --git a/lib/rules/max-statements-per-line.js b/lib/rules/max-statements-per-line.js index 566f04ab53b..f3fb8e9d5cf 100644 --- a/lib/rules/max-statements-per-line.js +++ b/lib/rules/max-statements-per-line.js @@ -16,6 +16,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "enforce a maximum number of statements allowed per line", category: "Stylistic Issues", diff --git a/lib/rules/max-statements.js b/lib/rules/max-statements.js index 525790df806..e32dedad632 100644 --- a/lib/rules/max-statements.js +++ b/lib/rules/max-statements.js @@ -19,6 +19,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "enforce a maximum number of statements allowed in function blocks", category: "Stylistic Issues", diff --git a/lib/rules/multiline-comment-style.js b/lib/rules/multiline-comment-style.js index 5dd39e00a77..73eab7c5741 100644 --- a/lib/rules/multiline-comment-style.js +++ b/lib/rules/multiline-comment-style.js @@ -12,12 +12,15 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "enforce a particular style for multiline comments", category: "Stylistic Issues", recommended: false, url: "https://eslint.org/docs/rules/multiline-comment-style" }, + fixable: "whitespace", schema: [{ enum: ["starred-block", "separate-lines", "bare-block"] }] }, diff --git a/lib/rules/multiline-ternary.js b/lib/rules/multiline-ternary.js index 6a22a1113c1..d1d577a4ffa 100644 --- a/lib/rules/multiline-ternary.js +++ b/lib/rules/multiline-ternary.js @@ -13,12 +13,15 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "enforce newlines between operands of ternary expressions", category: "Stylistic Issues", recommended: false, url: "https://eslint.org/docs/rules/multiline-ternary" }, + schema: [ { enum: ["always", "always-multiline", "never"] diff --git a/lib/rules/new-cap.js b/lib/rules/new-cap.js index cc33e3b8175..834f4605ed2 100644 --- a/lib/rules/new-cap.js +++ b/lib/rules/new-cap.js @@ -74,6 +74,8 @@ function calculateCapIsNewExceptions(config) { module.exports = { meta: { + type: "suggestion", + docs: { description: "require constructor names to begin with a capital letter", category: "Stylistic Issues", diff --git a/lib/rules/new-parens.js b/lib/rules/new-parens.js index fab302000c9..0637a8fbca2 100644 --- a/lib/rules/new-parens.js +++ b/lib/rules/new-parens.js @@ -21,6 +21,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "require parentheses when invoking a constructor with no arguments", category: "Stylistic Issues", @@ -29,7 +31,6 @@ module.exports = { }, schema: [], - fixable: "code" }, diff --git a/lib/rules/newline-after-var.js b/lib/rules/newline-after-var.js index df2ad7620e7..83fd420d733 100644 --- a/lib/rules/newline-after-var.js +++ b/lib/rules/newline-after-var.js @@ -18,6 +18,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "require or disallow an empty line after variable declarations", category: "Stylistic Issues", diff --git a/lib/rules/newline-before-return.js b/lib/rules/newline-before-return.js index e9de4bb1414..2743bf7a8be 100644 --- a/lib/rules/newline-before-return.js +++ b/lib/rules/newline-before-return.js @@ -11,12 +11,15 @@ module.exports = { meta: { + type: "layout", + docs: { description: "require an empty line before `return` statements", category: "Stylistic Issues", recommended: false, url: "https://eslint.org/docs/rules/newline-before-return" }, + fixable: "whitespace", schema: [], deprecated: true, diff --git a/lib/rules/newline-per-chained-call.js b/lib/rules/newline-per-chained-call.js index 2adcdfe45a6..9d993137682 100644 --- a/lib/rules/newline-per-chained-call.js +++ b/lib/rules/newline-per-chained-call.js @@ -14,13 +14,17 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "require a newline after each call in a method chain", category: "Stylistic Issues", recommended: false, url: "https://eslint.org/docs/rules/newline-per-chained-call" }, + fixable: "whitespace", + schema: [{ type: "object", properties: { diff --git a/lib/rules/no-alert.js b/lib/rules/no-alert.js index 1c08460f340..21f10b3c399 100644 --- a/lib/rules/no-alert.js +++ b/lib/rules/no-alert.js @@ -74,6 +74,8 @@ function isGlobalThisReferenceOrGlobalWindow(scope, node) { module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow the use of `alert`, `confirm`, and `prompt`", category: "Best Practices", diff --git a/lib/rules/no-array-constructor.js b/lib/rules/no-array-constructor.js index 51676f78211..90c6d6bbd59 100644 --- a/lib/rules/no-array-constructor.js +++ b/lib/rules/no-array-constructor.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow `Array` constructors", category: "Stylistic Issues", diff --git a/lib/rules/no-async-promise-executor.js b/lib/rules/no-async-promise-executor.js index 55d489eb6dd..fc65f539a3e 100644 --- a/lib/rules/no-async-promise-executor.js +++ b/lib/rules/no-async-promise-executor.js @@ -10,12 +10,15 @@ module.exports = { meta: { + type: "problem", + docs: { description: "disallow using an async function as a Promise executor", category: "Possible Errors", recommended: false, url: "https://eslint.org/docs/rules/no-async-promise-executor" }, + fixable: null, schema: [] }, diff --git a/lib/rules/no-await-in-loop.js b/lib/rules/no-await-in-loop.js index ef0bda90bf9..9ca89866a6e 100644 --- a/lib/rules/no-await-in-loop.js +++ b/lib/rules/no-await-in-loop.js @@ -55,13 +55,17 @@ function isLooped(node, parent) { module.exports = { meta: { + type: "problem", + docs: { description: "disallow `await` inside of loops", category: "Possible Errors", recommended: false, url: "https://eslint.org/docs/rules/no-await-in-loop" }, + schema: [], + messages: { unexpectedAwait: "Unexpected `await` inside a loop." } diff --git a/lib/rules/no-bitwise.js b/lib/rules/no-bitwise.js index 36bbdaf349c..df492937c0b 100644 --- a/lib/rules/no-bitwise.js +++ b/lib/rules/no-bitwise.js @@ -22,6 +22,8 @@ const BITWISE_OPERATORS = [ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow bitwise operators", category: "Stylistic Issues", diff --git a/lib/rules/no-buffer-constructor.js b/lib/rules/no-buffer-constructor.js index 51f78edb1fe..bf4c8891ad1 100644 --- a/lib/rules/no-buffer-constructor.js +++ b/lib/rules/no-buffer-constructor.js @@ -10,13 +10,17 @@ module.exports = { meta: { + type: "problem", + docs: { description: "disallow use of the `Buffer()` constructor", category: "Node.js and CommonJS", recommended: false, url: "https://eslint.org/docs/rules/no-buffer-constructor" }, + schema: [], + messages: { deprecated: "{{expr}} is deprecated. Use Buffer.from(), Buffer.alloc(), or Buffer.allocUnsafe() instead." } diff --git a/lib/rules/no-caller.js b/lib/rules/no-caller.js index 9756b212ffe..1703ad867dc 100644 --- a/lib/rules/no-caller.js +++ b/lib/rules/no-caller.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow the use of `arguments.caller` or `arguments.callee`", category: "Best Practices", diff --git a/lib/rules/no-case-declarations.js b/lib/rules/no-case-declarations.js index c05795200e6..1d54e221625 100644 --- a/lib/rules/no-case-declarations.js +++ b/lib/rules/no-case-declarations.js @@ -10,6 +10,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow lexical declarations in case clauses", category: "Best Practices", diff --git a/lib/rules/no-catch-shadow.js b/lib/rules/no-catch-shadow.js index a9253dde047..60a0493b343 100644 --- a/lib/rules/no-catch-shadow.js +++ b/lib/rules/no-catch-shadow.js @@ -18,16 +18,18 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow `catch` clause parameters from shadowing variables in the outer scope", category: "Variables", recommended: false, url: "https://eslint.org/docs/rules/no-catch-shadow" }, - deprecated: true, replacedBy: ["no-shadow"], + deprecated: true, schema: [], messages: { diff --git a/lib/rules/no-class-assign.js b/lib/rules/no-class-assign.js index 9b28d40d4a3..7bc65df1ba6 100644 --- a/lib/rules/no-class-assign.js +++ b/lib/rules/no-class-assign.js @@ -13,6 +13,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "problem", + docs: { description: "disallow reassigning class members", category: "ECMAScript 6", diff --git a/lib/rules/no-compare-neg-zero.js b/lib/rules/no-compare-neg-zero.js index 6903bd06544..f5c8d5f417b 100644 --- a/lib/rules/no-compare-neg-zero.js +++ b/lib/rules/no-compare-neg-zero.js @@ -10,14 +10,18 @@ module.exports = { meta: { + type: "problem", + docs: { description: "disallow comparing against -0", category: "Possible Errors", recommended: true, url: "https://eslint.org/docs/rules/no-compare-neg-zero" }, + fixable: null, schema: [], + messages: { unexpected: "Do not use the '{{operator}}' operator to compare against -0." } diff --git a/lib/rules/no-cond-assign.js b/lib/rules/no-cond-assign.js index caf9563e952..aed3e4a7a9b 100644 --- a/lib/rules/no-cond-assign.js +++ b/lib/rules/no-cond-assign.js @@ -19,6 +19,8 @@ const NODE_DESCRIPTIONS = { module.exports = { meta: { + type: "problem", + docs: { description: "disallow assignment operators in conditional expressions", category: "Possible Errors", diff --git a/lib/rules/no-confusing-arrow.js b/lib/rules/no-confusing-arrow.js index 503174e9a67..f18ec194530 100644 --- a/lib/rules/no-confusing-arrow.js +++ b/lib/rules/no-confusing-arrow.js @@ -27,6 +27,8 @@ function isConditional(node) { module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow arrow functions where they could be confused with comparisons", category: "ECMAScript 6", diff --git a/lib/rules/no-console.js b/lib/rules/no-console.js index 5fb3a159be8..d3a2e344751 100644 --- a/lib/rules/no-console.js +++ b/lib/rules/no-console.js @@ -17,6 +17,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow the use of `console`", category: "Possible Errors", diff --git a/lib/rules/no-const-assign.js b/lib/rules/no-const-assign.js index 3188bd34d3b..32f8154cc23 100644 --- a/lib/rules/no-const-assign.js +++ b/lib/rules/no-const-assign.js @@ -13,6 +13,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "problem", + docs: { description: "disallow reassigning `const` variables", category: "ECMAScript 6", diff --git a/lib/rules/no-constant-condition.js b/lib/rules/no-constant-condition.js index 48b1fbf689f..88984c36e7f 100644 --- a/lib/rules/no-constant-condition.js +++ b/lib/rules/no-constant-condition.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "problem", + docs: { description: "disallow constant expressions in conditions", category: "Possible Errors", diff --git a/lib/rules/no-continue.js b/lib/rules/no-continue.js index 3075b77f9fd..96718d17a3d 100644 --- a/lib/rules/no-continue.js +++ b/lib/rules/no-continue.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow `continue` statements", category: "Stylistic Issues", diff --git a/lib/rules/no-control-regex.js b/lib/rules/no-control-regex.js index 24bb6be6671..24e6b197be0 100644 --- a/lib/rules/no-control-regex.js +++ b/lib/rules/no-control-regex.js @@ -6,7 +6,7 @@ "use strict"; const RegExpValidator = require("regexpp").RegExpValidator; -const collector = new class { +const collector = new (class { constructor() { this.ecmaVersion = 2018; this._source = ""; @@ -41,7 +41,7 @@ const collector = new class { } return this._controlChars; } -}(); +})(); //------------------------------------------------------------------------------ // Rule Definition @@ -49,6 +49,8 @@ const collector = new class { module.exports = { meta: { + type: "problem", + docs: { description: "disallow control characters in regular expressions", category: "Possible Errors", diff --git a/lib/rules/no-debugger.js b/lib/rules/no-debugger.js index 5d63bb7e141..95a28a86215 100644 --- a/lib/rules/no-debugger.js +++ b/lib/rules/no-debugger.js @@ -11,14 +11,18 @@ module.exports = { meta: { + type: "problem", + docs: { description: "disallow the use of `debugger`", category: "Possible Errors", recommended: true, url: "https://eslint.org/docs/rules/no-debugger" }, + fixable: null, schema: [], + messages: { unexpected: "Unexpected 'debugger' statement." } diff --git a/lib/rules/no-delete-var.js b/lib/rules/no-delete-var.js index f54a396ec2d..aeab951d75f 100644 --- a/lib/rules/no-delete-var.js +++ b/lib/rules/no-delete-var.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow deleting variables", category: "Variables", diff --git a/lib/rules/no-div-regex.js b/lib/rules/no-div-regex.js index c050249fd6e..408e006528b 100644 --- a/lib/rules/no-div-regex.js +++ b/lib/rules/no-div-regex.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow division operators explicitly at the beginning of regular expressions", category: "Best Practices", diff --git a/lib/rules/no-dupe-args.js b/lib/rules/no-dupe-args.js index e5a7f4154e7..4e42336ae3d 100644 --- a/lib/rules/no-dupe-args.js +++ b/lib/rules/no-dupe-args.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "problem", + docs: { description: "disallow duplicate arguments in `function` definitions", category: "Possible Errors", diff --git a/lib/rules/no-dupe-class-members.js b/lib/rules/no-dupe-class-members.js index d0fc3597360..97f63a28962 100644 --- a/lib/rules/no-dupe-class-members.js +++ b/lib/rules/no-dupe-class-members.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "problem", + docs: { description: "disallow duplicate class members", category: "ECMAScript 6", diff --git a/lib/rules/no-dupe-keys.js b/lib/rules/no-dupe-keys.js index 31493bd048d..9b9c02f5efc 100644 --- a/lib/rules/no-dupe-keys.js +++ b/lib/rules/no-dupe-keys.js @@ -84,6 +84,8 @@ class ObjectInfo { module.exports = { meta: { + type: "problem", + docs: { description: "disallow duplicate keys in object literals", category: "Possible Errors", diff --git a/lib/rules/no-duplicate-case.js b/lib/rules/no-duplicate-case.js index 128b1fc1b1c..93c8548f91a 100644 --- a/lib/rules/no-duplicate-case.js +++ b/lib/rules/no-duplicate-case.js @@ -12,6 +12,8 @@ module.exports = { meta: { + type: "problem", + docs: { description: "disallow duplicate case labels", category: "Possible Errors", diff --git a/lib/rules/no-duplicate-imports.js b/lib/rules/no-duplicate-imports.js index 32071da15fd..1d5bdfdc1a2 100644 --- a/lib/rules/no-duplicate-imports.js +++ b/lib/rules/no-duplicate-imports.js @@ -101,6 +101,8 @@ function handleExports(context, importsInFile, exportsInFile) { module.exports = { meta: { + type: "problem", + docs: { description: "disallow duplicate module imports", category: "ECMAScript 6", diff --git a/lib/rules/no-else-return.js b/lib/rules/no-else-return.js index 1000fa807ac..eebdec76e0e 100644 --- a/lib/rules/no-else-return.js +++ b/lib/rules/no-else-return.js @@ -18,6 +18,8 @@ const FixTracker = require("../util/fix-tracker"); module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow `else` blocks after `return` statements in `if` statements", category: "Best Practices", diff --git a/lib/rules/no-empty-character-class.js b/lib/rules/no-empty-character-class.js index e3f06b069a8..6d2fb3c5018 100644 --- a/lib/rules/no-empty-character-class.js +++ b/lib/rules/no-empty-character-class.js @@ -29,6 +29,8 @@ const regex = /^\/([^\\[]|\\.|\[([^\\\]]|\\.)+])*\/[gimuys]*$/; module.exports = { meta: { + type: "problem", + docs: { description: "disallow empty character classes in regular expressions", category: "Possible Errors", diff --git a/lib/rules/no-empty-function.js b/lib/rules/no-empty-function.js index c8039314ab0..a443796e4e2 100644 --- a/lib/rules/no-empty-function.js +++ b/lib/rules/no-empty-function.js @@ -90,6 +90,8 @@ function getKind(node) { module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow empty functions", category: "Best Practices", diff --git a/lib/rules/no-empty-pattern.js b/lib/rules/no-empty-pattern.js index 939710560fa..9f34bfde92e 100644 --- a/lib/rules/no-empty-pattern.js +++ b/lib/rules/no-empty-pattern.js @@ -10,6 +10,8 @@ module.exports = { meta: { + type: "problem", + docs: { description: "disallow empty destructuring patterns", category: "Best Practices", diff --git a/lib/rules/no-empty.js b/lib/rules/no-empty.js index 2f4c258a26f..9d72969e67e 100644 --- a/lib/rules/no-empty.js +++ b/lib/rules/no-empty.js @@ -16,6 +16,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow empty block statements", category: "Possible Errors", diff --git a/lib/rules/no-eq-null.js b/lib/rules/no-eq-null.js index eadd16de37f..b8dead96d25 100644 --- a/lib/rules/no-eq-null.js +++ b/lib/rules/no-eq-null.js @@ -12,6 +12,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow `null` comparisons without type-checking operators", category: "Best Practices", diff --git a/lib/rules/no-eval.js b/lib/rules/no-eval.js index c3ea87d466d..39d91e776e9 100644 --- a/lib/rules/no-eval.js +++ b/lib/rules/no-eval.js @@ -76,6 +76,8 @@ function isMember(node, name) { module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow the use of `eval()`", category: "Best Practices", diff --git a/lib/rules/no-ex-assign.js b/lib/rules/no-ex-assign.js index 1c7beccf89e..4cc179a6e8f 100644 --- a/lib/rules/no-ex-assign.js +++ b/lib/rules/no-ex-assign.js @@ -13,6 +13,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "problem", + docs: { description: "disallow reassigning exceptions in `catch` clauses", category: "Possible Errors", diff --git a/lib/rules/no-extend-native.js b/lib/rules/no-extend-native.js index a1bf49f1325..13895f0d06b 100644 --- a/lib/rules/no-extend-native.js +++ b/lib/rules/no-extend-native.js @@ -24,6 +24,8 @@ const propertyDefinitionMethods = new Set(["defineProperty", "defineProperties"] module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow extending native types", category: "Best Practices", diff --git a/lib/rules/no-extra-bind.js b/lib/rules/no-extra-bind.js index 6d6cad13e97..abbe1868e89 100644 --- a/lib/rules/no-extra-bind.js +++ b/lib/rules/no-extra-bind.js @@ -22,6 +22,8 @@ const SIDE_EFFECT_FREE_NODE_TYPES = new Set(["Literal", "Identifier", "ThisExpre module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow unnecessary calls to `.bind()`", category: "Best Practices", @@ -30,7 +32,6 @@ module.exports = { }, schema: [], - fixable: "code", messages: { diff --git a/lib/rules/no-extra-boolean-cast.js b/lib/rules/no-extra-boolean-cast.js index 5eac6b53fe4..615603177a5 100644 --- a/lib/rules/no-extra-boolean-cast.js +++ b/lib/rules/no-extra-boolean-cast.js @@ -17,6 +17,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow unnecessary boolean casts", category: "Possible Errors", @@ -25,7 +27,6 @@ module.exports = { }, schema: [], - fixable: "code", messages: { diff --git a/lib/rules/no-extra-label.js b/lib/rules/no-extra-label.js index 9310e90f71e..f8acf7b2834 100644 --- a/lib/rules/no-extra-label.js +++ b/lib/rules/no-extra-label.js @@ -17,6 +17,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow unnecessary labels", category: "Best Practices", @@ -25,7 +27,6 @@ module.exports = { }, schema: [], - fixable: "code", messages: { diff --git a/lib/rules/no-extra-parens.js b/lib/rules/no-extra-parens.js index 47c58946cf1..3a21b69580b 100644 --- a/lib/rules/no-extra-parens.js +++ b/lib/rules/no-extra-parens.js @@ -12,6 +12,8 @@ const astUtils = require("../util/ast-utils.js"); module.exports = { meta: { + type: "layout", + docs: { description: "disallow unnecessary parentheses", category: "Possible Errors", @@ -382,8 +384,7 @@ module.exports = { * Allow extra parens around a new expression if * there are intervening parentheses. */ - callee.type === "MemberExpression" && - doesMemberExpressionContainCallExpression(callee) + (callee.type === "MemberExpression" && doesMemberExpressionContainCallExpression(callee)) ) ) { report(node.callee); @@ -574,15 +575,13 @@ module.exports = { * If `let` is the only thing on the left side of the loop, it's the loop variable: `for ((let) of foo);` * Removing it will cause a syntax error, because it will be parsed as the start of a VariableDeclarator. */ - firstLeftToken.range[1] === node.left.range[1] || - - /* + (firstLeftToken.range[1] === node.left.range[1] || /* * If `let` is followed by a `[` token, it's a property access on the `let` value: `for ((let[foo]) of bar);` * Removing it will cause the property access to be parsed as a destructuring declaration of `foo` instead. */ astUtils.isOpeningBracketToken( sourceCode.getTokenAfter(firstLeftToken, astUtils.isNotClosingParenToken) - ) + )) ) ) { tokensToIgnore.add(firstLeftToken); diff --git a/lib/rules/no-extra-semi.js b/lib/rules/no-extra-semi.js index 4d40b5e1538..d87a181672f 100644 --- a/lib/rules/no-extra-semi.js +++ b/lib/rules/no-extra-semi.js @@ -18,6 +18,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow unnecessary semicolons", category: "Possible Errors", diff --git a/lib/rules/no-fallthrough.js b/lib/rules/no-fallthrough.js index ce4f91ad964..b7fa221050d 100644 --- a/lib/rules/no-fallthrough.js +++ b/lib/rules/no-fallthrough.js @@ -55,6 +55,8 @@ function hasBlankLinesBetween(node, token) { module.exports = { meta: { + type: "problem", + docs: { description: "disallow fallthrough of `case` statements", category: "Best Practices", diff --git a/lib/rules/no-floating-decimal.js b/lib/rules/no-floating-decimal.js index a62846cc10f..c835d6a545f 100644 --- a/lib/rules/no-floating-decimal.js +++ b/lib/rules/no-floating-decimal.js @@ -17,6 +17,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow leading or trailing decimal points in numeric literals", category: "Best Practices", @@ -25,7 +27,6 @@ module.exports = { }, schema: [], - fixable: "code" }, diff --git a/lib/rules/no-func-assign.js b/lib/rules/no-func-assign.js index 029f6a9d7d1..ae96ab01f43 100644 --- a/lib/rules/no-func-assign.js +++ b/lib/rules/no-func-assign.js @@ -13,6 +13,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "problem", + docs: { description: "disallow reassigning `function` declarations", category: "Possible Errors", diff --git a/lib/rules/no-global-assign.js b/lib/rules/no-global-assign.js index 3397bdbe000..73f36b25e47 100644 --- a/lib/rules/no-global-assign.js +++ b/lib/rules/no-global-assign.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow assignments to native objects or read-only global variables", category: "Best Practices", diff --git a/lib/rules/no-implicit-coercion.js b/lib/rules/no-implicit-coercion.js index 3bfe3f0d3a2..826d9398cab 100644 --- a/lib/rules/no-implicit-coercion.js +++ b/lib/rules/no-implicit-coercion.js @@ -152,6 +152,8 @@ function getNonEmptyOperand(node) { module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow shorthand type conversions", category: "Best Practices", @@ -160,6 +162,7 @@ module.exports = { }, fixable: "code", + schema: [{ type: "object", properties: { diff --git a/lib/rules/no-implicit-globals.js b/lib/rules/no-implicit-globals.js index c4717b6a374..2eea2b28463 100644 --- a/lib/rules/no-implicit-globals.js +++ b/lib/rules/no-implicit-globals.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow variable and `function` declarations in the global scope", category: "Best Practices", diff --git a/lib/rules/no-implied-eval.js b/lib/rules/no-implied-eval.js index de294bc8858..d31b5dfee80 100644 --- a/lib/rules/no-implied-eval.js +++ b/lib/rules/no-implied-eval.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow the use of `eval()`-like methods", category: "Best Practices", diff --git a/lib/rules/no-inline-comments.js b/lib/rules/no-inline-comments.js index 2fb21909229..c282d16e754 100644 --- a/lib/rules/no-inline-comments.js +++ b/lib/rules/no-inline-comments.js @@ -12,6 +12,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow inline comments after code", category: "Stylistic Issues", diff --git a/lib/rules/no-inner-declarations.js b/lib/rules/no-inner-declarations.js index 032c0a0f096..60508d3e864 100644 --- a/lib/rules/no-inner-declarations.js +++ b/lib/rules/no-inner-declarations.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "problem", + docs: { description: "disallow variable or `function` declarations in nested blocks", category: "Possible Errors", diff --git a/lib/rules/no-invalid-regexp.js b/lib/rules/no-invalid-regexp.js index 7169e0ca770..74659001fdb 100644 --- a/lib/rules/no-invalid-regexp.js +++ b/lib/rules/no-invalid-regexp.js @@ -19,6 +19,8 @@ const undefined1 = void 0; module.exports = { meta: { + type: "problem", + docs: { description: "disallow invalid regular expression strings in `RegExp` constructors", category: "Possible Errors", diff --git a/lib/rules/no-invalid-this.js b/lib/rules/no-invalid-this.js index 480deebc14c..e9be4445260 100644 --- a/lib/rules/no-invalid-this.js +++ b/lib/rules/no-invalid-this.js @@ -17,6 +17,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow `this` keywords outside of classes or class-like objects", category: "Best Practices", diff --git a/lib/rules/no-irregular-whitespace.js b/lib/rules/no-irregular-whitespace.js index de6934c635a..7920ebdc564 100644 --- a/lib/rules/no-irregular-whitespace.js +++ b/lib/rules/no-irregular-whitespace.js @@ -27,6 +27,8 @@ const LINE_BREAK = astUtils.createGlobalLinebreakMatcher(); module.exports = { meta: { + type: "problem", + docs: { description: "disallow irregular whitespace outside of strings and comments", category: "Possible Errors", diff --git a/lib/rules/no-iterator.js b/lib/rules/no-iterator.js index ca12fcda477..82319a3fb1d 100644 --- a/lib/rules/no-iterator.js +++ b/lib/rules/no-iterator.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow the use of the `__iterator__` property", category: "Best Practices", diff --git a/lib/rules/no-label-var.js b/lib/rules/no-label-var.js index 3f5aba4fc1e..fdba2defc35 100644 --- a/lib/rules/no-label-var.js +++ b/lib/rules/no-label-var.js @@ -17,6 +17,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow labels that share a name with a variable", category: "Variables", diff --git a/lib/rules/no-labels.js b/lib/rules/no-labels.js index bd6ec57a350..34db20725b0 100644 --- a/lib/rules/no-labels.js +++ b/lib/rules/no-labels.js @@ -16,6 +16,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow labeled statements", category: "Best Practices", diff --git a/lib/rules/no-lone-blocks.js b/lib/rules/no-lone-blocks.js index 5e22aacf00f..6b51795863b 100644 --- a/lib/rules/no-lone-blocks.js +++ b/lib/rules/no-lone-blocks.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow unnecessary nested blocks", category: "Best Practices", diff --git a/lib/rules/no-lonely-if.js b/lib/rules/no-lonely-if.js index 3ecc41e8cf6..4bbb5399ff9 100644 --- a/lib/rules/no-lonely-if.js +++ b/lib/rules/no-lonely-if.js @@ -10,6 +10,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow `if` statements as the only statement in `else` blocks", category: "Stylistic Issues", @@ -18,7 +20,6 @@ module.exports = { }, schema: [], - fixable: "code" }, diff --git a/lib/rules/no-loop-func.js b/lib/rules/no-loop-func.js index d103cb53350..e6063806a5d 100644 --- a/lib/rules/no-loop-func.js +++ b/lib/rules/no-loop-func.js @@ -154,6 +154,8 @@ function isSafe(loopNode, reference) { module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow `function` declarations and expressions inside loop statements", category: "Best Practices", diff --git a/lib/rules/no-magic-numbers.js b/lib/rules/no-magic-numbers.js index b70ca826750..84c08dfb08e 100644 --- a/lib/rules/no-magic-numbers.js +++ b/lib/rules/no-magic-numbers.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow magic numbers", category: "Best Practices", @@ -40,6 +42,7 @@ module.exports = { }, additionalProperties: false }], + messages: { useConst: "Number constants declarations must use 'const'.", noMagic: "No magic number: {{raw}}." diff --git a/lib/rules/no-misleading-character-class.js b/lib/rules/no-misleading-character-class.js index e410efed9c9..4fa650ed527 100644 --- a/lib/rules/no-misleading-character-class.js +++ b/lib/rules/no-misleading-character-class.js @@ -101,13 +101,17 @@ const kinds = Object.keys(hasCharacterSequence); module.exports = { meta: { + type: "problem", + docs: { description: "disallow characters which are made with multiple code points in character class syntax", category: "Possible Errors", recommended: false, url: "https://eslint.org/docs/rules/no-misleading-character-class" }, + schema: [], + messages: { surrogatePairWithoutUFlag: "Unexpected surrogate pair in character class. Use 'u' flag.", combiningClass: "Unexpected combined character in character class.", diff --git a/lib/rules/no-mixed-operators.js b/lib/rules/no-mixed-operators.js index d4ead20062d..22ed65f5b1f 100644 --- a/lib/rules/no-mixed-operators.js +++ b/lib/rules/no-mixed-operators.js @@ -71,12 +71,15 @@ function includesBothInAGroup(groups, left, right) { module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow mixed binary operators", category: "Stylistic Issues", recommended: false, url: "https://eslint.org/docs/rules/no-mixed-operators" }, + schema: [ { type: "object", diff --git a/lib/rules/no-mixed-requires.js b/lib/rules/no-mixed-requires.js index 1058f3a511e..438ac668a80 100644 --- a/lib/rules/no-mixed-requires.js +++ b/lib/rules/no-mixed-requires.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow `require` calls to be mixed with regular variable declarations", category: "Node.js and CommonJS", diff --git a/lib/rules/no-mixed-spaces-and-tabs.js b/lib/rules/no-mixed-spaces-and-tabs.js index 7cb4b4ceeae..1fc0b6074b8 100644 --- a/lib/rules/no-mixed-spaces-and-tabs.js +++ b/lib/rules/no-mixed-spaces-and-tabs.js @@ -10,6 +10,8 @@ module.exports = { meta: { + type: "layout", + docs: { description: "disallow mixed spaces and tabs for indentation", category: "Stylistic Issues", diff --git a/lib/rules/no-multi-assign.js b/lib/rules/no-multi-assign.js index ca3f778ac6f..8524a1a571e 100644 --- a/lib/rules/no-multi-assign.js +++ b/lib/rules/no-multi-assign.js @@ -12,12 +12,15 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow use of chained assignment expressions", category: "Stylistic Issues", recommended: false, url: "https://eslint.org/docs/rules/no-multi-assign" }, + schema: [] }, diff --git a/lib/rules/no-multi-spaces.js b/lib/rules/no-multi-spaces.js index 41bcd4fb611..f1792c31ed7 100644 --- a/lib/rules/no-multi-spaces.js +++ b/lib/rules/no-multi-spaces.js @@ -13,6 +13,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "disallow multiple spaces", category: "Best Practices", diff --git a/lib/rules/no-multi-str.js b/lib/rules/no-multi-str.js index ee0aaaa4c0c..844842392df 100644 --- a/lib/rules/no-multi-str.js +++ b/lib/rules/no-multi-str.js @@ -17,6 +17,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow multiline strings", category: "Best Practices", diff --git a/lib/rules/no-multiple-empty-lines.js b/lib/rules/no-multiple-empty-lines.js index a111786a308..f945cfeffe2 100644 --- a/lib/rules/no-multiple-empty-lines.js +++ b/lib/rules/no-multiple-empty-lines.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "layout", + docs: { description: "disallow multiple empty lines", category: "Stylistic Issues", diff --git a/lib/rules/no-native-reassign.js b/lib/rules/no-native-reassign.js index f24499b1491..9ecfb4da7cb 100644 --- a/lib/rules/no-native-reassign.js +++ b/lib/rules/no-native-reassign.js @@ -12,6 +12,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow assignments to native objects or read-only global variables", category: "Best Practices", diff --git a/lib/rules/no-negated-condition.js b/lib/rules/no-negated-condition.js index 254dcb5c23c..e55a8287487 100644 --- a/lib/rules/no-negated-condition.js +++ b/lib/rules/no-negated-condition.js @@ -10,6 +10,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow negated conditions", category: "Stylistic Issues", diff --git a/lib/rules/no-negated-in-lhs.js b/lib/rules/no-negated-in-lhs.js index 54252cdbccd..0084ad1570b 100644 --- a/lib/rules/no-negated-in-lhs.js +++ b/lib/rules/no-negated-in-lhs.js @@ -12,16 +12,18 @@ module.exports = { meta: { + type: "problem", + docs: { description: "disallow negating the left operand in `in` expressions", category: "Possible Errors", recommended: false, url: "https://eslint.org/docs/rules/no-negated-in-lhs" }, - deprecated: true, replacedBy: ["no-unsafe-negation"], + deprecated: true, schema: [] }, diff --git a/lib/rules/no-nested-ternary.js b/lib/rules/no-nested-ternary.js index 15e72f20d1c..87a11e87962 100644 --- a/lib/rules/no-nested-ternary.js +++ b/lib/rules/no-nested-ternary.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow nested ternary expressions", category: "Stylistic Issues", diff --git a/lib/rules/no-new-func.js b/lib/rules/no-new-func.js index 8ee327baa1c..23e92f7bf30 100644 --- a/lib/rules/no-new-func.js +++ b/lib/rules/no-new-func.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow `new` operators with the `Function` object", category: "Best Practices", diff --git a/lib/rules/no-new-object.js b/lib/rules/no-new-object.js index 3f68cbc1b51..f5cc28664f4 100644 --- a/lib/rules/no-new-object.js +++ b/lib/rules/no-new-object.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow `Object` constructors", category: "Stylistic Issues", diff --git a/lib/rules/no-new-require.js b/lib/rules/no-new-require.js index f74daa7569c..1eae0659430 100644 --- a/lib/rules/no-new-require.js +++ b/lib/rules/no-new-require.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow `new` operators with calls to `require`", category: "Node.js and CommonJS", diff --git a/lib/rules/no-new-symbol.js b/lib/rules/no-new-symbol.js index a537268e38d..ccf757ed6a0 100644 --- a/lib/rules/no-new-symbol.js +++ b/lib/rules/no-new-symbol.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "problem", + docs: { description: "disallow `new` operators with the `Symbol` object", category: "ECMAScript 6", diff --git a/lib/rules/no-new-wrappers.js b/lib/rules/no-new-wrappers.js index e8d516212b6..ae2aeec0341 100644 --- a/lib/rules/no-new-wrappers.js +++ b/lib/rules/no-new-wrappers.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow `new` operators with the `String`, `Number`, and `Boolean` objects", category: "Best Practices", diff --git a/lib/rules/no-new.js b/lib/rules/no-new.js index f9121bc18f6..2e0702597ea 100644 --- a/lib/rules/no-new.js +++ b/lib/rules/no-new.js @@ -12,6 +12,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow `new` operators outside of assignments or comparisons", category: "Best Practices", diff --git a/lib/rules/no-obj-calls.js b/lib/rules/no-obj-calls.js index 320343cb2c0..92492b7a26e 100644 --- a/lib/rules/no-obj-calls.js +++ b/lib/rules/no-obj-calls.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "problem", + docs: { description: "disallow calling global object properties as functions", category: "Possible Errors", diff --git a/lib/rules/no-octal-escape.js b/lib/rules/no-octal-escape.js index e9509b87f82..fc073b14033 100644 --- a/lib/rules/no-octal-escape.js +++ b/lib/rules/no-octal-escape.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow octal escape sequences in string literals", category: "Best Practices", diff --git a/lib/rules/no-octal.js b/lib/rules/no-octal.js index d782c23a39b..db1fa40aa5d 100644 --- a/lib/rules/no-octal.js +++ b/lib/rules/no-octal.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow octal literals", category: "Best Practices", diff --git a/lib/rules/no-param-reassign.js b/lib/rules/no-param-reassign.js index be1a559178a..243bb6412cf 100644 --- a/lib/rules/no-param-reassign.js +++ b/lib/rules/no-param-reassign.js @@ -12,6 +12,8 @@ const stopNodePattern = /(?:Statement|Declaration|Function(?:Expression)?|Progra module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow reassigning `function` parameters", category: "Best Practices", diff --git a/lib/rules/no-path-concat.js b/lib/rules/no-path-concat.js index 1dee7bda111..dad56a4f56a 100644 --- a/lib/rules/no-path-concat.js +++ b/lib/rules/no-path-concat.js @@ -10,6 +10,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow string concatenation with `__dirname` and `__filename`", category: "Node.js and CommonJS", diff --git a/lib/rules/no-plusplus.js b/lib/rules/no-plusplus.js index f754b367219..4c854de1a06 100644 --- a/lib/rules/no-plusplus.js +++ b/lib/rules/no-plusplus.js @@ -12,6 +12,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow the unary operators `++` and `--`", category: "Stylistic Issues", diff --git a/lib/rules/no-process-env.js b/lib/rules/no-process-env.js index 71b27ffd720..a66d9709b09 100644 --- a/lib/rules/no-process-env.js +++ b/lib/rules/no-process-env.js @@ -10,6 +10,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow the use of `process.env`", category: "Node.js and CommonJS", diff --git a/lib/rules/no-process-exit.js b/lib/rules/no-process-exit.js index 2d22d7fd96a..fcfc6b2af59 100644 --- a/lib/rules/no-process-exit.js +++ b/lib/rules/no-process-exit.js @@ -10,6 +10,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow the use of `process.exit()`", category: "Node.js and CommonJS", diff --git a/lib/rules/no-proto.js b/lib/rules/no-proto.js index e37c6c22e62..80b96509416 100644 --- a/lib/rules/no-proto.js +++ b/lib/rules/no-proto.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow the use of the `__proto__` property", category: "Best Practices", diff --git a/lib/rules/no-prototype-builtins.js b/lib/rules/no-prototype-builtins.js index f52847f44d4..17139530672 100644 --- a/lib/rules/no-prototype-builtins.js +++ b/lib/rules/no-prototype-builtins.js @@ -10,6 +10,8 @@ module.exports = { meta: { + type: "problem", + docs: { description: "disallow calling some `Object.prototype` methods directly on objects", category: "Possible Errors", diff --git a/lib/rules/no-redeclare.js b/lib/rules/no-redeclare.js index 79ab21137ec..e88436d7c57 100644 --- a/lib/rules/no-redeclare.js +++ b/lib/rules/no-redeclare.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow variable redeclaration", category: "Best Practices", diff --git a/lib/rules/no-regex-spaces.js b/lib/rules/no-regex-spaces.js index 089e0602865..d0f7293d20e 100644 --- a/lib/rules/no-regex-spaces.js +++ b/lib/rules/no-regex-spaces.js @@ -13,6 +13,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow multiple spaces in regular expressions", category: "Possible Errors", @@ -21,7 +23,6 @@ module.exports = { }, schema: [], - fixable: "code" }, diff --git a/lib/rules/no-restricted-globals.js b/lib/rules/no-restricted-globals.js index 72b02c032aa..1a2629a8ec9 100644 --- a/lib/rules/no-restricted-globals.js +++ b/lib/rules/no-restricted-globals.js @@ -17,6 +17,8 @@ const DEFAULT_MESSAGE_TEMPLATE = "Unexpected use of '{{name}}'.", module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow specified global variables", category: "Variables", diff --git a/lib/rules/no-restricted-imports.js b/lib/rules/no-restricted-imports.js index fdebb8ca3ad..e4563172e0b 100644 --- a/lib/rules/no-restricted-imports.js +++ b/lib/rules/no-restricted-imports.js @@ -53,6 +53,8 @@ const arrayOfStringsOrObjects = { module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow specified modules when loaded by `import`", category: "ECMAScript 6", diff --git a/lib/rules/no-restricted-modules.js b/lib/rules/no-restricted-modules.js index d63d2ce4f45..ef8748a7d04 100644 --- a/lib/rules/no-restricted-modules.js +++ b/lib/rules/no-restricted-modules.js @@ -47,6 +47,8 @@ const arrayOfStringsOrObjects = { module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow specified modules when loaded by `require`", category: "Node.js and CommonJS", diff --git a/lib/rules/no-restricted-properties.js b/lib/rules/no-restricted-properties.js index c0f1cfb6d38..eede6ad1c16 100644 --- a/lib/rules/no-restricted-properties.js +++ b/lib/rules/no-restricted-properties.js @@ -13,6 +13,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow certain properties on certain objects", category: "Best Practices", diff --git a/lib/rules/no-restricted-syntax.js b/lib/rules/no-restricted-syntax.js index c472d9432e6..74eea147891 100644 --- a/lib/rules/no-restricted-syntax.js +++ b/lib/rules/no-restricted-syntax.js @@ -10,6 +10,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow specified syntax", category: "Stylistic Issues", diff --git a/lib/rules/no-return-assign.js b/lib/rules/no-return-assign.js index 519f9e0d039..b3c39ea2b8c 100644 --- a/lib/rules/no-return-assign.js +++ b/lib/rules/no-return-assign.js @@ -22,6 +22,8 @@ const SENTINEL_TYPE = /^(?:[a-zA-Z]+?Statement|ArrowFunctionExpression|FunctionE module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow assignment operators in `return` statements", category: "Best Practices", diff --git a/lib/rules/no-return-await.js b/lib/rules/no-return-await.js index 5f531a18310..24cb45ee5a7 100644 --- a/lib/rules/no-return-await.js +++ b/lib/rules/no-return-await.js @@ -14,6 +14,8 @@ const message = "Redundant use of `await` on a return value."; module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow unnecessary `return await`", category: "Best Practices", @@ -22,7 +24,9 @@ module.exports = { url: "https://eslint.org/docs/rules/no-return-await" }, + fixable: null, + schema: [ ] }, diff --git a/lib/rules/no-script-url.js b/lib/rules/no-script-url.js index ba74dafb8e2..40e9bfe8b27 100644 --- a/lib/rules/no-script-url.js +++ b/lib/rules/no-script-url.js @@ -13,6 +13,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow `javascript:` urls", category: "Best Practices", diff --git a/lib/rules/no-self-assign.js b/lib/rules/no-self-assign.js index 87d1f2ff4f7..d493855efe9 100644 --- a/lib/rules/no-self-assign.js +++ b/lib/rules/no-self-assign.js @@ -165,6 +165,8 @@ function eachSelfAssignment(left, right, props, report) { module.exports = { meta: { + type: "problem", + docs: { description: "disallow assignments where both sides are exactly the same", category: "Best Practices", diff --git a/lib/rules/no-self-compare.js b/lib/rules/no-self-compare.js index 6ebc3870feb..8986240ec5c 100644 --- a/lib/rules/no-self-compare.js +++ b/lib/rules/no-self-compare.js @@ -12,6 +12,8 @@ module.exports = { meta: { + type: "problem", + docs: { description: "disallow comparisons where both sides are exactly the same", category: "Best Practices", diff --git a/lib/rules/no-sequences.js b/lib/rules/no-sequences.js index e74943d8109..2570912f348 100644 --- a/lib/rules/no-sequences.js +++ b/lib/rules/no-sequences.js @@ -17,6 +17,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow comma operators", category: "Best Practices", diff --git a/lib/rules/no-shadow-restricted-names.js b/lib/rules/no-shadow-restricted-names.js index 70052f56f2d..9bdd5086804 100644 --- a/lib/rules/no-shadow-restricted-names.js +++ b/lib/rules/no-shadow-restricted-names.js @@ -10,6 +10,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow identifiers from shadowing restricted names", category: "Variables", diff --git a/lib/rules/no-shadow.js b/lib/rules/no-shadow.js index 955fc05e582..f910230d6a2 100644 --- a/lib/rules/no-shadow.js +++ b/lib/rules/no-shadow.js @@ -17,6 +17,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow variable declarations from shadowing variables declared in the outer scope", category: "Variables", diff --git a/lib/rules/no-spaced-func.js b/lib/rules/no-spaced-func.js index 1f584f88bf2..8535881f435 100644 --- a/lib/rules/no-spaced-func.js +++ b/lib/rules/no-spaced-func.js @@ -12,6 +12,8 @@ module.exports = { meta: { + type: "layout", + docs: { description: "disallow spacing between function identifiers and their applications (deprecated)", category: "Stylistic Issues", diff --git a/lib/rules/no-sparse-arrays.js b/lib/rules/no-sparse-arrays.js index 1cc6f7ccba9..985109c36b2 100644 --- a/lib/rules/no-sparse-arrays.js +++ b/lib/rules/no-sparse-arrays.js @@ -10,6 +10,8 @@ module.exports = { meta: { + type: "problem", + docs: { description: "disallow sparse arrays", category: "Possible Errors", diff --git a/lib/rules/no-sync.js b/lib/rules/no-sync.js index eb7b787d38c..a0096e3d043 100644 --- a/lib/rules/no-sync.js +++ b/lib/rules/no-sync.js @@ -13,6 +13,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow synchronous methods", category: "Node.js and CommonJS", diff --git a/lib/rules/no-tabs.js b/lib/rules/no-tabs.js index c22a94da38b..0002f559290 100644 --- a/lib/rules/no-tabs.js +++ b/lib/rules/no-tabs.js @@ -18,6 +18,8 @@ const anyNonWhitespaceRegex = /\S/; module.exports = { meta: { + type: "layout", + docs: { description: "disallow all tabs", category: "Stylistic Issues", diff --git a/lib/rules/no-template-curly-in-string.js b/lib/rules/no-template-curly-in-string.js index ed74fcc6f7f..c286ec69000 100644 --- a/lib/rules/no-template-curly-in-string.js +++ b/lib/rules/no-template-curly-in-string.js @@ -10,6 +10,8 @@ module.exports = { meta: { + type: "problem", + docs: { description: "disallow template literal placeholder syntax in regular strings", category: "Possible Errors", diff --git a/lib/rules/no-ternary.js b/lib/rules/no-ternary.js index 4dcc8db069e..890f2abfa0c 100644 --- a/lib/rules/no-ternary.js +++ b/lib/rules/no-ternary.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow ternary operators", category: "Stylistic Issues", diff --git a/lib/rules/no-this-before-super.js b/lib/rules/no-this-before-super.js index 8a489879edd..93fb094e9bc 100644 --- a/lib/rules/no-this-before-super.js +++ b/lib/rules/no-this-before-super.js @@ -36,6 +36,8 @@ function isConstructorFunction(node) { module.exports = { meta: { + type: "problem", + docs: { description: "disallow `this`/`super` before calling `super()` in constructors", category: "ECMAScript 6", diff --git a/lib/rules/no-throw-literal.js b/lib/rules/no-throw-literal.js index 301354b6b2c..c4a6b86bfb4 100644 --- a/lib/rules/no-throw-literal.js +++ b/lib/rules/no-throw-literal.js @@ -13,6 +13,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow throwing literals as exceptions", category: "Best Practices", diff --git a/lib/rules/no-trailing-spaces.js b/lib/rules/no-trailing-spaces.js index cca7af2aac3..18f0340ef01 100644 --- a/lib/rules/no-trailing-spaces.js +++ b/lib/rules/no-trailing-spaces.js @@ -16,6 +16,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "disallow trailing whitespace at the end of lines", category: "Stylistic Issues", diff --git a/lib/rules/no-undef-init.js b/lib/rules/no-undef-init.js index f00b05d4ff0..67f3944d47e 100644 --- a/lib/rules/no-undef-init.js +++ b/lib/rules/no-undef-init.js @@ -13,6 +13,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow initializing variables to `undefined`", category: "Variables", @@ -21,7 +23,6 @@ module.exports = { }, schema: [], - fixable: "code" }, diff --git a/lib/rules/no-undef.js b/lib/rules/no-undef.js index c8347d50d1a..f923644eca1 100644 --- a/lib/rules/no-undef.js +++ b/lib/rules/no-undef.js @@ -25,6 +25,8 @@ function hasTypeOfOperator(node) { module.exports = { meta: { + type: "problem", + docs: { description: "disallow the use of undeclared variables unless mentioned in `/*global */` comments", category: "Variables", diff --git a/lib/rules/no-undefined.js b/lib/rules/no-undefined.js index 8491ab5d540..b92f6700637 100644 --- a/lib/rules/no-undefined.js +++ b/lib/rules/no-undefined.js @@ -10,6 +10,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow the use of `undefined` as an identifier", category: "Variables", diff --git a/lib/rules/no-underscore-dangle.js b/lib/rules/no-underscore-dangle.js index c76488a9431..926803b992d 100644 --- a/lib/rules/no-underscore-dangle.js +++ b/lib/rules/no-underscore-dangle.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow dangling underscores in identifiers", category: "Stylistic Issues", diff --git a/lib/rules/no-unexpected-multiline.js b/lib/rules/no-unexpected-multiline.js index 181a00b2d0d..3bed96fc77d 100644 --- a/lib/rules/no-unexpected-multiline.js +++ b/lib/rules/no-unexpected-multiline.js @@ -16,6 +16,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "problem", + docs: { description: "disallow confusing multiline expressions", category: "Possible Errors", diff --git a/lib/rules/no-unmodified-loop-condition.js b/lib/rules/no-unmodified-loop-condition.js index fecd8ba5cca..95898c5f19d 100644 --- a/lib/rules/no-unmodified-loop-condition.js +++ b/lib/rules/no-unmodified-loop-condition.js @@ -165,6 +165,8 @@ function updateModifiedFlag(conditions, modifiers) { module.exports = { meta: { + type: "problem", + docs: { description: "disallow unmodified loop conditions", category: "Best Practices", diff --git a/lib/rules/no-unneeded-ternary.js b/lib/rules/no-unneeded-ternary.js index 6b58b018da0..3a7dd5fad7d 100644 --- a/lib/rules/no-unneeded-ternary.js +++ b/lib/rules/no-unneeded-ternary.js @@ -24,6 +24,8 @@ const OPERATOR_INVERSES = { module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow ternary operators when simpler alternatives exist", category: "Stylistic Issues", diff --git a/lib/rules/no-unreachable.js b/lib/rules/no-unreachable.js index 80d246307c3..5f90500a090 100644 --- a/lib/rules/no-unreachable.js +++ b/lib/rules/no-unreachable.js @@ -101,6 +101,8 @@ class ConsecutiveRange { module.exports = { meta: { + type: "problem", + docs: { description: "disallow unreachable code after `return`, `throw`, `continue`, and `break` statements", category: "Possible Errors", diff --git a/lib/rules/no-unsafe-finally.js b/lib/rules/no-unsafe-finally.js index 1ebdd2e3775..ab612ae6526 100644 --- a/lib/rules/no-unsafe-finally.js +++ b/lib/rules/no-unsafe-finally.js @@ -20,6 +20,8 @@ const SENTINEL_NODE_TYPE_CONTINUE = /^(?:Program|(?:Function|Class)(?:Declaratio module.exports = { meta: { + type: "problem", + docs: { description: "disallow control flow statements in `finally` blocks", category: "Possible Errors", diff --git a/lib/rules/no-unsafe-negation.js b/lib/rules/no-unsafe-negation.js index b04f80106c6..3a0402eb0d5 100644 --- a/lib/rules/no-unsafe-negation.js +++ b/lib/rules/no-unsafe-negation.js @@ -41,12 +41,15 @@ function isNegation(node) { module.exports = { meta: { + type: "problem", + docs: { description: "disallow negating the left operand of relational operators", category: "Possible Errors", recommended: true, url: "https://eslint.org/docs/rules/no-unsafe-negation" }, + schema: [], fixable: "code" }, diff --git a/lib/rules/no-unused-expressions.js b/lib/rules/no-unused-expressions.js index fedfac17d1f..854298b4119 100644 --- a/lib/rules/no-unused-expressions.js +++ b/lib/rules/no-unused-expressions.js @@ -10,6 +10,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow unused expressions", category: "Best Practices", diff --git a/lib/rules/no-unused-labels.js b/lib/rules/no-unused-labels.js index 3e1dcb6601f..c9e097df458 100644 --- a/lib/rules/no-unused-labels.js +++ b/lib/rules/no-unused-labels.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow unused labels", category: "Best Practices", @@ -19,7 +21,6 @@ module.exports = { }, schema: [], - fixable: "code" }, diff --git a/lib/rules/no-unused-vars.js b/lib/rules/no-unused-vars.js index 6f36813aca5..4bd4146ce99 100644 --- a/lib/rules/no-unused-vars.js +++ b/lib/rules/no-unused-vars.js @@ -18,6 +18,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "problem", + docs: { description: "disallow unused variables", category: "Variables", @@ -372,22 +374,18 @@ module.exports = { return ref.isRead() && ( // self update. e.g. `a += 1`, `a++` - ( - parent.type === "AssignmentExpression" && + (// in RHS of an assignment for itself. e.g. `a = a + 1` + (( + parent.type === "AssignmentExpression" && granpa.type === "ExpressionStatement" && parent.left === id - ) || + ) || ( parent.type === "UpdateExpression" && granpa.type === "ExpressionStatement" - ) || - - // in RHS of an assignment for itself. e.g. `a = a + 1` - ( - rhsNode && - isInside(id, rhsNode) && - !isInsideOfStorableFunction(id, rhsNode) - ) + ) || rhsNode && + isInside(id, rhsNode) && + !isInsideOfStorableFunction(id, rhsNode))) ); } diff --git a/lib/rules/no-use-before-define.js b/lib/rules/no-use-before-define.js index 64d82570279..500cd3a4103 100644 --- a/lib/rules/no-use-before-define.js +++ b/lib/rules/no-use-before-define.js @@ -136,6 +136,8 @@ function isInInitializer(variable, reference) { module.exports = { meta: { + type: "problem", + docs: { description: "disallow the use of variables before they are defined", category: "Variables", diff --git a/lib/rules/no-useless-call.js b/lib/rules/no-useless-call.js index 0778b374f4f..74e8bec08bc 100644 --- a/lib/rules/no-useless-call.js +++ b/lib/rules/no-useless-call.js @@ -49,6 +49,8 @@ function isValidThisArg(expectedThis, thisArg, sourceCode) { module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow unnecessary calls to `.call()` and `.apply()`", category: "Best Practices", diff --git a/lib/rules/no-useless-computed-key.js b/lib/rules/no-useless-computed-key.js index 189f50853c8..ef1f856f3ef 100644 --- a/lib/rules/no-useless-computed-key.js +++ b/lib/rules/no-useless-computed-key.js @@ -18,6 +18,8 @@ const MESSAGE_UNNECESSARY_COMPUTED = "Unnecessarily computed property [{{propert module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow unnecessary computed property keys in object literals", category: "ECMAScript 6", @@ -26,7 +28,6 @@ module.exports = { }, schema: [], - fixable: "code" }, create(context) { diff --git a/lib/rules/no-useless-concat.js b/lib/rules/no-useless-concat.js index e8e36aa1c1a..df310119032 100644 --- a/lib/rules/no-useless-concat.js +++ b/lib/rules/no-useless-concat.js @@ -66,6 +66,8 @@ function getRight(node) { module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow unnecessary concatenation of literals or template literals", category: "Best Practices", diff --git a/lib/rules/no-useless-constructor.js b/lib/rules/no-useless-constructor.js index 59e40bef8f4..c10376450eb 100644 --- a/lib/rules/no-useless-constructor.js +++ b/lib/rules/no-useless-constructor.js @@ -142,6 +142,8 @@ function isRedundantSuperCall(body, ctorParams) { module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow unnecessary constructors", category: "ECMAScript 6", diff --git a/lib/rules/no-useless-escape.js b/lib/rules/no-useless-escape.js index 7f4b87ed92c..c3c0421cc0c 100644 --- a/lib/rules/no-useless-escape.js +++ b/lib/rules/no-useless-escape.js @@ -79,6 +79,8 @@ function parseRegExp(regExpText) { module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow unnecessary escape characters", category: "Best Practices", diff --git a/lib/rules/no-useless-rename.js b/lib/rules/no-useless-rename.js index 83a03deb630..337f875b456 100644 --- a/lib/rules/no-useless-rename.js +++ b/lib/rules/no-useless-rename.js @@ -11,13 +11,17 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow renaming import, export, and destructured assignments to the same name", category: "ECMAScript 6", recommended: false, url: "https://eslint.org/docs/rules/no-useless-rename" }, + fixable: "code", + schema: [ { type: "object", diff --git a/lib/rules/no-useless-return.js b/lib/rules/no-useless-return.js index b5b8ebc32a1..bb11b4b3619 100644 --- a/lib/rules/no-useless-return.js +++ b/lib/rules/no-useless-return.js @@ -66,12 +66,15 @@ function isInFinally(node) { module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow redundant return statements", category: "Best Practices", recommended: false, url: "https://eslint.org/docs/rules/no-useless-return" }, + fixable: "code", schema: [] }, diff --git a/lib/rules/no-var.js b/lib/rules/no-var.js index 2c32a023dc9..edaed98f62e 100644 --- a/lib/rules/no-var.js +++ b/lib/rules/no-var.js @@ -180,6 +180,8 @@ function hasReferenceInTDZ(node) { module.exports = { meta: { + type: "suggestion", + docs: { description: "require `let` or `const` instead of `var`", category: "ECMAScript 6", diff --git a/lib/rules/no-void.js b/lib/rules/no-void.js index 1d3d887da66..d2b5d2f9631 100644 --- a/lib/rules/no-void.js +++ b/lib/rules/no-void.js @@ -10,6 +10,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow `void` operators", category: "Best Practices", diff --git a/lib/rules/no-warning-comments.js b/lib/rules/no-warning-comments.js index 5ff76e3a391..9ea39b490f8 100644 --- a/lib/rules/no-warning-comments.js +++ b/lib/rules/no-warning-comments.js @@ -13,6 +13,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow specified warning terms in comments", category: "Best Practices", diff --git a/lib/rules/no-whitespace-before-property.js b/lib/rules/no-whitespace-before-property.js index 4b71a9ec17d..1ecc51db67c 100644 --- a/lib/rules/no-whitespace-before-property.js +++ b/lib/rules/no-whitespace-before-property.js @@ -16,6 +16,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "disallow whitespace before properties", category: "Stylistic Issues", diff --git a/lib/rules/no-with.js b/lib/rules/no-with.js index d72dcdfb21e..ecdf22c7d91 100644 --- a/lib/rules/no-with.js +++ b/lib/rules/no-with.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow `with` statements", category: "Best Practices", diff --git a/lib/rules/nonblock-statement-body-position.js b/lib/rules/nonblock-statement-body-position.js index e447ef886b3..01763cea92f 100644 --- a/lib/rules/nonblock-statement-body-position.js +++ b/lib/rules/nonblock-statement-body-position.js @@ -12,13 +12,17 @@ const POSITION_SCHEMA = { enum: ["beside", "below", "any"] }; module.exports = { meta: { + type: "layout", + docs: { description: "enforce the location of single-line statements", category: "Stylistic Issues", recommended: false, url: "https://eslint.org/docs/rules/nonblock-statement-body-position" }, + fixable: "whitespace", + schema: [ POSITION_SCHEMA, { diff --git a/lib/rules/object-curly-newline.js b/lib/rules/object-curly-newline.js index 494e78cff4a..c460ea56bc3 100644 --- a/lib/rules/object-curly-newline.js +++ b/lib/rules/object-curly-newline.js @@ -134,13 +134,17 @@ function areLineBreaksRequired(node, options, first, last) { module.exports = { meta: { + type: "layout", + docs: { description: "enforce consistent line breaks inside braces", category: "Stylistic Issues", recommended: false, url: "https://eslint.org/docs/rules/object-curly-newline" }, + fixable: "whitespace", + schema: [ { oneOf: [ diff --git a/lib/rules/object-curly-spacing.js b/lib/rules/object-curly-spacing.js index e7c847a6a95..bde4f14253e 100644 --- a/lib/rules/object-curly-spacing.js +++ b/lib/rules/object-curly-spacing.js @@ -12,6 +12,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "enforce consistent spacing inside braces", category: "Stylistic Issues", diff --git a/lib/rules/object-property-newline.js b/lib/rules/object-property-newline.js index 65baf0a95e3..3e2c0171577 100644 --- a/lib/rules/object-property-newline.js +++ b/lib/rules/object-property-newline.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "layout", + docs: { description: "enforce placing object properties on separate lines", category: "Stylistic Issues", @@ -38,8 +40,7 @@ module.exports = { create(context) { const allowSameLine = context.options[0] && ( - Boolean(context.options[0].allowAllPropertiesOnSameLine) || - Boolean(context.options[0].allowMultiplePropertiesPerLine) // Deprecated + (Boolean(context.options[0].allowAllPropertiesOnSameLine) || Boolean(context.options[0].allowMultiplePropertiesPerLine)) // Deprecated ); const errorMessage = allowSameLine ? "Object properties must go on a new line if they aren't all on the same line." diff --git a/lib/rules/object-shorthand.js b/lib/rules/object-shorthand.js index 21f039f8b6e..ff6a51a4d17 100644 --- a/lib/rules/object-shorthand.js +++ b/lib/rules/object-shorthand.js @@ -24,6 +24,8 @@ const astUtils = require("../util/ast-utils"); //------------------------------------------------------------------------------ module.exports = { meta: { + type: "suggestion", + docs: { description: "require or disallow method and property shorthand syntax for object literals", category: "ECMAScript 6", diff --git a/lib/rules/one-var-declaration-per-line.js b/lib/rules/one-var-declaration-per-line.js index e17529b6bed..e7e40d66c0c 100644 --- a/lib/rules/one-var-declaration-per-line.js +++ b/lib/rules/one-var-declaration-per-line.js @@ -10,6 +10,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "require or disallow newlines around variable declarations", category: "Stylistic Issues", diff --git a/lib/rules/one-var.js b/lib/rules/one-var.js index 3efd0f27f7f..44f05fb700a 100644 --- a/lib/rules/one-var.js +++ b/lib/rules/one-var.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "enforce variables to be declared either together or separately in functions", category: "Stylistic Issues", diff --git a/lib/rules/operator-assignment.js b/lib/rules/operator-assignment.js index 8e4b7025eda..8bb01737dd6 100644 --- a/lib/rules/operator-assignment.js +++ b/lib/rules/operator-assignment.js @@ -89,6 +89,8 @@ function canBeFixed(node) { module.exports = { meta: { + type: "suggestion", + docs: { description: "require or disallow assignment operator shorthand where possible", category: "Stylistic Issues", diff --git a/lib/rules/operator-linebreak.js b/lib/rules/operator-linebreak.js index be2709a1bda..cd6e996b1b1 100644 --- a/lib/rules/operator-linebreak.js +++ b/lib/rules/operator-linebreak.js @@ -17,6 +17,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "enforce consistent linebreak style for operators", category: "Stylistic Issues", diff --git a/lib/rules/padded-blocks.js b/lib/rules/padded-blocks.js index 370d47bccff..7c0b56ba7f8 100644 --- a/lib/rules/padded-blocks.js +++ b/lib/rules/padded-blocks.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "layout", + docs: { description: "require or disallow padding within blocks", category: "Stylistic Issues", diff --git a/lib/rules/padding-line-between-statements.js b/lib/rules/padding-line-between-statements.js index 4af85fef015..3e55a2516d0 100644 --- a/lib/rules/padding-line-between-statements.js +++ b/lib/rules/padding-line-between-statements.js @@ -400,13 +400,17 @@ const StatementTypes = { module.exports = { meta: { + type: "layout", + docs: { description: "require or disallow padding lines between statements", category: "Stylistic Issues", recommended: false, url: "https://eslint.org/docs/rules/padding-line-between-statements" }, + fixable: "whitespace", + schema: { definitions: { paddingType: { diff --git a/lib/rules/prefer-arrow-callback.js b/lib/rules/prefer-arrow-callback.js index 1bc140b101b..b4bbf33f296 100644 --- a/lib/rules/prefer-arrow-callback.js +++ b/lib/rules/prefer-arrow-callback.js @@ -132,6 +132,8 @@ function hasDuplicateParams(paramsList) { module.exports = { meta: { + type: "suggestion", + docs: { description: "require using arrow functions for callbacks", category: "ECMAScript 6", diff --git a/lib/rules/prefer-const.js b/lib/rules/prefer-const.js index 8b3bc5e0e43..acf846c998a 100644 --- a/lib/rules/prefer-const.js +++ b/lib/rules/prefer-const.js @@ -330,6 +330,8 @@ function findUp(node, type, shouldStop) { module.exports = { meta: { + type: "suggestion", + docs: { description: "require `const` declarations for variables that are never reassigned after declared", category: "ECMAScript 6", diff --git a/lib/rules/prefer-destructuring.js b/lib/rules/prefer-destructuring.js index 112ea64613c..119fae56089 100644 --- a/lib/rules/prefer-destructuring.js +++ b/lib/rules/prefer-destructuring.js @@ -10,12 +10,15 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "require destructuring from arrays and/or objects", category: "ECMAScript 6", recommended: false, url: "https://eslint.org/docs/rules/prefer-destructuring" }, + schema: [ { diff --git a/lib/rules/prefer-numeric-literals.js b/lib/rules/prefer-numeric-literals.js index 051a91c81cb..ca7358aa013 100644 --- a/lib/rules/prefer-numeric-literals.js +++ b/lib/rules/prefer-numeric-literals.js @@ -38,6 +38,8 @@ function isParseInt(calleeNode) { module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow `parseInt()` and `Number.parseInt()` in favor of binary, octal, and hexadecimal literals", category: "ECMAScript 6", @@ -46,7 +48,6 @@ module.exports = { }, schema: [], - fixable: "code" }, diff --git a/lib/rules/prefer-object-spread.js b/lib/rules/prefer-object-spread.js index 8e54de2496a..a8dac696be0 100644 --- a/lib/rules/prefer-object-spread.js +++ b/lib/rules/prefer-object-spread.js @@ -212,6 +212,8 @@ function defineFixer(node, sourceCode) { module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow using Object.assign with an object literal as the first argument and prefer the use of object spread instead.", @@ -219,8 +221,10 @@ module.exports = { recommended: false, url: "https://eslint.org/docs/rules/prefer-object-spread" }, + schema: [], fixable: "code", + messages: { useSpreadMessage: "Use an object spread instead of `Object.assign` eg: `{ ...foo }`", useLiteralMessage: "Use an object literal instead of `Object.assign`. eg: `{ foo: bar }`" diff --git a/lib/rules/prefer-promise-reject-errors.js b/lib/rules/prefer-promise-reject-errors.js index e3d298a743c..0db5ae874cf 100644 --- a/lib/rules/prefer-promise-reject-errors.js +++ b/lib/rules/prefer-promise-reject-errors.js @@ -12,13 +12,17 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "require using Error objects as Promise rejection reasons", category: "Best Practices", recommended: false, url: "https://eslint.org/docs/rules/prefer-promise-reject-errors" }, + fixable: null, + schema: [ { type: "object", diff --git a/lib/rules/prefer-reflect.js b/lib/rules/prefer-reflect.js index bda827cb7a6..796bbdf05fd 100644 --- a/lib/rules/prefer-reflect.js +++ b/lib/rules/prefer-reflect.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "require `Reflect` methods where applicable", category: "ECMAScript 6", diff --git a/lib/rules/prefer-rest-params.js b/lib/rules/prefer-rest-params.js index 133456e4d17..95a562c4a2f 100644 --- a/lib/rules/prefer-rest-params.js +++ b/lib/rules/prefer-rest-params.js @@ -62,6 +62,8 @@ function isNotNormalMemberAccess(reference) { module.exports = { meta: { + type: "suggestion", + docs: { description: "require rest parameters instead of `arguments`", category: "ECMAScript 6", diff --git a/lib/rules/prefer-spread.js b/lib/rules/prefer-spread.js index 9bf69c80f7b..790fd3b82aa 100644 --- a/lib/rules/prefer-spread.js +++ b/lib/rules/prefer-spread.js @@ -49,6 +49,8 @@ function isValidThisArg(expectedThis, thisArg, context) { module.exports = { meta: { + type: "suggestion", + docs: { description: "require spread operators instead of `.apply()`", category: "ECMAScript 6", @@ -57,7 +59,6 @@ module.exports = { }, schema: [], - fixable: "code" }, diff --git a/lib/rules/prefer-template.js b/lib/rules/prefer-template.js index 0471d61caef..386674a92ef 100644 --- a/lib/rules/prefer-template.js +++ b/lib/rules/prefer-template.js @@ -141,6 +141,8 @@ function endsWithTemplateCurly(node) { module.exports = { meta: { + type: "suggestion", + docs: { description: "require template literals instead of string concatenation", category: "ECMAScript 6", @@ -149,7 +151,6 @@ module.exports = { }, schema: [], - fixable: "code" }, diff --git a/lib/rules/quote-props.js b/lib/rules/quote-props.js index 36739494da4..7184bd34d35 100644 --- a/lib/rules/quote-props.js +++ b/lib/rules/quote-props.js @@ -17,6 +17,8 @@ const espree = require("espree"), module.exports = { meta: { + type: "suggestion", + docs: { description: "require quotes around object literal property names", category: "Stylistic Issues", diff --git a/lib/rules/quotes.js b/lib/rules/quotes.js index 8dd61c3e371..e0db17fcb7c 100644 --- a/lib/rules/quotes.js +++ b/lib/rules/quotes.js @@ -76,6 +76,8 @@ const AVOID_ESCAPE = "avoid-escape"; module.exports = { meta: { + type: "layout", + docs: { description: "enforce the consistent use of either backticks, double, or single quotes", category: "Stylistic Issues", diff --git a/lib/rules/radix.js b/lib/rules/radix.js index f71220beb4e..5d3805d0a70 100644 --- a/lib/rules/radix.js +++ b/lib/rules/radix.js @@ -78,6 +78,8 @@ function isDefaultRadix(radix) { module.exports = { meta: { + type: "suggestion", + docs: { description: "enforce the consistent use of the radix argument when using `parseInt()`", category: "Best Practices", diff --git a/lib/rules/require-atomic-updates.js b/lib/rules/require-atomic-updates.js index c6cf0d74774..e8dbe17b88d 100644 --- a/lib/rules/require-atomic-updates.js +++ b/lib/rules/require-atomic-updates.js @@ -12,14 +12,18 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "problem", + docs: { description: "disallow assignments that can lead to race conditions due to usage of `await` or `yield`", category: "Possible Errors", recommended: false, url: "https://eslint.org/docs/rules/require-atomic-updates" }, + fixable: null, schema: [], + messages: { nonAtomicUpdate: "Possible race condition: `{{value}}` might be reassigned based on an outdated value of `{{value}}`." } diff --git a/lib/rules/require-await.js b/lib/rules/require-await.js index de39f372fd6..5e614c50251 100644 --- a/lib/rules/require-await.js +++ b/lib/rules/require-await.js @@ -31,12 +31,15 @@ function capitalizeFirstLetter(text) { module.exports = { meta: { + type: "suggestion", + docs: { description: "disallow async functions which have no `await` expression", category: "Best Practices", recommended: false, url: "https://eslint.org/docs/rules/require-await" }, + schema: [] }, diff --git a/lib/rules/require-jsdoc.js b/lib/rules/require-jsdoc.js index 91b90b7d10a..949314993b6 100644 --- a/lib/rules/require-jsdoc.js +++ b/lib/rules/require-jsdoc.js @@ -6,6 +6,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "require JSDoc comments", category: "Stylistic Issues", diff --git a/lib/rules/require-unicode-regexp.js b/lib/rules/require-unicode-regexp.js index 55ca4ff89a6..880405e9a25 100644 --- a/lib/rules/require-unicode-regexp.js +++ b/lib/rules/require-unicode-regexp.js @@ -22,15 +22,19 @@ const { module.exports = { meta: { + type: "suggestion", + docs: { description: "enforce the use of `u` flag on RegExp", category: "Best Practices", recommended: false, url: "https://eslint.org/docs/rules/require-unicode-regexp" }, + messages: { requireUFlag: "Use the 'u' flag." }, + schema: [] }, diff --git a/lib/rules/require-yield.js b/lib/rules/require-yield.js index 83a29876f09..7bb7cf9a872 100644 --- a/lib/rules/require-yield.js +++ b/lib/rules/require-yield.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "require generator functions to contain `yield`", category: "ECMAScript 6", diff --git a/lib/rules/rest-spread-spacing.js b/lib/rules/rest-spread-spacing.js index e87d881298b..04539395ef4 100644 --- a/lib/rules/rest-spread-spacing.js +++ b/lib/rules/rest-spread-spacing.js @@ -11,13 +11,17 @@ module.exports = { meta: { + type: "layout", + docs: { description: "enforce spacing between rest and spread operators and their expressions", category: "ECMAScript 6", recommended: false, url: "https://eslint.org/docs/rules/rest-spread-spacing" }, + fixable: "whitespace", + schema: [ { enum: ["always", "never"] diff --git a/lib/rules/semi-spacing.js b/lib/rules/semi-spacing.js index 75b53055a69..56ae687d856 100644 --- a/lib/rules/semi-spacing.js +++ b/lib/rules/semi-spacing.js @@ -13,6 +13,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "enforce consistent spacing before and after semicolons", category: "Stylistic Issues", diff --git a/lib/rules/semi-style.js b/lib/rules/semi-style.js index 34899bb5444..dd76b68f82b 100644 --- a/lib/rules/semi-style.js +++ b/lib/rules/semi-style.js @@ -65,12 +65,15 @@ function isLastChild(node) { module.exports = { meta: { + type: "layout", + docs: { description: "enforce location of semicolons", category: "Stylistic Issues", recommended: false, url: "https://eslint.org/docs/rules/semi-style" }, + schema: [{ enum: ["last", "first"] }], fixable: "whitespace" }, diff --git a/lib/rules/semi.js b/lib/rules/semi.js index 129d106414d..e8f4c959d4c 100644 --- a/lib/rules/semi.js +++ b/lib/rules/semi.js @@ -17,6 +17,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "require or disallow semicolons instead of ASI", category: "Stylistic Issues", diff --git a/lib/rules/sort-imports.js b/lib/rules/sort-imports.js index 8735be5d307..76997cc73d8 100644 --- a/lib/rules/sort-imports.js +++ b/lib/rules/sort-imports.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "enforce sorted import declarations within modules", category: "ECMAScript 6", diff --git a/lib/rules/sort-keys.js b/lib/rules/sort-keys.js index 6e538f73291..0668e617d3c 100644 --- a/lib/rules/sort-keys.js +++ b/lib/rules/sort-keys.js @@ -73,12 +73,15 @@ const isValidOrders = { module.exports = { meta: { + type: "suggestion", + docs: { description: "require object keys to be sorted", category: "Stylistic Issues", recommended: false, url: "https://eslint.org/docs/rules/sort-keys" }, + schema: [ { enum: ["asc", "desc"] diff --git a/lib/rules/sort-vars.js b/lib/rules/sort-vars.js index 334deb0657f..b6a2c86779c 100644 --- a/lib/rules/sort-vars.js +++ b/lib/rules/sort-vars.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "require variables within the same declaration block to be sorted", category: "Stylistic Issues", diff --git a/lib/rules/space-before-blocks.js b/lib/rules/space-before-blocks.js index 4f22ae6b653..195c756593e 100644 --- a/lib/rules/space-before-blocks.js +++ b/lib/rules/space-before-blocks.js @@ -13,6 +13,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "enforce consistent spacing before blocks", category: "Stylistic Issues", diff --git a/lib/rules/space-before-function-paren.js b/lib/rules/space-before-function-paren.js index 81697d64f1f..64ba72bf9ea 100644 --- a/lib/rules/space-before-function-paren.js +++ b/lib/rules/space-before-function-paren.js @@ -16,6 +16,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "enforce consistent spacing before `function` definition opening parenthesis", category: "Stylistic Issues", diff --git a/lib/rules/space-in-parens.js b/lib/rules/space-in-parens.js index aa137438034..88f4f0b50e1 100644 --- a/lib/rules/space-in-parens.js +++ b/lib/rules/space-in-parens.js @@ -12,6 +12,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "enforce consistent spacing inside parentheses", category: "Stylistic Issues", diff --git a/lib/rules/space-infix-ops.js b/lib/rules/space-infix-ops.js index 17b49cc1184..45b76795eae 100644 --- a/lib/rules/space-infix-ops.js +++ b/lib/rules/space-infix-ops.js @@ -10,6 +10,8 @@ module.exports = { meta: { + type: "layout", + docs: { description: "require spacing around infix operators", category: "Stylistic Issues", diff --git a/lib/rules/space-unary-ops.js b/lib/rules/space-unary-ops.js index 5032b46c3b0..b56fa4f2fac 100644 --- a/lib/rules/space-unary-ops.js +++ b/lib/rules/space-unary-ops.js @@ -16,6 +16,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "enforce consistent spacing before or after unary operators", category: "Stylistic Issues", diff --git a/lib/rules/spaced-comment.js b/lib/rules/spaced-comment.js index 6fbe2aac790..d4c86d27cf8 100644 --- a/lib/rules/spaced-comment.js +++ b/lib/rules/spaced-comment.js @@ -151,6 +151,8 @@ function createNeverStylePattern(markers) { module.exports = { meta: { + type: "suggestion", + docs: { description: "enforce consistent spacing after the `//` or `/*` in a comment", category: "Stylistic Issues", diff --git a/lib/rules/strict.js b/lib/rules/strict.js index 8b5757738de..bec1baf4653 100644 --- a/lib/rules/strict.js +++ b/lib/rules/strict.js @@ -80,6 +80,8 @@ function isSimpleParameterList(params) { module.exports = { meta: { + type: "suggestion", + docs: { description: "require or disallow strict mode directives", category: "Strict Mode", diff --git a/lib/rules/switch-colon-spacing.js b/lib/rules/switch-colon-spacing.js index 23dfff6133d..e94b3292106 100644 --- a/lib/rules/switch-colon-spacing.js +++ b/lib/rules/switch-colon-spacing.js @@ -17,12 +17,15 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "enforce spacing around colons of switch statements", category: "Stylistic Issues", recommended: false, url: "https://eslint.org/docs/rules/switch-colon-spacing" }, + schema: [ { type: "object", @@ -33,6 +36,7 @@ module.exports = { additionalProperties: false } ], + fixable: "whitespace" }, diff --git a/lib/rules/symbol-description.js b/lib/rules/symbol-description.js index 271012b5429..7bb4e2dec69 100644 --- a/lib/rules/symbol-description.js +++ b/lib/rules/symbol-description.js @@ -18,6 +18,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "suggestion", + docs: { description: "require symbol descriptions", category: "ECMAScript 6", diff --git a/lib/rules/template-curly-spacing.js b/lib/rules/template-curly-spacing.js index 6702d730cd3..ea801cbe5d2 100644 --- a/lib/rules/template-curly-spacing.js +++ b/lib/rules/template-curly-spacing.js @@ -24,6 +24,8 @@ const CLOSE_PAREN = /^\}/; module.exports = { meta: { + type: "layout", + docs: { description: "require or disallow spacing around embedded expressions of template strings", category: "ECMAScript 6", diff --git a/lib/rules/template-tag-spacing.js b/lib/rules/template-tag-spacing.js index aee7ac108be..f258cde3d88 100644 --- a/lib/rules/template-tag-spacing.js +++ b/lib/rules/template-tag-spacing.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "layout", + docs: { description: "require or disallow spacing between template tags and their literals", category: "Stylistic Issues", diff --git a/lib/rules/unicode-bom.js b/lib/rules/unicode-bom.js index 03b2d5ae68e..20f48e22b3c 100644 --- a/lib/rules/unicode-bom.js +++ b/lib/rules/unicode-bom.js @@ -10,6 +10,8 @@ module.exports = { meta: { + type: "layout", + docs: { description: "require or disallow Unicode byte order mark (BOM)", category: "Stylistic Issues", diff --git a/lib/rules/use-isnan.js b/lib/rules/use-isnan.js index 5bad5b3c6dd..343ca045444 100644 --- a/lib/rules/use-isnan.js +++ b/lib/rules/use-isnan.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "problem", + docs: { description: "require calls to `isNaN()` when checking for `NaN`", category: "Possible Errors", diff --git a/lib/rules/valid-jsdoc.js b/lib/rules/valid-jsdoc.js index 42d66a8a79b..b434491bfad 100644 --- a/lib/rules/valid-jsdoc.js +++ b/lib/rules/valid-jsdoc.js @@ -16,6 +16,8 @@ const doctrine = require("doctrine"); module.exports = { meta: { + type: "suggestion", + docs: { description: "enforce valid JSDoc comments", category: "Possible Errors", diff --git a/lib/rules/valid-typeof.js b/lib/rules/valid-typeof.js index ac4e74f20ba..e3245e8f306 100644 --- a/lib/rules/valid-typeof.js +++ b/lib/rules/valid-typeof.js @@ -10,6 +10,8 @@ module.exports = { meta: { + type: "problem", + docs: { description: "enforce comparing `typeof` expressions against valid strings", category: "Possible Errors", diff --git a/lib/rules/vars-on-top.js b/lib/rules/vars-on-top.js index 0489aa61fcc..d69c223388f 100644 --- a/lib/rules/vars-on-top.js +++ b/lib/rules/vars-on-top.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "suggestion", + docs: { description: "require `var` declarations be placed at the top of their containing scope", category: "Best Practices", diff --git a/lib/rules/wrap-iife.js b/lib/rules/wrap-iife.js index d006d30a004..ce272235b4f 100644 --- a/lib/rules/wrap-iife.js +++ b/lib/rules/wrap-iife.js @@ -17,6 +17,8 @@ const astUtils = require("../util/ast-utils"); module.exports = { meta: { + type: "layout", + docs: { description: "require parentheses around immediate `function` invocations", category: "Best Practices", diff --git a/lib/rules/wrap-regex.js b/lib/rules/wrap-regex.js index 1816e0e9e64..4ecbcecbbeb 100644 --- a/lib/rules/wrap-regex.js +++ b/lib/rules/wrap-regex.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "layout", + docs: { description: "require parenthesis around regex literals", category: "Stylistic Issues", @@ -19,8 +21,8 @@ module.exports = { }, schema: [], - fixable: "code", + messages: { requireParens: "Wrap the regexp literal in parens to disambiguate the slash." } diff --git a/lib/rules/yield-star-spacing.js b/lib/rules/yield-star-spacing.js index 33a37f0d991..e7712a51dbf 100644 --- a/lib/rules/yield-star-spacing.js +++ b/lib/rules/yield-star-spacing.js @@ -11,6 +11,8 @@ module.exports = { meta: { + type: "layout", + docs: { description: "require or disallow spacing around the `*` in `yield*` expressions", category: "ECMAScript 6", diff --git a/lib/rules/yoda.js b/lib/rules/yoda.js index 35368dd4df9..8789c001ef9 100644 --- a/lib/rules/yoda.js +++ b/lib/rules/yoda.js @@ -152,6 +152,8 @@ function same(a, b) { module.exports = { meta: { + type: "suggestion", + docs: { description: "require or disallow \"Yoda\" conditions", category: "Best Practices", diff --git a/tests/fixtures/fix-types/fix-both-semi-and-prefer-arrow-callback.expected.js b/tests/fixtures/fix-types/fix-both-semi-and-prefer-arrow-callback.expected.js new file mode 100644 index 00000000000..cd5a78eb4d3 --- /dev/null +++ b/tests/fixtures/fix-types/fix-both-semi-and-prefer-arrow-callback.expected.js @@ -0,0 +1,7 @@ +/* eslint semi: "error" */ +/* eslint prefer-arrow-callback: "error" */ +"use strict"; + +func(() => { + return true; +}); diff --git a/tests/fixtures/fix-types/fix-both-semi-and-prefer-arrow-callback.js b/tests/fixtures/fix-types/fix-both-semi-and-prefer-arrow-callback.js new file mode 100644 index 00000000000..26d3429d028 --- /dev/null +++ b/tests/fixtures/fix-types/fix-both-semi-and-prefer-arrow-callback.js @@ -0,0 +1,7 @@ +/* eslint semi: "error" */ +/* eslint prefer-arrow-callback: "error" */ +"use strict"; + +func(function() { + return true; +}) diff --git a/tests/fixtures/fix-types/fix-only-prefer-arrow-callback.expected.js b/tests/fixtures/fix-types/fix-only-prefer-arrow-callback.expected.js new file mode 100644 index 00000000000..392dbf08994 --- /dev/null +++ b/tests/fixtures/fix-types/fix-only-prefer-arrow-callback.expected.js @@ -0,0 +1,7 @@ +/* eslint semi: "error" */ +/* eslint prefer-arrow-callback: "error" */ +"use strict"; + +func(() => { + return true; +}) diff --git a/tests/fixtures/fix-types/fix-only-prefer-arrow-callback.js b/tests/fixtures/fix-types/fix-only-prefer-arrow-callback.js new file mode 100644 index 00000000000..26d3429d028 --- /dev/null +++ b/tests/fixtures/fix-types/fix-only-prefer-arrow-callback.js @@ -0,0 +1,7 @@ +/* eslint semi: "error" */ +/* eslint prefer-arrow-callback: "error" */ +"use strict"; + +func(function() { + return true; +}) diff --git a/tests/fixtures/fix-types/fix-only-semi.expected.js b/tests/fixtures/fix-types/fix-only-semi.expected.js new file mode 100644 index 00000000000..3a8f9f44e01 --- /dev/null +++ b/tests/fixtures/fix-types/fix-only-semi.expected.js @@ -0,0 +1,7 @@ +/* eslint semi: "error" */ +/* eslint prefer-arrow-callback: "error" */ +"use strict"; + +func(function() { + return true; +}); diff --git a/tests/fixtures/fix-types/fix-only-semi.js b/tests/fixtures/fix-types/fix-only-semi.js new file mode 100644 index 00000000000..26d3429d028 --- /dev/null +++ b/tests/fixtures/fix-types/fix-only-semi.js @@ -0,0 +1,7 @@ +/* eslint semi: "error" */ +/* eslint prefer-arrow-callback: "error" */ +"use strict"; + +func(function() { + return true; +}) diff --git a/tests/fixtures/fix-types/ignore-missing-meta.expected.js b/tests/fixtures/fix-types/ignore-missing-meta.expected.js new file mode 100644 index 00000000000..b6e3019aa01 --- /dev/null +++ b/tests/fixtures/fix-types/ignore-missing-meta.expected.js @@ -0,0 +1,8 @@ +/* eslint semi: "error" */ +/* eslint no-program: "error" */ +/* eslint prefer-arrow-callback: "error" */ +"use strict"; + +func(function() { + return true; +}); diff --git a/tests/fixtures/fix-types/ignore-missing-meta.js b/tests/fixtures/fix-types/ignore-missing-meta.js new file mode 100644 index 00000000000..ee9b9d9d869 --- /dev/null +++ b/tests/fixtures/fix-types/ignore-missing-meta.js @@ -0,0 +1,8 @@ +/* eslint semi: "error" */ +/* eslint no-program: "error" */ +/* eslint prefer-arrow-callback: "error" */ +"use strict"; + +func(function() { + return true; +}) diff --git a/tests/fixtures/rules/fix-types-test/no-program.js b/tests/fixtures/rules/fix-types-test/no-program.js new file mode 100644 index 00000000000..fd33c11cd3d --- /dev/null +++ b/tests/fixtures/rules/fix-types-test/no-program.js @@ -0,0 +1,22 @@ +"use strict"; + +module.exports = { + fixable: "code", + + create(context) { + + return { + + "Program": function(node) { + context.report({ + node, + message: "Program!", + fix(fixer) { + return fixer.insertTextAfter(node, ";"); + } + }); + } + }; + } + +} \ No newline at end of file diff --git a/tests/lib/cli-engine.js b/tests/lib/cli-engine.js index acc093b3101..d5b0b3728aa 100644 --- a/tests/lib/cli-engine.js +++ b/tests/lib/cli-engine.js @@ -332,6 +332,133 @@ describe("CLIEngine", () => { assert.strictEqual(report.results[0].output, expectedOutput); }); + describe("Fix Types", () => { + + it("should throw an error when an invalid fix type is specified", () => { + assert.throws(() => { + engine = new CLIEngine({ + cwd: path.join(fixtureDir, ".."), + useEslintrc: false, + fix: true, + fixTypes: ["layou"] + }); + }, /invalid fix type/i); + }); + + it("should not fix any rules when fixTypes is used without fix", () => { + engine = new CLIEngine({ + cwd: path.join(fixtureDir, ".."), + useEslintrc: false, + fix: false, + fixTypes: ["layout"] + }); + + const inputPath = getFixturePath("fix-types/fix-only-semi.js"); + const report = engine.executeOnFiles([inputPath]); + + assert.isUndefined(report.results[0].output); + }); + + it("should not fix non-style rules when fixTypes has only 'layout'", () => { + engine = new CLIEngine({ + cwd: path.join(fixtureDir, ".."), + useEslintrc: false, + fix: true, + fixTypes: ["layout"] + }); + const inputPath = getFixturePath("fix-types/fix-only-semi.js"); + const outputPath = getFixturePath("fix-types/fix-only-semi.expected.js"); + const report = engine.executeOnFiles([inputPath]); + const expectedOutput = fs.readFileSync(outputPath, "utf8"); + + assert.strictEqual(report.results[0].output, expectedOutput); + }); + + it("should not fix style or problem rules when fixTypes has only 'suggestion'", () => { + engine = new CLIEngine({ + cwd: path.join(fixtureDir, ".."), + useEslintrc: false, + fix: true, + fixTypes: ["suggestion"] + }); + const inputPath = getFixturePath("fix-types/fix-only-prefer-arrow-callback.js"); + const outputPath = getFixturePath("fix-types/fix-only-prefer-arrow-callback.expected.js"); + const report = engine.executeOnFiles([inputPath]); + const expectedOutput = fs.readFileSync(outputPath, "utf8"); + + assert.strictEqual(report.results[0].output, expectedOutput); + }); + + it("should fix both style and problem rules when fixTypes has 'suggestion' and 'layout'", () => { + engine = new CLIEngine({ + cwd: path.join(fixtureDir, ".."), + useEslintrc: false, + fix: true, + fixTypes: ["suggestion", "layout"] + }); + const inputPath = getFixturePath("fix-types/fix-both-semi-and-prefer-arrow-callback.js"); + const outputPath = getFixturePath("fix-types/fix-both-semi-and-prefer-arrow-callback.expected.js"); + const report = engine.executeOnFiles([inputPath]); + const expectedOutput = fs.readFileSync(outputPath, "utf8"); + + assert.strictEqual(report.results[0].output, expectedOutput); + }); + + it("should not throw an error when a rule doesn't have a 'meta' property", () => { + engine = new CLIEngine({ + cwd: path.join(fixtureDir, ".."), + useEslintrc: false, + fix: true, + fixTypes: ["layout"], + rulePaths: [getFixturePath("rules", "fix-types-test")] + }); + + const inputPath = getFixturePath("fix-types/ignore-missing-meta.js"); + const outputPath = getFixturePath("fix-types/ignore-missing-meta.expected.js"); + const report = engine.executeOnFiles([inputPath]); + const expectedOutput = fs.readFileSync(outputPath, "utf8"); + + assert.strictEqual(report.results[0].output, expectedOutput); + }); + + it("should not throw an error when a rule is loaded after initialization with executeOnFiles()", () => { + engine = new CLIEngine({ + cwd: path.join(fixtureDir, ".."), + useEslintrc: false, + fix: true, + fixTypes: ["layout"] + }); + + engine.linter.defineRule("no-program", require(getFixturePath("rules", "fix-types-test", "no-program.js"))); + + const inputPath = getFixturePath("fix-types/ignore-missing-meta.js"); + const outputPath = getFixturePath("fix-types/ignore-missing-meta.expected.js"); + const report = engine.executeOnFiles([inputPath]); + const expectedOutput = fs.readFileSync(outputPath, "utf8"); + + assert.strictEqual(report.results[0].output, expectedOutput); + }); + + it("should not throw an error when a rule is loaded after initialization with executeOnText()", () => { + engine = new CLIEngine({ + cwd: path.join(fixtureDir, ".."), + useEslintrc: false, + fix: true, + fixTypes: ["layout"] + }); + + engine.linter.defineRule("no-program", require(getFixturePath("rules", "fix-types-test", "no-program.js"))); + + const inputPath = getFixturePath("fix-types/ignore-missing-meta.js"); + const outputPath = getFixturePath("fix-types/ignore-missing-meta.expected.js"); + const report = engine.executeOnText(fs.readFileSync(inputPath, { encoding: "utf8" }), inputPath); + const expectedOutput = fs.readFileSync(outputPath, "utf8"); + + assert.strictEqual(report.results[0].output, expectedOutput); + }); + + }); + it("should return a message and omit fixed text when in fix mode and fixes aren't done", () => { engine = new CLIEngine({ @@ -638,7 +765,6 @@ describe("CLIEngine", () => { }); - it("should report zero messages when given a config file and a valid file", () => { engine = new CLIEngine({ diff --git a/tests/lib/cli.js b/tests/lib/cli.js index 9824edbadad..50d80c38472 100644 --- a/tests/lib/cli.js +++ b/tests/lib/cli.js @@ -267,6 +267,17 @@ describe("cli", () => { }); }); + describe("when using --fix-type without --fix or --fix-dry-run", () => { + it("should exit with error", () => { + const filePath = getFixturePath("passing.js"); + const code = `--fix-type suggestion ${filePath}`; + + const exit = cli.execute(code); + + assert.strictEqual(exit, 2); + }); + }); + describe("when executing a file with a syntax error", () => { it("should exit with error", () => { const filePath = getFixturePath("syntax-error.js"); @@ -764,6 +775,7 @@ describe("cli", () => { }); + it("should rewrite files when in fix mode", () => { const report = { @@ -887,6 +899,35 @@ describe("cli", () => { }); + it("should pass fixTypes to CLIEngine when --fix-type is passed", () => { + + const expectedCLIEngineOptions = { + fix: true, + fixTypes: ["suggestion"] + }; + + // create a fake CLIEngine to test with + const fakeCLIEngine = sandbox.mock().withExactArgs(sinon.match(expectedCLIEngineOptions)); + + fakeCLIEngine.prototype = leche.fake(CLIEngine.prototype); + sandbox.stub(fakeCLIEngine.prototype, "executeOnFiles").returns({ + errorCount: 0, + warningCount: 0, + results: [] + }); + sandbox.stub(fakeCLIEngine.prototype, "getFormatter").returns(() => "done"); + fakeCLIEngine.outputFixes = sandbox.stub(); + + localCLI = proxyquire("../../lib/cli", { + "./cli-engine": fakeCLIEngine, + "./util/logging": log + }); + + const exitCode = localCLI.execute("--fix-dry-run --fix-type suggestion ."); + + assert.strictEqual(exitCode, 0); + }); + it("should not rewrite files when in fix-dry-run mode", () => { const report = { diff --git a/tests/lib/options.js b/tests/lib/options.js index 26a84b4a090..60cd7b716b3 100644 --- a/tests/lib/options.js +++ b/tests/lib/options.js @@ -328,6 +328,31 @@ describe("options", () => { }); }); + describe("--fix-type", () => { + it("should return one value with --fix-type is passed", () => { + const currentOptions = options.parse("--fix-type problem"); + + assert.strictEqual(currentOptions.fixType.length, 1); + assert.strictEqual(currentOptions.fixType[0], "problem"); + }); + + it("should return two values when --fix-type is passed twice", () => { + const currentOptions = options.parse("--fix-type problem --fix-type suggestion"); + + assert.strictEqual(currentOptions.fixType.length, 2); + assert.strictEqual(currentOptions.fixType[0], "problem"); + assert.strictEqual(currentOptions.fixType[1], "suggestion"); + }); + + it("should return two values when --fix-type is passed a comma-separated value", () => { + const currentOptions = options.parse("--fix-type problem,suggestion"); + + assert.strictEqual(currentOptions.fixType.length, 2); + assert.strictEqual(currentOptions.fixType[0], "problem"); + assert.strictEqual(currentOptions.fixType[1], "suggestion"); + }); + }); + describe("--debug", () => { it("should return true for --debug when passed", () => { const currentOptions = options.parse("--debug"); diff --git a/tools/rule-types.json b/tools/rule-types.json new file mode 100644 index 00000000000..40010c8969d --- /dev/null +++ b/tools/rule-types.json @@ -0,0 +1,266 @@ +{ + "accessor-pairs": "suggestion", + "array-bracket-newline": "layout", + "array-bracket-spacing": "layout", + "array-callback-return": "problem", + "array-element-newline": "layout", + "arrow-body-style": "suggestion", + "arrow-parens": "layout", + "arrow-spacing": "layout", + "block-scoped-var": "suggestion", + "block-spacing": "layout", + "brace-style": "layout", + "callback-return": "suggestion", + "camelcase": "suggestion", + "capitalized-comments": "suggestion", + "class-methods-use-this": "suggestion", + "comma-dangle": "layout", + "comma-spacing": "layout", + "comma-style": "layout", + "complexity": "suggestion", + "computed-property-spacing": "layout", + "consistent-return": "suggestion", + "consistent-this": "suggestion", + "constructor-super": "problem", + "curly": "suggestion", + "default-case": "suggestion", + "dot-location": "layout", + "dot-notation": "suggestion", + "eol-last": "layout", + "eqeqeq": "suggestion", + "for-direction": "problem", + "func-call-spacing": "layout", + "func-name-matching": "suggestion", + "func-names": "suggestion", + "func-style": "suggestion", + "function-paren-newline": "layout", + "generator-star-spacing": "layout", + "getter-return": "problem", + "global-require": "suggestion", + "guard-for-in": "suggestion", + "handle-callback-err": "suggestion", + "id-blacklist": "suggestion", + "id-length": "suggestion", + "id-match": "suggestion", + "implicit-arrow-linebreak": "layout", + "indent": "layout", + "indent-legacy": "layout", + "init-declarations": "suggestion", + "jsx-quotes": "layout", + "key-spacing": "layout", + "keyword-spacing": "layout", + "line-comment-position": "layout", + "linebreak-style": "layout", + "lines-around-comment": "layout", + "lines-around-directive": "layout", + "lines-between-class-members": "layout", + "max-classes-per-file": "suggestion", + "max-depth": "suggestion", + "max-len": "layout", + "max-lines": "suggestion", + "max-lines-per-function": "suggestion", + "max-nested-callbacks": "suggestion", + "max-params": "suggestion", + "max-statements": "suggestion", + "max-statements-per-line": "layout", + "multiline-comment-style": "suggestion", + "multiline-ternary": "layout", + "new-cap": "suggestion", + "new-parens": "layout", + "newline-after-var": "layout", + "newline-before-return": "layout", + "newline-per-chained-call": "layout", + "no-alert": "suggestion", + "no-array-constructor": "suggestion", + "no-async-promise-executor": "problem", + "no-await-in-loop": "problem", + "no-bitwise": "suggestion", + "no-buffer-constructor": "problem", + "no-caller": "suggestion", + "no-case-declarations": "suggestion", + "no-catch-shadow": "suggestion", + "no-class-assign": "problem", + "no-compare-neg-zero": "problem", + "no-cond-assign": "problem", + "no-confusing-arrow": "suggestion", + "no-console": "suggestion", + "no-const-assign": "problem", + "no-constant-condition": "problem", + "no-continue": "suggestion", + "no-control-regex": "problem", + "no-debugger": "problem", + "no-delete-var": "suggestion", + "no-div-regex": "suggestion", + "no-dupe-args": "problem", + "no-dupe-class-members": "problem", + "no-dupe-keys": "problem", + "no-duplicate-case": "problem", + "no-duplicate-imports": "problem", + "no-else-return": "suggestion", + "no-empty": "suggestion", + "no-empty-character-class": "problem", + "no-empty-function": "suggestion", + "no-empty-pattern": "problem", + "no-eq-null": "suggestion", + "no-eval": "suggestion", + "no-ex-assign": "problem", + "no-extend-native": "suggestion", + "no-extra-bind": "suggestion", + "no-extra-boolean-cast": "suggestion", + "no-extra-label": "suggestion", + "no-extra-parens": "layout", + "no-extra-semi": "suggestion", + "no-fallthrough": "problem", + "no-floating-decimal": "suggestion", + "no-func-assign": "problem", + "no-global-assign": "suggestion", + "no-implicit-coercion": "suggestion", + "no-implicit-globals": "suggestion", + "no-implied-eval": "suggestion", + "no-inline-comments": "suggestion", + "no-inner-declarations": "problem", + "no-invalid-regexp": "problem", + "no-invalid-this": "suggestion", + "no-irregular-whitespace": "problem", + "no-iterator": "suggestion", + "no-label-var": "suggestion", + "no-labels": "suggestion", + "no-lone-blocks": "suggestion", + "no-lonely-if": "suggestion", + "no-loop-func": "suggestion", + "no-magic-numbers": "suggestion", + "no-misleading-character-class": "problem", + "no-mixed-operators": "suggestion", + "no-mixed-requires": "suggestion", + "no-mixed-spaces-and-tabs": "layout", + "no-multi-assign": "suggestion", + "no-multi-spaces": "layout", + "no-multi-str": "suggestion", + "no-multiple-empty-lines": "layout", + "no-native-reassign": "suggestion", + "no-negated-condition": "suggestion", + "no-negated-in-lhs": "problem", + "no-nested-ternary": "suggestion", + "no-new": "suggestion", + "no-new-func": "suggestion", + "no-new-object": "suggestion", + "no-new-require": "suggestion", + "no-new-symbol": "problem", + "no-new-wrappers": "suggestion", + "no-obj-calls": "problem", + "no-octal": "suggestion", + "no-octal-escape": "suggestion", + "no-param-reassign": "suggestion", + "no-path-concat": "suggestion", + "no-plusplus": "suggestion", + "no-process-env": "suggestion", + "no-process-exit": "suggestion", + "no-proto": "suggestion", + "no-prototype-builtins": "problem", + "no-redeclare": "suggestion", + "no-regex-spaces": "suggestion", + "no-restricted-globals": "suggestion", + "no-restricted-imports": "suggestion", + "no-restricted-modules": "suggestion", + "no-restricted-properties": "suggestion", + "no-restricted-syntax": "suggestion", + "no-return-assign": "suggestion", + "no-return-await": "suggestion", + "no-script-url": "suggestion", + "no-self-assign": "problem", + "no-self-compare": "problem", + "no-sequences": "suggestion", + "no-shadow": "suggestion", + "no-shadow-restricted-names": "suggestion", + "no-spaced-func": "layout", + "no-sparse-arrays": "problem", + "no-sync": "suggestion", + "no-tabs": "layout", + "no-template-curly-in-string": "problem", + "no-ternary": "suggestion", + "no-this-before-super": "problem", + "no-throw-literal": "suggestion", + "no-trailing-spaces": "layout", + "no-undef": "problem", + "no-undef-init": "suggestion", + "no-undefined": "suggestion", + "no-underscore-dangle": "suggestion", + "no-unexpected-multiline": "problem", + "no-unmodified-loop-condition": "problem", + "no-unneeded-ternary": "suggestion", + "no-unreachable": "problem", + "no-unsafe-finally": "problem", + "no-unsafe-negation": "problem", + "no-unused-expressions": "suggestion", + "no-unused-labels": "suggestion", + "no-unused-vars": "problem", + "no-use-before-define": "problem", + "no-useless-call": "suggestion", + "no-useless-computed-key": "suggestion", + "no-useless-concat": "suggestion", + "no-useless-constructor": "suggestion", + "no-useless-escape": "suggestion", + "no-useless-rename": "suggestion", + "no-useless-return": "suggestion", + "no-var": "suggestion", + "no-void": "suggestion", + "no-warning-comments": "suggestion", + "no-whitespace-before-property": "layout", + "no-with": "suggestion", + "nonblock-statement-body-position": "layout", + "object-curly-newline": "layout", + "object-curly-spacing": "layout", + "object-property-newline": "layout", + "object-shorthand": "suggestion", + "one-var": "suggestion", + "one-var-declaration-per-line": "suggestion", + "operator-assignment": "suggestion", + "operator-linebreak": "layout", + "padded-blocks": "layout", + "padding-line-between-statements": "layout", + "prefer-arrow-callback": "suggestion", + "prefer-const": "suggestion", + "prefer-destructuring": "suggestion", + "prefer-numeric-literals": "suggestion", + "prefer-object-spread": "suggestion", + "prefer-promise-reject-errors": "suggestion", + "prefer-reflect": "suggestion", + "prefer-rest-params": "suggestion", + "prefer-spread": "suggestion", + "prefer-template": "suggestion", + "quote-props": "suggestion", + "quotes": "layout", + "radix": "suggestion", + "require-atomic-updates": "problem", + "require-await": "suggestion", + "require-jsdoc": "suggestion", + "require-unicode-regexp": "suggestion", + "require-yield": "suggestion", + "rest-spread-spacing": "layout", + "semi": "layout", + "semi-spacing": "layout", + "semi-style": "layout", + "sort-imports": "suggestion", + "sort-keys": "suggestion", + "sort-vars": "suggestion", + "space-before-blocks": "layout", + "space-before-function-paren": "layout", + "space-in-parens": "layout", + "space-infix-ops": "layout", + "space-unary-ops": "layout", + "spaced-comment": "suggestion", + "strict": "suggestion", + "switch-colon-spacing": "layout", + "symbol-description": "suggestion", + "template-curly-spacing": "layout", + "template-tag-spacing": "layout", + "unicode-bom": "layout", + "use-isnan": "problem", + "valid-jsdoc": "suggestion", + "valid-typeof": "problem", + "vars-on-top": "suggestion", + "wrap-iife": "layout", + "wrap-regex": "layout", + "yield-star-spacing": "layout", + "yoda": "suggestion" +} \ No newline at end of file diff --git a/tools/update-rule-types.js b/tools/update-rule-types.js new file mode 100644 index 00000000000..527cf2288e6 --- /dev/null +++ b/tools/update-rule-types.js @@ -0,0 +1,77 @@ +/** + * JSCodeShift script to update meta.type in rules. + * Run over the rules directory only. Use this command: + * + * jscodeshift -t tools/update-rule-types.js lib/rules/ + * + * @author Nicholas C. Zakas + */ +"use strict"; + +const path = require("path"); +const ruleTypes = require("./rule-types.json"); + +module.exports = (fileInfo, api) => { + const j = api.jscodeshift; + const source = fileInfo.source; + const ruleName = path.basename(fileInfo.path, ".js"); + + // get the object literal representing the rule + const nodes = j(source).find(j.ObjectExpression).filter(p => p.node.properties.some(node => node.key.name === "meta")); + + // updating logic + return nodes.replaceWith(p => { + + // gather important nodes from the rule + const metaNode = p.node.properties.find(node => node.key.name === "meta"); + + // if there's no properties, just exit + if (!metaNode.value.properties) { + return p.node; + } + + const typeNode = metaNode.value.properties.find(node => node.key.name === "type"); + const docsNode = metaNode.value.properties.find(node => node.key.name === "docs"); + const categoryNode = docsNode.value.properties.find(node => node.key.name === "category").value; + + let ruleType; + + // the rule-types.json file takes highest priority + if (ruleName in ruleTypes) { + ruleType = ruleTypes[ruleName]; + } else { + + // otherwise fallback to category + switch (categoryNode.value) { + case "Stylistic Issues": + ruleType = "style"; + break; + + case "Possible Errors": + ruleType = "problem"; + break; + + default: + ruleType = "suggestion"; + } + } + + if (typeNode) { + + // update existing type node + typeNode.value = j.literal(ruleType); + } else { + + // add new type node if one doesn't exist + const newProp = j.property( + "init", + j.identifier("type"), + j.literal(ruleType) + ); + + p.node.properties[0].value.properties.unshift(newProp); + } + + return p.node; + }).toSource(); +};