Skip to content

Commit

Permalink
chore: move rule tests parserOptions to ruleTester (#157)
Browse files Browse the repository at this point in the history
it can help migrating to the eslint v9 RuleTester
  • Loading branch information
aladdin-add authored Jan 3, 2024
1 parent bc6c538 commit ad8f4f4
Show file tree
Hide file tree
Showing 33 changed files with 352 additions and 708 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
"@types/eslint": "^8.44.6",
"@typescript-eslint/parser": "^5.60.0",
"esbuild": "^0.18.7",
"eslint": "^8.53.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^8.8.0",
"eslint-doc-generator": "^1.6.1",
"eslint-plugin-eslint-plugin": "^5.1.0",
"eslint-plugin-eslint-plugin": "^5.2.1",
"eslint-plugin-n": "file:.",
"fast-glob": "^3.2.12",
"husky": "^8.0.3",
Expand Down
14 changes: 2 additions & 12 deletions tests/lib/rules/callback-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

const RuleTester = require("eslint").RuleTester
const rule = require("../../../lib/rules/callback-return")
const ruleTester = new RuleTester({ env: { node: true, es6: true } })

new RuleTester().run("callback-return", rule, {
ruleTester.run("callback-return", rule, {
valid: [
// callbacks inside of functions should return
"function a(err) { if (err) return callback (err); }",
Expand Down Expand Up @@ -40,25 +41,20 @@ new RuleTester().run("callback-return", rule, {
// arrow functions
{
code: "var x = err => { if (err) { callback(); return; } }",
parserOptions: { ecmaVersion: 6 },
},
{
code: "var x = err => callback(err)",
parserOptions: { ecmaVersion: 6 },
},
{
code: "var x = err => { setTimeout( () => { callback(); }); }",
parserOptions: { ecmaVersion: 6 },
},

// classes
{
code: "class x { horse() { callback(); } } ",
parserOptions: { ecmaVersion: 6 },
},
{
code: "class x { horse() { if (err) { return callback(); } callback(); } } ",
parserOptions: { ecmaVersion: 6 },
},

// options (only warns with the correct callback name)
Expand Down Expand Up @@ -188,7 +184,6 @@ new RuleTester().run("callback-return", rule, {
},
{
code: "var x = (err) => { if (err) { callback (err); } }",
parserOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "missingReturn",
Expand All @@ -200,7 +195,6 @@ new RuleTester().run("callback-return", rule, {
},
{
code: "var x = { x(err) { if (err) { callback (err); } } }",
parserOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "missingReturn",
Expand All @@ -223,7 +217,6 @@ new RuleTester().run("callback-return", rule, {
},
{
code: "var x = { x(err) { if (err) { callback && callback (err); } } }",
parserOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "missingReturn",
Expand Down Expand Up @@ -268,7 +261,6 @@ new RuleTester().run("callback-return", rule, {
},
{
code: "var a = (err) => { callback (err); callback(); }",
parserOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "missingReturn",
Expand Down Expand Up @@ -302,7 +294,6 @@ new RuleTester().run("callback-return", rule, {
},
{
code: "class x { horse() { if (err) { callback(); } callback(); } } ",
parserOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "missingReturn",
Expand Down Expand Up @@ -344,7 +335,6 @@ new RuleTester().run("callback-return", rule, {
},
{
code: "() => { if (x) { callback(); } }",
parserOptions: { ecmaVersion: 6 },
errors: [
{
messageId: "missingReturn",
Expand Down
Loading

0 comments on commit ad8f4f4

Please sign in to comment.