Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Convert rule tests to FlatRuleTester #17819

Merged
merged 4 commits into from Dec 12, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion eslint.config.js
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
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 || {};
mdjermanovic marked this conversation as resolved.
Show resolved Hide resolved

// `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
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