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

refactor: migrate off deprecated function-style rules in all tests #16618

Merged
merged 2 commits into from Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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