eslint 8.18.0 → 8.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -9
- package/lib/config/default-config.js +16 -7
- package/lib/config/flat-config-array.js +41 -2
- package/lib/config/flat-config-helpers.js +9 -1
- package/lib/eslint/eslint-helpers.js +621 -0
- package/lib/eslint/flat-eslint.js +1164 -0
- package/lib/eslint/index.js +3 -1
- package/lib/linter/linter.js +72 -4
- package/lib/rule-tester/flat-rule-tester.js +41 -38
- package/lib/rule-tester/rule-tester.js +42 -0
- package/lib/rules/accessor-pairs.js +1 -1
- package/lib/rules/array-bracket-newline.js +1 -1
- package/lib/rules/array-bracket-spacing.js +1 -1
- package/lib/rules/array-callback-return.js +1 -1
- package/lib/rules/array-element-newline.js +1 -1
- package/lib/rules/arrow-body-style.js +1 -1
- package/lib/rules/arrow-parens.js +1 -1
- package/lib/rules/arrow-spacing.js +1 -1
- package/lib/rules/block-scoped-var.js +1 -1
- package/lib/rules/block-spacing.js +1 -1
- package/lib/rules/brace-style.js +1 -1
- package/lib/rules/callback-return.js +1 -1
- package/lib/rules/camelcase.js +1 -1
- package/lib/rules/capitalized-comments.js +1 -1
- package/lib/rules/class-methods-use-this.js +1 -1
- package/lib/rules/comma-dangle.js +1 -1
- package/lib/rules/comma-spacing.js +36 -42
- package/lib/rules/comma-style.js +1 -1
- package/lib/rules/complexity.js +1 -1
- package/lib/rules/computed-property-spacing.js +1 -1
- package/lib/rules/consistent-return.js +1 -1
- package/lib/rules/consistent-this.js +1 -1
- package/lib/rules/constructor-super.js +1 -1
- package/lib/rules/curly.js +1 -1
- package/lib/rules/default-case-last.js +1 -1
- package/lib/rules/default-case.js +1 -1
- package/lib/rules/default-param-last.js +1 -1
- package/lib/rules/dot-location.js +1 -1
- package/lib/rules/dot-notation.js +1 -1
- package/lib/rules/eol-last.js +1 -1
- package/lib/rules/eqeqeq.js +1 -1
- package/lib/rules/for-direction.js +1 -1
- package/lib/rules/func-call-spacing.js +1 -1
- package/lib/rules/func-name-matching.js +1 -1
- package/lib/rules/func-names.js +1 -1
- package/lib/rules/func-style.js +1 -1
- package/lib/rules/function-call-argument-newline.js +1 -1
- package/lib/rules/function-paren-newline.js +1 -1
- package/lib/rules/generator-star-spacing.js +1 -1
- package/lib/rules/getter-return.js +1 -1
- package/lib/rules/global-require.js +1 -1
- package/lib/rules/grouped-accessor-pairs.js +1 -1
- package/lib/rules/guard-for-in.js +1 -1
- package/lib/rules/handle-callback-err.js +1 -1
- package/lib/rules/id-blacklist.js +1 -1
- package/lib/rules/id-denylist.js +1 -1
- package/lib/rules/id-length.js +1 -1
- package/lib/rules/id-match.js +1 -1
- package/lib/rules/implicit-arrow-linebreak.js +1 -1
- package/lib/rules/indent-legacy.js +1 -1
- package/lib/rules/indent.js +3 -3
- package/lib/rules/init-declarations.js +1 -1
- package/lib/rules/jsx-quotes.js +1 -1
- package/lib/rules/key-spacing.js +5 -2
- package/lib/rules/keyword-spacing.js +1 -1
- package/lib/rules/line-comment-position.js +1 -1
- package/lib/rules/linebreak-style.js +1 -1
- package/lib/rules/lines-around-comment.js +12 -5
- package/lib/rules/lines-around-directive.js +1 -1
- package/lib/rules/lines-between-class-members.js +1 -1
- package/lib/rules/max-classes-per-file.js +1 -1
- package/lib/rules/max-depth.js +1 -1
- package/lib/rules/max-len.js +1 -1
- package/lib/rules/max-lines-per-function.js +1 -1
- package/lib/rules/max-lines.js +1 -1
- package/lib/rules/max-nested-callbacks.js +1 -1
- package/lib/rules/max-params.js +1 -1
- package/lib/rules/max-statements-per-line.js +1 -1
- package/lib/rules/max-statements.js +1 -1
- package/lib/rules/multiline-comment-style.js +1 -1
- package/lib/rules/multiline-ternary.js +1 -1
- package/lib/rules/new-cap.js +1 -1
- package/lib/rules/new-parens.js +1 -1
- package/lib/rules/newline-after-var.js +1 -1
- package/lib/rules/newline-before-return.js +1 -1
- package/lib/rules/newline-per-chained-call.js +1 -1
- package/lib/rules/no-alert.js +1 -1
- package/lib/rules/no-array-constructor.js +1 -1
- package/lib/rules/no-async-promise-executor.js +1 -1
- package/lib/rules/no-await-in-loop.js +1 -1
- package/lib/rules/no-bitwise.js +1 -1
- package/lib/rules/no-buffer-constructor.js +1 -1
- package/lib/rules/no-caller.js +1 -1
- package/lib/rules/no-case-declarations.js +1 -1
- package/lib/rules/no-catch-shadow.js +1 -1
- package/lib/rules/no-class-assign.js +1 -1
- package/lib/rules/no-compare-neg-zero.js +1 -1
- package/lib/rules/no-cond-assign.js +1 -1
- package/lib/rules/no-confusing-arrow.js +1 -1
- package/lib/rules/no-console.js +1 -1
- package/lib/rules/no-const-assign.js +1 -1
- package/lib/rules/no-constant-binary-expression.js +1 -1
- package/lib/rules/no-constant-condition.js +1 -1
- package/lib/rules/no-constructor-return.js +1 -1
- package/lib/rules/no-continue.js +1 -1
- package/lib/rules/no-control-regex.js +1 -1
- package/lib/rules/no-debugger.js +1 -1
- package/lib/rules/no-delete-var.js +1 -1
- package/lib/rules/no-div-regex.js +1 -1
- package/lib/rules/no-dupe-args.js +1 -1
- package/lib/rules/no-dupe-class-members.js +1 -1
- package/lib/rules/no-dupe-else-if.js +1 -1
- package/lib/rules/no-dupe-keys.js +1 -1
- package/lib/rules/no-duplicate-case.js +1 -1
- package/lib/rules/no-duplicate-imports.js +1 -1
- package/lib/rules/no-else-return.js +1 -1
- package/lib/rules/no-empty-character-class.js +1 -1
- package/lib/rules/no-empty-function.js +1 -1
- package/lib/rules/no-empty-pattern.js +1 -1
- package/lib/rules/no-empty.js +1 -1
- package/lib/rules/no-eq-null.js +1 -1
- package/lib/rules/no-eval.js +1 -1
- package/lib/rules/no-ex-assign.js +1 -1
- package/lib/rules/no-extend-native.js +1 -1
- package/lib/rules/no-extra-bind.js +1 -1
- package/lib/rules/no-extra-boolean-cast.js +1 -1
- package/lib/rules/no-extra-label.js +1 -1
- package/lib/rules/no-extra-parens.js +1 -1
- package/lib/rules/no-extra-semi.js +1 -1
- package/lib/rules/no-fallthrough.js +1 -1
- package/lib/rules/no-floating-decimal.js +1 -1
- package/lib/rules/no-func-assign.js +1 -1
- package/lib/rules/no-global-assign.js +1 -1
- package/lib/rules/no-implicit-coercion.js +1 -1
- package/lib/rules/no-implicit-globals.js +1 -1
- package/lib/rules/no-implied-eval.js +1 -1
- package/lib/rules/no-import-assign.js +1 -1
- package/lib/rules/no-inline-comments.js +1 -1
- package/lib/rules/no-inner-declarations.js +1 -1
- package/lib/rules/no-invalid-regexp.js +1 -1
- package/lib/rules/no-invalid-this.js +1 -1
- package/lib/rules/no-irregular-whitespace.js +1 -1
- package/lib/rules/no-iterator.js +1 -1
- package/lib/rules/no-label-var.js +1 -1
- package/lib/rules/no-labels.js +1 -1
- package/lib/rules/no-lone-blocks.js +1 -1
- package/lib/rules/no-lonely-if.js +1 -1
- package/lib/rules/no-loop-func.js +1 -1
- package/lib/rules/no-loss-of-precision.js +1 -1
- package/lib/rules/no-magic-numbers.js +1 -1
- package/lib/rules/no-misleading-character-class.js +1 -1
- package/lib/rules/no-mixed-operators.js +1 -1
- package/lib/rules/no-mixed-requires.js +1 -1
- package/lib/rules/no-mixed-spaces-and-tabs.js +1 -1
- package/lib/rules/no-multi-assign.js +1 -1
- package/lib/rules/no-multi-spaces.js +1 -1
- package/lib/rules/no-multi-str.js +1 -1
- package/lib/rules/no-multiple-empty-lines.js +1 -1
- package/lib/rules/no-native-reassign.js +1 -1
- package/lib/rules/no-negated-condition.js +1 -1
- package/lib/rules/no-negated-in-lhs.js +1 -1
- package/lib/rules/no-nested-ternary.js +1 -1
- package/lib/rules/no-new-func.js +1 -1
- package/lib/rules/no-new-object.js +1 -1
- package/lib/rules/no-new-require.js +1 -1
- package/lib/rules/no-new-symbol.js +1 -1
- package/lib/rules/no-new-wrappers.js +1 -1
- package/lib/rules/no-new.js +1 -1
- package/lib/rules/no-nonoctal-decimal-escape.js +1 -1
- package/lib/rules/no-obj-calls.js +1 -1
- package/lib/rules/no-octal-escape.js +1 -1
- package/lib/rules/no-octal.js +1 -1
- package/lib/rules/no-param-reassign.js +1 -1
- package/lib/rules/no-path-concat.js +1 -1
- package/lib/rules/no-plusplus.js +1 -1
- package/lib/rules/no-process-env.js +1 -1
- package/lib/rules/no-process-exit.js +1 -1
- package/lib/rules/no-promise-executor-return.js +1 -1
- package/lib/rules/no-proto.js +1 -1
- package/lib/rules/no-prototype-builtins.js +1 -1
- package/lib/rules/no-redeclare.js +1 -1
- package/lib/rules/no-regex-spaces.js +1 -1
- package/lib/rules/no-restricted-exports.js +1 -1
- package/lib/rules/no-restricted-globals.js +1 -1
- package/lib/rules/no-restricted-imports.js +77 -12
- package/lib/rules/no-restricted-modules.js +1 -1
- package/lib/rules/no-restricted-properties.js +1 -1
- package/lib/rules/no-restricted-syntax.js +1 -1
- package/lib/rules/no-return-assign.js +1 -1
- package/lib/rules/no-return-await.js +1 -1
- package/lib/rules/no-script-url.js +1 -1
- package/lib/rules/no-self-assign.js +1 -1
- package/lib/rules/no-self-compare.js +1 -1
- package/lib/rules/no-sequences.js +1 -1
- package/lib/rules/no-setter-return.js +1 -1
- package/lib/rules/no-shadow-restricted-names.js +1 -1
- package/lib/rules/no-shadow.js +1 -1
- package/lib/rules/no-spaced-func.js +1 -1
- package/lib/rules/no-sparse-arrays.js +1 -1
- package/lib/rules/no-sync.js +1 -1
- package/lib/rules/no-tabs.js +1 -1
- package/lib/rules/no-template-curly-in-string.js +1 -1
- package/lib/rules/no-ternary.js +1 -1
- package/lib/rules/no-this-before-super.js +1 -1
- package/lib/rules/no-throw-literal.js +1 -1
- package/lib/rules/no-trailing-spaces.js +1 -1
- package/lib/rules/no-undef-init.js +1 -1
- package/lib/rules/no-undef.js +1 -1
- package/lib/rules/no-undefined.js +1 -1
- package/lib/rules/no-underscore-dangle.js +1 -1
- package/lib/rules/no-unexpected-multiline.js +1 -1
- package/lib/rules/no-unmodified-loop-condition.js +1 -1
- package/lib/rules/no-unneeded-ternary.js +1 -1
- package/lib/rules/no-unreachable-loop.js +1 -1
- package/lib/rules/no-unreachable.js +1 -1
- package/lib/rules/no-unsafe-finally.js +1 -1
- package/lib/rules/no-unsafe-negation.js +1 -1
- package/lib/rules/no-unsafe-optional-chaining.js +1 -1
- package/lib/rules/no-unused-expressions.js +1 -1
- package/lib/rules/no-unused-labels.js +1 -1
- package/lib/rules/no-unused-private-class-members.js +1 -1
- package/lib/rules/no-unused-vars.js +1 -1
- package/lib/rules/no-use-before-define.js +1 -1
- package/lib/rules/no-useless-backreference.js +1 -1
- package/lib/rules/no-useless-call.js +1 -1
- package/lib/rules/no-useless-catch.js +1 -1
- package/lib/rules/no-useless-computed-key.js +1 -1
- package/lib/rules/no-useless-concat.js +1 -1
- package/lib/rules/no-useless-constructor.js +1 -1
- package/lib/rules/no-useless-escape.js +1 -1
- package/lib/rules/no-useless-rename.js +1 -1
- package/lib/rules/no-useless-return.js +1 -1
- package/lib/rules/no-var.js +1 -1
- package/lib/rules/no-void.js +1 -1
- package/lib/rules/no-warning-comments.js +27 -41
- package/lib/rules/no-whitespace-before-property.js +1 -1
- package/lib/rules/no-with.js +1 -1
- package/lib/rules/nonblock-statement-body-position.js +1 -1
- package/lib/rules/object-curly-newline.js +1 -1
- package/lib/rules/object-curly-spacing.js +1 -1
- package/lib/rules/object-property-newline.js +1 -1
- package/lib/rules/object-shorthand.js +1 -1
- package/lib/rules/one-var-declaration-per-line.js +1 -1
- package/lib/rules/one-var.js +1 -1
- package/lib/rules/operator-assignment.js +1 -1
- package/lib/rules/operator-linebreak.js +1 -1
- package/lib/rules/padded-blocks.js +1 -1
- package/lib/rules/padding-line-between-statements.js +1 -1
- package/lib/rules/prefer-arrow-callback.js +1 -1
- package/lib/rules/prefer-const.js +1 -1
- package/lib/rules/prefer-destructuring.js +1 -1
- package/lib/rules/prefer-exponentiation-operator.js +1 -1
- package/lib/rules/prefer-named-capture-group.js +1 -1
- package/lib/rules/prefer-numeric-literals.js +1 -1
- package/lib/rules/prefer-object-has-own.js +1 -1
- package/lib/rules/prefer-object-spread.js +1 -1
- package/lib/rules/prefer-promise-reject-errors.js +1 -1
- package/lib/rules/prefer-reflect.js +1 -1
- package/lib/rules/prefer-regex-literals.js +1 -1
- package/lib/rules/prefer-rest-params.js +1 -1
- package/lib/rules/prefer-spread.js +1 -1
- package/lib/rules/prefer-template.js +1 -1
- package/lib/rules/quote-props.js +1 -1
- package/lib/rules/quotes.js +1 -1
- package/lib/rules/radix.js +1 -1
- package/lib/rules/require-atomic-updates.js +1 -1
- package/lib/rules/require-await.js +1 -1
- package/lib/rules/require-jsdoc.js +1 -1
- package/lib/rules/require-unicode-regexp.js +1 -1
- package/lib/rules/require-yield.js +1 -1
- package/lib/rules/rest-spread-spacing.js +1 -1
- package/lib/rules/semi-spacing.js +1 -1
- package/lib/rules/semi-style.js +1 -1
- package/lib/rules/semi.js +1 -1
- package/lib/rules/sort-imports.js +1 -1
- package/lib/rules/sort-keys.js +44 -1
- package/lib/rules/sort-vars.js +1 -1
- package/lib/rules/space-before-blocks.js +1 -1
- package/lib/rules/space-before-function-paren.js +1 -1
- package/lib/rules/space-in-parens.js +1 -1
- package/lib/rules/space-infix-ops.js +1 -1
- package/lib/rules/space-unary-ops.js +1 -1
- package/lib/rules/spaced-comment.js +1 -1
- package/lib/rules/strict.js +1 -1
- package/lib/rules/switch-colon-spacing.js +1 -1
- package/lib/rules/symbol-description.js +1 -1
- package/lib/rules/template-curly-spacing.js +1 -1
- package/lib/rules/template-tag-spacing.js +1 -1
- package/lib/rules/unicode-bom.js +1 -1
- package/lib/rules/use-isnan.js +1 -1
- package/lib/rules/valid-jsdoc.js +1 -1
- package/lib/rules/valid-typeof.js +1 -1
- package/lib/rules/vars-on-top.js +1 -1
- package/lib/rules/wrap-iife.js +1 -1
- package/lib/rules/wrap-regex.js +1 -1
- package/lib/rules/yield-star-spacing.js +1 -1
- package/lib/rules/yoda.js +1 -1
- package/lib/unsupported-api.js +4 -0
- package/package.json +13 -10
package/lib/eslint/index.js
CHANGED
package/lib/linter/linter.js
CHANGED
@@ -1119,6 +1119,10 @@ function runRules(sourceCode, configuredRules, ruleMapper, parserName, languageO
|
|
1119
1119
|
};
|
1120
1120
|
}
|
1121
1121
|
|
1122
|
+
if (typeof ruleListeners === "undefined" || ruleListeners === null) {
|
1123
|
+
throw new Error(`The create() function for rule '${ruleId}' did not return an object.`);
|
1124
|
+
}
|
1125
|
+
|
1122
1126
|
// add all the selectors from the rule as listeners
|
1123
1127
|
Object.keys(ruleListeners).forEach(selector => {
|
1124
1128
|
const ruleListener = timing.enabled
|
@@ -1506,7 +1510,31 @@ class Linter {
|
|
1506
1510
|
options.filterCodeBlock ||
|
1507
1511
|
(blockFilename => blockFilename.endsWith(".js"));
|
1508
1512
|
const originalExtname = path.extname(filename);
|
1509
|
-
|
1513
|
+
|
1514
|
+
let blocks;
|
1515
|
+
|
1516
|
+
try {
|
1517
|
+
blocks = preprocess(text, filenameToExpose);
|
1518
|
+
} catch (ex) {
|
1519
|
+
|
1520
|
+
// If the message includes a leading line number, strip it:
|
1521
|
+
const message = `Preprocessing error: ${ex.message.replace(/^line \d+:/iu, "").trim()}`;
|
1522
|
+
|
1523
|
+
debug("%s\n%s", message, ex.stack);
|
1524
|
+
|
1525
|
+
return [
|
1526
|
+
{
|
1527
|
+
ruleId: null,
|
1528
|
+
fatal: true,
|
1529
|
+
severity: 2,
|
1530
|
+
message,
|
1531
|
+
line: ex.lineNumber,
|
1532
|
+
column: ex.column
|
1533
|
+
}
|
1534
|
+
];
|
1535
|
+
}
|
1536
|
+
|
1537
|
+
const messageLists = blocks.map((block, i) => {
|
1510
1538
|
debug("A code block was found: %o", block.filename || "(unnamed)");
|
1511
1539
|
|
1512
1540
|
// Keep the legacy behavior.
|
@@ -1580,6 +1608,11 @@ class Linter {
|
|
1580
1608
|
...languageOptions.globals
|
1581
1609
|
};
|
1582
1610
|
|
1611
|
+
// double check that there is a parser to avoid mysterious error messages
|
1612
|
+
if (!languageOptions.parser) {
|
1613
|
+
throw new TypeError(`No parser specified for ${options.filename}`);
|
1614
|
+
}
|
1615
|
+
|
1583
1616
|
// Espree expects this information to be passed in
|
1584
1617
|
if (isEspree(languageOptions.parser)) {
|
1585
1618
|
const parserOptions = languageOptions.parserOptions;
|
@@ -1742,12 +1775,24 @@ class Linter {
|
|
1742
1775
|
debug("With flat config: %s", options.filename);
|
1743
1776
|
|
1744
1777
|
// we need a filename to match configs against
|
1745
|
-
const filename = options.filename || "
|
1778
|
+
const filename = options.filename || "__placeholder__.js";
|
1746
1779
|
|
1747
1780
|
// Store the config array in order to get plugin envs and rules later.
|
1748
1781
|
internalSlotsMap.get(this).lastConfigArray = configArray;
|
1749
1782
|
const config = configArray.getConfig(filename);
|
1750
1783
|
|
1784
|
+
if (!config) {
|
1785
|
+
return [
|
1786
|
+
{
|
1787
|
+
ruleId: null,
|
1788
|
+
severity: 1,
|
1789
|
+
message: `No matching configuration found for ${filename}.`,
|
1790
|
+
line: 0,
|
1791
|
+
column: 0
|
1792
|
+
}
|
1793
|
+
];
|
1794
|
+
}
|
1795
|
+
|
1751
1796
|
// Verify.
|
1752
1797
|
if (config.processor) {
|
1753
1798
|
debug("Apply the processor: %o", config.processor);
|
@@ -1784,13 +1829,36 @@ class Linter {
|
|
1784
1829
|
const physicalFilename = options.physicalFilename || filenameToExpose;
|
1785
1830
|
const text = ensureText(textOrSourceCode);
|
1786
1831
|
const preprocess = options.preprocess || (rawText => [rawText]);
|
1787
|
-
|
1788
1832
|
const postprocess = options.postprocess || (messagesList => messagesList.flat());
|
1789
1833
|
const filterCodeBlock =
|
1790
1834
|
options.filterCodeBlock ||
|
1791
1835
|
(blockFilename => blockFilename.endsWith(".js"));
|
1792
1836
|
const originalExtname = path.extname(filename);
|
1793
|
-
|
1837
|
+
|
1838
|
+
let blocks;
|
1839
|
+
|
1840
|
+
try {
|
1841
|
+
blocks = preprocess(text, filenameToExpose);
|
1842
|
+
} catch (ex) {
|
1843
|
+
|
1844
|
+
// If the message includes a leading line number, strip it:
|
1845
|
+
const message = `Preprocessing error: ${ex.message.replace(/^line \d+:/iu, "").trim()}`;
|
1846
|
+
|
1847
|
+
debug("%s\n%s", message, ex.stack);
|
1848
|
+
|
1849
|
+
return [
|
1850
|
+
{
|
1851
|
+
ruleId: null,
|
1852
|
+
fatal: true,
|
1853
|
+
severity: 2,
|
1854
|
+
message,
|
1855
|
+
line: ex.lineNumber,
|
1856
|
+
column: ex.column
|
1857
|
+
}
|
1858
|
+
];
|
1859
|
+
}
|
1860
|
+
|
1861
|
+
const messageLists = blocks.map((block, i) => {
|
1794
1862
|
debug("A code block was found: %o", block.filename || "(unnamed)");
|
1795
1863
|
|
1796
1864
|
// Keep the legacy behavior.
|
@@ -480,51 +480,54 @@ class FlatRuleTester {
|
|
480
480
|
].concat(scenarioErrors).join("\n"));
|
481
481
|
}
|
482
482
|
|
483
|
-
const baseConfig =
|
484
|
-
|
485
|
-
|
486
|
-
// copy root plugin over
|
487
|
-
"@": {
|
488
|
-
|
489
|
-
/*
|
490
|
-
* Parsers are wrapped to detect more errors, so this needs
|
491
|
-
* to be a new object for each call to run(), otherwise the
|
492
|
-
* parsers will be wrapped multiple times.
|
493
|
-
*/
|
494
|
-
parsers: {
|
495
|
-
...defaultConfig[0].plugins["@"].parsers
|
496
|
-
},
|
483
|
+
const baseConfig = [
|
484
|
+
{
|
485
|
+
plugins: {
|
497
486
|
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
487
|
+
// copy root plugin over
|
488
|
+
"@": {
|
489
|
+
|
490
|
+
/*
|
491
|
+
* Parsers are wrapped to detect more errors, so this needs
|
492
|
+
* to be a new object for each call to run(), otherwise the
|
493
|
+
* parsers will be wrapped multiple times.
|
494
|
+
*/
|
495
|
+
parsers: {
|
496
|
+
...defaultConfig[0].plugins["@"].parsers
|
497
|
+
},
|
498
|
+
|
499
|
+
/*
|
500
|
+
* The rules key on the default plugin is a proxy to lazy-load
|
501
|
+
* just the rules that are needed. So, don't create a new object
|
502
|
+
* here, just use the default one to keep that performance
|
503
|
+
* enhancement.
|
504
|
+
*/
|
505
|
+
rules: defaultConfig[0].plugins["@"].rules
|
506
|
+
},
|
507
|
+
"rule-to-test": {
|
508
|
+
rules: {
|
509
|
+
[ruleName]: Object.assign({}, rule, {
|
509
510
|
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
511
|
+
// Create a wrapper rule that freezes the `context` properties.
|
512
|
+
create(context) {
|
513
|
+
freezeDeeply(context.options);
|
514
|
+
freezeDeeply(context.settings);
|
515
|
+
freezeDeeply(context.parserOptions);
|
515
516
|
|
516
|
-
|
517
|
+
// freezeDeeply(context.languageOptions);
|
517
518
|
|
518
|
-
|
519
|
-
|
520
|
-
|
519
|
+
return (typeof rule === "function" ? rule : rule.create)(context);
|
520
|
+
}
|
521
|
+
})
|
522
|
+
}
|
521
523
|
}
|
524
|
+
},
|
525
|
+
languageOptions: {
|
526
|
+
...defaultConfig[0].languageOptions
|
522
527
|
}
|
523
528
|
},
|
524
|
-
|
525
|
-
|
526
|
-
}
|
527
|
-
};
|
529
|
+
...defaultConfig.slice(1)
|
530
|
+
];
|
528
531
|
|
529
532
|
/**
|
530
533
|
* Run the rule for the given item
|
@@ -305,6 +305,36 @@ function getCommentsDeprecation() {
|
|
305
305
|
);
|
306
306
|
}
|
307
307
|
|
308
|
+
/**
|
309
|
+
* Emit a deprecation warning if function-style format is being used.
|
310
|
+
* @param {string} ruleName Name of the rule.
|
311
|
+
* @returns {void}
|
312
|
+
*/
|
313
|
+
function emitLegacyRuleAPIWarning(ruleName) {
|
314
|
+
if (!emitLegacyRuleAPIWarning[`warned-${ruleName}`]) {
|
315
|
+
emitLegacyRuleAPIWarning[`warned-${ruleName}`] = true;
|
316
|
+
process.emitWarning(
|
317
|
+
`"${ruleName}" rule is using the deprecated function-style format and will stop working in ESLint v9. Please use object-style format: https://eslint.org/docs/developer-guide/working-with-rules`,
|
318
|
+
"DeprecationWarning"
|
319
|
+
);
|
320
|
+
}
|
321
|
+
}
|
322
|
+
|
323
|
+
/**
|
324
|
+
* Emit a deprecation warning if rule has options but is missing the "meta.schema" property
|
325
|
+
* @param {string} ruleName Name of the rule.
|
326
|
+
* @returns {void}
|
327
|
+
*/
|
328
|
+
function emitMissingSchemaWarning(ruleName) {
|
329
|
+
if (!emitMissingSchemaWarning[`warned-${ruleName}`]) {
|
330
|
+
emitMissingSchemaWarning[`warned-${ruleName}`] = true;
|
331
|
+
process.emitWarning(
|
332
|
+
`"${ruleName}" rule has options but is missing the "meta.schema" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas`,
|
333
|
+
"DeprecationWarning"
|
334
|
+
);
|
335
|
+
}
|
336
|
+
}
|
337
|
+
|
308
338
|
//------------------------------------------------------------------------------
|
309
339
|
// Public Interface
|
310
340
|
//------------------------------------------------------------------------------
|
@@ -521,6 +551,9 @@ class RuleTester {
|
|
521
551
|
].concat(scenarioErrors).join("\n"));
|
522
552
|
}
|
523
553
|
|
554
|
+
if (typeof rule === "function") {
|
555
|
+
emitLegacyRuleAPIWarning(ruleName);
|
556
|
+
}
|
524
557
|
|
525
558
|
linter.defineRule(ruleName, Object.assign({}, rule, {
|
526
559
|
|
@@ -578,6 +611,15 @@ class RuleTester {
|
|
578
611
|
|
579
612
|
if (hasOwnProperty(item, "options")) {
|
580
613
|
assert(Array.isArray(item.options), "options must be an array");
|
614
|
+
if (
|
615
|
+
item.options.length > 0 &&
|
616
|
+
typeof rule === "object" &&
|
617
|
+
(
|
618
|
+
!rule.meta || (rule.meta && (typeof rule.meta.schema === "undefined" || rule.meta.schema === null))
|
619
|
+
)
|
620
|
+
) {
|
621
|
+
emitMissingSchemaWarning(ruleName);
|
622
|
+
}
|
581
623
|
config.rules[ruleName] = [1].concat(item.options);
|
582
624
|
} else {
|
583
625
|
config.rules[ruleName] = 1;
|
@@ -140,7 +140,7 @@ module.exports = {
|
|
140
140
|
type: "suggestion",
|
141
141
|
|
142
142
|
docs: {
|
143
|
-
description: "
|
143
|
+
description: "Enforce getter and setter pairs in objects and classes",
|
144
144
|
recommended: false,
|
145
145
|
url: "https://eslint.org/docs/rules/accessor-pairs"
|
146
146
|
},
|
@@ -17,7 +17,7 @@ module.exports = {
|
|
17
17
|
type: "layout",
|
18
18
|
|
19
19
|
docs: {
|
20
|
-
description: "
|
20
|
+
description: "Enforce linebreaks after opening and before closing array brackets",
|
21
21
|
recommended: false,
|
22
22
|
url: "https://eslint.org/docs/rules/array-bracket-newline"
|
23
23
|
},
|
@@ -16,7 +16,7 @@ module.exports = {
|
|
16
16
|
type: "layout",
|
17
17
|
|
18
18
|
docs: {
|
19
|
-
description: "
|
19
|
+
description: "Enforce consistent spacing inside array brackets",
|
20
20
|
recommended: false,
|
21
21
|
url: "https://eslint.org/docs/rules/array-bracket-spacing"
|
22
22
|
},
|
@@ -139,7 +139,7 @@ module.exports = {
|
|
139
139
|
type: "problem",
|
140
140
|
|
141
141
|
docs: {
|
142
|
-
description: "
|
142
|
+
description: "Enforce `return` statements in callbacks of array methods",
|
143
143
|
recommended: false,
|
144
144
|
url: "https://eslint.org/docs/rules/array-callback-return"
|
145
145
|
},
|
@@ -17,7 +17,7 @@ module.exports = {
|
|
17
17
|
type: "layout",
|
18
18
|
|
19
19
|
docs: {
|
20
|
-
description: "
|
20
|
+
description: "Enforce line breaks after each array element",
|
21
21
|
recommended: false,
|
22
22
|
url: "https://eslint.org/docs/rules/array-element-newline"
|
23
23
|
},
|
@@ -20,7 +20,7 @@ module.exports = {
|
|
20
20
|
type: "suggestion",
|
21
21
|
|
22
22
|
docs: {
|
23
|
-
description: "
|
23
|
+
description: "Require braces around arrow function bodies",
|
24
24
|
recommended: false,
|
25
25
|
url: "https://eslint.org/docs/rules/arrow-body-style"
|
26
26
|
},
|
@@ -33,7 +33,7 @@ module.exports = {
|
|
33
33
|
type: "layout",
|
34
34
|
|
35
35
|
docs: {
|
36
|
-
description: "
|
36
|
+
description: "Require parentheses around arrow function arguments",
|
37
37
|
recommended: false,
|
38
38
|
url: "https://eslint.org/docs/rules/arrow-parens"
|
39
39
|
},
|
@@ -20,7 +20,7 @@ module.exports = {
|
|
20
20
|
type: "layout",
|
21
21
|
|
22
22
|
docs: {
|
23
|
-
description: "
|
23
|
+
description: "Enforce consistent spacing before and after the arrow in arrow functions",
|
24
24
|
recommended: false,
|
25
25
|
url: "https://eslint.org/docs/rules/arrow-spacing"
|
26
26
|
},
|
@@ -14,7 +14,7 @@ module.exports = {
|
|
14
14
|
type: "suggestion",
|
15
15
|
|
16
16
|
docs: {
|
17
|
-
description: "
|
17
|
+
description: "Enforce the use of variables within the scope they are defined",
|
18
18
|
recommended: false,
|
19
19
|
url: "https://eslint.org/docs/rules/block-scoped-var"
|
20
20
|
},
|
@@ -17,7 +17,7 @@ module.exports = {
|
|
17
17
|
type: "layout",
|
18
18
|
|
19
19
|
docs: {
|
20
|
-
description: "
|
20
|
+
description: "Disallow or enforce spaces inside of blocks after opening block and before closing block",
|
21
21
|
recommended: false,
|
22
22
|
url: "https://eslint.org/docs/rules/block-spacing"
|
23
23
|
},
|
package/lib/rules/brace-style.js
CHANGED
@@ -19,7 +19,7 @@ module.exports = {
|
|
19
19
|
type: "suggestion",
|
20
20
|
|
21
21
|
docs: {
|
22
|
-
description: "
|
22
|
+
description: "Require `return` statements after callbacks",
|
23
23
|
recommended: false,
|
24
24
|
url: "https://eslint.org/docs/rules/callback-return"
|
25
25
|
},
|
package/lib/rules/camelcase.js
CHANGED
@@ -105,7 +105,7 @@ module.exports = {
|
|
105
105
|
type: "suggestion",
|
106
106
|
|
107
107
|
docs: {
|
108
|
-
description: "
|
108
|
+
description: "Enforce or disallow capitalization of the first letter of a comment",
|
109
109
|
recommended: false,
|
110
110
|
url: "https://eslint.org/docs/rules/capitalized-comments"
|
111
111
|
},
|
@@ -21,7 +21,7 @@ module.exports = {
|
|
21
21
|
type: "suggestion",
|
22
22
|
|
23
23
|
docs: {
|
24
|
-
description: "
|
24
|
+
description: "Enforce that class methods utilize `this`",
|
25
25
|
recommended: false,
|
26
26
|
url: "https://eslint.org/docs/rules/class-methods-use-this"
|
27
27
|
},
|
@@ -16,7 +16,7 @@ module.exports = {
|
|
16
16
|
type: "layout",
|
17
17
|
|
18
18
|
docs: {
|
19
|
-
description: "
|
19
|
+
description: "Enforce consistent spacing before and after commas",
|
20
20
|
recommended: false,
|
21
21
|
url: "https://eslint.org/docs/rules/comma-spacing"
|
22
22
|
},
|
@@ -103,38 +103,6 @@ module.exports = {
|
|
103
103
|
});
|
104
104
|
}
|
105
105
|
|
106
|
-
/**
|
107
|
-
* Validates the spacing around a comma token.
|
108
|
-
* @param {Object} tokens The tokens to be validated.
|
109
|
-
* @param {Token} tokens.comma The token representing the comma.
|
110
|
-
* @param {Token} [tokens.left] The last token before the comma.
|
111
|
-
* @param {Token} [tokens.right] The first token after the comma.
|
112
|
-
* @param {Token|ASTNode} reportItem The item to use when reporting an error.
|
113
|
-
* @returns {void}
|
114
|
-
* @private
|
115
|
-
*/
|
116
|
-
function validateCommaItemSpacing(tokens, reportItem) {
|
117
|
-
if (tokens.left && astUtils.isTokenOnSameLine(tokens.left, tokens.comma) &&
|
118
|
-
(options.before !== sourceCode.isSpaceBetweenTokens(tokens.left, tokens.comma))
|
119
|
-
) {
|
120
|
-
report(reportItem, "before", tokens.left);
|
121
|
-
}
|
122
|
-
|
123
|
-
if (tokens.right && astUtils.isClosingParenToken(tokens.right)) {
|
124
|
-
return;
|
125
|
-
}
|
126
|
-
|
127
|
-
if (tokens.right && !options.after && tokens.right.type === "Line") {
|
128
|
-
return;
|
129
|
-
}
|
130
|
-
|
131
|
-
if (tokens.right && astUtils.isTokenOnSameLine(tokens.comma, tokens.right) &&
|
132
|
-
(options.after !== sourceCode.isSpaceBetweenTokens(tokens.comma, tokens.right))
|
133
|
-
) {
|
134
|
-
report(reportItem, "after", tokens.right);
|
135
|
-
}
|
136
|
-
}
|
137
|
-
|
138
106
|
/**
|
139
107
|
* Adds null elements of the given ArrayExpression or ArrayPattern node to the ignore list.
|
140
108
|
* @param {ASTNode} node An ArrayExpression or ArrayPattern node.
|
@@ -172,18 +140,44 @@ module.exports = {
|
|
172
140
|
return;
|
173
141
|
}
|
174
142
|
|
175
|
-
if (token && token.type === "JSXText") {
|
176
|
-
return;
|
177
|
-
}
|
178
|
-
|
179
143
|
const previousToken = tokensAndComments[i - 1];
|
180
144
|
const nextToken = tokensAndComments[i + 1];
|
181
145
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
146
|
+
if (
|
147
|
+
previousToken &&
|
148
|
+
!astUtils.isCommaToken(previousToken) && // ignore spacing between two commas
|
149
|
+
|
150
|
+
/*
|
151
|
+
* `commaTokensToIgnore` are ending commas of `null` elements (array holes/elisions).
|
152
|
+
* In addition to spacing between two commas, this can also ignore:
|
153
|
+
*
|
154
|
+
* - Spacing after `[` (controlled by array-bracket-spacing)
|
155
|
+
* Example: [ , ]
|
156
|
+
* ^
|
157
|
+
* - Spacing after a comment (for backwards compatibility, this was possibly unintentional)
|
158
|
+
* Example: [a, /* * / ,]
|
159
|
+
* ^
|
160
|
+
*/
|
161
|
+
!commaTokensToIgnore.includes(token) &&
|
162
|
+
|
163
|
+
astUtils.isTokenOnSameLine(previousToken, token) &&
|
164
|
+
options.before !== sourceCode.isSpaceBetweenTokens(previousToken, token)
|
165
|
+
) {
|
166
|
+
report(token, "before", previousToken);
|
167
|
+
}
|
168
|
+
|
169
|
+
if (
|
170
|
+
nextToken &&
|
171
|
+
!astUtils.isCommaToken(nextToken) && // ignore spacing between two commas
|
172
|
+
!astUtils.isClosingParenToken(nextToken) && // controlled by space-in-parens
|
173
|
+
!astUtils.isClosingBracketToken(nextToken) && // controlled by array-bracket-spacing
|
174
|
+
!astUtils.isClosingBraceToken(nextToken) && // controlled by object-curly-spacing
|
175
|
+
!(!options.after && nextToken.type === "Line") && // special case, allow space before line comment
|
176
|
+
astUtils.isTokenOnSameLine(token, nextToken) &&
|
177
|
+
options.after !== sourceCode.isSpaceBetweenTokens(token, nextToken)
|
178
|
+
) {
|
179
|
+
report(token, "after", nextToken);
|
180
|
+
}
|
187
181
|
});
|
188
182
|
},
|
189
183
|
ArrayExpression: addNullElementsToIgnoreList,
|
package/lib/rules/comma-style.js
CHANGED
package/lib/rules/complexity.js
CHANGED
@@ -23,7 +23,7 @@ module.exports = {
|
|
23
23
|
type: "suggestion",
|
24
24
|
|
25
25
|
docs: {
|
26
|
-
description: "
|
26
|
+
description: "Enforce a maximum cyclomatic complexity allowed in a program",
|
27
27
|
recommended: false,
|
28
28
|
url: "https://eslint.org/docs/rules/complexity"
|
29
29
|
},
|
@@ -16,7 +16,7 @@ module.exports = {
|
|
16
16
|
type: "layout",
|
17
17
|
|
18
18
|
docs: {
|
19
|
-
description: "
|
19
|
+
description: "Enforce consistent spacing inside computed property brackets",
|
20
20
|
recommended: false,
|
21
21
|
url: "https://eslint.org/docs/rules/computed-property-spacing"
|
22
22
|
},
|
@@ -46,7 +46,7 @@ module.exports = {
|
|
46
46
|
type: "suggestion",
|
47
47
|
|
48
48
|
docs: {
|
49
|
-
description: "
|
49
|
+
description: "Require `return` statements to either always or never specify values",
|
50
50
|
recommended: false,
|
51
51
|
url: "https://eslint.org/docs/rules/consistent-return"
|
52
52
|
},
|
@@ -14,7 +14,7 @@ module.exports = {
|
|
14
14
|
type: "suggestion",
|
15
15
|
|
16
16
|
docs: {
|
17
|
-
description: "
|
17
|
+
description: "Enforce consistent naming when capturing the current execution context",
|
18
18
|
recommended: false,
|
19
19
|
url: "https://eslint.org/docs/rules/consistent-this"
|
20
20
|
},
|
@@ -122,7 +122,7 @@ module.exports = {
|
|
122
122
|
type: "problem",
|
123
123
|
|
124
124
|
docs: {
|
125
|
-
description: "
|
125
|
+
description: "Require `super()` calls in constructors",
|
126
126
|
recommended: true,
|
127
127
|
url: "https://eslint.org/docs/rules/constructor-super"
|
128
128
|
},
|
package/lib/rules/curly.js
CHANGED
@@ -20,7 +20,7 @@ module.exports = {
|
|
20
20
|
type: "suggestion",
|
21
21
|
|
22
22
|
docs: {
|
23
|
-
description: "
|
23
|
+
description: "Enforce consistent brace style for all control statements",
|
24
24
|
recommended: false,
|
25
25
|
url: "https://eslint.org/docs/rules/curly"
|
26
26
|
},
|
@@ -15,7 +15,7 @@ module.exports = {
|
|
15
15
|
type: "suggestion",
|
16
16
|
|
17
17
|
docs: {
|
18
|
-
description: "
|
18
|
+
description: "Enforce default clauses in switch statements to be last",
|
19
19
|
recommended: false,
|
20
20
|
url: "https://eslint.org/docs/rules/default-case-last"
|
21
21
|
},
|
@@ -16,7 +16,7 @@ module.exports = {
|
|
16
16
|
type: "suggestion",
|
17
17
|
|
18
18
|
docs: {
|
19
|
-
description: "
|
19
|
+
description: "Require `default` cases in `switch` statements",
|
20
20
|
recommended: false,
|
21
21
|
url: "https://eslint.org/docs/rules/default-case"
|
22
22
|
},
|