eslint 8.0.0-beta.0 → 8.0.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 +4 -4
- package/bin/eslint.js +1 -1
- package/conf/eslint-recommended.js +1 -1
- package/conf/{category-list.json → rule-type-list.json} +4 -7
- package/lib/cli-engine/cli-engine.js +11 -3
- package/lib/cli-engine/file-enumerator.js +4 -3
- package/lib/cli-engine/formatters/html.js +1 -1
- package/lib/cli-engine/hash.js +2 -2
- package/lib/cli-engine/xml-escape.js +1 -1
- package/lib/config/flat-config-array.js +2 -2
- package/lib/config/flat-config-schema.js +1 -1
- package/lib/config/rule-validator.js +25 -8
- package/lib/eslint/eslint.js +4 -0
- package/lib/init/autoconfig.js +17 -18
- package/lib/init/config-file.js +3 -3
- package/lib/init/config-initializer.js +11 -10
- package/lib/init/config-rule.js +15 -16
- package/lib/init/npm-utils.js +16 -15
- package/lib/init/source-code-utils.js +6 -5
- package/lib/linter/apply-disable-directives.js +80 -11
- package/lib/linter/code-path-analysis/code-path-analyzer.js +115 -36
- package/lib/linter/code-path-analysis/code-path-segment.js +0 -1
- package/lib/linter/code-path-analysis/code-path-state.js +4 -1
- package/lib/linter/code-path-analysis/code-path.js +14 -5
- package/lib/linter/code-path-analysis/debug-helpers.js +2 -2
- package/lib/linter/code-path-analysis/fork-context.js +0 -1
- package/lib/linter/code-path-analysis/id-generator.js +0 -1
- package/lib/linter/config-comment-parser.js +1 -1
- package/lib/linter/linter.js +51 -22
- package/lib/linter/node-event-generator.js +0 -1
- package/lib/linter/report-translator.js +12 -12
- package/lib/linter/rules.js +3 -0
- package/lib/linter/safe-emitter.js +2 -2
- package/lib/linter/source-code-fixer.js +2 -2
- package/lib/linter/timing.js +2 -2
- package/lib/rule-tester/rule-tester.js +12 -2
- package/lib/rules/accessor-pairs.js +0 -1
- package/lib/rules/array-bracket-newline.js +0 -1
- package/lib/rules/array-bracket-spacing.js +0 -1
- package/lib/rules/array-callback-return.js +0 -1
- package/lib/rules/array-element-newline.js +0 -1
- package/lib/rules/arrow-body-style.js +0 -1
- package/lib/rules/arrow-parens.js +0 -1
- package/lib/rules/arrow-spacing.js +0 -1
- package/lib/rules/block-scoped-var.js +0 -1
- package/lib/rules/block-spacing.js +0 -1
- package/lib/rules/brace-style.js +0 -1
- package/lib/rules/callback-return.js +1 -1
- package/lib/rules/camelcase.js +17 -19
- package/lib/rules/capitalized-comments.js +0 -1
- package/lib/rules/class-methods-use-this.js +51 -9
- package/lib/rules/comma-dangle.js +0 -1
- package/lib/rules/comma-spacing.js +0 -1
- package/lib/rules/comma-style.js +0 -1
- package/lib/rules/complexity.js +47 -56
- package/lib/rules/computed-property-spacing.js +0 -1
- package/lib/rules/consistent-return.js +0 -1
- package/lib/rules/consistent-this.js +1 -2
- package/lib/rules/constructor-super.js +0 -1
- package/lib/rules/curly.js +0 -1
- package/lib/rules/default-case-last.js +0 -1
- package/lib/rules/default-case.js +2 -3
- package/lib/rules/default-param-last.js +1 -2
- package/lib/rules/dot-location.js +0 -1
- package/lib/rules/dot-notation.js +0 -1
- package/lib/rules/eol-last.js +6 -2
- package/lib/rules/eqeqeq.js +1 -2
- package/lib/rules/for-direction.js +0 -1
- package/lib/rules/func-call-spacing.js +0 -1
- package/lib/rules/func-name-matching.js +9 -6
- package/lib/rules/func-names.js +0 -1
- package/lib/rules/func-style.js +0 -1
- package/lib/rules/function-call-argument-newline.js +0 -1
- package/lib/rules/function-paren-newline.js +1 -1
- package/lib/rules/generator-star-spacing.js +0 -1
- package/lib/rules/getter-return.js +0 -1
- package/lib/rules/global-require.js +1 -1
- package/lib/rules/grouped-accessor-pairs.js +0 -1
- package/lib/rules/guard-for-in.js +0 -1
- package/lib/rules/handle-callback-err.js +1 -1
- package/lib/rules/id-blacklist.js +1 -1
- package/lib/rules/id-denylist.js +0 -1
- package/lib/rules/id-length.js +0 -1
- package/lib/rules/id-match.js +0 -1
- package/lib/rules/implicit-arrow-linebreak.js +0 -1
- package/lib/rules/indent-legacy.js +1 -1
- package/lib/rules/indent.js +7 -10
- package/lib/rules/index.js +1 -1
- package/lib/rules/init-declarations.js +0 -1
- package/lib/rules/jsx-quotes.js +0 -1
- package/lib/rules/key-spacing.js +4 -5
- package/lib/rules/keyword-spacing.js +19 -3
- package/lib/rules/line-comment-position.js +0 -1
- package/lib/rules/linebreak-style.js +0 -1
- package/lib/rules/lines-around-comment.js +0 -1
- package/lib/rules/lines-around-directive.js +1 -2
- package/lib/rules/lines-between-class-members.js +50 -3
- package/lib/rules/max-classes-per-file.js +31 -8
- package/lib/rules/max-depth.js +0 -1
- package/lib/rules/max-len.js +1 -2
- package/lib/rules/max-lines-per-function.js +1 -2
- package/lib/rules/max-lines.js +0 -1
- package/lib/rules/max-nested-callbacks.js +0 -1
- package/lib/rules/max-params.js +0 -1
- package/lib/rules/max-statements-per-line.js +0 -1
- package/lib/rules/max-statements.js +0 -1
- package/lib/rules/multiline-comment-style.js +0 -1
- package/lib/rules/multiline-ternary.js +0 -1
- package/lib/rules/new-cap.js +2 -2
- package/lib/rules/new-parens.js +0 -1
- package/lib/rules/newline-after-var.js +4 -5
- package/lib/rules/newline-before-return.js +2 -3
- package/lib/rules/newline-per-chained-call.js +1 -2
- package/lib/rules/no-alert.js +0 -1
- package/lib/rules/no-array-constructor.js +0 -1
- package/lib/rules/no-async-promise-executor.js +0 -1
- package/lib/rules/no-await-in-loop.js +0 -1
- package/lib/rules/no-bitwise.js +5 -6
- package/lib/rules/no-buffer-constructor.js +1 -1
- package/lib/rules/no-caller.js +0 -1
- package/lib/rules/no-case-declarations.js +0 -1
- package/lib/rules/no-catch-shadow.js +0 -1
- package/lib/rules/no-class-assign.js +0 -1
- package/lib/rules/no-compare-neg-zero.js +0 -1
- package/lib/rules/no-cond-assign.js +0 -1
- package/lib/rules/no-confusing-arrow.js +0 -1
- package/lib/rules/no-console.js +0 -1
- package/lib/rules/no-const-assign.js +0 -1
- package/lib/rules/no-constant-condition.js +0 -1
- package/lib/rules/no-constructor-return.js +0 -1
- package/lib/rules/no-continue.js +0 -1
- package/lib/rules/no-control-regex.js +0 -1
- package/lib/rules/no-debugger.js +0 -1
- package/lib/rules/no-delete-var.js +0 -1
- package/lib/rules/no-div-regex.js +0 -1
- package/lib/rules/no-dupe-args.js +0 -1
- package/lib/rules/no-dupe-class-members.js +0 -1
- package/lib/rules/no-dupe-else-if.js +0 -1
- package/lib/rules/no-dupe-keys.js +0 -2
- package/lib/rules/no-duplicate-case.js +0 -1
- package/lib/rules/no-duplicate-imports.js +0 -1
- package/lib/rules/no-else-return.js +0 -1
- package/lib/rules/no-empty-character-class.js +0 -1
- package/lib/rules/no-empty-function.js +0 -1
- package/lib/rules/no-empty-pattern.js +0 -1
- package/lib/rules/no-empty.js +0 -1
- package/lib/rules/no-eq-null.js +0 -1
- package/lib/rules/no-eval.js +0 -1
- package/lib/rules/no-ex-assign.js +0 -1
- package/lib/rules/no-extend-native.js +0 -1
- package/lib/rules/no-extra-bind.js +0 -1
- package/lib/rules/no-extra-boolean-cast.js +1 -1
- package/lib/rules/no-extra-label.js +0 -1
- package/lib/rules/no-extra-parens.js +0 -1
- package/lib/rules/no-extra-semi.js +0 -1
- package/lib/rules/no-fallthrough.js +0 -1
- package/lib/rules/no-floating-decimal.js +0 -1
- package/lib/rules/no-func-assign.js +0 -1
- package/lib/rules/no-global-assign.js +0 -1
- package/lib/rules/no-implicit-coercion.js +0 -1
- package/lib/rules/no-implicit-globals.js +0 -1
- package/lib/rules/no-implied-eval.js +0 -1
- package/lib/rules/no-import-assign.js +0 -1
- package/lib/rules/no-inline-comments.js +0 -1
- package/lib/rules/no-inner-declarations.js +0 -1
- package/lib/rules/no-invalid-regexp.js +0 -1
- package/lib/rules/no-invalid-this.js +0 -1
- package/lib/rules/no-irregular-whitespace.js +0 -1
- package/lib/rules/no-iterator.js +0 -1
- package/lib/rules/no-label-var.js +0 -1
- package/lib/rules/no-labels.js +0 -1
- package/lib/rules/no-lone-blocks.js +0 -1
- package/lib/rules/no-lonely-if.js +0 -1
- package/lib/rules/no-loop-func.js +1 -2
- package/lib/rules/no-loss-of-precision.js +0 -1
- package/lib/rules/no-magic-numbers.js +0 -1
- package/lib/rules/no-misleading-character-class.js +0 -1
- package/lib/rules/no-mixed-operators.js +1 -2
- package/lib/rules/no-mixed-requires.js +1 -1
- package/lib/rules/no-mixed-spaces-and-tabs.js +0 -1
- package/lib/rules/no-multi-assign.js +0 -1
- package/lib/rules/no-multi-spaces.js +0 -1
- package/lib/rules/no-multi-str.js +0 -1
- package/lib/rules/no-multiple-empty-lines.js +0 -1
- package/lib/rules/no-native-reassign.js +0 -1
- package/lib/rules/no-negated-condition.js +0 -1
- package/lib/rules/no-negated-in-lhs.js +0 -1
- package/lib/rules/no-nested-ternary.js +0 -1
- package/lib/rules/no-new-func.js +34 -7
- package/lib/rules/no-new-object.js +0 -1
- package/lib/rules/no-new-require.js +1 -1
- package/lib/rules/no-new-symbol.js +0 -1
- package/lib/rules/no-new-wrappers.js +0 -1
- package/lib/rules/no-new.js +0 -1
- package/lib/rules/no-nonoctal-decimal-escape.js +0 -1
- package/lib/rules/no-obj-calls.js +0 -1
- package/lib/rules/no-octal-escape.js +0 -1
- package/lib/rules/no-octal.js +0 -1
- package/lib/rules/no-param-reassign.js +0 -1
- package/lib/rules/no-path-concat.js +1 -1
- package/lib/rules/no-plusplus.js +0 -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 +0 -1
- package/lib/rules/no-proto.js +0 -1
- package/lib/rules/no-prototype-builtins.js +0 -1
- package/lib/rules/no-redeclare.js +0 -1
- package/lib/rules/no-regex-spaces.js +0 -1
- package/lib/rules/no-restricted-exports.js +0 -1
- package/lib/rules/no-restricted-globals.js +1 -2
- package/lib/rules/no-restricted-imports.js +5 -6
- package/lib/rules/no-restricted-modules.js +3 -3
- package/lib/rules/no-restricted-properties.js +2 -3
- package/lib/rules/no-restricted-syntax.js +1 -2
- package/lib/rules/no-return-assign.js +0 -1
- package/lib/rules/no-return-await.js +0 -1
- package/lib/rules/no-script-url.js +1 -3
- package/lib/rules/no-self-assign.js +0 -1
- package/lib/rules/no-self-compare.js +0 -1
- package/lib/rules/no-sequences.js +0 -1
- package/lib/rules/no-setter-return.js +0 -1
- package/lib/rules/no-shadow-restricted-names.js +0 -1
- package/lib/rules/no-shadow.js +1 -2
- package/lib/rules/no-spaced-func.js +0 -1
- package/lib/rules/no-sparse-arrays.js +0 -1
- package/lib/rules/no-sync.js +1 -3
- package/lib/rules/no-tabs.js +0 -1
- package/lib/rules/no-template-curly-in-string.js +0 -1
- package/lib/rules/no-ternary.js +0 -1
- package/lib/rules/no-this-before-super.js +0 -1
- package/lib/rules/no-throw-literal.js +0 -1
- package/lib/rules/no-trailing-spaces.js +0 -1
- package/lib/rules/no-undef-init.js +9 -61
- package/lib/rules/no-undef.js +0 -1
- package/lib/rules/no-undefined.js +0 -1
- package/lib/rules/no-underscore-dangle.js +0 -1
- package/lib/rules/no-unexpected-multiline.js +0 -1
- package/lib/rules/no-unmodified-loop-condition.js +0 -1
- package/lib/rules/no-unneeded-ternary.js +0 -1
- package/lib/rules/no-unreachable-loop.js +0 -1
- package/lib/rules/no-unreachable.js +26 -25
- package/lib/rules/no-unsafe-finally.js +0 -1
- package/lib/rules/no-unsafe-negation.js +0 -1
- package/lib/rules/no-unsafe-optional-chaining.js +0 -1
- package/lib/rules/no-unused-expressions.js +4 -5
- package/lib/rules/no-unused-labels.js +0 -1
- package/lib/rules/no-unused-vars.js +26 -28
- package/lib/rules/no-use-before-define.js +0 -1
- package/lib/rules/no-useless-backreference.js +0 -1
- package/lib/rules/no-useless-call.js +0 -1
- package/lib/rules/no-useless-catch.js +0 -1
- package/lib/rules/no-useless-computed-key.js +1 -1
- package/lib/rules/no-useless-concat.js +0 -1
- package/lib/rules/no-useless-constructor.js +0 -1
- package/lib/rules/no-useless-escape.js +9 -9
- package/lib/rules/no-useless-rename.js +0 -1
- package/lib/rules/no-useless-return.js +0 -1
- package/lib/rules/no-var.js +0 -1
- package/lib/rules/no-void.js +0 -1
- package/lib/rules/no-warning-comments.js +0 -1
- package/lib/rules/no-whitespace-before-property.js +0 -1
- package/lib/rules/no-with.js +0 -1
- package/lib/rules/nonblock-statement-body-position.js +0 -1
- package/lib/rules/object-curly-newline.js +0 -1
- package/lib/rules/object-curly-spacing.js +0 -1
- package/lib/rules/object-property-newline.js +0 -1
- package/lib/rules/object-shorthand.js +3 -8
- package/lib/rules/one-var-declaration-per-line.js +0 -1
- package/lib/rules/one-var.js +1 -2
- package/lib/rules/operator-assignment.js +6 -7
- package/lib/rules/operator-linebreak.js +0 -1
- package/lib/rules/padded-blocks.js +1 -1
- package/lib/rules/padding-line-between-statements.js +0 -1
- package/lib/rules/prefer-arrow-callback.js +1 -1
- package/lib/rules/prefer-const.js +0 -1
- package/lib/rules/prefer-destructuring.js +1 -2
- package/lib/rules/prefer-exponentiation-operator.js +0 -1
- package/lib/rules/prefer-named-capture-group.js +0 -1
- package/lib/rules/prefer-numeric-literals.js +0 -1
- package/lib/rules/prefer-object-spread.js +0 -1
- package/lib/rules/prefer-promise-reject-errors.js +0 -1
- package/lib/rules/prefer-reflect.js +0 -1
- package/lib/rules/prefer-regex-literals.js +0 -1
- package/lib/rules/prefer-rest-params.js +0 -1
- package/lib/rules/prefer-spread.js +0 -1
- package/lib/rules/prefer-template.js +0 -1
- package/lib/rules/quote-props.js +8 -9
- package/lib/rules/quotes.js +0 -1
- package/lib/rules/radix.js +0 -1
- package/lib/rules/require-atomic-updates.js +24 -9
- package/lib/rules/require-await.js +0 -1
- package/lib/rules/require-jsdoc.js +1 -1
- package/lib/rules/require-unicode-regexp.js +0 -1
- package/lib/rules/require-yield.js +0 -1
- package/lib/rules/rest-spread-spacing.js +0 -1
- package/lib/rules/semi-spacing.js +0 -1
- package/lib/rules/semi-style.js +0 -1
- package/lib/rules/semi.js +66 -6
- package/lib/rules/sort-imports.js +0 -1
- package/lib/rules/sort-keys.js +0 -1
- package/lib/rules/sort-vars.js +0 -1
- package/lib/rules/space-before-blocks.js +14 -3
- package/lib/rules/space-before-function-paren.js +0 -1
- package/lib/rules/space-in-parens.js +0 -1
- package/lib/rules/space-infix-ops.js +0 -1
- package/lib/rules/space-unary-ops.js +0 -1
- package/lib/rules/spaced-comment.js +0 -1
- package/lib/rules/strict.js +0 -1
- package/lib/rules/switch-colon-spacing.js +1 -14
- package/lib/rules/symbol-description.js +0 -1
- package/lib/rules/template-curly-spacing.js +0 -1
- package/lib/rules/template-tag-spacing.js +0 -1
- package/lib/rules/unicode-bom.js +0 -1
- package/lib/rules/use-isnan.js +0 -1
- package/lib/rules/utils/ast-utils.js +29 -7
- package/lib/rules/utils/lazy-loading-rule-map.js +3 -3
- package/lib/rules/valid-jsdoc.js +1 -1
- package/lib/rules/valid-typeof.js +0 -1
- package/lib/rules/vars-on-top.js +1 -2
- package/lib/rules/wrap-iife.js +0 -1
- package/lib/rules/wrap-regex.js +0 -1
- package/lib/rules/yield-star-spacing.js +0 -1
- package/lib/rules/yoda.js +0 -1
- package/lib/shared/ajv.js +1 -1
- package/lib/shared/config-validator.js +10 -5
- package/lib/shared/logging.js +1 -1
- package/lib/shared/relative-module-resolver.js +1 -0
- package/lib/shared/runtime-info.js +3 -0
- package/lib/shared/traverser.js +2 -2
- package/lib/shared/types.js +2 -2
- package/lib/source-code/source-code.js +11 -5
- package/lib/source-code/token-store/cursor.js +1 -1
- package/package.json +5 -5
package/lib/rules/key-spacing.js
CHANGED
@@ -139,7 +139,6 @@ module.exports = {
|
|
139
139
|
|
140
140
|
docs: {
|
141
141
|
description: "enforce consistent spacing between keys and values in object literal properties",
|
142
|
-
category: "Stylistic Issues",
|
143
142
|
recommended: false,
|
144
143
|
url: "https://eslint.org/docs/rules/key-spacing"
|
145
144
|
},
|
@@ -531,8 +530,8 @@ module.exports = {
|
|
531
530
|
|
532
531
|
/**
|
533
532
|
* Creates groups of properties.
|
534
|
-
* @param
|
535
|
-
* @returns {Array
|
533
|
+
* @param {ASTNode} node ObjectExpression node being evaluated.
|
534
|
+
* @returns {Array<ASTNode[]>} Groups of property AST node lists.
|
536
535
|
*/
|
537
536
|
function createGroups(node) {
|
538
537
|
if (node.properties.length === 1) {
|
@@ -600,7 +599,7 @@ module.exports = {
|
|
600
599
|
|
601
600
|
/**
|
602
601
|
* Verifies spacing of property conforms to specified options.
|
603
|
-
* @param
|
602
|
+
* @param {ASTNode} node Property node being evaluated.
|
604
603
|
* @param {Object} lineOptions Configured singleLine or multiLine options
|
605
604
|
* @returns {void}
|
606
605
|
*/
|
@@ -629,7 +628,7 @@ module.exports = {
|
|
629
628
|
|
630
629
|
/**
|
631
630
|
* Verifies vertical alignment, taking into account groups of properties.
|
632
|
-
* @param
|
631
|
+
* @param {ASTNode} node ObjectExpression node being evaluated.
|
633
632
|
* @returns {void}
|
634
633
|
*/
|
635
634
|
function verifyAlignment(node) {
|
@@ -67,7 +67,6 @@ module.exports = {
|
|
67
67
|
|
68
68
|
docs: {
|
69
69
|
description: "enforce consistent spacing before and after keywords",
|
70
|
-
category: "Stylistic Issues",
|
71
70
|
recommended: false,
|
72
71
|
url: "https://eslint.org/docs/rules/keyword-spacing"
|
73
72
|
},
|
@@ -403,7 +402,15 @@ module.exports = {
|
|
403
402
|
*/
|
404
403
|
function checkSpacingForForInStatement(node) {
|
405
404
|
checkSpacingAroundFirstToken(node);
|
406
|
-
|
405
|
+
|
406
|
+
const inToken = sourceCode.getTokenBefore(node.right, astUtils.isNotOpeningParenToken);
|
407
|
+
const previousToken = sourceCode.getTokenBefore(inToken);
|
408
|
+
|
409
|
+
if (previousToken.type !== "PrivateIdentifier") {
|
410
|
+
checkSpacingBefore(inToken);
|
411
|
+
}
|
412
|
+
|
413
|
+
checkSpacingAfter(inToken);
|
407
414
|
}
|
408
415
|
|
409
416
|
/**
|
@@ -419,7 +426,15 @@ module.exports = {
|
|
419
426
|
} else {
|
420
427
|
checkSpacingAroundFirstToken(node);
|
421
428
|
}
|
422
|
-
|
429
|
+
|
430
|
+
const ofToken = sourceCode.getTokenBefore(node.right, astUtils.isNotOpeningParenToken);
|
431
|
+
const previousToken = sourceCode.getTokenBefore(ofToken);
|
432
|
+
|
433
|
+
if (previousToken.type !== "PrivateIdentifier") {
|
434
|
+
checkSpacingBefore(ofToken);
|
435
|
+
}
|
436
|
+
|
437
|
+
checkSpacingAfter(ofToken);
|
423
438
|
}
|
424
439
|
|
425
440
|
/**
|
@@ -473,6 +488,7 @@ module.exports = {
|
|
473
488
|
* Reports `static`, `get`, and `set` keywords of a given node if usage of
|
474
489
|
* spacing around those keywords is invalid.
|
475
490
|
* @param {ASTNode} node A node to report.
|
491
|
+
* @throws {Error} If unable to find token get, set, or async beside method name.
|
476
492
|
* @returns {void}
|
477
493
|
*/
|
478
494
|
function checkSpacingForProperty(node) {
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* @fileoverview Require or disallow newlines around directives.
|
3
3
|
* @author Kai Cataldo
|
4
|
-
* @deprecated
|
4
|
+
* @deprecated in ESLint v4.0.0
|
5
5
|
*/
|
6
6
|
|
7
7
|
"use strict";
|
@@ -18,7 +18,6 @@ module.exports = {
|
|
18
18
|
|
19
19
|
docs: {
|
20
20
|
description: "require or disallow newlines around directives",
|
21
|
-
category: "Stylistic Issues",
|
22
21
|
recommended: false,
|
23
22
|
url: "https://eslint.org/docs/rules/lines-around-directive"
|
24
23
|
},
|
@@ -4,6 +4,10 @@
|
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
6
|
|
7
|
+
//------------------------------------------------------------------------------
|
8
|
+
// Requirements
|
9
|
+
//------------------------------------------------------------------------------
|
10
|
+
|
7
11
|
const astUtils = require("./utils/ast-utils");
|
8
12
|
|
9
13
|
//------------------------------------------------------------------------------
|
@@ -16,7 +20,6 @@ module.exports = {
|
|
16
20
|
|
17
21
|
docs: {
|
18
22
|
description: "require or disallow an empty line between class members",
|
19
|
-
category: "Stylistic Issues",
|
20
23
|
recommended: false,
|
21
24
|
url: "https://eslint.org/docs/rules/lines-between-class-members"
|
22
25
|
},
|
@@ -53,6 +56,51 @@ module.exports = {
|
|
53
56
|
|
54
57
|
const sourceCode = context.getSourceCode();
|
55
58
|
|
59
|
+
/**
|
60
|
+
* Gets a pair of tokens that should be used to check lines between two class member nodes.
|
61
|
+
*
|
62
|
+
* In most cases, this returns the very last token of the current node and
|
63
|
+
* the very first token of the next node.
|
64
|
+
* For example:
|
65
|
+
*
|
66
|
+
* class C {
|
67
|
+
* x = 1; // curLast: `;` nextFirst: `in`
|
68
|
+
* in = 2
|
69
|
+
* }
|
70
|
+
*
|
71
|
+
* There is only one exception. If the given node ends with a semicolon, and it looks like
|
72
|
+
* a semicolon-less style's semicolon - one that is not on the same line as the preceding
|
73
|
+
* token, but is on the line where the next class member starts - this returns the preceding
|
74
|
+
* token and the semicolon as boundary tokens.
|
75
|
+
* For example:
|
76
|
+
*
|
77
|
+
* class C {
|
78
|
+
* x = 1 // curLast: `1` nextFirst: `;`
|
79
|
+
* ;in = 2
|
80
|
+
* }
|
81
|
+
* When determining the desired layout of the code, we should treat this semicolon as
|
82
|
+
* a part of the next class member node instead of the one it technically belongs to.
|
83
|
+
* @param {ASTNode} curNode Current class member node.
|
84
|
+
* @param {ASTNode} nextNode Next class member node.
|
85
|
+
* @returns {Token} The actual last token of `node`.
|
86
|
+
* @private
|
87
|
+
*/
|
88
|
+
function getBoundaryTokens(curNode, nextNode) {
|
89
|
+
const lastToken = sourceCode.getLastToken(curNode);
|
90
|
+
const prevToken = sourceCode.getTokenBefore(lastToken);
|
91
|
+
const nextToken = sourceCode.getFirstToken(nextNode); // skip possible lone `;` between nodes
|
92
|
+
|
93
|
+
const isSemicolonLessStyle = (
|
94
|
+
astUtils.isSemicolonToken(lastToken) &&
|
95
|
+
!astUtils.isTokenOnSameLine(prevToken, lastToken) &&
|
96
|
+
astUtils.isTokenOnSameLine(lastToken, nextToken)
|
97
|
+
);
|
98
|
+
|
99
|
+
return isSemicolonLessStyle
|
100
|
+
? { curLast: prevToken, nextFirst: lastToken }
|
101
|
+
: { curLast: lastToken, nextFirst: nextToken };
|
102
|
+
}
|
103
|
+
|
56
104
|
/**
|
57
105
|
* Return the last token among the consecutive tokens that have no exceed max line difference in between, before the first token in the next member.
|
58
106
|
* @param {Token} prevLastToken The last token in the previous member node.
|
@@ -101,8 +149,7 @@ module.exports = {
|
|
101
149
|
|
102
150
|
for (let i = 0; i < body.length - 1; i++) {
|
103
151
|
const curFirst = sourceCode.getFirstToken(body[i]);
|
104
|
-
const curLast =
|
105
|
-
const nextFirst = sourceCode.getFirstToken(body[i + 1]);
|
152
|
+
const { curLast, nextFirst } = getBoundaryTokens(body[i], body[i + 1]);
|
106
153
|
const isMulti = !astUtils.isTokenOnSameLine(curFirst, curLast);
|
107
154
|
const skip = !isMulti && options[1].exceptAfterSingleLine;
|
108
155
|
const beforePadding = findLastConsecutiveTokenAfter(curLast, nextFirst, 1);
|
@@ -19,15 +19,31 @@ module.exports = {
|
|
19
19
|
|
20
20
|
docs: {
|
21
21
|
description: "enforce a maximum number of classes per file",
|
22
|
-
category: "Best Practices",
|
23
22
|
recommended: false,
|
24
23
|
url: "https://eslint.org/docs/rules/max-classes-per-file"
|
25
24
|
},
|
26
25
|
|
27
26
|
schema: [
|
28
27
|
{
|
29
|
-
|
30
|
-
|
28
|
+
oneOf: [
|
29
|
+
{
|
30
|
+
type: "integer",
|
31
|
+
minimum: 1
|
32
|
+
},
|
33
|
+
{
|
34
|
+
type: "object",
|
35
|
+
properties: {
|
36
|
+
ignoreExpressions: {
|
37
|
+
type: "boolean"
|
38
|
+
},
|
39
|
+
max: {
|
40
|
+
type: "integer",
|
41
|
+
minimum: 1
|
42
|
+
}
|
43
|
+
},
|
44
|
+
additionalProperties: false
|
45
|
+
}
|
46
|
+
]
|
31
47
|
}
|
32
48
|
],
|
33
49
|
|
@@ -36,8 +52,10 @@ module.exports = {
|
|
36
52
|
}
|
37
53
|
},
|
38
54
|
create(context) {
|
39
|
-
|
40
|
-
const
|
55
|
+
const [option = {}] = context.options;
|
56
|
+
const [ignoreExpressions, max] = typeof option === "number"
|
57
|
+
? [false, option || 1]
|
58
|
+
: [option.ignoreExpressions, option.max || 1];
|
41
59
|
|
42
60
|
let classCount = 0;
|
43
61
|
|
@@ -46,19 +64,24 @@ module.exports = {
|
|
46
64
|
classCount = 0;
|
47
65
|
},
|
48
66
|
"Program:exit"(node) {
|
49
|
-
if (classCount >
|
67
|
+
if (classCount > max) {
|
50
68
|
context.report({
|
51
69
|
node,
|
52
70
|
messageId: "maximumExceeded",
|
53
71
|
data: {
|
54
72
|
classCount,
|
55
|
-
max
|
73
|
+
max
|
56
74
|
}
|
57
75
|
});
|
58
76
|
}
|
59
77
|
},
|
60
|
-
"ClassDeclaration
|
78
|
+
"ClassDeclaration"() {
|
61
79
|
classCount++;
|
80
|
+
},
|
81
|
+
"ClassExpression"() {
|
82
|
+
if (!ignoreExpressions) {
|
83
|
+
classCount++;
|
84
|
+
}
|
62
85
|
}
|
63
86
|
};
|
64
87
|
}
|
package/lib/rules/max-depth.js
CHANGED
package/lib/rules/max-len.js
CHANGED
@@ -69,7 +69,6 @@ module.exports = {
|
|
69
69
|
|
70
70
|
docs: {
|
71
71
|
description: "enforce a maximum line length",
|
72
|
-
category: "Stylistic Issues",
|
73
72
|
recommended: false,
|
74
73
|
url: "https://eslint.org/docs/rules/max-len"
|
75
74
|
},
|
@@ -215,7 +214,7 @@ module.exports = {
|
|
215
214
|
* Ensure that an array exists at [key] on `object`, and add `value` to it.
|
216
215
|
* @param {Object} object the object to mutate
|
217
216
|
* @param {string} key the object's key
|
218
|
-
* @param {
|
217
|
+
* @param {any} value the value to add
|
219
218
|
* @returns {void}
|
220
219
|
* @private
|
221
220
|
*/
|
@@ -48,7 +48,7 @@ const OPTIONS_OR_INTEGER_SCHEMA = {
|
|
48
48
|
/**
|
49
49
|
* Given a list of comment nodes, return a map with numeric keys (source code line numbers) and comment token values.
|
50
50
|
* @param {Array} comments An array of comment nodes.
|
51
|
-
* @returns {Map
|
51
|
+
* @returns {Map<string, Node>} A map with numeric keys (source code line numbers) and comment token values.
|
52
52
|
*/
|
53
53
|
function getCommentLineNumbers(comments) {
|
54
54
|
const map = new Map();
|
@@ -71,7 +71,6 @@ module.exports = {
|
|
71
71
|
|
72
72
|
docs: {
|
73
73
|
description: "enforce a maximum number of lines of code in a function",
|
74
|
-
category: "Stylistic Issues",
|
75
74
|
recommended: false,
|
76
75
|
url: "https://eslint.org/docs/rules/max-lines-per-function"
|
77
76
|
},
|
package/lib/rules/max-lines.js
CHANGED
package/lib/rules/max-params.js
CHANGED
package/lib/rules/new-cap.js
CHANGED
@@ -33,7 +33,8 @@ const CAPS_ALLOWED = [
|
|
33
33
|
* Ensure that if the key is provided, it must be an array.
|
34
34
|
* @param {Object} obj Object to check with `key`.
|
35
35
|
* @param {string} key Object key to check on `obj`.
|
36
|
-
* @param {
|
36
|
+
* @param {any} fallback If obj[key] is not present, this will be returned.
|
37
|
+
* @throws {TypeError} If key is not an own array type property of `obj`.
|
37
38
|
* @returns {string[]} Returns obj[key] if it's an Array, otherwise `fallback`
|
38
39
|
*/
|
39
40
|
function checkArray(obj, key, fallback) {
|
@@ -81,7 +82,6 @@ module.exports = {
|
|
81
82
|
|
82
83
|
docs: {
|
83
84
|
description: "require constructor names to begin with a capital letter",
|
84
|
-
category: "Stylistic Issues",
|
85
85
|
recommended: false,
|
86
86
|
url: "https://eslint.org/docs/rules/new-cap"
|
87
87
|
},
|
package/lib/rules/new-parens.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* @fileoverview Rule to check empty newline after "var" statement
|
3
3
|
* @author Gopal Venkatesan
|
4
|
-
* @deprecated
|
4
|
+
* @deprecated in ESLint v4.0.0
|
5
5
|
*/
|
6
6
|
|
7
7
|
"use strict";
|
@@ -22,7 +22,6 @@ module.exports = {
|
|
22
22
|
|
23
23
|
docs: {
|
24
24
|
description: "require or disallow an empty line after variable declarations",
|
25
|
-
category: "Stylistic Issues",
|
26
25
|
recommended: false,
|
27
26
|
url: "https://eslint.org/docs/rules/newline-after-var"
|
28
27
|
},
|
@@ -145,9 +144,9 @@ module.exports = {
|
|
145
144
|
|
146
145
|
/**
|
147
146
|
* Determine if a token starts more than one line after a comment ends
|
148
|
-
* @param
|
149
|
-
* @param {integer}
|
150
|
-
* @returns {boolean}
|
147
|
+
* @param {token} token The token being checked
|
148
|
+
* @param {integer} commentStartLine The line number on which the comment starts
|
149
|
+
* @returns {boolean} True if `token` does not start immediately after a comment
|
151
150
|
*/
|
152
151
|
function hasBlankLineAfterComment(token, commentStartLine) {
|
153
152
|
return token.loc.start.line > getLastCommentLineOfBlock(commentStartLine) + 1;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* @fileoverview Rule to require newlines before `return` statement
|
3
3
|
* @author Kai Cataldo
|
4
|
-
* @deprecated
|
4
|
+
* @deprecated in ESLint v4.0.0
|
5
5
|
*/
|
6
6
|
"use strict";
|
7
7
|
|
@@ -15,7 +15,6 @@ module.exports = {
|
|
15
15
|
|
16
16
|
docs: {
|
17
17
|
description: "require an empty line before `return` statements",
|
18
|
-
category: "Stylistic Issues",
|
19
18
|
recommended: false,
|
20
19
|
url: "https://eslint.org/docs/rules/newline-before-return"
|
21
20
|
},
|
@@ -134,7 +133,7 @@ module.exports = {
|
|
134
133
|
if (tokenBefore) {
|
135
134
|
lineNumTokenBefore = tokenBefore.loc.end.line;
|
136
135
|
} else {
|
137
|
-
lineNumTokenBefore = 0; //
|
136
|
+
lineNumTokenBefore = 0; // global return at beginning of script
|
138
137
|
}
|
139
138
|
|
140
139
|
return lineNumTokenBefore;
|
@@ -18,7 +18,6 @@ module.exports = {
|
|
18
18
|
|
19
19
|
docs: {
|
20
20
|
description: "require a newline after each call in a method chain",
|
21
|
-
category: "Stylistic Issues",
|
22
21
|
recommended: false,
|
23
22
|
url: "https://eslint.org/docs/rules/newline-per-chained-call"
|
24
23
|
},
|
@@ -53,7 +52,7 @@ module.exports = {
|
|
53
52
|
* Get the prefix of a given MemberExpression node.
|
54
53
|
* If the MemberExpression node is a computed value it returns a
|
55
54
|
* left bracket. If not it returns a period.
|
56
|
-
* @param
|
55
|
+
* @param {ASTNode} node A MemberExpression node to get
|
57
56
|
* @returns {string} The prefix of the node.
|
58
57
|
*/
|
59
58
|
function getPrefix(node) {
|
package/lib/rules/no-alert.js
CHANGED
package/lib/rules/no-bitwise.js
CHANGED
@@ -26,7 +26,6 @@ module.exports = {
|
|
26
26
|
|
27
27
|
docs: {
|
28
28
|
description: "disallow bitwise operators",
|
29
|
-
category: "Stylistic Issues",
|
30
29
|
recommended: false,
|
31
30
|
url: "https://eslint.org/docs/rules/no-bitwise"
|
32
31
|
},
|
@@ -63,7 +62,7 @@ module.exports = {
|
|
63
62
|
|
64
63
|
/**
|
65
64
|
* Reports an unexpected use of a bitwise operator.
|
66
|
-
* @param
|
65
|
+
* @param {ASTNode} node Node which contains the bitwise operator.
|
67
66
|
* @returns {void}
|
68
67
|
*/
|
69
68
|
function report(node) {
|
@@ -72,7 +71,7 @@ module.exports = {
|
|
72
71
|
|
73
72
|
/**
|
74
73
|
* Checks if the given node has a bitwise operator.
|
75
|
-
* @param
|
74
|
+
* @param {ASTNode} node The node to check.
|
76
75
|
* @returns {boolean} Whether or not the node has a bitwise operator.
|
77
76
|
*/
|
78
77
|
function hasBitwiseOperator(node) {
|
@@ -81,7 +80,7 @@ module.exports = {
|
|
81
80
|
|
82
81
|
/**
|
83
82
|
* Checks if exceptions were provided, e.g. `{ allow: ['~', '|'] }`.
|
84
|
-
* @param
|
83
|
+
* @param {ASTNode} node The node to check.
|
85
84
|
* @returns {boolean} Whether or not the node has a bitwise operator.
|
86
85
|
*/
|
87
86
|
function allowedOperator(node) {
|
@@ -90,7 +89,7 @@ module.exports = {
|
|
90
89
|
|
91
90
|
/**
|
92
91
|
* Checks if the given bitwise operator is used for integer typecasting, i.e. "|0"
|
93
|
-
* @param
|
92
|
+
* @param {ASTNode} node The node to check.
|
94
93
|
* @returns {boolean} whether the node is used in integer typecasting.
|
95
94
|
*/
|
96
95
|
function isInt32Hint(node) {
|
@@ -100,7 +99,7 @@ module.exports = {
|
|
100
99
|
|
101
100
|
/**
|
102
101
|
* Report if the given node contains a bitwise operator.
|
103
|
-
* @param
|
102
|
+
* @param {ASTNode} node The node to check.
|
104
103
|
* @returns {void}
|
105
104
|
*/
|
106
105
|
function checkNodeForBitwiseOperator(node) {
|
@@ -1,6 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* @fileoverview disallow use of the Buffer() constructor
|
3
3
|
* @author Teddy Katz
|
4
|
+
* @deprecated in ESLint v7.0.0
|
4
5
|
*/
|
5
6
|
"use strict";
|
6
7
|
|
@@ -18,7 +19,6 @@ module.exports = {
|
|
18
19
|
|
19
20
|
docs: {
|
20
21
|
description: "disallow use of the `Buffer()` constructor",
|
21
|
-
category: "Node.js and CommonJS",
|
22
22
|
recommended: false,
|
23
23
|
url: "https://eslint.org/docs/rules/no-buffer-constructor"
|
24
24
|
},
|
package/lib/rules/no-caller.js
CHANGED