// Requirements
//------------------------------------------------------------------------------
-const path = require("path");
const rule = require("../../../lib/rules/no-redeclare");
const { RuleTester } = require("../../../lib/rule-tester");
// Tests
//------------------------------------------------------------------------------
-const looseParserPath = path.resolve(__dirname, "../../tools/loose-parser.js");
const ruleTester = new RuleTester();
ruleTester.run("no-redeclare", rule, {
]
},
- // let/const
- {
- code: "let a; let a;",
- parser: looseParserPath,
- parserOptions: { ecmaVersion: 2015 },
- errors: [
- { message: "'a' is already defined.", type: "Identifier" }
- ]
- },
- {
- code: "let a; let a;",
- parser: looseParserPath,
- parserOptions: { ecmaVersion: 2015, sourceType: "module" },
- errors: [
- { message: "'a' is already defined.", type: "Identifier" }
- ]
- },
- {
- code: "let a; let a;",
- parser: looseParserPath,
- parserOptions: { ecmaVersion: 2015, ecmaFeatures: { globalReturn: true } },
- errors: [
- { message: "'a' is already defined.", type: "Identifier" }
- ]
- },
- {
- code: "let a; const a = 0;",
- parser: looseParserPath,
- parserOptions: { ecmaVersion: 2015 },
- errors: [
- { message: "'a' is already defined.", type: "Identifier" }
- ]
- },
- {
- code: "const a = 0; const a = 0;",
- parser: looseParserPath,
- parserOptions: { ecmaVersion: 2015 },
- errors: [
- { message: "'a' is already defined.", type: "Identifier" }
- ]
- },
- {
- code: "if (test) { let a; let a; }",
- parser: looseParserPath,
- parserOptions: { ecmaVersion: 2015 },
- errors: [
- { message: "'a' is already defined.", type: "Identifier" }
- ]
- },
- {
- code: "switch (test) { case 0: let a; let a; }",
- parser: looseParserPath,
- parserOptions: { ecmaVersion: 2015 },
- errors: [
- { message: "'a' is already defined.", type: "Identifier" }
- ]
- },
- {
- code: "for (let a, a;;);",
- parser: looseParserPath,
- parserOptions: { ecmaVersion: 2015 },
- errors: [
- { message: "'a' is already defined.", type: "Identifier" }
- ]
- },
- {
- code: "for (let [a, a] in xs);",
- parser: looseParserPath,
- parserOptions: { ecmaVersion: 2015 },
- errors: [
- { message: "'a' is already defined.", type: "Identifier" }
- ]
- },
- {
- code: "for (let [a, a] of xs);",
- parser: looseParserPath,
- parserOptions: { ecmaVersion: 2015 },
- errors: [
- { message: "'a' is already defined.", type: "Identifier" }
- ]
- },
- {
- code: "function f() { let a; let a; }",
- parser: looseParserPath,
- parserOptions: { ecmaVersion: 2015 },
- errors: [
- { message: "'a' is already defined.", type: "Identifier" }
- ]
- },
- {
- code: "function f(a) { let a; }",
- parser: looseParserPath,
- parserOptions: { ecmaVersion: 2015 },
- errors: [
- { message: "'a' is already defined.", type: "Identifier" }
- ]
- },
- {
- code: "function f() { if (test) { let a; let a; } }",
- parser: looseParserPath,
- parserOptions: { ecmaVersion: 2015 },
- errors: [
- { message: "'a' is already defined.", type: "Identifier" }
- ]
- },
-
// Comments and built-ins.
{
code: "/*globals Array */",