eslint 6.0.0-alpha.1 → 6.0.1
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/CHANGELOG.md +71 -0
- package/README.md +28 -21
- package/bin/eslint.js +2 -2
- package/conf/config-schema.js +38 -31
- package/conf/environments.js +1 -1
- package/conf/eslint-all.js +2 -2
- package/conf/eslint-recommended.js +1 -1
- package/lib/api.js +7 -3
- package/lib/cli-engine/cascading-config-array-factory.js +20 -8
- package/lib/{cli-engine.js → cli-engine/cli-engine.js} +44 -21
- package/lib/cli-engine/config-array/config-array.js +7 -8
- package/lib/cli-engine/config-array/config-dependency.js +2 -2
- package/lib/cli-engine/config-array/extracted-config.js +3 -3
- package/lib/cli-engine/config-array/override-tester.js +11 -1
- package/lib/cli-engine/config-array-factory.js +75 -65
- package/lib/cli-engine/file-enumerator.js +14 -6
- package/lib/{formatters → cli-engine/formatters}/checkstyle.js +1 -1
- package/lib/{formatters → cli-engine/formatters}/codeframe.js +0 -0
- package/lib/{formatters → cli-engine/formatters}/compact.js +0 -0
- package/lib/{formatters → cli-engine/formatters}/html-template-message.html +0 -0
- package/lib/{formatters → cli-engine/formatters}/html-template-page.html +0 -0
- package/lib/{formatters → cli-engine/formatters}/html-template-result.html +0 -0
- package/lib/{formatters → cli-engine/formatters}/html.js +0 -0
- package/lib/{formatters → cli-engine/formatters}/jslint-xml.js +1 -1
- package/lib/{formatters → cli-engine/formatters}/json-with-metadata.js +0 -0
- package/lib/{formatters → cli-engine/formatters}/json.js +0 -0
- package/lib/{formatters → cli-engine/formatters}/junit.js +15 -3
- package/lib/{formatters → cli-engine/formatters}/stylish.js +0 -0
- package/lib/{formatters → cli-engine/formatters}/table.js +0 -0
- package/lib/{formatters → cli-engine/formatters}/tap.js +0 -0
- package/lib/{formatters → cli-engine/formatters}/unix.js +0 -0
- package/lib/{formatters → cli-engine/formatters}/visualstudio.js +0 -0
- package/lib/{util → cli-engine}/hash.js +0 -0
- package/lib/{util → cli-engine}/ignored-paths.js +6 -1
- package/lib/cli-engine/index.js +7 -0
- package/lib/{util → cli-engine}/lint-result-cache.js +0 -0
- package/lib/{load-rules.js → cli-engine/load-rules.js} +0 -0
- package/lib/{util → cli-engine}/naming.js +0 -0
- package/lib/{util → cli-engine}/xml-escape.js +0 -0
- package/lib/cli.js +3 -3
- package/lib/{config → init}/autoconfig.js +3 -3
- package/lib/{config → init}/config-file.js +0 -0
- package/lib/{config → init}/config-initializer.js +6 -6
- package/lib/{config → init}/config-rule.js +8 -2
- package/lib/{util → init}/npm-utils.js +1 -1
- package/lib/{util → init}/source-code-utils.js +16 -1
- package/lib/{util → linter}/apply-disable-directives.js +0 -0
- package/lib/{code-path-analysis → linter/code-path-analysis}/code-path-analyzer.js +19 -6
- package/lib/{code-path-analysis → linter/code-path-analysis}/code-path-segment.js +0 -0
- package/lib/{code-path-analysis → linter/code-path-analysis}/code-path-state.js +0 -0
- package/lib/{code-path-analysis → linter/code-path-analysis}/code-path.js +0 -0
- package/lib/{code-path-analysis → linter/code-path-analysis}/debug-helpers.js +0 -0
- package/lib/{code-path-analysis → linter/code-path-analysis}/fork-context.js +0 -0
- package/lib/{code-path-analysis → linter/code-path-analysis}/id-generator.js +0 -0
- package/lib/{util → linter}/config-comment-parser.js +1 -1
- package/lib/linter/index.js +13 -0
- package/lib/{util → linter}/interpolate.js +0 -0
- package/lib/{linter.js → linter/linter.js} +298 -152
- package/lib/{util → linter}/node-event-generator.js +7 -5
- package/lib/{util → linter}/report-translator.js +0 -0
- package/lib/{util → linter}/rule-fixer.js +0 -0
- package/lib/{rules.js → linter/rules.js} +3 -29
- package/lib/{util → linter}/safe-emitter.js +0 -0
- package/lib/{util → linter}/source-code-fixer.js +0 -0
- package/lib/{util → linter}/timing.js +1 -1
- package/lib/rule-tester/index.js +5 -0
- package/lib/{testers → rule-tester}/rule-tester.js +43 -15
- 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 +22 -1
- package/lib/rules/arrow-spacing.js +1 -1
- package/lib/rules/block-spacing.js +1 -1
- package/lib/rules/brace-style.js +1 -1
- package/lib/rules/capitalized-comments.js +2 -2
- package/lib/rules/comma-dangle.js +1 -1
- package/lib/rules/comma-spacing.js +1 -1
- package/lib/rules/comma-style.js +1 -1
- package/lib/rules/complexity.js +3 -3
- package/lib/rules/computed-property-spacing.js +1 -1
- package/lib/rules/consistent-return.js +1 -1
- package/lib/rules/curly.js +1 -1
- package/lib/rules/dot-location.js +1 -1
- package/lib/rules/dot-notation.js +2 -2
- package/lib/rules/eqeqeq.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/function-paren-newline.js +1 -1
- package/lib/rules/getter-return.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 +1 -1
- package/lib/rules/index.js +281 -0
- package/lib/rules/jsx-quotes.js +1 -1
- package/lib/rules/key-spacing.js +1 -1
- package/lib/rules/keyword-spacing.js +2 -2
- package/lib/rules/line-comment-position.js +1 -1
- package/lib/rules/linebreak-style.js +1 -1
- package/lib/rules/lines-around-comment.js +1 -1
- 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 +2 -1
- package/lib/rules/max-depth.js +2 -2
- package/lib/rules/max-len.js +11 -4
- package/lib/rules/max-lines-per-function.js +4 -2
- package/lib/rules/max-lines.js +2 -2
- 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 +3 -2
- package/lib/rules/multiline-ternary.js +1 -1
- package/lib/rules/new-parens.js +43 -11
- package/lib/rules/newline-after-var.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-catch-shadow.js +1 -1
- package/lib/rules/no-class-assign.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-div-regex.js +9 -1
- package/lib/rules/no-dupe-keys.js +1 -1
- package/lib/rules/no-else-return.js +129 -2
- package/lib/rules/no-empty-function.js +1 -1
- package/lib/rules/no-empty.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 +2 -2
- package/lib/rules/no-floating-decimal.js +1 -1
- package/lib/rules/no-func-assign.js +1 -1
- package/lib/rules/no-implicit-coercion.js +1 -1
- package/lib/rules/no-inline-comments.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-label-var.js +1 -1
- package/lib/rules/no-labels.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-multi-spaces.js +1 -1
- package/lib/rules/no-multi-str.js +1 -1
- package/lib/rules/no-octal.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-imports.js +18 -14
- package/lib/rules/no-restricted-properties.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-self-assign.js +1 -1
- package/lib/rules/no-sequences.js +1 -1
- package/lib/rules/no-shadow.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-unexpected-multiline.js +1 -1
- package/lib/rules/no-unmodified-loop-condition.js +2 -2
- package/lib/rules/no-unneeded-ternary.js +1 -1
- package/lib/rules/no-unsafe-negation.js +1 -1
- package/lib/rules/no-unused-vars.js +1 -1
- package/lib/rules/no-useless-call.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-escape.js +7 -2
- package/lib/rules/no-useless-return.js +2 -2
- package/lib/rules/no-var.js +15 -2
- package/lib/rules/no-warning-comments.js +1 -1
- package/lib/rules/no-whitespace-before-property.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-shorthand.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-const.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-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 +63 -84
- package/lib/rules/require-await.js +1 -1
- package/lib/rules/semi-spacing.js +1 -1
- package/lib/rules/semi-style.js +1 -1
- package/lib/rules/semi.js +2 -2
- package/lib/rules/sort-keys.js +12 -4
- 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-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/{util → rules/utils}/ast-utils.js +8 -27
- package/lib/{util → rules/utils}/fix-tracker.js +1 -1
- package/lib/{util → rules/utils}/keywords.js +0 -0
- package/lib/{util → rules/utils}/lazy-loading-rule-map.js +0 -0
- package/lib/{util → rules/utils}/patterns/letters.js +0 -0
- package/lib/{util → rules/utils}/unicode/index.js +0 -0
- package/lib/{util → rules/utils}/unicode/is-combining-character.js +0 -0
- package/lib/{util → rules/utils}/unicode/is-emoji-modifier.js +0 -0
- package/lib/{util → rules/utils}/unicode/is-regional-indicator-symbol.js +0 -0
- package/lib/{util → rules/utils}/unicode/is-surrogate-pair.js +0 -0
- package/lib/rules/valid-typeof.js +1 -1
- package/lib/rules/wrap-iife.js +1 -1
- package/lib/rules/yoda.js +1 -1
- package/lib/{util → shared}/ajv.js +0 -0
- package/lib/shared/ast-utils.js +29 -0
- package/lib/{config → shared}/config-ops.js +0 -0
- package/lib/{config → shared}/config-validator.js +22 -7
- package/lib/{util → shared}/logging.js +0 -0
- package/lib/{util → shared}/relative-module-resolver.js +10 -3
- package/lib/{util → shared}/traverser.js +0 -0
- package/lib/{util → shared}/types.js +4 -0
- package/lib/source-code/index.js +5 -0
- package/lib/{util → source-code}/source-code.js +10 -8
- package/lib/{token-store → source-code/token-store}/backward-token-comment-cursor.js +0 -0
- package/lib/{token-store → source-code/token-store}/backward-token-cursor.js +0 -0
- package/lib/{token-store → source-code/token-store}/cursor.js +0 -0
- package/lib/{token-store → source-code/token-store}/cursors.js +0 -0
- package/lib/{token-store → source-code/token-store}/decorative-cursor.js +0 -0
- package/lib/{token-store → source-code/token-store}/filter-cursor.js +0 -0
- package/lib/{token-store → source-code/token-store}/forward-token-comment-cursor.js +0 -0
- package/lib/{token-store → source-code/token-store}/forward-token-cursor.js +0 -0
- package/lib/{token-store → source-code/token-store}/index.js +3 -3
- package/lib/{token-store → source-code/token-store}/limit-cursor.js +0 -0
- package/lib/{token-store → source-code/token-store}/padded-token-cursor.js +0 -0
- package/lib/{token-store → source-code/token-store}/skip-cursor.js +0 -0
- package/lib/{token-store → source-code/token-store}/utils.js +0 -0
- package/messages/extend-config-missing.txt +2 -0
- package/messages/print-config-with-directory-path.txt +2 -0
- package/package.json +8 -11
- package/lib/built-in-rules-index.js +0 -281
@@ -206,7 +206,7 @@ class NodeEventGenerator {
|
|
206
206
|
* @param {SafeEmitter} emitter
|
207
207
|
* An SafeEmitter which is the destination of events. This emitter must already
|
208
208
|
* have registered listeners for all of the events that it needs to listen for.
|
209
|
-
* (See lib/
|
209
|
+
* (See lib/linter/safe-emitter.js for more details on `SafeEmitter`.)
|
210
210
|
* @returns {NodeEventGenerator} new instance
|
211
211
|
*/
|
212
212
|
constructor(emitter) {
|
@@ -221,17 +221,19 @@ class NodeEventGenerator {
|
|
221
221
|
const selector = parseSelector(rawSelector);
|
222
222
|
|
223
223
|
if (selector.listenerTypes) {
|
224
|
-
selector.
|
225
|
-
const typeMap = selector.isExit ? this.exitSelectorsByNodeType : this.enterSelectorsByNodeType;
|
224
|
+
const typeMap = selector.isExit ? this.exitSelectorsByNodeType : this.enterSelectorsByNodeType;
|
226
225
|
|
226
|
+
selector.listenerTypes.forEach(nodeType => {
|
227
227
|
if (!typeMap.has(nodeType)) {
|
228
228
|
typeMap.set(nodeType, []);
|
229
229
|
}
|
230
230
|
typeMap.get(nodeType).push(selector);
|
231
231
|
});
|
232
|
-
|
233
|
-
(selector.isExit ? this.anyTypeExitSelectors : this.anyTypeEnterSelectors).push(selector);
|
232
|
+
return;
|
234
233
|
}
|
234
|
+
const selectors = selector.isExit ? this.anyTypeExitSelectors : this.anyTypeEnterSelectors;
|
235
|
+
|
236
|
+
selectors.push(selector);
|
235
237
|
});
|
236
238
|
|
237
239
|
this.anyTypeEnterSelectors.sort(compareSpecificity);
|
File without changes
|
File without changes
|
@@ -1,6 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* @fileoverview Defines a storage for rules.
|
3
3
|
* @author Nicholas C. Zakas
|
4
|
+
* @author aladdin-add
|
4
5
|
*/
|
5
6
|
|
6
7
|
"use strict";
|
@@ -9,39 +10,12 @@
|
|
9
10
|
// Requirements
|
10
11
|
//------------------------------------------------------------------------------
|
11
12
|
|
12
|
-
const
|
13
|
-
const ruleReplacements = require("../conf/replacements").rules;
|
14
|
-
const builtInRules = require("./built-in-rules-index");
|
13
|
+
const builtInRules = require("../rules");
|
15
14
|
|
16
15
|
//------------------------------------------------------------------------------
|
17
16
|
// Helpers
|
18
17
|
//------------------------------------------------------------------------------
|
19
18
|
|
20
|
-
/**
|
21
|
-
* Creates a stub rule that gets used when a rule with a given ID is not found.
|
22
|
-
* @param {string} ruleId The ID of the missing rule
|
23
|
-
* @returns {{create: function(RuleContext): Object}} A rule that reports an error at the first location
|
24
|
-
* in the program. The report has the message `Definition for rule '${ruleId}' was not found` if the rule is unknown,
|
25
|
-
* or `Rule '${ruleId}' was removed and replaced by: ${replacements.join(", ")}` if the rule is known to have been
|
26
|
-
* replaced.
|
27
|
-
*/
|
28
|
-
const createMissingRule = lodash.memoize(ruleId => {
|
29
|
-
const message = Object.prototype.hasOwnProperty.call(ruleReplacements, ruleId)
|
30
|
-
? `Rule '${ruleId}' was removed and replaced by: ${ruleReplacements[ruleId].join(", ")}`
|
31
|
-
: `Definition for rule '${ruleId}' was not found`;
|
32
|
-
|
33
|
-
return {
|
34
|
-
create: context => ({
|
35
|
-
Program() {
|
36
|
-
context.report({
|
37
|
-
loc: { line: 1, column: 0 },
|
38
|
-
message
|
39
|
-
});
|
40
|
-
}
|
41
|
-
})
|
42
|
-
};
|
43
|
-
});
|
44
|
-
|
45
19
|
/**
|
46
20
|
* Normalizes a rule module to the new-style API
|
47
21
|
* @param {(Function|{create: Function})} rule A rule object, which can either be a function
|
@@ -88,7 +62,7 @@ class Rules {
|
|
88
62
|
return builtInRules.get(ruleId);
|
89
63
|
}
|
90
64
|
|
91
|
-
return
|
65
|
+
return null;
|
92
66
|
}
|
93
67
|
|
94
68
|
*[Symbol.iterator]() {
|
File without changes
|
File without changes
|
@@ -48,7 +48,7 @@ const ALIGN = [alignLeft, alignRight, alignRight];
|
|
48
48
|
/**
|
49
49
|
* display the data
|
50
50
|
* @param {Object} data Data object to be displayed
|
51
|
-
* @returns {
|
51
|
+
* @returns {void} prints modified string with console.log
|
52
52
|
* @private
|
53
53
|
*/
|
54
54
|
function display(data) {
|
@@ -45,12 +45,10 @@ const
|
|
45
45
|
path = require("path"),
|
46
46
|
util = require("util"),
|
47
47
|
lodash = require("lodash"),
|
48
|
-
{ getRuleOptionsSchema, validate } = require("../
|
49
|
-
{ Linter } = require("../linter")
|
50
|
-
SourceCodeFixer = require("../util/source-code-fixer"),
|
51
|
-
interpolate = require("../util/interpolate");
|
48
|
+
{ getRuleOptionsSchema, validate } = require("../shared/config-validator"),
|
49
|
+
{ Linter, SourceCodeFixer, interpolate } = require("../linter");
|
52
50
|
|
53
|
-
const ajv = require("../
|
51
|
+
const ajv = require("../shared/ajv")({ strictDefaults: true });
|
54
52
|
|
55
53
|
//------------------------------------------------------------------------------
|
56
54
|
// Private Members
|
@@ -125,6 +123,18 @@ function freezeDeeply(x) {
|
|
125
123
|
}
|
126
124
|
}
|
127
125
|
|
126
|
+
/**
|
127
|
+
* Replace control characters by `\u00xx` form.
|
128
|
+
* @param {string} text The text to sanitize.
|
129
|
+
* @returns {string} The sanitized text.
|
130
|
+
*/
|
131
|
+
function sanitize(text) {
|
132
|
+
return text.replace(
|
133
|
+
/[\u0000-\u001f]/gu, // eslint-disable-line no-control-regex
|
134
|
+
c => `\\u${c.codePointAt(0).toString(16).padStart(4, "0")}`
|
135
|
+
);
|
136
|
+
}
|
137
|
+
|
128
138
|
//------------------------------------------------------------------------------
|
129
139
|
// Public Interface
|
130
140
|
//------------------------------------------------------------------------------
|
@@ -315,7 +325,7 @@ class RuleTester {
|
|
315
325
|
*/
|
316
326
|
function runRuleForItem(item) {
|
317
327
|
let config = lodash.cloneDeep(testerConfig),
|
318
|
-
code, filename, beforeAST, afterAST;
|
328
|
+
code, filename, output, beforeAST, afterAST;
|
319
329
|
|
320
330
|
if (typeof item === "string") {
|
321
331
|
code = item;
|
@@ -398,8 +408,29 @@ class RuleTester {
|
|
398
408
|
|
399
409
|
validate(config, "rule-tester", id => (id === ruleName ? rule : null));
|
400
410
|
|
411
|
+
// Verify the code.
|
412
|
+
const messages = linter.verify(code, config, filename);
|
413
|
+
|
414
|
+
// Ignore syntax errors for backward compatibility if `errors` is a number.
|
415
|
+
if (typeof item.errors !== "number") {
|
416
|
+
const errorMessage = messages.find(m => m.fatal);
|
417
|
+
|
418
|
+
assert(!errorMessage, `A fatal parsing error occurred: ${errorMessage && errorMessage.message}`);
|
419
|
+
}
|
420
|
+
|
421
|
+
// Verify if autofix makes a syntax error or not.
|
422
|
+
if (messages.some(m => m.fix)) {
|
423
|
+
output = SourceCodeFixer.applyFixes(code, messages).output;
|
424
|
+
const errorMessageInFix = linter.verify(output, config, filename).find(m => m.fatal);
|
425
|
+
|
426
|
+
assert(!errorMessageInFix, `A fatal parsing error occurred in autofix: ${errorMessageInFix && errorMessageInFix.message}`);
|
427
|
+
} else {
|
428
|
+
output = code;
|
429
|
+
}
|
430
|
+
|
401
431
|
return {
|
402
|
-
messages
|
432
|
+
messages,
|
433
|
+
output,
|
403
434
|
beforeAST,
|
404
435
|
afterAST: cloneDeeplyExcludesParent(afterAST)
|
405
436
|
};
|
@@ -490,7 +521,6 @@ class RuleTester {
|
|
490
521
|
const error = item.errors[i];
|
491
522
|
const message = messages[i];
|
492
523
|
|
493
|
-
assert(!message.fatal, `A fatal parsing error occurred: ${message.message}`);
|
494
524
|
assert(hasMessageOfThisRule, "Error rule name should be the same as the name of the rule being tested");
|
495
525
|
|
496
526
|
if (typeof error === "string" || error instanceof RegExp) {
|
@@ -576,14 +606,12 @@ class RuleTester {
|
|
576
606
|
if (Object.prototype.hasOwnProperty.call(item, "output")) {
|
577
607
|
if (item.output === null) {
|
578
608
|
assert.strictEqual(
|
579
|
-
|
580
|
-
|
609
|
+
result.output,
|
610
|
+
item.code,
|
581
611
|
"Expected no autofixes to be suggested"
|
582
612
|
);
|
583
613
|
} else {
|
584
|
-
|
585
|
-
|
586
|
-
assert.strictEqual(fixResult.output, item.output, "Output is incorrect.");
|
614
|
+
assert.strictEqual(result.output, item.output, "Output is incorrect.");
|
587
615
|
}
|
588
616
|
}
|
589
617
|
|
@@ -597,7 +625,7 @@ class RuleTester {
|
|
597
625
|
RuleTester.describe(ruleName, () => {
|
598
626
|
RuleTester.describe("valid", () => {
|
599
627
|
test.valid.forEach(valid => {
|
600
|
-
RuleTester.it(typeof valid === "object" ? valid.code : valid, () => {
|
628
|
+
RuleTester.it(sanitize(typeof valid === "object" ? valid.code : valid), () => {
|
601
629
|
testValidTemplate(valid);
|
602
630
|
});
|
603
631
|
});
|
@@ -605,7 +633,7 @@ class RuleTester {
|
|
605
633
|
|
606
634
|
RuleTester.describe("invalid", () => {
|
607
635
|
test.invalid.forEach(invalid => {
|
608
|
-
RuleTester.it(invalid.code, () => {
|
636
|
+
RuleTester.it(sanitize(invalid.code), () => {
|
609
637
|
testInvalidTemplate(invalid);
|
610
638
|
});
|
611
639
|
});
|
@@ -8,7 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const astUtils = require("
|
11
|
+
const astUtils = require("./utils/ast-utils");
|
12
12
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
// Rule Definition
|
@@ -8,7 +8,24 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const astUtils = require("
|
11
|
+
const astUtils = require("./utils/ast-utils");
|
12
|
+
|
13
|
+
//------------------------------------------------------------------------------
|
14
|
+
// Helpers
|
15
|
+
//------------------------------------------------------------------------------
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Get location should be reported by AST node.
|
19
|
+
*
|
20
|
+
* @param {ASTNode} node AST Node.
|
21
|
+
* @returns {Location} Location information.
|
22
|
+
*/
|
23
|
+
function getLocation(node) {
|
24
|
+
return {
|
25
|
+
start: node.params[0].loc.start,
|
26
|
+
end: node.params[node.params.length - 1].loc.end
|
27
|
+
};
|
28
|
+
}
|
12
29
|
|
13
30
|
//------------------------------------------------------------------------------
|
14
31
|
// Rule Definition
|
@@ -102,6 +119,7 @@ module.exports = {
|
|
102
119
|
context.report({
|
103
120
|
node,
|
104
121
|
messageId: "unexpectedParensInline",
|
122
|
+
loc: getLocation(node),
|
105
123
|
fix: fixParamsWithParenthesis
|
106
124
|
});
|
107
125
|
}
|
@@ -116,6 +134,7 @@ module.exports = {
|
|
116
134
|
context.report({
|
117
135
|
node,
|
118
136
|
messageId: "expectedParensBlock",
|
137
|
+
loc: getLocation(node),
|
119
138
|
fix(fixer) {
|
120
139
|
return fixer.replaceText(firstTokenOfParam, `(${firstTokenOfParam.value})`);
|
121
140
|
}
|
@@ -135,6 +154,7 @@ module.exports = {
|
|
135
154
|
context.report({
|
136
155
|
node,
|
137
156
|
messageId: "unexpectedParens",
|
157
|
+
loc: getLocation(node),
|
138
158
|
fix: fixParamsWithParenthesis
|
139
159
|
});
|
140
160
|
}
|
@@ -149,6 +169,7 @@ module.exports = {
|
|
149
169
|
context.report({
|
150
170
|
node,
|
151
171
|
messageId: "expectedParens",
|
172
|
+
loc: getLocation(node),
|
152
173
|
fix(fixer) {
|
153
174
|
return fixer.replaceText(firstTokenOfParam, `(${firstTokenOfParam.value})`);
|
154
175
|
}
|
@@ -8,7 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const astUtils = require("
|
11
|
+
const astUtils = require("./utils/ast-utils");
|
12
12
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
// Rule Definition
|
package/lib/rules/brace-style.js
CHANGED
@@ -8,8 +8,8 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const LETTER_PATTERN = require("
|
12
|
-
const astUtils = require("
|
11
|
+
const LETTER_PATTERN = require("./utils/patterns/letters");
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Helpers
|
@@ -10,7 +10,7 @@
|
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
12
|
const lodash = require("lodash");
|
13
|
-
const astUtils = require("
|
13
|
+
const astUtils = require("./utils/ast-utils");
|
14
14
|
|
15
15
|
//------------------------------------------------------------------------------
|
16
16
|
// Helpers
|
package/lib/rules/comma-style.js
CHANGED
package/lib/rules/complexity.js
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
const lodash = require("lodash");
|
14
14
|
|
15
|
-
const astUtils = require("
|
15
|
+
const astUtils = require("./utils/ast-utils");
|
16
16
|
|
17
17
|
//------------------------------------------------------------------------------
|
18
18
|
// Rule Definition
|
@@ -55,7 +55,7 @@ module.exports = {
|
|
55
55
|
],
|
56
56
|
|
57
57
|
messages: {
|
58
|
-
complex: "{{name}} has a complexity of {{complexity}}."
|
58
|
+
complex: "{{name}} has a complexity of {{complexity}}. Maximum allowed is {{max}}."
|
59
59
|
}
|
60
60
|
},
|
61
61
|
|
@@ -102,7 +102,7 @@ module.exports = {
|
|
102
102
|
context.report({
|
103
103
|
node,
|
104
104
|
messageId: "complex",
|
105
|
-
data: { name, complexity }
|
105
|
+
data: { name, complexity, max: THRESHOLD }
|
106
106
|
});
|
107
107
|
}
|
108
108
|
}
|
package/lib/rules/curly.js
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const astUtils = require("
|
11
|
+
const astUtils = require("./utils/ast-utils");
|
12
12
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
// Rule Definition
|
@@ -8,14 +8,14 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const astUtils = require("
|
11
|
+
const astUtils = require("./utils/ast-utils");
|
12
12
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
// Rule Definition
|
15
15
|
//------------------------------------------------------------------------------
|
16
16
|
|
17
17
|
const validIdentifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/u;
|
18
|
-
const keywords = require("
|
18
|
+
const keywords = require("./utils/keywords");
|
19
19
|
|
20
20
|
module.exports = {
|
21
21
|
meta: {
|
package/lib/rules/eqeqeq.js
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Rule Definition
|
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Rule Definition
|
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//--------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
13
13
|
const esutils = require("esutils");
|
14
14
|
|
15
15
|
//--------------------------------------------------------------------------
|
package/lib/rules/func-names.js
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
13
13
|
|
14
14
|
/**
|
15
15
|
* Checks whether or not a given variable is a function name.
|
@@ -8,7 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const astUtils = require("
|
11
|
+
const astUtils = require("./utils/ast-utils");
|
12
12
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
// Rule Definition
|
@@ -9,7 +9,7 @@
|
|
9
9
|
// Requirements
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
|
-
const astUtils = require("
|
12
|
+
const astUtils = require("./utils/ast-utils");
|
13
13
|
|
14
14
|
//------------------------------------------------------------------------------
|
15
15
|
// Helpers
|
@@ -4,7 +4,7 @@
|
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
6
|
|
7
|
-
const { isCommentToken, isNotOpeningParenToken } = require("
|
7
|
+
const { isCommentToken, isNotOpeningParenToken } = require("./utils/ast-utils");
|
8
8
|
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
// Rule Definition
|
@@ -12,7 +12,7 @@
|
|
12
12
|
// Requirements
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
|
15
|
-
const astUtils = require("
|
15
|
+
const astUtils = require("./utils/ast-utils");
|
16
16
|
|
17
17
|
//------------------------------------------------------------------------------
|
18
18
|
// Rule Definition
|
package/lib/rules/indent.js
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
|
15
15
|
const lodash = require("lodash");
|
16
|
-
const astUtils = require("
|
16
|
+
const astUtils = require("./utils/ast-utils");
|
17
17
|
const createTree = require("functional-red-black-tree");
|
18
18
|
|
19
19
|
//------------------------------------------------------------------------------
|