Skip to content

Commit 2edc0f0

Browse files
authored
refactor: Use eslint-config-eslint for linting this repo (#43)
1 parent 16ee1fa commit 2edc0f0

23 files changed

+211
-191
lines changed

eslint.config.js

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,45 @@
1-
import js from "@eslint/js";
1+
import eslintConfigESLint from "eslint-config-eslint";
2+
3+
const eslintPluginJSDoc = eslintConfigESLint.find(
4+
config => config.plugins?.jsdoc,
5+
).plugins.jsdoc;
26

37
export default [
4-
js.configs.recommended,
58
{
6-
ignores: ["**/tests/fixtures/**/*.*"],
9+
ignores: ["**/tests/fixtures/", "**/dist/"],
10+
},
11+
12+
...eslintConfigESLint,
13+
14+
{
15+
rules: {
16+
// disable rules we don't want to use from eslint-config-eslint
17+
"no-undefined": "off",
18+
19+
// TODO: re-enable eslint-plugin-jsdoc rules
20+
...Object.fromEntries(
21+
Object.keys(eslintPluginJSDoc.rules).map(name => [
22+
`jsdoc/${name}`,
23+
"off",
24+
]),
25+
),
26+
},
27+
},
28+
29+
// Tools and CLI
30+
{
31+
files: [
32+
"scripts/**",
33+
"packages/migrate-config/src/migrate-config-cli.js",
34+
],
35+
rules: {
36+
"no-console": "off",
37+
"n/no-process-exit": "off",
38+
},
739
},
40+
841
{
9-
files: ["**/*.test.js"],
42+
files: ["**/tests/**"],
1043
languageOptions: {
1144
globals: {
1245
describe: "readonly",

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@
2626
"!(*.js)": "prettier --write --ignore-unknown"
2727
},
2828
"devDependencies": {
29-
"@eslint/js": "^9.0.0",
30-
"eslint": "^9.0.0",
31-
"eslint-config-eslint": "^10.0.0",
29+
"eslint": "^9.4.0",
30+
"eslint-config-eslint": "^11.0.0",
3231
"lint-staged": "^15.2.0",
3332
"prettier": "^3.1.1",
3433
"yorkie": "^2.0.0"

packages/compat/src/fixup-rules.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/**
2-
* @filedescription Object Schema
2+
* @fileoverview Object Schema
33
*/
44

5-
"use strict";
6-
75
//-----------------------------------------------------------------------------
86
// Imports
97
//-----------------------------------------------------------------------------
@@ -102,7 +100,7 @@ export function fixupRule(ruleDefinition) {
102100
? ruleDefinition
103101
: ruleDefinition.create.bind(ruleDefinition);
104102

105-
const ruleCreate = context => {
103+
function ruleCreate(context) {
106104
// if getScope is already there then no need to create old methods
107105
if ("getScope" in context) {
108106
return originalCreate(context);
@@ -161,6 +159,7 @@ export function fixupRule(ruleDefinition) {
161159
* and the third argument for onCodePathSegmentLoop.
162160
*/
163161
if (methodName.startsWith("on")) {
162+
// eslint-disable-next-line no-loop-func -- intentionally updating shared `currentNode` variable
164163
visitor[methodName] = (...args) => {
165164
currentNode =
166165
args[methodName === "onCodePathSegmentLoop" ? 2 : 1];
@@ -171,6 +170,7 @@ export function fixupRule(ruleDefinition) {
171170
continue;
172171
}
173172

173+
// eslint-disable-next-line no-loop-func -- intentionally updating shared `currentNode` variable
174174
visitor[methodName] = (...args) => {
175175
currentNode = args[0];
176176

@@ -179,7 +179,7 @@ export function fixupRule(ruleDefinition) {
179179
}
180180

181181
return visitor;
182-
};
182+
}
183183

184184
const newRuleDefinition = {
185185
...(isLegacyRule ? undefined : ruleDefinition),
@@ -239,20 +239,20 @@ export function fixupPluginRules(plugin) {
239239
export function fixupConfigRules(config) {
240240
const configs = Array.isArray(config) ? config : [config];
241241

242-
return configs.map(config => {
243-
if (!config.plugins) {
244-
return config;
242+
return configs.map(configItem => {
243+
if (!configItem.plugins) {
244+
return configItem;
245245
}
246246

247247
const newPlugins = Object.fromEntries(
248-
Object.entries(config.plugins).map(([pluginName, plugin]) => [
248+
Object.entries(configItem.plugins).map(([pluginName, plugin]) => [
249249
pluginName,
250250
fixupPluginRules(plugin),
251251
]),
252252
);
253253

254254
return {
255-
...config,
255+
...configItem,
256256
plugins: newPlugins,
257257
};
258258
});

packages/compat/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @filedescription Object Schema Package
2+
* @fileoverview Object Schema Package
33
*/
44

55
export * from "./fixup-rules.js";

packages/compat/tests/fixup-rules.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/**
2-
* @filedescription Fixup tests
2+
* @fileoverview Fixup tests
33
*/
4-
/* global it, describe */
54

65
//-----------------------------------------------------------------------------
76
// Imports

packages/compat/tests/rules/prefer-rest-params.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
* @author Toru Nagashima
44
*/
55

6-
"use strict";
7-
86
//------------------------------------------------------------------------------
97
// Requirements
108
//------------------------------------------------------------------------------

packages/compat/tests/rules/require-atomic-updates.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* @fileoverview disallow assignments that can lead to race conditions due to usage of `await` or `yield`
33
* @author Teddy Katz
44
*/
5-
"use strict";
65

76
//------------------------------------------------------------------------------
87
// Requirements

packages/config-array/src/config-array.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ function pathMatches(filePath, basePath, config) {
425425
const relativeFilePath = path.relative(basePath, filePath);
426426

427427
// match both strings and functions
428-
const match = pattern => {
428+
function match(pattern) {
429429
if (isString(pattern)) {
430430
return doMatch(relativeFilePath, pattern);
431431
}
@@ -435,7 +435,7 @@ function pathMatches(filePath, basePath, config) {
435435
}
436436

437437
throw new TypeError(`Unexpected matcher type ${pattern}.`);
438-
};
438+
}
439439

440440
// check for all matches to config.files
441441
let filePathMatchesPattern = config.files.some(pattern => {
@@ -756,6 +756,8 @@ export class ConfigArray extends Array {
756756
return this;
757757
}
758758

759+
/* eslint-disable class-methods-use-this -- Desired as instance methods */
760+
759761
/**
760762
* Finalizes the state of a config before being cached and returned by
761763
* `getConfig()`. Does nothing by default but is provided to be
@@ -779,6 +781,8 @@ export class ConfigArray extends Array {
779781
return config;
780782
}
781783

784+
/* eslint-enable class-methods-use-this -- Desired as instance methods */
785+
782786
/**
783787
* Determines if a given file path explicitly matches a `files` entry
784788
* and also doesn't match an `ignores` entry. Configs that don't have
@@ -793,9 +797,9 @@ export class ConfigArray extends Array {
793797
const cache = dataCache.get(this);
794798

795799
// first check the cache to avoid duplicate work
796-
let result = cache.explicitMatches.get(filePath);
800+
const result = cache.explicitMatches.get(filePath);
797801

798-
if (typeof result == "boolean") {
802+
if (typeof result === "boolean") {
799803
return result;
800804
}
801805

@@ -880,7 +884,7 @@ export class ConfigArray extends Array {
880884

881885
const matchingConfigIndices = [];
882886
let matchFound = false;
883-
const universalPattern = /\/\*{1,2}$/;
887+
const universalPattern = /\/\*{1,2}$/u;
884888

885889
this.forEach((config, index) => {
886890
if (!config.files) {
@@ -959,7 +963,6 @@ export class ConfigArray extends Array {
959963
debug(`Matching config found for ${filePath}`);
960964
matchingConfigIndices.push(index);
961965
matchFound = true;
962-
return;
963966
}
964967
});
965968

@@ -985,6 +988,7 @@ export class ConfigArray extends Array {
985988

986989
// otherwise construct the config
987990

991+
// eslint-disable-next-line array-callback-return, consistent-return -- rethrowConfigError always throws an error
988992
let finalConfig = matchingConfigIndices.reduce((result, index) => {
989993
try {
990994
return this[ConfigArraySymbol.schema].merge(
@@ -1065,7 +1069,7 @@ export class ConfigArray extends Array {
10651069

10661070
const relativeDirectoryPath = path
10671071
.relative(this.basePath, directoryPath)
1068-
.replace(/\\/g, "/");
1072+
.replace(/\\/gu, "/");
10691073

10701074
if (relativeDirectoryPath.startsWith("..")) {
10711075
return true;
@@ -1080,7 +1084,7 @@ export class ConfigArray extends Array {
10801084

10811085
const directoryParts = relativeDirectoryPath.split("/");
10821086
let relativeDirectoryToCheck = "";
1083-
let result = false;
1087+
let result;
10841088

10851089
/*
10861090
* In order to get the correct gitignore-style ignores, where an
@@ -1092,7 +1096,7 @@ export class ConfigArray extends Array {
10921096
* have to recalculate everything for every call.
10931097
*/
10941098
do {
1095-
relativeDirectoryToCheck += directoryParts.shift() + "/";
1099+
relativeDirectoryToCheck += `${directoryParts.shift()}/`;
10961100

10971101
result = shouldIgnorePath(
10981102
this.ignores,

0 commit comments

Comments
 (0)