Skip to content

Commit

Permalink
refactor: migrate off deprecated function-style rules in all tests
Browse files Browse the repository at this point in the history
Preparing for RFC-85.
  • Loading branch information
bmish committed Dec 5, 2022
1 parent e6cb05a commit 379bad9
Show file tree
Hide file tree
Showing 13 changed files with 2,635 additions and 1,958 deletions.
20 changes: 11 additions & 9 deletions lib/rule-tester/flat-rule-tester.js
Expand Up @@ -619,15 +619,17 @@ class FlatRuleTester {
plugins: {
"rule-tester": {
rules: {
"validate-ast"() {
return {
Program(node) {
beforeAST = cloneDeeplyExcludesParent(node);
},
"Program:exit"(node) {
afterAST = node;
}
};
"validate-ast": {
create() {
return {
Program(node) {
beforeAST = cloneDeeplyExcludesParent(node);
},
"Program:exit"(node) {
afterAST = node;
}
};
}
}
}
}
Expand Down
18 changes: 11 additions & 7 deletions lib/rule-tester/rule-tester.js
Expand Up @@ -632,14 +632,18 @@ class RuleTester {
* The goal is to check whether or not AST was modified when
* running the rule under test.
*/
linter.defineRule("rule-tester/validate-ast", () => ({
Program(node) {
beforeAST = cloneDeeplyExcludesParent(node);
},
"Program:exit"(node) {
afterAST = node;
linter.defineRule("rule-tester/validate-ast", {
create() {
return {
Program(node) {
beforeAST = cloneDeeplyExcludesParent(node);
},
"Program:exit"(node) {
afterAST = node;
}
};
}
}));
});

if (typeof config.parser === "string") {
assert(path.isAbsolute(config.parser), "Parsers provided as strings to RuleTester must be absolute paths");
Expand Down
24 changes: 13 additions & 11 deletions tests/fixtures/rules/custom-rule.js
@@ -1,15 +1,17 @@
module.exports = function(context) {
module.exports = {
meta: {
schema: []
},
create(context) {

"use strict";
"use strict";

return {
"Identifier": function(node) {
if (node.name === "foo") {
context.report(node, "Identifier cannot be named 'foo'.");
return {
"Identifier": function(node) {
if (node.name === "foo") {
context.report(node, "Identifier cannot be named 'foo'.");
}
}
}
};

};
}
};

module.exports.schema = [];
42 changes: 23 additions & 19 deletions tests/lib/config/flat-config-array.js
Expand Up @@ -25,15 +25,17 @@ const baseConfig = {
"@": {
rules: {
foo: {
schema: {
type: "array",
items: [
{
enum: ["always", "never"]
}
],
minItems: 0,
maxItems: 1
meta: {
schema: {
type: "array",
items: [
{
enum: ["always", "never"]
}
],
minItems: 0,
maxItems: 1
}
}

},
Expand All @@ -48,13 +50,15 @@ const baseConfig = {
boom() {},

foo2: {
schema: {
type: "array",
items: {
type: "string"
},
uniqueItems: true,
minItems: 1
meta: {
schema: {
type: "array",
items: {
type: "string"
},
uniqueItems: true,
minItems: 1
}
}
}
}
Expand Down Expand Up @@ -1505,20 +1509,20 @@ describe("FlatConfigArray", () => {
{
rules: {
foo: 1,
bar: "error"
foo2: "error"
}
},
{
rules: {
foo: ["error", "never"],
bar: ["warn", "foo"]
foo2: ["warn", "foo"]
}
}
], {
plugins: baseConfig.plugins,
rules: {
foo: [2, "never"],
bar: [1, "foo"]
foo2: [1, "foo"]
}
}));

Expand Down

0 comments on commit 379bad9

Please sign in to comment.