eslint 6.2.2 → 6.3.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/CHANGELOG.md +19 -0
- package/README.md +1 -0
- package/conf/config-schema.js +1 -0
- package/conf/default-cli-options.js +1 -1
- package/lib/cli-engine/config-array/config-array.js +6 -0
- package/lib/cli-engine/config-array/extracted-config.js +6 -0
- package/lib/cli-engine/config-array-factory.js +2 -0
- package/lib/cli-engine/formatters/stylish.js +2 -1
- package/lib/init/config-initializer.js +29 -0
- package/lib/init/npm-utils.js +8 -8
- package/lib/linter/apply-disable-directives.js +17 -9
- package/lib/linter/linter.js +23 -3
- package/lib/options.js +1 -1
- package/lib/rules/func-name-matching.js +1 -0
- package/lib/rules/function-paren-newline.js +2 -2
- package/lib/rules/no-extra-boolean-cast.js +11 -1
- package/lib/rules/no-extra-parens.js +8 -1
- package/lib/rules/no-self-assign.js +11 -1
- package/lib/rules/yoda.js +11 -2
- package/lib/shared/types.js +2 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
v6.3.0 - August 30, 2019
|
2
|
+
|
3
|
+
* [`0acdefb`](https://github.com/eslint/eslint/commit/0acdefb97f35bb09db2910540c70dc377a01ad62) Chore: refactor code (#12113) (James George)
|
4
|
+
* [`52e2cf5`](https://github.com/eslint/eslint/commit/52e2cf50b35d57fb8466e0bcd0581eff1590fb4c) New: reportUnusedDisableDirectives in config (refs eslint/rfcs#22) (#12151) (Toru Nagashima)
|
5
|
+
* [`020f952`](https://github.com/eslint/eslint/commit/020f9526b618a191566acea3e17e20815d484c58) Update: enforceForSequenceExpressions to no-extra-parens (fixes #11916) (#12142) (Milos Djermanovic)
|
6
|
+
* [`aab1b84`](https://github.com/eslint/eslint/commit/aab1b840f9cffb2a76a5c9fe1852961be71dc184) Fix: reset to the default color (#12174) (Ricardo Gobbo de Souza)
|
7
|
+
* [`4009d39`](https://github.com/eslint/eslint/commit/4009d39aa59451510aa24911e758d664f216289a) Fix: yoda rule produces invalid autofix with preceding yield (#12166) (Milos Djermanovic)
|
8
|
+
* [`febb660`](https://github.com/eslint/eslint/commit/febb6605d350c936d64cb73e694482cfbb20b29c) Fix: no-extra-boolean-cast invalid autofix with yield before negation (#12164) (Milos Djermanovic)
|
9
|
+
* [`4c0b70b`](https://github.com/eslint/eslint/commit/4c0b70b869c16647f7af6de9d5c5479fc19f49db) New: support TypeScript at config initializer (fixes #11789) (#12172) (Pig Fang)
|
10
|
+
* [`94e39d9`](https://github.com/eslint/eslint/commit/94e39d9f782f45db86a079e07508d63040118ef1) Chore: use GitHub Actions (#12144) (Toru Nagashima)
|
11
|
+
* [`e88f305`](https://github.com/eslint/eslint/commit/e88f305df9d454868624c559fd93b981a680c215) Chore: support es2020 in fuzz (#12180) (薛定谔的猫)
|
12
|
+
* [`00d2c5b`](https://github.com/eslint/eslint/commit/00d2c5be9a89efd90135c4368a9589f33df3f7ba) Docs: corrected class extension example (#12176) (Marius M)
|
13
|
+
* [`31e5428`](https://github.com/eslint/eslint/commit/31e542819967b2aa1191e1abaa1c4a49fddbe3cf) Chore: Fix wrong error object keys in test files (#12162) (Milos Djermanovic)
|
14
|
+
* [`197f443`](https://github.com/eslint/eslint/commit/197f4432fca70a574028e5568c48afad12213224) Fix: func-name-matching crash on descriptor-like arguments (#12100) (Milos Djermanovic)
|
15
|
+
* [`644ce33`](https://github.com/eslint/eslint/commit/644ce3306748a33b74fc6a94be0267c2c9f19348) Fix: no-self-assign false positive with rest and spread in array (#12099) (Milos Djermanovic)
|
16
|
+
* [`a81d263`](https://github.com/eslint/eslint/commit/a81d2636ce41fb34d6826c2e9857814e11cb9c30) Fix: fix message of function-paren-newline (#12136) (Pig Fang)
|
17
|
+
* [`77f8ed1`](https://github.com/eslint/eslint/commit/77f8ed1ad9656c526217ce54a6717fa232d522c8) Chore: update blogpost template (#12154) (Toru Nagashima)
|
18
|
+
* [`6abc7b7`](https://github.com/eslint/eslint/commit/6abc7b72dfb824a372379708ca39340b2c7abc03) Docs: Document the exception in no-unsafe-negation (#12161) (Milos Djermanovic)
|
19
|
+
|
1
20
|
v6.2.2 - August 23, 2019
|
2
21
|
|
3
22
|
* [`0e0b784`](https://github.com/eslint/eslint/commit/0e0b784b922051c2a1d39dd8160382114b645800) Upgrade: espree@^6.1.1 (#12158) (Kevin Partington)
|
package/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
[![NPM version][npm-image]][npm-url]
|
2
2
|
[](https://dev.azure.com/eslint/eslint/_build/latest?definitionId=1&branchName=master)
|
3
|
+
[](https://github.com/eslint/eslint/actions)
|
3
4
|
[![Downloads][downloads-image]][downloads-url]
|
4
5
|
[](https://www.bountysource.com/trackers/282608-eslint?utm_source=282608&utm_medium=shield&utm_campaign=TRACKER_BADGE)
|
5
6
|
[](https://gitter.im/eslint/eslint?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
package/conf/config-schema.js
CHANGED
@@ -21,6 +21,7 @@ const baseConfigProperties = {
|
|
21
21
|
rules: { type: "object" },
|
22
22
|
settings: { type: "object" },
|
23
23
|
noInlineConfig: { type: "boolean" },
|
24
|
+
reportUnusedDisableDirectives: { type: "boolean" },
|
24
25
|
|
25
26
|
ecmaFeatures: { type: "object" } // deprecated; logs a warning when used
|
26
27
|
};
|
@@ -59,6 +59,7 @@ const { ExtractedConfig } = require("./extracted-config");
|
|
59
59
|
* @property {Object|undefined} parserOptions The parser options.
|
60
60
|
* @property {Record<string, DependentPlugin>|undefined} plugins The plugin loaders.
|
61
61
|
* @property {string|undefined} processor The processor name to refer plugin's processor.
|
62
|
+
* @property {boolean|undefined} reportUnusedDisableDirectives The flag to report unused `eslint-disable` comments.
|
62
63
|
* @property {boolean|undefined} root The flag to express root.
|
63
64
|
* @property {Record<string, RuleConf>|undefined} rules The rule settings
|
64
65
|
* @property {Object|undefined} settings The shared settings.
|
@@ -257,6 +258,11 @@ function createConfig(instance, indices) {
|
|
257
258
|
config.configNameOfNoInlineConfig = element.name;
|
258
259
|
}
|
259
260
|
|
261
|
+
// Adopt the reportUnusedDisableDirectives which was found at first.
|
262
|
+
if (config.reportUnusedDisableDirectives === void 0 && element.reportUnusedDisableDirectives !== void 0) {
|
263
|
+
config.reportUnusedDisableDirectives = element.reportUnusedDisableDirectives;
|
264
|
+
}
|
265
|
+
|
260
266
|
// Merge others.
|
261
267
|
mergeWithoutOverwrite(config.env, element.env);
|
262
268
|
mergeWithoutOverwrite(config.globals, element.globals);
|
@@ -77,6 +77,12 @@ class ExtractedConfig {
|
|
77
77
|
*/
|
78
78
|
this.processor = null;
|
79
79
|
|
80
|
+
/**
|
81
|
+
* The flag that reports unused `eslint-disable` directive comments.
|
82
|
+
* @type {boolean|undefined}
|
83
|
+
*/
|
84
|
+
this.reportUnusedDisableDirectives = void 0;
|
85
|
+
|
80
86
|
/**
|
81
87
|
* Rule settings.
|
82
88
|
* @type {Record<string, [SeverityConf, ...any[]]>}
|
@@ -531,6 +531,7 @@ class ConfigArrayFactory {
|
|
531
531
|
parserOptions,
|
532
532
|
plugins: pluginList,
|
533
533
|
processor,
|
534
|
+
reportUnusedDisableDirectives,
|
534
535
|
root,
|
535
536
|
rules,
|
536
537
|
settings,
|
@@ -573,6 +574,7 @@ class ConfigArrayFactory {
|
|
573
574
|
parserOptions,
|
574
575
|
plugins,
|
575
576
|
processor,
|
577
|
+
reportUnusedDisableDirectives,
|
576
578
|
root,
|
577
579
|
rules,
|
578
580
|
settings
|
@@ -120,6 +120,12 @@ function getModulesList(config, installESLint) {
|
|
120
120
|
}
|
121
121
|
}
|
122
122
|
|
123
|
+
const parser = config.parser || (config.parserOptions && config.parserOptions.parser);
|
124
|
+
|
125
|
+
if (parser) {
|
126
|
+
modules[parser] = "latest";
|
127
|
+
}
|
128
|
+
|
123
129
|
if (installESLint === false) {
|
124
130
|
delete modules.eslint;
|
125
131
|
} else {
|
@@ -291,6 +297,20 @@ function processAnswers(answers) {
|
|
291
297
|
config.extends.push("plugin:vue/essential");
|
292
298
|
}
|
293
299
|
|
300
|
+
if (answers.typescript) {
|
301
|
+
if (answers.framework === "vue") {
|
302
|
+
config.parserOptions.parser = "@typescript-eslint/parser";
|
303
|
+
} else {
|
304
|
+
config.parser = "@typescript-eslint/parser";
|
305
|
+
}
|
306
|
+
|
307
|
+
if (Array.isArray(config.plugins)) {
|
308
|
+
config.plugins.push("@typescript-eslint");
|
309
|
+
} else {
|
310
|
+
config.plugins = ["@typescript-eslint"];
|
311
|
+
}
|
312
|
+
}
|
313
|
+
|
294
314
|
// setup rules based on problems/style enforcement preferences
|
295
315
|
if (answers.purpose === "problems") {
|
296
316
|
config.extends.unshift("eslint:recommended");
|
@@ -306,6 +326,9 @@ function processAnswers(answers) {
|
|
306
326
|
config = autoconfig.extendFromRecommended(config);
|
307
327
|
}
|
308
328
|
}
|
329
|
+
if (answers.typescript && config.extends.includes("eslint:recommended")) {
|
330
|
+
config.extends.push("plugin:@typescript-eslint/eslint-recommended");
|
331
|
+
}
|
309
332
|
|
310
333
|
// normalize extends
|
311
334
|
if (config.extends.length === 0) {
|
@@ -465,6 +488,12 @@ function promptUser() {
|
|
465
488
|
{ name: "None of these", value: "none" }
|
466
489
|
]
|
467
490
|
},
|
491
|
+
{
|
492
|
+
type: "confirm",
|
493
|
+
name: "typescript",
|
494
|
+
message: "Does your project use TypeScript?",
|
495
|
+
default: false
|
496
|
+
},
|
468
497
|
{
|
469
498
|
type: "checkbox",
|
470
499
|
name: "env",
|
package/lib/init/npm-utils.js
CHANGED
@@ -98,7 +98,7 @@ function fetchPeerDependencies(packageName) {
|
|
98
98
|
* and values are booleans indicating installation.
|
99
99
|
*/
|
100
100
|
function check(packages, opt) {
|
101
|
-
|
101
|
+
const deps = new Set();
|
102
102
|
const pkgJson = (opt) ? findPackageJson(opt.startDir) : findPackageJson();
|
103
103
|
let fileJson;
|
104
104
|
|
@@ -119,14 +119,14 @@ function check(packages, opt) {
|
|
119
119
|
throw error;
|
120
120
|
}
|
121
121
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
122
|
+
["dependencies", "devDependencies"].forEach(key => {
|
123
|
+
if (opt[key] && typeof fileJson[key] === "object") {
|
124
|
+
Object.keys(fileJson[key]).forEach(dep => deps.add(dep));
|
125
|
+
}
|
126
|
+
});
|
127
|
+
|
128
128
|
return packages.reduce((status, pkg) => {
|
129
|
-
status[pkg] = deps.
|
129
|
+
status[pkg] = deps.has(pkg);
|
130
130
|
return status;
|
131
131
|
}, {});
|
132
132
|
}
|
@@ -93,7 +93,7 @@ function applyDirectives(options) {
|
|
93
93
|
: "Unused eslint-disable directive (no problems were reported).",
|
94
94
|
line: directive.unprocessedDirective.line,
|
95
95
|
column: directive.unprocessedDirective.column,
|
96
|
-
severity: 2,
|
96
|
+
severity: options.reportUnusedDisableDirectives === "warn" ? 1 : 2,
|
97
97
|
nodeType: null
|
98
98
|
}));
|
99
99
|
|
@@ -114,17 +114,17 @@ function applyDirectives(options) {
|
|
114
114
|
* comment for two different rules is represented as two directives).
|
115
115
|
* @param {{ruleId: (string|null), line: number, column: number}[]} options.problems
|
116
116
|
* A list of problems reported by rules, sorted by increasing location in the file, with one-based columns.
|
117
|
-
* @param {
|
117
|
+
* @param {"off" | "warn" | "error"} options.reportUnusedDisableDirectives If `"warn"` or `"error"`, adds additional problems for unused directives
|
118
118
|
* @returns {{ruleId: (string|null), line: number, column: number}[]}
|
119
119
|
* A list of reported problems that were not disabled by the directive comments.
|
120
120
|
*/
|
121
|
-
module.exports =
|
122
|
-
const blockDirectives =
|
121
|
+
module.exports = ({ directives, problems, reportUnusedDisableDirectives = "off" }) => {
|
122
|
+
const blockDirectives = directives
|
123
123
|
.filter(directive => directive.type === "disable" || directive.type === "enable")
|
124
124
|
.map(directive => Object.assign({}, directive, { unprocessedDirective: directive }))
|
125
125
|
.sort(compareLocations);
|
126
126
|
|
127
|
-
const lineDirectives = lodash.flatMap(
|
127
|
+
const lineDirectives = lodash.flatMap(directives, directive => {
|
128
128
|
switch (directive.type) {
|
129
129
|
case "disable":
|
130
130
|
case "enable":
|
@@ -147,10 +147,18 @@ module.exports = options => {
|
|
147
147
|
}
|
148
148
|
}).sort(compareLocations);
|
149
149
|
|
150
|
-
const blockDirectivesResult = applyDirectives({
|
151
|
-
|
152
|
-
|
153
|
-
|
150
|
+
const blockDirectivesResult = applyDirectives({
|
151
|
+
problems,
|
152
|
+
directives: blockDirectives,
|
153
|
+
reportUnusedDisableDirectives
|
154
|
+
});
|
155
|
+
const lineDirectivesResult = applyDirectives({
|
156
|
+
problems: blockDirectivesResult.problems,
|
157
|
+
directives: lineDirectives,
|
158
|
+
reportUnusedDisableDirectives
|
159
|
+
});
|
160
|
+
|
161
|
+
return reportUnusedDisableDirectives !== "off"
|
154
162
|
? lineDirectivesResult.problems
|
155
163
|
.concat(blockDirectivesResult.unusedDisableDirectives)
|
156
164
|
.concat(lineDirectivesResult.unusedDisableDirectives)
|
package/lib/linter/linter.js
CHANGED
@@ -54,6 +54,11 @@ const DEFAULT_ERROR_LOC = { start: { line: 1, column: 0 }, end: { line: 1, colum
|
|
54
54
|
/** @typedef {import("../shared/types").Processor} Processor */
|
55
55
|
/** @typedef {import("../shared/types").Rule} Rule */
|
56
56
|
|
57
|
+
/**
|
58
|
+
* @template T
|
59
|
+
* @typedef {{ [P in keyof T]-?: T[P] }} Required
|
60
|
+
*/
|
61
|
+
|
57
62
|
/**
|
58
63
|
* @typedef {Object} DisableDirective
|
59
64
|
* @property {("disable"|"enable"|"disable-line"|"disable-next-line")} type
|
@@ -79,7 +84,7 @@ const DEFAULT_ERROR_LOC = { start: { line: 1, column: 0 }, end: { line: 1, colum
|
|
79
84
|
* @property {boolean} [disableFixes] if `true` then the linter doesn't make `fix`
|
80
85
|
* properties into the lint result.
|
81
86
|
* @property {string} [filename] the filename of the source code.
|
82
|
-
* @property {boolean} [reportUnusedDisableDirectives] Adds reported errors for
|
87
|
+
* @property {boolean | "off" | "warn" | "error"} [reportUnusedDisableDirectives] Adds reported errors for
|
83
88
|
* unused `eslint-disable` directives.
|
84
89
|
*/
|
85
90
|
|
@@ -103,6 +108,12 @@ const DEFAULT_ERROR_LOC = { start: { line: 1, column: 0 }, end: { line: 1, colum
|
|
103
108
|
* whether fixes should be applied.
|
104
109
|
*/
|
105
110
|
|
111
|
+
/**
|
112
|
+
* @typedef {Object} InternalOptions
|
113
|
+
* @property {string | null} warnInlineConfig The config name what `noInlineConfig` setting came from. If `noInlineConfig` setting didn't exist, this is null. If this is a config name, then the linter warns directive comments.
|
114
|
+
* @property {"off" | "warn" | "error"} reportUnusedDisableDirectives (boolean values were normalized)
|
115
|
+
*/
|
116
|
+
|
106
117
|
//------------------------------------------------------------------------------
|
107
118
|
// Helpers
|
108
119
|
//------------------------------------------------------------------------------
|
@@ -467,7 +478,7 @@ function normalizeFilename(filename) {
|
|
467
478
|
* consistent shape.
|
468
479
|
* @param {VerifyOptions} providedOptions Options
|
469
480
|
* @param {ConfigData} config Config.
|
470
|
-
* @returns {Required<VerifyOptions> &
|
481
|
+
* @returns {Required<VerifyOptions> & InternalOptions} Normalized options
|
471
482
|
*/
|
472
483
|
function normalizeVerifyOptions(providedOptions, config) {
|
473
484
|
const disableInlineConfig = config.noInlineConfig === true;
|
@@ -476,13 +487,22 @@ function normalizeVerifyOptions(providedOptions, config) {
|
|
476
487
|
? ` (${config.configNameOfNoInlineConfig})`
|
477
488
|
: "";
|
478
489
|
|
490
|
+
let reportUnusedDisableDirectives = providedOptions.reportUnusedDisableDirectives;
|
491
|
+
|
492
|
+
if (typeof reportUnusedDisableDirectives === "boolean") {
|
493
|
+
reportUnusedDisableDirectives = reportUnusedDisableDirectives ? "error" : "off";
|
494
|
+
}
|
495
|
+
if (typeof reportUnusedDisableDirectives !== "string") {
|
496
|
+
reportUnusedDisableDirectives = config.reportUnusedDisableDirectives ? "warn" : "off";
|
497
|
+
}
|
498
|
+
|
479
499
|
return {
|
480
500
|
filename: normalizeFilename(providedOptions.filename || "<input>"),
|
481
501
|
allowInlineConfig: !ignoreInlineConfig,
|
482
502
|
warnInlineConfig: disableInlineConfig && !ignoreInlineConfig
|
483
503
|
? `your config${configNameOfNoInlineConfig}`
|
484
504
|
: null,
|
485
|
-
reportUnusedDisableDirectives
|
505
|
+
reportUnusedDisableDirectives,
|
486
506
|
disableFixes: Boolean(providedOptions.disableFixes)
|
487
507
|
};
|
488
508
|
}
|
package/lib/options.js
CHANGED
@@ -51,8 +51,8 @@ module.exports = {
|
|
51
51
|
expectedBefore: "Expected newline before ')'.",
|
52
52
|
expectedAfter: "Expected newline after '('.",
|
53
53
|
expectedBetween: "Expected newline between arguments/params.",
|
54
|
-
unexpectedBefore: "Unexpected newline before '
|
55
|
-
unexpectedAfter: "Unexpected newline after '
|
54
|
+
unexpectedBefore: "Unexpected newline before ')'.",
|
55
|
+
unexpectedAfter: "Unexpected newline after '('."
|
56
56
|
}
|
57
57
|
},
|
58
58
|
|
@@ -102,7 +102,17 @@ module.exports = {
|
|
102
102
|
if (hasCommentsInside(parent)) {
|
103
103
|
return null;
|
104
104
|
}
|
105
|
-
|
105
|
+
|
106
|
+
let prefix = "";
|
107
|
+
const tokenBefore = sourceCode.getTokenBefore(parent);
|
108
|
+
const firstReplacementToken = sourceCode.getFirstToken(node.argument);
|
109
|
+
|
110
|
+
if (tokenBefore && tokenBefore.range[1] === parent.range[0] &&
|
111
|
+
!astUtils.canTokensBeAdjacent(tokenBefore, firstReplacementToken)) {
|
112
|
+
prefix = " ";
|
113
|
+
}
|
114
|
+
|
115
|
+
return fixer.replaceText(parent, prefix + sourceCode.getText(node.argument));
|
106
116
|
}
|
107
117
|
});
|
108
118
|
}
|
@@ -49,7 +49,8 @@ module.exports = {
|
|
49
49
|
nestedBinaryExpressions: { type: "boolean" },
|
50
50
|
returnAssign: { type: "boolean" },
|
51
51
|
ignoreJSX: { enum: ["none", "all", "single-line", "multi-line"] },
|
52
|
-
enforceForArrowConditionals: { type: "boolean" }
|
52
|
+
enforceForArrowConditionals: { type: "boolean" },
|
53
|
+
enforceForSequenceExpressions: { type: "boolean" }
|
53
54
|
},
|
54
55
|
additionalProperties: false
|
55
56
|
}
|
@@ -77,6 +78,8 @@ module.exports = {
|
|
77
78
|
const IGNORE_JSX = ALL_NODES && context.options[1] && context.options[1].ignoreJSX;
|
78
79
|
const IGNORE_ARROW_CONDITIONALS = ALL_NODES && context.options[1] &&
|
79
80
|
context.options[1].enforceForArrowConditionals === false;
|
81
|
+
const IGNORE_SEQUENCE_EXPRESSIONS = ALL_NODES && context.options[1] &&
|
82
|
+
context.options[1].enforceForSequenceExpressions === false;
|
80
83
|
|
81
84
|
const PRECEDENCE_OF_ASSIGNMENT_EXPR = precedence({ type: "AssignmentExpression" });
|
82
85
|
const PRECEDENCE_OF_UPDATE_EXPR = precedence({ type: "UpdateExpression" });
|
@@ -115,6 +118,10 @@ module.exports = {
|
|
115
118
|
}
|
116
119
|
}
|
117
120
|
|
121
|
+
if (node.type === "SequenceExpression" && IGNORE_SEQUENCE_EXPRESSIONS) {
|
122
|
+
return false;
|
123
|
+
}
|
124
|
+
|
118
125
|
return ALL_NODES || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression";
|
119
126
|
}
|
120
127
|
|
@@ -94,9 +94,19 @@ function eachSelfAssignment(left, right, props, report) {
|
|
94
94
|
const end = Math.min(left.elements.length, right.elements.length);
|
95
95
|
|
96
96
|
for (let i = 0; i < end; ++i) {
|
97
|
+
const leftElement = left.elements[i];
|
97
98
|
const rightElement = right.elements[i];
|
98
99
|
|
99
|
-
|
100
|
+
// Avoid cases such as [...a] = [...a, 1]
|
101
|
+
if (
|
102
|
+
leftElement &&
|
103
|
+
leftElement.type === "RestElement" &&
|
104
|
+
i < right.elements.length - 1
|
105
|
+
) {
|
106
|
+
break;
|
107
|
+
}
|
108
|
+
|
109
|
+
eachSelfAssignment(leftElement, rightElement, props, report);
|
100
110
|
|
101
111
|
// After a spread element, those indices are unknown.
|
102
112
|
if (rightElement && rightElement.type === "SpreadElement") {
|
package/lib/rules/yoda.js
CHANGED
@@ -274,13 +274,22 @@ module.exports = {
|
|
274
274
|
* @returns {string} A string representation of the node with the sides and operator flipped
|
275
275
|
*/
|
276
276
|
function getFlippedString(node) {
|
277
|
+
const tokenBefore = sourceCode.getTokenBefore(node);
|
277
278
|
const operatorToken = sourceCode.getFirstTokenBetween(node.left, node.right, token => token.value === node.operator);
|
278
279
|
const textBeforeOperator = sourceCode.getText().slice(sourceCode.getTokenBefore(operatorToken).range[1], operatorToken.range[0]);
|
279
280
|
const textAfterOperator = sourceCode.getText().slice(operatorToken.range[1], sourceCode.getTokenAfter(operatorToken).range[0]);
|
280
281
|
const leftText = sourceCode.getText().slice(node.range[0], sourceCode.getTokenBefore(operatorToken).range[1]);
|
281
|
-
const
|
282
|
+
const firstRightToken = sourceCode.getTokenAfter(operatorToken);
|
283
|
+
const rightText = sourceCode.getText().slice(firstRightToken.range[0], node.range[1]);
|
282
284
|
|
283
|
-
|
285
|
+
let prefix = "";
|
286
|
+
|
287
|
+
if (tokenBefore && tokenBefore.range[1] === node.range[0] &&
|
288
|
+
!astUtils.canTokensBeAdjacent(tokenBefore, firstRightToken)) {
|
289
|
+
prefix = " ";
|
290
|
+
}
|
291
|
+
|
292
|
+
return prefix + rightText + textBeforeOperator + OPERATOR_FLIP_MAP[operatorToken.value] + textAfterOperator + leftText;
|
284
293
|
}
|
285
294
|
|
286
295
|
//--------------------------------------------------------------------------
|
package/lib/shared/types.js
CHANGED
@@ -36,6 +36,7 @@ module.exports = {};
|
|
36
36
|
* @property {ParserOptions} [parserOptions] The parser options.
|
37
37
|
* @property {string[]} [plugins] The plugin specifiers.
|
38
38
|
* @property {string} [processor] The processor specifier.
|
39
|
+
* @property {boolean|undefined} reportUnusedDisableDirectives The flag to report unused `eslint-disable` comments.
|
39
40
|
* @property {boolean} [root] The root flag.
|
40
41
|
* @property {Record<string, RuleConf>} [rules] The rule settings.
|
41
42
|
* @property {Object} [settings] The shared settings.
|
@@ -54,6 +55,7 @@ module.exports = {};
|
|
54
55
|
* @property {ParserOptions} [parserOptions] The parser options.
|
55
56
|
* @property {string[]} [plugins] The plugin specifiers.
|
56
57
|
* @property {string} [processor] The processor specifier.
|
58
|
+
* @property {boolean|undefined} reportUnusedDisableDirectives The flag to report unused `eslint-disable` comments.
|
57
59
|
* @property {Record<string, RuleConf>} [rules] The rule settings.
|
58
60
|
* @property {Object} [settings] The shared settings.
|
59
61
|
*/
|