Skip to content

Commit

Permalink
Chore: make test-case-property-ordering reasonable (#11511)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea authored and not-an-aardvark committed Mar 15, 2019
1 parent f354770 commit 1f715a2
Show file tree
Hide file tree
Showing 22 changed files with 131 additions and 116 deletions.
17 changes: 16 additions & 1 deletion .eslintrc.js
Expand Up @@ -17,7 +17,22 @@ module.exports = {
"eslint-plugin/prefer-placeholders": "error",
"eslint-plugin/report-message-format": ["error", "[^a-z].*\\.$"],
"eslint-plugin/require-meta-type": "error",
"eslint-plugin/test-case-property-ordering": "error",
"eslint-plugin/test-case-property-ordering": [
"error",

// https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/issues/79
[
"filename",
"code",
"output",
"options",
"parser",
"parserOptions",
"globals",
"env",
"errors"
]
],
"eslint-plugin/test-case-shorthand-strings": "error",
"internal-rules/multiline-comment-style": "error"
},
Expand Down
12 changes: 6 additions & 6 deletions tests/lib/rules/array-bracket-spacing.js
Expand Up @@ -174,8 +174,8 @@ ruleTester.run("array-bracket-spacing", rule, {
{ code: "var obj = {'foo': [1, 2]}", options: ["never"] },

// destructuring with type annotation
{ code: "([ a, b ]: Array<any>) => {}", options: ["always"], parserOptions: { ecmaVersion: 6 }, parser: parser("flow-destructuring-1") },
{ code: "([a, b]: Array< any >) => {}", options: ["never"], parserOptions: { ecmaVersion: 6 }, parser: parser("flow-destructuring-2") }
{ code: "([ a, b ]: Array<any>) => {}", options: ["always"], parser: parser("flow-destructuring-1"), parserOptions: { ecmaVersion: 6 } },
{ code: "([a, b]: Array< any >) => {}", options: ["never"], parser: parser("flow-destructuring-2"), parserOptions: { ecmaVersion: 6 } }
],

invalid: [
Expand Down Expand Up @@ -830,6 +830,7 @@ ruleTester.run("array-bracket-spacing", rule, {
code: "([ a, b ]: Array<any>) => {}",
output: "([a, b]: Array<any>) => {}",
options: ["never"],
parser: parser("flow-destructuring-1"),
parserOptions: {
ecmaVersion: 6
},
Expand All @@ -852,13 +853,13 @@ ruleTester.run("array-bracket-spacing", rule, {
line: 1,
column: 9
}
],
parser: parser("flow-destructuring-1")
]
},
{
code: "([a, b]: Array< any >) => {}",
output: "([ a, b ]: Array< any >) => {}",
options: ["always"],
parser: parser("flow-destructuring-2"),
parserOptions: {
ecmaVersion: 6
},
Expand All @@ -881,8 +882,7 @@ ruleTester.run("array-bracket-spacing", rule, {
line: 1,
column: 7
}
],
parser: parser("flow-destructuring-2")
]
}
]
});
16 changes: 8 additions & 8 deletions tests/lib/rules/comma-dangle.js
Expand Up @@ -1410,29 +1410,29 @@ let d = 0;export {d,};
code: "function foo({a}: {a: string,}) {}",
output: "function foo({a,}: {a: string,}) {}",
options: ["always"],
errors: [{ messageId: "missing" }],
parser: parser("object-pattern-1")
parser: parser("object-pattern-1"),
errors: [{ messageId: "missing" }]
},
{
code: "function foo({a,}: {a: string}) {}",
output: "function foo({a}: {a: string}) {}",
options: ["never"],
errors: [{ messageId: "unexpected" }],
parser: parser("object-pattern-2")
parser: parser("object-pattern-2"),
errors: [{ messageId: "unexpected" }]
},
{
code: "function foo(a): {b: boolean,} {}",
output: "function foo(a,): {b: boolean,} {}",
options: [{ functions: "always" }],
errors: [{ messageId: "missing" }],
parser: parser("return-type-1")
parser: parser("return-type-1"),
errors: [{ messageId: "missing" }]
},
{
code: "function foo(a,): {b: boolean} {}",
output: "function foo(a): {b: boolean} {}",
options: [{ functions: "never" }],
errors: [{ messageId: "unexpected" }],
parser: parser("return-type-2")
parser: parser("return-type-2"),
errors: [{ messageId: "unexpected" }]
}
]
});
28 changes: 14 additions & 14 deletions tests/lib/rules/indent.js
Expand Up @@ -8686,8 +8686,8 @@ ruleTester.run("indent", rule, {
}
}
`,
errors: expectedErrors([[3, 8, 4, "Identifier"], [6, 8, 4, "Keyword"]]),
parser: parser("unknown-nodes/namespace-invalid")
parser: parser("unknown-nodes/namespace-invalid"),
errors: expectedErrors([[3, 8, 4, "Identifier"], [6, 8, 4, "Keyword"]])
},
{
code: unIndent`
Expand Down Expand Up @@ -8718,8 +8718,8 @@ ruleTester.run("indent", rule, {
}
}
`,
errors: expectedErrors([[4, 12, 8, "Identifier"], [7, 12, 8, "Identifier"], [10, 8, 4, "Identifier"]]),
parser: parser("unknown-nodes/abstract-class-invalid")
parser: parser("unknown-nodes/abstract-class-invalid"),
errors: expectedErrors([[4, 12, 8, "Identifier"], [7, 12, 8, "Identifier"], [10, 8, 4, "Identifier"]])
},
{
code: unIndent`
Expand Down Expand Up @@ -8748,14 +8748,14 @@ ruleTester.run("indent", rule, {
}
}
`,
parser: parser("unknown-nodes/functions-with-abstract-class-invalid"),
errors: expectedErrors([
[4, 12, 8, "Keyword"],
[5, 16, 8, "Keyword"],
[6, 20, 8, "Identifier"],
[7, 16, 8, "Punctuator"],
[8, 12, 8, "Punctuator"]
]),
parser: parser("unknown-nodes/functions-with-abstract-class-invalid")
])
},
{
code: unIndent`
Expand Down Expand Up @@ -8788,11 +8788,11 @@ ruleTester.run("indent", rule, {
}
}
`,
parser: parser("unknown-nodes/namespace-with-functions-with-abstract-class-invalid"),
errors: expectedErrors([
[3, 8, 4, "Keyword"],
[7, 24, 20, "Identifier"]
]),
parser: parser("unknown-nodes/namespace-with-functions-with-abstract-class-invalid")
])
},

//----------------------------------------------------------------------
Expand Down Expand Up @@ -9369,8 +9369,8 @@ ruleTester.run("indent", rule, {
foo
}: bar) => baz
`,
errors: expectedErrors([3, 0, 4, "Punctuator"]),
parser: require.resolve("../../fixtures/parsers/babel-eslint7/object-pattern-with-annotation")
parser: require.resolve("../../fixtures/parsers/babel-eslint7/object-pattern-with-annotation"),
errors: expectedErrors([3, 0, 4, "Punctuator"])
},
{
code: unIndent`
Expand All @@ -9383,8 +9383,8 @@ ruleTester.run("indent", rule, {
foo
]: bar) => baz
`,
errors: expectedErrors([3, 0, 4, "Punctuator"]),
parser: require.resolve("../../fixtures/parsers/babel-eslint7/array-pattern-with-annotation")
parser: require.resolve("../../fixtures/parsers/babel-eslint7/array-pattern-with-annotation"),
errors: expectedErrors([3, 0, 4, "Punctuator"])
},
{
code: unIndent`
Expand All @@ -9397,8 +9397,8 @@ ruleTester.run("indent", rule, {
foo
}: {}) => baz
`,
errors: expectedErrors([3, 0, 4, "Punctuator"]),
parser: require.resolve("../../fixtures/parsers/babel-eslint7/object-pattern-with-object-annotation")
parser: require.resolve("../../fixtures/parsers/babel-eslint7/object-pattern-with-object-annotation"),
errors: expectedErrors([3, 0, 4, "Punctuator"])
},
{
code: unIndent`
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/rules/keyword-spacing.js
Expand Up @@ -3135,8 +3135,8 @@ ruleTester.run("keyword-spacing", rule, {
{
code: "class Foo { @desc({set a(value) {}, get a() {}, async c() {}}) async[foo]() {} }",
output: "class Foo { @desc({set a(value) {}, get a() {}, async c() {}}) async [foo]() {} }",
errors: expectedAfter("async"),
parser: parser("typescript-parsers/decorator-with-keywords-class-method")
parser: parser("typescript-parsers/decorator-with-keywords-class-method"),
errors: expectedAfter("async")
}
]
});
2 changes: 1 addition & 1 deletion tests/lib/rules/no-console.js
Expand Up @@ -58,6 +58,6 @@ ruleTester.run("no-console", rule, {
{ code: "console.warn(foo)", options: [{ allow: ["info", "log"] }], errors: [{ messageId: "unexpected", type: "MemberExpression" }] },

// In case that implicit global variable of 'console' exists
{ code: "console.log(foo)", errors: [{ messageId: "unexpected", type: "MemberExpression" }], env: { node: true } }
{ code: "console.log(foo)", env: { node: true }, errors: [{ messageId: "unexpected", type: "MemberExpression" }] }
]
});
16 changes: 8 additions & 8 deletions tests/lib/rules/no-eval.js
Expand Up @@ -72,17 +72,17 @@ ruleTester.run("no-eval", rule, {

// Indirect eval
{ code: "(0, eval)('foo')", errors: [{ messageId: "unexpected", type: "Identifier" }] },
{ code: "(0, window.eval)('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression" }], env: { browser: true } },
{ code: "(0, window['eval'])('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression" }], env: { browser: true } },
{ code: "(0, window.eval)('foo')", env: { browser: true }, errors: [{ messageId: "unexpected", type: "MemberExpression" }] },
{ code: "(0, window['eval'])('foo')", env: { browser: true }, errors: [{ messageId: "unexpected", type: "MemberExpression" }] },
{ code: "var EVAL = eval; EVAL('foo')", errors: [{ messageId: "unexpected", type: "Identifier" }] },
{ code: "var EVAL = this.eval; EVAL('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression" }] },
{ code: "(function(exe){ exe('foo') })(eval);", errors: [{ messageId: "unexpected", type: "Identifier" }] },
{ code: "window.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression" }], env: { browser: true } },
{ code: "window.window.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression" }], env: { browser: true } },
{ code: "window.window['eval']('foo')", errors: [{ messageId: "unexpected", type: "CallExpression" }], env: { browser: true } },
{ code: "global.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression" }], env: { node: true } },
{ code: "global.global.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression" }], env: { node: true } },
{ code: "global.global[`eval`]('foo')", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "CallExpression" }], env: { node: true } },
{ code: "window.eval('foo')", env: { browser: true }, errors: [{ messageId: "unexpected", type: "CallExpression" }] },
{ code: "window.window.eval('foo')", env: { browser: true }, errors: [{ messageId: "unexpected", type: "CallExpression" }] },
{ code: "window.window['eval']('foo')", env: { browser: true }, errors: [{ messageId: "unexpected", type: "CallExpression" }] },
{ code: "global.eval('foo')", env: { node: true }, errors: [{ messageId: "unexpected", type: "CallExpression" }] },
{ code: "global.global.eval('foo')", env: { node: true }, errors: [{ messageId: "unexpected", type: "CallExpression" }] },
{ code: "global.global[`eval`]('foo')", parserOptions: { ecmaVersion: 6 }, env: { node: true }, errors: [{ messageId: "unexpected", type: "CallExpression" }] },
{ code: "this.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression" }] },
{ code: "function foo() { this.eval('foo') }", errors: [{ messageId: "unexpected", type: "CallExpression" }] }
]
Expand Down
10 changes: 5 additions & 5 deletions tests/lib/rules/no-global-assign.js
Expand Up @@ -42,18 +42,18 @@ ruleTester.run("no-global-assign", rule, {
},
{
code: "top = 0;",
errors: [{ message: "Read-only global 'top' should not be modified.", type: "Identifier" }],
env: { browser: true }
env: { browser: true },
errors: [{ message: "Read-only global 'top' should not be modified.", type: "Identifier" }]
},
{
code: "require = 0;",
errors: [{ message: "Read-only global 'require' should not be modified.", type: "Identifier" }],
env: { node: true }
env: { node: true },
errors: [{ message: "Read-only global 'require' should not be modified.", type: "Identifier" }]
},

// Notifications of readonly are moved from no-undef: https://github.com/eslint/eslint/issues/4504
{ code: "/*global b:false*/ function f() { b = 1; }", errors: [{ message: "Read-only global 'b' should not be modified.", type: "Identifier" }] },
{ code: "function f() { b = 1; }", errors: [{ message: "Read-only global 'b' should not be modified.", type: "Identifier" }], globals: { b: false } },
{ code: "function f() { b = 1; }", globals: { b: false }, errors: [{ message: "Read-only global 'b' should not be modified.", type: "Identifier" }] },
{ code: "/*global b:false*/ function f() { b++; }", errors: [{ message: "Read-only global 'b' should not be modified.", type: "Identifier" }] },
{ code: "/*global b*/ b = 1;", errors: [{ message: "Read-only global 'b' should not be modified.", type: "Identifier" }] },
{ code: "Array = 1;", errors: [{ message: "Read-only global 'Array' should not be modified.", type: "Identifier" }] }
Expand Down
8 changes: 4 additions & 4 deletions tests/lib/rules/no-magic-numbers.js
Expand Up @@ -83,8 +83,8 @@ ruleTester.run("no-magic-numbers", rule, {
options: [{
enforceConst: true
}],
errors: [{ messageId: "useConst" }],
env: { es6: true }
env: { es6: true },
errors: [{ messageId: "useConst" }]
},
{
code: "var foo = 0 + 1;",
Expand Down Expand Up @@ -189,15 +189,15 @@ ruleTester.run("no-magic-numbers", rule, {
"function invokeInTen(func) {\n" +
"setTimeout(func, 10);\n" +
"}\n",
env: { es6: true },
errors: [
{ messageId: "noMagic", data: { raw: "10" }, line: 7 },
{ messageId: "noMagic", data: { raw: "10" }, line: 7 },
{ messageId: "noMagic", data: { raw: "24" }, line: 11 },
{ messageId: "noMagic", data: { raw: "1000" }, line: 15 },
{ messageId: "noMagic", data: { raw: "0" }, line: 19 },
{ messageId: "noMagic", data: { raw: "10" }, line: 22 }
],
env: { es6: true }
]
},
{
code: "var data = ['foo', 'bar', 'baz']; var third = data[3];",
Expand Down
8 changes: 4 additions & 4 deletions tests/lib/rules/no-mixed-spaces-and-tabs.js
Expand Up @@ -136,27 +136,27 @@ ruleTester.run("no-mixed-spaces-and-tabs", rule, {
{
code: "`foo${\n \t 5 }bar`;",
options: ["smart-tabs"],
env: { es6: true },
errors: [
{
message: "Mixed spaces and tabs.",
type: "Program",
line: 2,
column: 2
}
],
env: { es6: true }
]
},
{
code: "`foo${\n\t 5 }bar`;",
env: { es6: true },
errors: [
{
message: "Mixed spaces and tabs.",
type: "Program",
line: 2,
column: 2
}
],
env: { es6: true }
]
}
]
});
10 changes: 5 additions & 5 deletions tests/lib/rules/no-native-reassign.js
Expand Up @@ -43,18 +43,18 @@ ruleTester.run("no-native-reassign", rule, {
},
{
code: "top = 0;",
errors: [{ message: "Read-only global 'top' should not be modified.", type: "Identifier" }],
env: { browser: true }
env: { browser: true },
errors: [{ message: "Read-only global 'top' should not be modified.", type: "Identifier" }]
},
{
code: "require = 0;",
errors: [{ message: "Read-only global 'require' should not be modified.", type: "Identifier" }],
env: { node: true }
env: { node: true },
errors: [{ message: "Read-only global 'require' should not be modified.", type: "Identifier" }]
},

// Notifications of readonly are moved from no-undef: https://github.com/eslint/eslint/issues/4504
{ code: "/*global b:false*/ function f() { b = 1; }", errors: [{ message: "Read-only global 'b' should not be modified.", type: "Identifier" }] },
{ code: "function f() { b = 1; }", errors: [{ message: "Read-only global 'b' should not be modified.", type: "Identifier" }], globals: { b: false } },
{ code: "function f() { b = 1; }", globals: { b: false }, errors: [{ message: "Read-only global 'b' should not be modified.", type: "Identifier" }] },
{ code: "/*global b:false*/ function f() { b++; }", errors: [{ message: "Read-only global 'b' should not be modified.", type: "Identifier" }] },
{ code: "/*global b*/ b = 1;", errors: [{ message: "Read-only global 'b' should not be modified.", type: "Identifier" }] },
{ code: "Array = 1;", errors: [{ message: "Read-only global 'Array' should not be modified.", type: "Identifier" }] }
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/rules/no-redeclare.js
Expand Up @@ -62,8 +62,8 @@ ruleTester.run("no-redeclare", rule, {
{
code: "var top = 0;",
options: [{ builtinGlobals: true }],
errors: [{ message: "'top' is already defined.", type: "Identifier" }],
env: { browser: true }
env: { browser: true },
errors: [{ message: "'top' is already defined.", type: "Identifier" }]
},
{
code: "var a; var {a = 0, b: Object = 0} = {};",
Expand Down

0 comments on commit 1f715a2

Please sign in to comment.