Skip to content

Commit

Permalink
refactor: Use eslint-config-eslint for linting this repo (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic authored Jun 7, 2024
1 parent 16ee1fa commit 2edc0f0
Show file tree
Hide file tree
Showing 23 changed files with 211 additions and 191 deletions.
41 changes: 37 additions & 4 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,45 @@
import js from "@eslint/js";
import eslintConfigESLint from "eslint-config-eslint";

const eslintPluginJSDoc = eslintConfigESLint.find(
config => config.plugins?.jsdoc,
).plugins.jsdoc;

export default [
js.configs.recommended,
{
ignores: ["**/tests/fixtures/**/*.*"],
ignores: ["**/tests/fixtures/", "**/dist/"],
},

...eslintConfigESLint,

{
rules: {
// disable rules we don't want to use from eslint-config-eslint
"no-undefined": "off",

// TODO: re-enable eslint-plugin-jsdoc rules
...Object.fromEntries(
Object.keys(eslintPluginJSDoc.rules).map(name => [
`jsdoc/${name}`,
"off",
]),
),
},
},

// Tools and CLI
{
files: [
"scripts/**",
"packages/migrate-config/src/migrate-config-cli.js",
],
rules: {
"no-console": "off",
"n/no-process-exit": "off",
},
},

{
files: ["**/*.test.js"],
files: ["**/tests/**"],
languageOptions: {
globals: {
describe: "readonly",
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
"!(*.js)": "prettier --write --ignore-unknown"
},
"devDependencies": {
"@eslint/js": "^9.0.0",
"eslint": "^9.0.0",
"eslint-config-eslint": "^10.0.0",
"eslint": "^9.4.0",
"eslint-config-eslint": "^11.0.0",
"lint-staged": "^15.2.0",
"prettier": "^3.1.1",
"yorkie": "^2.0.0"
Expand Down
20 changes: 10 additions & 10 deletions packages/compat/src/fixup-rules.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/**
* @filedescription Object Schema
* @fileoverview Object Schema
*/

"use strict";

//-----------------------------------------------------------------------------
// Imports
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -102,7 +100,7 @@ export function fixupRule(ruleDefinition) {
? ruleDefinition
: ruleDefinition.create.bind(ruleDefinition);

const ruleCreate = context => {
function ruleCreate(context) {
// if getScope is already there then no need to create old methods
if ("getScope" in context) {
return originalCreate(context);
Expand Down Expand Up @@ -161,6 +159,7 @@ export function fixupRule(ruleDefinition) {
* and the third argument for onCodePathSegmentLoop.
*/
if (methodName.startsWith("on")) {
// eslint-disable-next-line no-loop-func -- intentionally updating shared `currentNode` variable
visitor[methodName] = (...args) => {
currentNode =
args[methodName === "onCodePathSegmentLoop" ? 2 : 1];
Expand All @@ -171,6 +170,7 @@ export function fixupRule(ruleDefinition) {
continue;
}

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

Expand All @@ -179,7 +179,7 @@ export function fixupRule(ruleDefinition) {
}

return visitor;
};
}

const newRuleDefinition = {
...(isLegacyRule ? undefined : ruleDefinition),
Expand Down Expand Up @@ -239,20 +239,20 @@ export function fixupPluginRules(plugin) {
export function fixupConfigRules(config) {
const configs = Array.isArray(config) ? config : [config];

return configs.map(config => {
if (!config.plugins) {
return config;
return configs.map(configItem => {
if (!configItem.plugins) {
return configItem;
}

const newPlugins = Object.fromEntries(
Object.entries(config.plugins).map(([pluginName, plugin]) => [
Object.entries(configItem.plugins).map(([pluginName, plugin]) => [
pluginName,
fixupPluginRules(plugin),
]),
);

return {
...config,
...configItem,
plugins: newPlugins,
};
});
Expand Down
2 changes: 1 addition & 1 deletion packages/compat/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @filedescription Object Schema Package
* @fileoverview Object Schema Package
*/

export * from "./fixup-rules.js";
3 changes: 1 addition & 2 deletions packages/compat/tests/fixup-rules.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* @filedescription Fixup tests
* @fileoverview Fixup tests
*/
/* global it, describe */

//-----------------------------------------------------------------------------
// Imports
Expand Down
2 changes: 0 additions & 2 deletions packages/compat/tests/rules/prefer-rest-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* @author Toru Nagashima
*/

"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion packages/compat/tests/rules/require-atomic-updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @fileoverview disallow assignments that can lead to race conditions due to usage of `await` or `yield`
* @author Teddy Katz
*/
"use strict";

//------------------------------------------------------------------------------
// Requirements
Expand Down
22 changes: 13 additions & 9 deletions packages/config-array/src/config-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ function pathMatches(filePath, basePath, config) {
const relativeFilePath = path.relative(basePath, filePath);

// match both strings and functions
const match = pattern => {
function match(pattern) {
if (isString(pattern)) {
return doMatch(relativeFilePath, pattern);
}
Expand All @@ -435,7 +435,7 @@ function pathMatches(filePath, basePath, config) {
}

throw new TypeError(`Unexpected matcher type ${pattern}.`);
};
}

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

/* eslint-disable class-methods-use-this -- Desired as instance methods */

/**
* Finalizes the state of a config before being cached and returned by
* `getConfig()`. Does nothing by default but is provided to be
Expand All @@ -779,6 +781,8 @@ export class ConfigArray extends Array {
return config;
}

/* eslint-enable class-methods-use-this -- Desired as instance methods */

/**
* Determines if a given file path explicitly matches a `files` entry
* and also doesn't match an `ignores` entry. Configs that don't have
Expand All @@ -793,9 +797,9 @@ export class ConfigArray extends Array {
const cache = dataCache.get(this);

// first check the cache to avoid duplicate work
let result = cache.explicitMatches.get(filePath);
const result = cache.explicitMatches.get(filePath);

if (typeof result == "boolean") {
if (typeof result === "boolean") {
return result;
}

Expand Down Expand Up @@ -880,7 +884,7 @@ export class ConfigArray extends Array {

const matchingConfigIndices = [];
let matchFound = false;
const universalPattern = /\/\*{1,2}$/;
const universalPattern = /\/\*{1,2}$/u;

this.forEach((config, index) => {
if (!config.files) {
Expand Down Expand Up @@ -959,7 +963,6 @@ export class ConfigArray extends Array {
debug(`Matching config found for ${filePath}`);
matchingConfigIndices.push(index);
matchFound = true;
return;
}
});

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

// otherwise construct the config

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

const relativeDirectoryPath = path
.relative(this.basePath, directoryPath)
.replace(/\\/g, "/");
.replace(/\\/gu, "/");

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

const directoryParts = relativeDirectoryPath.split("/");
let relativeDirectoryToCheck = "";
let result = false;
let result;

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

result = shouldIgnorePath(
this.ignores,
Expand Down
Loading

0 comments on commit 2edc0f0

Please sign in to comment.