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
…16618)

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

Preparing for RFC-85.

* chore: enable object-shorthand rule always avoidExplicitReturnArrows
  • Loading branch information
bmish committed Dec 8, 2022
1 parent 9b8bb72 commit 90c9219
Show file tree
Hide file tree
Showing 21 changed files with 2,645 additions and 1,969 deletions.
2 changes: 1 addition & 1 deletion docs/.eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ module.exports = function(eleventyConfig) {
* URLs with a file extension, like main.css, main.js, sitemap.xml, etc. should not be rewritten
*/
eleventyConfig.setBrowserSyncConfig({
middleware: (req, res, next) => {
middleware(req, res, next) {
if (!/(?:\.[a-zA-Z][^/]*|\/)$/u.test(req.url)) {
req.url += ".html";
}
Expand Down
20 changes: 11 additions & 9 deletions lib/rule-tester/flat-rule-tester.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion lib/rules/comma-dangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ module.exports = {
"always-multiline": forceTrailingCommaIfMultiline,
"only-multiline": allowTrailingCommaIfMultiline,
never: forbidTrailingComma,
ignore: () => {}
ignore() {}
};

return {
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/multiline-ternary.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module.exports = {
end: lastTokenOfTest.loc.end
},
messageId: "unexpectedTestCons",
fix: fixer => {
fix(fixer) {
if (hasComments) {
return null;
}
Expand Down Expand Up @@ -101,7 +101,7 @@ module.exports = {
end: lastTokenOfConsequent.loc.end
},
messageId: "unexpectedConsAlt",
fix: fixer => {
fix(fixer) {
if (hasComments) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-else-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ module.exports = {
context.report({
node,
messageId: "unexpected",
fix: fixer => {
fix(fixer) {

if (!isSafeFromNameCollisions(node, currentScope)) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-unneeded-ternary.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ module.exports = {
context.report({
node,
messageId: "unnecessaryConditionalAssignment",
fix: fixer => {
fix(fixer) {
const shouldParenthesizeAlternate =
(
astUtils.getPrecedence(node.alternate) < OR_PRECEDENCE ||
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-eslint/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ rules:
object-curly-newline: ["error", { "consistent": true, "multiline": true }]
object-curly-spacing: ["error", "always"]
object-property-newline: ["error", { "allowAllPropertiesOnSameLine": true }]
object-shorthand: "error"
object-shorthand: ["error", "always", { "avoidExplicitReturnArrows": true }]
one-var-declaration-per-line: "error"
operator-assignment: "error"
operator-linebreak: "error"
Expand Down
24 changes: 13 additions & 11 deletions tests/fixtures/rules/custom-rule.js
Original file line number Diff line number Diff line change
@@ -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 = [];
4 changes: 2 additions & 2 deletions tests/lib/cli-engine/cli-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -5018,7 +5018,7 @@ describe("CLIEngine", () => {

it("should call fs.writeFileSync() for each result with output", () => {
const fakeFS = {
writeFileSync: () => {}
writeFileSync() {}
},
localCLIEngine = proxyquire("../../../lib/cli-engine/cli-engine", {
fs: fakeFS
Expand Down Expand Up @@ -5048,7 +5048,7 @@ describe("CLIEngine", () => {

it("should call fs.writeFileSync() for each result with output and not at all for a result without output", () => {
const fakeFS = {
writeFileSync: () => {}
writeFileSync() {}
},
localCLIEngine = proxyquire("../../../lib/cli-engine/cli-engine", {
fs: fakeFS
Expand Down
42 changes: 23 additions & 19 deletions tests/lib/config/flat-config-array.js
Original file line number Diff line number Diff line change
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 90c9219

Please sign in to comment.