Skip to content

Commit 4d3c015

Browse files
committed
fix: Update eslint dependencies and rules
Added the eslint's global variable registry and refactored the existing dependencies from a specific package of eslint-check into a global config file. Each eslint plugin now determines the rules by referring to the global config instead of their own. This removes the possibility of different eslint plugins having its own version of the same package and alleviates the concern on duplicated and conflicting packages, providing consistency through out the application and avoiding possible bugs. Additionally, updated eslint rules to enable better code checking and control of code quality. Signed-off-by: prisis <[email protected]>
1 parent c967bcc commit 4d3c015

27 files changed

+522
-501
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ packages/babel-preset/babel.config.js
66
packages/babel-preset/fixture/test.js
77
packages/babel-preset/fixture/test.ts
88
packages/stylelint-config/.stylelintrc.js
9+
packages/lint-staged-config/.lintstagedrc.js
910

1011
tsup.config.ts
File renamed without changes.

.github/workflows/dependency-review.yml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
name: "Dependency Review"
1010

1111
on: # yamllint disable-line rule:truthy
12+
# eslint-disable-next-line yml/no-empty-mapping-value
1213
pull_request: # yamllint disable-line rule:empty-values
1314

1415
permissions:

.github/workflows/lint.yml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on: # yamllint disable-line rule:truthy
66
push:
77
branches:
88
- "main"
9+
# eslint-disable-next-line yml/no-empty-mapping-value
910
pull_request: # yamllint disable-line rule:empty-values
1011

1112
concurrency:

.github/workflows/scorecards.yml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ name: "Scorecard supply-chain security"
77
on: # yamllint disable-line rule:truthy
88
# For Branch-Protection check. Only the default branch is supported. See
99
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection
10+
# eslint-disable-next-line yml/no-empty-mapping-value
1011
branch_protection_rule: # yamllint disable-line rule:empty-values
1112
# To guarantee Maintained check is occasionally updated. See
1213
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained

.github/workflows/stale-issues.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ jobs:
2626
with:
2727
repo-token: "${{ secrets.GITHUB_TOKEN }}"
2828
stale-issue-message: |
29-
This issue has been automatically marked as stale because it has been open for 21 days with no activity. It will be closed in 7 days if no further activity (Remove label or comment) occurs.
29+
This issue has been automatically marked as stale because it has been open for 21 days with no activity.
30+
It will be closed in 7 days if no further activity (Remove label or comment) occurs.
3031
If we missed this issue please reply to keep it active.
3132
Thanks for being a part of this project. 🙏
3233
stale-issue-label: "Stale"

.github/workflows/test.yml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on: # yamllint disable-line rule:truthy
66
push:
77
branches:
88
- "main"
9+
# eslint-disable-next-line yml/no-empty-mapping-value
910
pull_request: # yamllint disable-line rule:empty-values
1011

1112
concurrency:

packages/eslint-config/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
"eslint-find-rules": "^4.1.0",
164164
"eslint-plugin-babel": "^5.3.1",
165165
"eslint-plugin-cypress": "^2.13.3",
166+
"eslint-plugin-etc": "^2.0.3",
166167
"eslint-plugin-jest": "^27.2.2",
167168
"eslint-plugin-jest-async": "^1.0.3",
168169
"eslint-plugin-jest-dom": "^5.0.1",
@@ -176,7 +177,6 @@
176177
"eslint-plugin-react-redux": "^4.0.0",
177178
"eslint-plugin-storybook": "^0.6.12",
178179
"eslint-plugin-tailwindcss": "^3.12.1",
179-
"eslint-plugin-etc": "^2.0.3",
180180
"eslint-plugin-testing-library": "^5.11.0",
181181
"eslint-plugin-vitest": "^0.2.6",
182182
"eslint-plugin-you-dont-need-lodash-underscore": "^6.12.0",
@@ -192,6 +192,7 @@
192192
"eslint": "^8.15.0"
193193
},
194194
"optionalDependencies": {
195+
"@tanstack/eslint-plugin-query": "^4.29.9",
195196
"eslint-plugin-array-func": "^3.1.8",
196197
"eslint-plugin-ava": "^14.0.0",
197198
"eslint-plugin-babel": "^5.3.1",
@@ -200,13 +201,12 @@
200201
"eslint-plugin-jest-async": "^1.0.3",
201202
"eslint-plugin-jest-dom": "^5.0.1",
202203
"eslint-plugin-jest-formatting": "^3.1.0",
203-
"eslint-plugin-playwright": "^0.15.1",
204204
"eslint-plugin-jsdoc": "^46.3.0",
205205
"eslint-plugin-jsx-a11y": "^6.7.1",
206206
"eslint-plugin-n": "^16.0.1",
207207
"eslint-plugin-no-unsanitized": "^4.0.2",
208+
"eslint-plugin-playwright": "^0.15.1",
208209
"eslint-plugin-prefer-object-spread": "^1.2.1",
209-
"@tanstack/eslint-plugin-query": "^4.29.9",
210210
"eslint-plugin-react": "^7.32.2",
211211
"eslint-plugin-react-hooks": "^4.6.0",
212212
"eslint-plugin-react-redux": "^4.0.0",

packages/eslint-config/src/config.ts

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { hasDependency, hasDevDependency, pkg } from "@anolilab/package-json-utils";
1+
import { hasDependency, hasDevDependency } from "@anolilab/package-json-utils";
22

33
import type { PackageRules } from "./types";
4+
import anolilabEslintConfig from "./utils/eslint-config";
45

56
const baseConfig = ["best-practices", "errors", "style", "es6", "variables"];
67

@@ -93,7 +94,7 @@ const pluginConfig: PackageRules = [
9394
},
9495
{
9596
configName: "cypress",
96-
dependencies: ["eslint-plugin-cypress"],
97+
dependencies: ["cypress", "eslint-plugin-cypress"],
9798
},
9899
{
99100
configName: "jest",
@@ -164,17 +165,10 @@ const pluginConfig: PackageRules = [
164165
const loadedPlugins: string[] = [...internalPluginConfig];
165166
const possiblePlugins: { [rule: string]: { [packageName: string]: boolean } } = {};
166167

167-
let anolilabEslintConfig: { [key: string]: { [key: string]: false | undefined } } = {};
168-
169-
if (pkg) {
170-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
171-
anolilabEslintConfig = pkg?.["anolilab"]?.["eslint-config"];
172-
}
173-
174168
pluginConfig.forEach((plugin) => {
175169
const { dependencies, configName } = plugin;
176170

177-
if (anolilabEslintConfig?.["plugin"]?.[configName] !== false) {
171+
if ((anolilabEslintConfig as unknown as { [key: string]: { [key: string]: false | undefined } })?.["plugin"]?.[configName] !== false) {
178172
const foundDependencies = [];
179173

180174
dependencies.forEach((dependency) => {

packages/eslint-config/src/config/plugins/babel.ts

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { hasAnyDep } from "@anolilab/package-json-utils";
1+
import { hasDependency, hasDevDependency } from "@anolilab/package-json-utils";
22
import type { Linter } from "eslint";
33

44
import { createConfig } from "../../utils/create-config";
@@ -10,14 +10,8 @@ const bestPracticesRules = bestPracticesConfig.rules as Linter.RulesRecord;
1010
const errorsRules = errorsConfig.rules as Linter.RulesRecord;
1111
const styleRules = styleConfig.rules as Linter.RulesRecord;
1212

13-
let prettierRules: Linter.RulesRecord = {};
14-
15-
if (
16-
hasAnyDep(["prettier"], {
17-
peerDeps: false,
18-
})
19-
) {
20-
prettierRules = {
13+
if (global.anolilabEslintConfigBabelPrettierRules === undefined && (hasDependency("prettier") || hasDevDependency("prettier"))) {
14+
global.anolilabEslintConfigBabelPrettierRules = {
2115
"babel/quotes": 0,
2216

2317
"@babel/object-curly-spacing": "off",
@@ -56,7 +50,7 @@ const config: Linter.Config = createConfig("all", {
5650
"valid-typeof": "off",
5751
"babel/valid-typeof": errorsRules["valid-typeof"],
5852

59-
...prettierRules,
53+
...global.anolilabEslintConfigBabelPrettierRules,
6054
},
6155
});
6256

packages/eslint-config/src/config/plugins/html.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { hasAnyDep } from "@anolilab/package-json-utils";
1+
import { hasDependency, hasDevDependency } from "@anolilab/package-json-utils";
22
import type { Linter } from "eslint";
33

44
import styleConfig from "../style";
@@ -9,11 +9,7 @@ let hasPrettier = false;
99

1010
let prettierRules: Linter.RulesRecord = {};
1111

12-
if (
13-
hasAnyDep(["prettier"], {
14-
peerDeps: false,
15-
})
16-
) {
12+
if (hasDependency("prettier") || hasDevDependency("prettier")) {
1713
hasPrettier = true;
1814

1915
prettierRules = {

0 commit comments

Comments
 (0)