Skip to content

Commit

Permalink
chore: Convert rule tests to FlatRuleTester (#17819)
Browse files Browse the repository at this point in the history
* chore: Convert rule tests to FlatRuleTester

* Fix ast-utils

* Fix no-useless-return

* Fix test case ordering
  • Loading branch information
nzakas authored Dec 12, 2023
1 parent 9007719 commit 70a686b
Show file tree
Hide file tree
Showing 293 changed files with 8,403 additions and 7,855 deletions.
13 changes: 12 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,18 @@ module.exports = [
files: ["tests/lib/rules/*", "tests/tools/internal-rules/*"],
...merge({}, eslintPluginTestsRecommendedConfig, {
rules: {
"eslint-plugin/test-case-property-ordering": "error",
"eslint-plugin/test-case-property-ordering": [
"error",
[
"name",
"filename",
"code",
"output",
"options",
"languageOptions",
"errors"
]
],
"eslint-plugin/test-case-shorthand-strings": "error"
}
})
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-invalid-this.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ module.exports = {

if (codePath.origin === "program") {
const scope = sourceCode.getScope(node);
const features = context.parserOptions.ecmaFeatures || {};
const features = context.languageOptions.parserOptions.ecmaFeatures || {};

// `this` at the top level of scripts always refers to the global object
stack.push({
Expand Down
428 changes: 214 additions & 214 deletions tests/lib/rules/accessor-pairs.js

Large diffs are not rendered by default.

100 changes: 50 additions & 50 deletions tests/lib/rules/array-bracket-newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//------------------------------------------------------------------------------

const rule = require("../../../lib/rules/array-bracket-newline");
const { RuleTester } = require("../../../lib/rule-tester");
const RuleTester = require("../../../lib/rule-tester/flat-rule-tester");


//------------------------------------------------------------------------------
Expand Down Expand Up @@ -281,160 +281,160 @@ ruleTester.run("array-bracket-newline", rule, {
* ArrayPattern
* default { multiline: true }
*/
{ code: "var [] = foo", parserOptions: { ecmaVersion: 6 } },
{ code: "var [a] = foo;", parserOptions: { ecmaVersion: 6 } },
{ code: "var [] = foo", languageOptions: { ecmaVersion: 6 } },
{ code: "var [a] = foo;", languageOptions: { ecmaVersion: 6 } },
{
code: "var /* any comment */[a] = foo;",
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{
code: "var /* any comment */\n[a] = foo;",
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{ code: "var [a, b] = foo;", parserOptions: { ecmaVersion: 6 } },
{ code: "var [a, b] = foo;", languageOptions: { ecmaVersion: 6 } },
{
code: "var [ // any comment\na, b\n] = foo;",
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{
code: "var [\n// any comment\na, b\n] = foo;",
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{
code: "var [\na, b\n// any comment\n] = foo;",
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{ code: "var [\na,\nb\n] = foo;", parserOptions: { ecmaVersion: 6 } },
{ code: "var [\na,\nb\n] = foo;", languageOptions: { ecmaVersion: 6 } },

// "always"
{
code: "var [\n] = foo;",
options: ["always"],
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{
code: "var [\na\n] = foo;",
options: ["always"],
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{
code: "var [\n// any\na\n] = foo;",
options: ["always"],
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{
code: "var [\n/* any */\na\n] = foo;",
options: ["always"],
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{
code: "var [\na, b\n] = foo;",
options: ["always"],
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{
code: "var [\na, b // any comment\n] = foo;",
options: ["always"],
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{
code: "var [\na, b /* any comment */\n] = foo;",
options: ["always"],
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{
code: "var [\na,\nb\n] = foo;",
options: ["always"],
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},

// "consistent"
{
code: "var [] = foo",
options: ["consistent"],
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{
code: "var [\n] = foo",
options: ["consistent"],
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{
code: "var [a] = foo",
options: ["consistent"],
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{
code: "var [\na\n] = foo",
options: ["consistent"],
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{
code: "var [//\na\n] = foo",
options: ["consistent"],
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{
code: "var [/**/\na\n] = foo",
options: ["consistent"],
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{
code: "var [/*\n*/a\n] = foo",
options: ["consistent"],
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{
code: "var [//\n] = foo",
options: ["consistent"],
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},

// { multiline: true }
{
code: "var [] = foo;",
options: [{ multiline: true }],
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{
code: "var [a] = foo;",
options: [{ multiline: true }],
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{
code: "var /* any comment */[a] = foo;",
options: [{ multiline: true }],
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{
code: "var /* any comment */\n[a] = foo;",
options: [{ multiline: true }],
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{
code: "var [a, b] = foo;",
options: [{ multiline: true }],
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{
code: "var [ // any comment\na, b\n] = foo;",
options: [{ multiline: true }],
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{
code: "var [\n// any comment\na, b\n] = foo;",
options: [{ multiline: true }],
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{
code: "var [\na, b\n// any comment\n] = foo;",
options: [{ multiline: true }],
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
},
{
code: "var [\na,\nb\n] = foo;",
options: [{ multiline: true }],
parserOptions: { ecmaVersion: 6 }
languageOptions: { ecmaVersion: 6 }
}
],

Expand Down Expand Up @@ -1736,7 +1736,7 @@ ruleTester.run("array-bracket-newline", rule, {
code: "var [] = foo;",
output: "var [\n] = foo;",
options: ["always"],
parserOptions: { ecmaVersion: 6 },
languageOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "missingOpeningLinebreak",
Expand All @@ -1756,7 +1756,7 @@ ruleTester.run("array-bracket-newline", rule, {
code: "var [a] = foo;",
output: "var [\na\n] = foo;",
options: ["always"],
parserOptions: { ecmaVersion: 6 },
languageOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "missingOpeningLinebreak",
Expand All @@ -1776,7 +1776,7 @@ ruleTester.run("array-bracket-newline", rule, {
code: "var [ // any comment\na] = foo;",
output: "var [ // any comment\na\n] = foo;",
options: ["always"],
parserOptions: { ecmaVersion: 6 },
languageOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "missingClosingLinebreak",
Expand All @@ -1790,7 +1790,7 @@ ruleTester.run("array-bracket-newline", rule, {
code: "var [ /* any comment */\na] = foo;",
output: "var [ /* any comment */\na\n] = foo;",
options: ["always"],
parserOptions: { ecmaVersion: 6 },
languageOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "missingClosingLinebreak",
Expand All @@ -1804,7 +1804,7 @@ ruleTester.run("array-bracket-newline", rule, {
code: "var [a, b] = foo;",
output: "var [\na, b\n] = foo;",
options: ["always"],
parserOptions: { ecmaVersion: 6 },
languageOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "missingOpeningLinebreak",
Expand All @@ -1824,7 +1824,7 @@ ruleTester.run("array-bracket-newline", rule, {
code: "var [a, b // any comment\n] = foo;",
output: "var [\na, b // any comment\n] = foo;",
options: ["always"],
parserOptions: { ecmaVersion: 6 },
languageOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "missingOpeningLinebreak",
Expand All @@ -1838,7 +1838,7 @@ ruleTester.run("array-bracket-newline", rule, {
code: "var [a, b /* any comment */] = foo;",
output: "var [\na, b /* any comment */\n] = foo;",
options: ["always"],
parserOptions: { ecmaVersion: 6 },
languageOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "missingOpeningLinebreak",
Expand All @@ -1858,7 +1858,7 @@ ruleTester.run("array-bracket-newline", rule, {
code: "var [a,\nb] = foo;",
output: "var [\na,\nb\n] = foo;",
options: ["always"],
parserOptions: { ecmaVersion: 6 },
languageOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "missingOpeningLinebreak",
Expand All @@ -1880,7 +1880,7 @@ ruleTester.run("array-bracket-newline", rule, {
code: "var [\na] = foo",
output: "var [\na\n] = foo",
options: ["consistent"],
parserOptions: { ecmaVersion: 6 },
languageOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "missingClosingLinebreak",
Expand All @@ -1896,7 +1896,7 @@ ruleTester.run("array-bracket-newline", rule, {
code: "var [a\n] = foo",
output: "var [a] = foo",
options: ["consistent"],
parserOptions: { ecmaVersion: 6 },
languageOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "unexpectedClosingLinebreak",
Expand All @@ -1912,7 +1912,7 @@ ruleTester.run("array-bracket-newline", rule, {
code: "var [//\na] = foo",
output: "var [//\na\n] = foo",
options: ["consistent"],
parserOptions: { ecmaVersion: 6 },
languageOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "missingClosingLinebreak",
Expand All @@ -1930,7 +1930,7 @@ ruleTester.run("array-bracket-newline", rule, {
code: "var [\n] = foo;",
output: "var [] = foo;",
options: [{ minItems: 2 }],
parserOptions: { ecmaVersion: 6 },
languageOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "unexpectedOpeningLinebreak",
Expand All @@ -1950,7 +1950,7 @@ ruleTester.run("array-bracket-newline", rule, {
code: "var [\na\n] = foo;",
output: "var [a] = foo;",
options: [{ minItems: 2 }],
parserOptions: { ecmaVersion: 6 },
languageOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "unexpectedOpeningLinebreak",
Expand All @@ -1970,7 +1970,7 @@ ruleTester.run("array-bracket-newline", rule, {
code: "var [a, b] = foo;",
output: "var [\na, b\n] = foo;",
options: [{ minItems: 2 }],
parserOptions: { ecmaVersion: 6 },
languageOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "missingOpeningLinebreak",
Expand All @@ -1990,7 +1990,7 @@ ruleTester.run("array-bracket-newline", rule, {
code: "var [a,\nb] = foo;",
output: "var [\na,\nb\n] = foo;",
options: [{ minItems: 2 }],
parserOptions: { ecmaVersion: 6 },
languageOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "missingOpeningLinebreak",
Expand Down
Loading

0 comments on commit 70a686b

Please sign in to comment.