Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ language: node_js
node_js:
- "4"
- "6"
- "8"
after_success:
- npm run codecov
28 changes: 10 additions & 18 deletions lib/rules/block-scoped-var.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ function PseudoScope(def) {
PseudoScope.createScopesFrom = function(variable) {
const defs = variable.defs
const scopes = []
for (let j = 0; j < defs.length; ++j) {
const def = defs[j]
for (const def of defs) {
if (!shouldSkip(def, defs, variable)) {
PseudoScope.push(scopes, new PseudoScope(def))
}
Expand All @@ -135,9 +134,7 @@ PseudoScope.createScopesFrom = function(variable) {
* @returns {void}
*/
PseudoScope.push = function(scopes, newScope) {
for (let i = 0; i < scopes.length; ++i) {
const scope = scopes[i]

for (const scope of scopes) {
if (scope.start === newScope.start && scope.end === newScope.end) {
scope.redeclarations.push(newScope.identifier)
return
Expand All @@ -161,9 +158,7 @@ PseudoScope.push = function(scopes, newScope) {
PseudoScope.findScope = function(scopes, reference) {
const range = reference.identifier.range

for (let i = 0; i < scopes.length; ++i) {
const scope = scopes[i]

for (const scope of scopes) {
if (scope.start <= range[0] && range[1] <= scope.end) {
return PseudoScope.findScope(scope.children, reference) || scope
}
Expand Down Expand Up @@ -200,8 +195,7 @@ module.exports = function(context) {
*/
function checkForVariables(node) {
const variables = context.getDeclaredVariables(node)
for (let i = 0; i < variables.length; ++i) {
const variable = variables[i]
for (const variable of variables) {
const defs = variable.defs
const lastDef = defs[defs.length - 1]

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

if (reference.isRead()) {
Expand All @@ -236,32 +229,31 @@ module.exports = function(context) {
context.report(
reference.identifier,
"\"{{name}}\" is not defined.",
{name: reference.identifier.name})
{ name: reference.identifier.name })
}
}

// Warn re-declarations, shadowing, and unused.
scopes.forEach(function walk(scope) {
for (let j = 0; j < scope.redeclarations.length; ++j) {
const identifier = scope.redeclarations[j]
for (const identifier of scope.redeclarations) {
context.report(
identifier,
"\"{{name}}\" is already defined.",
{name: identifier.name})
{ name: identifier.name })
}

if (scope.shadowing) {
context.report(
scope.identifier,
"\"{{name}}\" is already defined in the upper scope.",
{name: scope.identifier.name})
{ name: scope.identifier.name })
}

if (hasReadRef && !scope.used) {
context.report(
scope.identifier,
"\"{{name}}\" is defined but never used.",
{name: scope.identifier.name})
{ name: scope.identifier.name })
}

scope.children.forEach(walk)
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-instanceof-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports = {
node,
loc: node.loc,
message: "Unexpected 'instanceof' operator. Use 'typeof x === \"{{typeName}}\"' instead.",
data: {typeName},
data: { typeName },
fix: (fixer) => fixer.replaceText(
node,
`typeof ${sourceCode.getText(node.left)} === "${typeName}"`
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-this-in-static.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports = {
node,
loc: node.loc,
message: "Unexpected '{{type}}'.",
data: {type: sourceCode.getText(node)},
data: { type: sourceCode.getText(node) },
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-use-ignored-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = {
recommended: false,
},
schema: [
{type: "string"},
{ type: "string" },
],
},

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/prefer-for-of.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ function create(context) {
},

"ForInStatement"(node) {
context.report({node, message: MESSAGE})
context.report({ node, message: MESSAGE })
},
}
}
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
"dependencies": {},
"devDependencies": {
"chokidar-cli": "^1.2.0",
"codecov": "^1.0.1",
"eslint": "^3.16.1",
"eslint-config-mysticatea": "^8.0.0",
"codecov": "^2.3.0",
"eslint": "^4.7.2",
"eslint-config-mysticatea": "^12.0.0",
"mocha": "^3.0.2",
"nyc": "^10.1.2",
"nyc": "^11.2.1",
"opener": "^1.4.1",
"rimraf": "^2.5.4"
},
Expand Down
6 changes: 3 additions & 3 deletions scripts/generate-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ fs.writeFileSync(path.resolve(__dirname, "../index.js"), `/**
module.exports = {
rules: {
${fs.readdirSync(path.resolve(__dirname, "../lib/rules"))
.map(fileName => path.basename(fileName, ".js"))
.map(ruleId => ` "${ruleId}": require("./lib/rules/${ruleId}"),`)
.join("\n")}
.map(fileName => path.basename(fileName, ".js"))
.map(ruleId => ` "${ruleId}": require("./lib/rules/${ruleId}"),`)
.join("\n")}
},
}
`)
46 changes: 23 additions & 23 deletions tests/lib/rules/arrow-parens.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const RuleTester = require("eslint").RuleTester
const rule = require("../../../lib/rules/arrow-parens")

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

{code: "var foo = async (x) => x;", parserOptions: {ecmaVersion: 2017}},
{code: "var foo = async (x => x);", parserOptions: {ecmaVersion: 2017}},
{code: "foo(async () => 0);", parserOptions: {ecmaVersion: 2017}},
{code: "foo(async (x, y) => x);", parserOptions: {ecmaVersion: 2017}},
{code: "foo(async (x = 0) => x);", parserOptions: {ecmaVersion: 2017}},
{code: "foo(async ([x]) => x);", parserOptions: {ecmaVersion: 2017}},
{code: "foo(async ({x}) => x);", parserOptions: {ecmaVersion: 2017}},
{code: "foo(x => x, async (x) => x);", parserOptions: {ecmaVersion: 2017}},
{code: "foo(\n async (x) => x,\n async (x) => x\n);", parserOptions: {ecmaVersion: 2017}},
{ code: "var foo = async (x) => x;", parserOptions: { ecmaVersion: 2017 } },
{ code: "var foo = async (x => x);", parserOptions: { ecmaVersion: 2017 } },
{ code: "foo(async () => 0);", parserOptions: { ecmaVersion: 2017 } },
{ code: "foo(async (x, y) => x);", parserOptions: { ecmaVersion: 2017 } },
{ code: "foo(async (x = 0) => x);", parserOptions: { ecmaVersion: 2017 } },
{ code: "foo(async ([x]) => x);", parserOptions: { ecmaVersion: 2017 } },
{ code: "foo(async ({x}) => x);", parserOptions: { ecmaVersion: 2017 } },
{ code: "foo(x => x, async (x) => x);", parserOptions: { ecmaVersion: 2017 } },
{ code: "foo(\n async (x) => x,\n async (x) => x\n);", parserOptions: { ecmaVersion: 2017 } },
],
invalid: [
{
code: "var foo = x => x;",
output: "var foo = (x) => x;",
errors: [
{column: 11, message: "Expected to enclose this argument with parentheses."},
{ column: 11, message: "Expected to enclose this argument with parentheses." },
],
},
{
code: "foo(x => x, x => x);",
output: "foo(x => x, (x) => x);",
errors: [
{column: 13, message: "Expected to enclose this argument with parentheses."},
{ column: 13, message: "Expected to enclose this argument with parentheses." },
],
},
{
code: "foo(\n x => x,\n x => x\n);",
output: "foo(\n (x) => x,\n (x) => x\n);",
errors: [
{line: 2, message: "Expected to enclose this argument with parentheses."},
{line: 3, message: "Expected to enclose this argument with parentheses."},
{ line: 2, message: "Expected to enclose this argument with parentheses." },
{ line: 3, message: "Expected to enclose this argument with parentheses." },
],
},
{
code: "foo((x) => x);",
output: "foo(x => x);",
errors: [
{message: "Unexpected parentheses enclosing this argument."},
{ message: "Unexpected parentheses enclosing this argument." },
],
},

{
code: "var foo = async x => x;",
output: "var foo = async (x) => x;",
parserOptions: {ecmaVersion: 2017},
parserOptions: { ecmaVersion: 2017 },
errors: [
{column: 11, message: "Expected to enclose this argument with parentheses."},
{ column: 11, message: "Expected to enclose this argument with parentheses." },
],
},
{
code: "foo(async x => x, async x => x);",
output: "foo(async (x) => x, async (x) => x);",
parserOptions: {ecmaVersion: 2017},
parserOptions: { ecmaVersion: 2017 },
errors: [
{column: 5, message: "Expected to enclose this argument with parentheses."},
{column: 19, message: "Expected to enclose this argument with parentheses."},
{ column: 5, message: "Expected to enclose this argument with parentheses." },
{ column: 19, message: "Expected to enclose this argument with parentheses." },
],
},
{
code: "foo(\n async x => x,\n async x => x\n);",
output: "foo(\n async (x) => x,\n async (x) => x\n);",
parserOptions: {ecmaVersion: 2017},
parserOptions: { ecmaVersion: 2017 },
errors: [
{line: 2, message: "Expected to enclose this argument with parentheses."},
{line: 3, message: "Expected to enclose this argument with parentheses."},
{ line: 2, message: "Expected to enclose this argument with parentheses." },
{ line: 3, message: "Expected to enclose this argument with parentheses." },
],
},
],
Expand Down
56 changes: 26 additions & 30 deletions tests/lib/rules/block-scoped-var.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,37 @@
"use strict"

const RuleTester = require("eslint").RuleTester
const rule = require("../../../lib/rules/block-scoped-var");

(new RuleTester()).run("block-scoped-var", rule, {
const rule = require("../../../lib/rules/block-scoped-var")
;(new RuleTester()).run("block-scoped-var", rule, {
valid: [
{code: "{ var a; a; } { var a; a; }"},
{code: "{ var a; a; } { { var a; a; } { var a; { a; } } }"},
{code: "if (true) { var a; a; } else if (true) { var a; a; } else { var a; a; }"},
{code: "while (true) { var a; a; } do { var a; a; } while (true);"},
{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}},
{code: "switch (0) { case 0: var a; a; case 1: a; default: a; } { var a; a; }"},
{code: "var a = {}; module.exports = a"},
{ code: "{ var a; a; } { var a; a; }" },
{ code: "{ var a; a; } { { var a; a; } { var a; { a; } } }" },
{ code: "if (true) { var a; a; } else if (true) { var a; a; } else { var a; a; }" },
{ code: "while (true) { var a; a; } do { var a; a; } while (true);" },
{ 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 } },
{ code: "switch (0) { case 0: var a; a; case 1: a; default: a; } { var a; a; }" },
{ code: "var a = {}; module.exports = a" },

// below should be warned by no-shadow rule.
// this rule ignores those merely.
{code: "var a; function foo() { var a; }"},
{code: "var a; function foo(a) { }"},
{code: "function a() { var a; }"},
{code: "(function a() { var a; })();"},
{code: "class a { foo() { var a; } }", env: {es6: true}},
{code: "(class a { foo() { var a; } })();", env: {es6: true}},
{ code: "var a; function foo() { var a; }" },
{ code: "var a; function foo(a) { }" },
{ code: "function a() { var a; }" },
{ code: "(function a() { var a; })();" },
{ code: "class a { foo() { var a; } }", env: { es6: true } },
{ code: "(class a { foo() { var a; } })();", env: { es6: true } },
],
invalid: [
{code: "{ var a; a; } a;", errors: [{type: "Identifier", message: "\"a\" is not defined."}]},
{code: "a; { var a; a; }", errors: [{type: "Identifier", message: "\"a\" is not defined."}]},
{code: "for (var a; a; a) { } a;", errors: [{type: "Identifier", message: "\"a\" is not defined."}]},
{code: "a; for (var a; a; a) { }", errors: [{type: "Identifier", message: "\"a\" is not defined."}]},
{code: "{ var a; var a; }", errors: [{type: "Identifier", message: "\"a\" is already defined."}]},
{code: "for (var a; a; a) { var a; }", errors: [{type: "Identifier", message: "\"a\" is already defined."}]},
{code: "{ var a; function a() {} }", errors: [{type: "Identifier", message: "\"a\" is already defined."}]},
{code: "function foo(a) { var a; } var a;", errors: [{type: "Identifier", message: "\"a\" is already defined."}]},
{code: "import a from \"a\"; var a;", parserOptions: {sourceType: "module"}, errors: [{type: "Identifier", message: "\"a\" is already defined."}]},
{code: "import a from \"a\"; import a from \"b/a\";", parserOptions: {sourceType: "module"}, errors: [{type: "Identifier", message: "\"a\" is already defined."}]},
{code: "{ var a; { var a; } }", errors: [{type: "Identifier", message: "\"a\" is already defined in the upper scope."}]},
{code: "import a from \"a\"; { var a; }", parserOptions: {sourceType: "module"}, errors: [{type: "Identifier", message: "\"a\" is already defined in the upper scope."}]},
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question, do 3 test cases which include import declarations throw syntax error currently?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. You can't shadow an import at all in modern babel

{code: "{ var a; } { var a; a; }", errors: [{type: "Identifier", message: "\"a\" is defined but never used.", column: 7}]},
{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}]},
{ code: "{ var a; a; } a;", errors: [{ type: "Identifier", message: "\"a\" is not defined." }] },
{ code: "a; { var a; a; }", errors: [{ type: "Identifier", message: "\"a\" is not defined." }] },
{ code: "for (var a; a; a) { } a;", errors: [{ type: "Identifier", message: "\"a\" is not defined." }] },
{ code: "a; for (var a; a; a) { }", errors: [{ type: "Identifier", message: "\"a\" is not defined." }] },
{ code: "{ var a; var a; }", errors: [{ type: "Identifier", message: "\"a\" is already defined." }] },
{ code: "for (var a; a; a) { var a; }", errors: [{ type: "Identifier", message: "\"a\" is already defined." }] },
{ code: "{ var a; function a() {} }", errors: [{ type: "Identifier", message: "\"a\" is already defined." }] },
{ code: "function foo(a) { var a; } var a;", errors: [{ type: "Identifier", message: "\"a\" is already defined." }] },
{ code: "{ var a; { var a; } }", errors: [{ type: "Identifier", message: "\"a\" is already defined in the upper scope." }] },
{ code: "{ var a; } { var a; a; }", errors: [{ type: "Identifier", message: "\"a\" is defined but never used.", column: 7 }] },
{ 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 }] },
],
})
6 changes: 3 additions & 3 deletions tests/lib/rules/no-instanceof-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ tester.run("no-instanceof-wrapper", rule, {
"typeof x === \"string\"",
"typeof x === \"object\"",
"typeof x === \"function\"",
{code: "typeof x === \"symbol\"", env: {es6: true}},
{ code: "typeof x === \"symbol\"", env: { es6: true } },
"function foo(Boolean) { x instanceof Boolean }",
"function foo(Number) { x instanceof Number }",
"function foo(String) { x instanceof String }",
"function foo(Object) { x instanceof Object }",
"function foo(Function) { x instanceof Function }",
{code: "function foo(Symbol) { x instanceof Symbol }", env: {es6: true}},
{ code: "function foo(Symbol) { x instanceof Symbol }", env: { es6: true } },
"Boolean",
],
invalid: [
Expand Down Expand Up @@ -63,7 +63,7 @@ tester.run("no-instanceof-wrapper", rule, {
{
code: "x instanceof Symbol",
output: "typeof x === \"symbol\"",
env: {es6: true},
env: { es6: true },
errors: ["Unexpected 'instanceof' operator. Use 'typeof x === \"symbol\"' instead."],
},
],
Expand Down
Loading