Skip to content

Commit fbad017

Browse files
author
Thomas Grainger
committed
eslint autofix
1 parent 582b4ba commit fbad017

13 files changed

+124
-133
lines changed

lib/rules/block-scoped-var.js

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ function PseudoScope(def) {
118118
PseudoScope.createScopesFrom = function(variable) {
119119
const defs = variable.defs
120120
const scopes = []
121-
for (let j = 0; j < defs.length; ++j) {
122-
const def = defs[j]
121+
for (const def of defs) {
123122
if (!shouldSkip(def, defs, variable)) {
124123
PseudoScope.push(scopes, new PseudoScope(def))
125124
}
@@ -135,9 +134,7 @@ PseudoScope.createScopesFrom = function(variable) {
135134
* @returns {void}
136135
*/
137136
PseudoScope.push = function(scopes, newScope) {
138-
for (let i = 0; i < scopes.length; ++i) {
139-
const scope = scopes[i]
140-
137+
for (const scope of scopes) {
141138
if (scope.start === newScope.start && scope.end === newScope.end) {
142139
scope.redeclarations.push(newScope.identifier)
143140
return
@@ -161,9 +158,7 @@ PseudoScope.push = function(scopes, newScope) {
161158
PseudoScope.findScope = function(scopes, reference) {
162159
const range = reference.identifier.range
163160

164-
for (let i = 0; i < scopes.length; ++i) {
165-
const scope = scopes[i]
166-
161+
for (const scope of scopes) {
167162
if (scope.start <= range[0] && range[1] <= scope.end) {
168163
return PseudoScope.findScope(scope.children, reference) || scope
169164
}
@@ -200,8 +195,7 @@ module.exports = function(context) {
200195
*/
201196
function checkForVariables(node) {
202197
const variables = context.getDeclaredVariables(node)
203-
for (let i = 0; i < variables.length; ++i) {
204-
const variable = variables[i]
198+
for (const variable of variables) {
205199
const defs = variable.defs
206200
const lastDef = defs[defs.length - 1]
207201

@@ -221,8 +215,7 @@ module.exports = function(context) {
221215
// And while it does, warn references which does not belong to any
222216
// scope.
223217
let hasReadRef = false
224-
for (let j = 0; j < variable.references.length; ++j) {
225-
const reference = variable.references[j]
218+
for (const reference of variable.references) {
226219
const scope = PseudoScope.findScope(scopes, reference)
227220

228221
if (reference.isRead()) {
@@ -236,32 +229,31 @@ module.exports = function(context) {
236229
context.report(
237230
reference.identifier,
238231
"\"{{name}}\" is not defined.",
239-
{name: reference.identifier.name})
232+
{ name: reference.identifier.name })
240233
}
241234
}
242235

243236
// Warn re-declarations, shadowing, and unused.
244237
scopes.forEach(function walk(scope) {
245-
for (let j = 0; j < scope.redeclarations.length; ++j) {
246-
const identifier = scope.redeclarations[j]
238+
for (const identifier of scope.redeclarations) {
247239
context.report(
248240
identifier,
249241
"\"{{name}}\" is already defined.",
250-
{name: identifier.name})
242+
{ name: identifier.name })
251243
}
252244

253245
if (scope.shadowing) {
254246
context.report(
255247
scope.identifier,
256248
"\"{{name}}\" is already defined in the upper scope.",
257-
{name: scope.identifier.name})
249+
{ name: scope.identifier.name })
258250
}
259251

260252
if (hasReadRef && !scope.used) {
261253
context.report(
262254
scope.identifier,
263255
"\"{{name}}\" is defined but never used.",
264-
{name: scope.identifier.name})
256+
{ name: scope.identifier.name })
265257
}
266258

267259
scope.children.forEach(walk)

lib/rules/no-instanceof-wrapper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ module.exports = {
7171
node,
7272
loc: node.loc,
7373
message: "Unexpected 'instanceof' operator. Use 'typeof x === \"{{typeName}}\"' instead.",
74-
data: {typeName},
74+
data: { typeName },
7575
fix: (fixer) => fixer.replaceText(
7676
node,
7777
`typeof ${sourceCode.getText(node.left)} === "${typeName}"`

lib/rules/no-this-in-static.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ module.exports = {
7171
node,
7272
loc: node.loc,
7373
message: "Unexpected '{{type}}'.",
74-
data: {type: sourceCode.getText(node)},
74+
data: { type: sourceCode.getText(node) },
7575
})
7676
}
7777
}

lib/rules/no-use-ignored-vars.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = {
2222
recommended: false,
2323
},
2424
schema: [
25-
{type: "string"},
25+
{ type: "string" },
2626
],
2727
},
2828

lib/rules/prefer-for-of.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ function create(context) {
604604
},
605605

606606
"ForInStatement"(node) {
607-
context.report({node, message: MESSAGE})
607+
context.report({ node, message: MESSAGE })
608608
},
609609
}
610610
}

scripts/generate-index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ fs.writeFileSync(path.resolve(__dirname, "../index.js"), `/**
2626
module.exports = {
2727
rules: {
2828
${fs.readdirSync(path.resolve(__dirname, "../lib/rules"))
29-
.map(fileName => path.basename(fileName, ".js"))
30-
.map(ruleId => ` "${ruleId}": require("./lib/rules/${ruleId}"),`)
31-
.join("\n")}
29+
.map(fileName => path.basename(fileName, ".js"))
30+
.map(ruleId => ` "${ruleId}": require("./lib/rules/${ruleId}"),`)
31+
.join("\n")}
3232
},
3333
}
3434
`)

tests/lib/rules/arrow-parens.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
const RuleTester = require("eslint").RuleTester
99
const rule = require("../../../lib/rules/arrow-parens")
1010

11-
;(new RuleTester({parserOptions: {ecmaVersion: 2015}})).run("arrow-parens", rule, {
11+
;(new RuleTester({ parserOptions: { ecmaVersion: 2015 } })).run("arrow-parens", rule, {
1212
valid: [
1313
"var foo = (x) => x;",
1414
"var foo = (x => x);",
@@ -21,71 +21,71 @@ const rule = require("../../../lib/rules/arrow-parens")
2121
"foo(x => x, (x) => x);",
2222
"foo(\n (x) => x,\n (x) => x\n);",
2323

24-
{code: "var foo = async (x) => x;", parserOptions: {ecmaVersion: 2017}},
25-
{code: "var foo = async (x => x);", parserOptions: {ecmaVersion: 2017}},
26-
{code: "foo(async () => 0);", parserOptions: {ecmaVersion: 2017}},
27-
{code: "foo(async (x, y) => x);", parserOptions: {ecmaVersion: 2017}},
28-
{code: "foo(async (x = 0) => x);", parserOptions: {ecmaVersion: 2017}},
29-
{code: "foo(async ([x]) => x);", parserOptions: {ecmaVersion: 2017}},
30-
{code: "foo(async ({x}) => x);", parserOptions: {ecmaVersion: 2017}},
31-
{code: "foo(x => x, async (x) => x);", parserOptions: {ecmaVersion: 2017}},
32-
{code: "foo(\n async (x) => x,\n async (x) => x\n);", parserOptions: {ecmaVersion: 2017}},
24+
{ code: "var foo = async (x) => x;", parserOptions: { ecmaVersion: 2017 } },
25+
{ code: "var foo = async (x => x);", parserOptions: { ecmaVersion: 2017 } },
26+
{ code: "foo(async () => 0);", parserOptions: { ecmaVersion: 2017 } },
27+
{ code: "foo(async (x, y) => x);", parserOptions: { ecmaVersion: 2017 } },
28+
{ code: "foo(async (x = 0) => x);", parserOptions: { ecmaVersion: 2017 } },
29+
{ code: "foo(async ([x]) => x);", parserOptions: { ecmaVersion: 2017 } },
30+
{ code: "foo(async ({x}) => x);", parserOptions: { ecmaVersion: 2017 } },
31+
{ code: "foo(x => x, async (x) => x);", parserOptions: { ecmaVersion: 2017 } },
32+
{ code: "foo(\n async (x) => x,\n async (x) => x\n);", parserOptions: { ecmaVersion: 2017 } },
3333
],
3434
invalid: [
3535
{
3636
code: "var foo = x => x;",
3737
output: "var foo = (x) => x;",
3838
errors: [
39-
{column: 11, message: "Expected to enclose this argument with parentheses."},
39+
{ column: 11, message: "Expected to enclose this argument with parentheses." },
4040
],
4141
},
4242
{
4343
code: "foo(x => x, x => x);",
4444
output: "foo(x => x, (x) => x);",
4545
errors: [
46-
{column: 13, message: "Expected to enclose this argument with parentheses."},
46+
{ column: 13, message: "Expected to enclose this argument with parentheses." },
4747
],
4848
},
4949
{
5050
code: "foo(\n x => x,\n x => x\n);",
5151
output: "foo(\n (x) => x,\n (x) => x\n);",
5252
errors: [
53-
{line: 2, message: "Expected to enclose this argument with parentheses."},
54-
{line: 3, message: "Expected to enclose this argument with parentheses."},
53+
{ line: 2, message: "Expected to enclose this argument with parentheses." },
54+
{ line: 3, message: "Expected to enclose this argument with parentheses." },
5555
],
5656
},
5757
{
5858
code: "foo((x) => x);",
5959
output: "foo(x => x);",
6060
errors: [
61-
{message: "Unexpected parentheses enclosing this argument."},
61+
{ message: "Unexpected parentheses enclosing this argument." },
6262
],
6363
},
6464

6565
{
6666
code: "var foo = async x => x;",
6767
output: "var foo = async (x) => x;",
68-
parserOptions: {ecmaVersion: 2017},
68+
parserOptions: { ecmaVersion: 2017 },
6969
errors: [
70-
{column: 11, message: "Expected to enclose this argument with parentheses."},
70+
{ column: 11, message: "Expected to enclose this argument with parentheses." },
7171
],
7272
},
7373
{
7474
code: "foo(async x => x, async x => x);",
7575
output: "foo(async (x) => x, async (x) => x);",
76-
parserOptions: {ecmaVersion: 2017},
76+
parserOptions: { ecmaVersion: 2017 },
7777
errors: [
78-
{column: 5, message: "Expected to enclose this argument with parentheses."},
79-
{column: 19, message: "Expected to enclose this argument with parentheses."},
78+
{ column: 5, message: "Expected to enclose this argument with parentheses." },
79+
{ column: 19, message: "Expected to enclose this argument with parentheses." },
8080
],
8181
},
8282
{
8383
code: "foo(\n async x => x,\n async x => x\n);",
8484
output: "foo(\n async (x) => x,\n async (x) => x\n);",
85-
parserOptions: {ecmaVersion: 2017},
85+
parserOptions: { ecmaVersion: 2017 },
8686
errors: [
87-
{line: 2, message: "Expected to enclose this argument with parentheses."},
88-
{line: 3, message: "Expected to enclose this argument with parentheses."},
87+
{ line: 2, message: "Expected to enclose this argument with parentheses." },
88+
{ line: 3, message: "Expected to enclose this argument with parentheses." },
8989
],
9090
},
9191
],

tests/lib/rules/block-scoped-var.js

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,37 @@
66
"use strict"
77

88
const RuleTester = require("eslint").RuleTester
9-
const rule = require("../../../lib/rules/block-scoped-var");
10-
11-
(new RuleTester()).run("block-scoped-var", rule, {
9+
const rule = require("../../../lib/rules/block-scoped-var")
10+
;(new RuleTester()).run("block-scoped-var", rule, {
1211
valid: [
13-
{code: "{ var a; a; } { var a; a; }"},
14-
{code: "{ var a; a; } { { var a; a; } { var a; { a; } } }"},
15-
{code: "if (true) { var a; a; } else if (true) { var a; a; } else { var a; a; }"},
16-
{code: "while (true) { var a; a; } do { var a; a; } while (true);"},
17-
{code: "for (var a = 0; a; a) { a; var b; b; } for (var a in []) { a; var b; b; } for (var a of []) { a; var b; b; }", env: {es6: true}},
18-
{code: "switch (0) { case 0: var a; a; case 1: a; default: a; } { var a; a; }"},
19-
{code: "var a = {}; module.exports = a"},
12+
{ code: "{ var a; a; } { var a; a; }" },
13+
{ code: "{ var a; a; } { { var a; a; } { var a; { a; } } }" },
14+
{ code: "if (true) { var a; a; } else if (true) { var a; a; } else { var a; a; }" },
15+
{ code: "while (true) { var a; a; } do { var a; a; } while (true);" },
16+
{ code: "for (var a = 0; a; a) { a; var b; b; } for (var a in []) { a; var b; b; } for (var a of []) { a; var b; b; }", env: { es6: true } },
17+
{ code: "switch (0) { case 0: var a; a; case 1: a; default: a; } { var a; a; }" },
18+
{ code: "var a = {}; module.exports = a" },
2019

2120
// below should be warned by no-shadow rule.
2221
// this rule ignores those merely.
23-
{code: "var a; function foo() { var a; }"},
24-
{code: "var a; function foo(a) { }"},
25-
{code: "function a() { var a; }"},
26-
{code: "(function a() { var a; })();"},
27-
{code: "class a { foo() { var a; } }", env: {es6: true}},
28-
{code: "(class a { foo() { var a; } })();", env: {es6: true}},
22+
{ code: "var a; function foo() { var a; }" },
23+
{ code: "var a; function foo(a) { }" },
24+
{ code: "function a() { var a; }" },
25+
{ code: "(function a() { var a; })();" },
26+
{ code: "class a { foo() { var a; } }", env: { es6: true } },
27+
{ code: "(class a { foo() { var a; } })();", env: { es6: true } },
2928
],
3029
invalid: [
31-
{code: "{ var a; a; } a;", errors: [{type: "Identifier", message: "\"a\" is not defined."}]},
32-
{code: "a; { var a; a; }", errors: [{type: "Identifier", message: "\"a\" is not defined."}]},
33-
{code: "for (var a; a; a) { } a;", errors: [{type: "Identifier", message: "\"a\" is not defined."}]},
34-
{code: "a; for (var a; a; a) { }", errors: [{type: "Identifier", message: "\"a\" is not defined."}]},
35-
{code: "{ var a; var a; }", errors: [{type: "Identifier", message: "\"a\" is already defined."}]},
36-
{code: "for (var a; a; a) { var a; }", errors: [{type: "Identifier", message: "\"a\" is already defined."}]},
37-
{code: "{ var a; function a() {} }", errors: [{type: "Identifier", message: "\"a\" is already defined."}]},
38-
{code: "function foo(a) { var a; } var a;", errors: [{type: "Identifier", message: "\"a\" is already defined."}]},
39-
{code: "{ var a; { var a; } }", errors: [{type: "Identifier", message: "\"a\" is already defined in the upper scope."}]},
40-
{code: "{ var a; } { var a; a; }", errors: [{type: "Identifier", message: "\"a\" is defined but never used.", column: 7}]},
41-
{code: "{ var {x: [a = 0]} = {x: [1]}; a; } { var a; ({x: [a = 0]} = {x: [1]}); }", env: {es6: true}, errors: [{type: "Identifier", message: "\"a\" is defined but never used.", column: 43}]},
30+
{ code: "{ var a; a; } a;", errors: [{ type: "Identifier", message: "\"a\" is not defined." }] },
31+
{ code: "a; { var a; a; }", errors: [{ type: "Identifier", message: "\"a\" is not defined." }] },
32+
{ code: "for (var a; a; a) { } a;", errors: [{ type: "Identifier", message: "\"a\" is not defined." }] },
33+
{ code: "a; for (var a; a; a) { }", errors: [{ type: "Identifier", message: "\"a\" is not defined." }] },
34+
{ code: "{ var a; var a; }", errors: [{ type: "Identifier", message: "\"a\" is already defined." }] },
35+
{ code: "for (var a; a; a) { var a; }", errors: [{ type: "Identifier", message: "\"a\" is already defined." }] },
36+
{ code: "{ var a; function a() {} }", errors: [{ type: "Identifier", message: "\"a\" is already defined." }] },
37+
{ code: "function foo(a) { var a; } var a;", errors: [{ type: "Identifier", message: "\"a\" is already defined." }] },
38+
{ code: "{ var a; { var a; } }", errors: [{ type: "Identifier", message: "\"a\" is already defined in the upper scope." }] },
39+
{ code: "{ var a; } { var a; a; }", errors: [{ type: "Identifier", message: "\"a\" is defined but never used.", column: 7 }] },
40+
{ code: "{ var {x: [a = 0]} = {x: [1]}; a; } { var a; ({x: [a = 0]} = {x: [1]}); }", env: { es6: true }, errors: [{ type: "Identifier", message: "\"a\" is defined but never used.", column: 43 }] },
4241
],
4342
})

tests/lib/rules/no-instanceof-wrapper.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ tester.run("no-instanceof-wrapper", rule, {
2525
"typeof x === \"string\"",
2626
"typeof x === \"object\"",
2727
"typeof x === \"function\"",
28-
{code: "typeof x === \"symbol\"", env: {es6: true}},
28+
{ code: "typeof x === \"symbol\"", env: { es6: true } },
2929
"function foo(Boolean) { x instanceof Boolean }",
3030
"function foo(Number) { x instanceof Number }",
3131
"function foo(String) { x instanceof String }",
3232
"function foo(Object) { x instanceof Object }",
3333
"function foo(Function) { x instanceof Function }",
34-
{code: "function foo(Symbol) { x instanceof Symbol }", env: {es6: true}},
34+
{ code: "function foo(Symbol) { x instanceof Symbol }", env: { es6: true } },
3535
"Boolean",
3636
],
3737
invalid: [
@@ -63,7 +63,7 @@ tester.run("no-instanceof-wrapper", rule, {
6363
{
6464
code: "x instanceof Symbol",
6565
output: "typeof x === \"symbol\"",
66-
env: {es6: true},
66+
env: { es6: true },
6767
errors: ["Unexpected 'instanceof' operator. Use 'typeof x === \"symbol\"' instead."],
6868
},
6969
],

0 commit comments

Comments
 (0)