Skip to content

Commit fb6b8d2

Browse files
committed
fix: Remove splitting option and improve react version retrieval
In 'react.ts', refactored the react version retrieval to parse the version and store in a global variable. This guarantees more accuracy and easier debugging. A global variable 'anolilabEslintConfigReactVersion' was added in 'global.d.ts' to hold the parsed react version. These changes enhance code efficiency. Signed-off-by: prisis <[email protected]>
1 parent ca88fbc commit fb6b8d2

File tree

8 files changed

+44
-11
lines changed

8 files changed

+44
-11
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ packages/babel-preset/fixture/test.js
77
packages/babel-preset/fixture/test.ts
88
packages/stylelint-config/.stylelintrc.js
99
packages/lint-staged-config/.lintstagedrc.js
10+
packages/eslint-config/src/global.d.ts
1011

1112
tsup.config.ts

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@
109109
"cz-conventional-changelog": "^3.3.0",
110110
"eslint": "^8.43.0",
111111
"eslint-plugin-vitest": "^0.2.6",
112+
"eslint-plugin-etc": "^2.0.3",
113+
"eslint-plugin-typescript-sort-keys": "^2.3.0",
112114
"husky": "^8.0.3",
113115
"is-ci": "^3.0.1",
114116
"lint-staged": "^13.2.3",
@@ -136,6 +138,9 @@
136138
"eslint": {
137139
"config": "./.eslintrc.js"
138140
}
141+
},
142+
"plugin": {
143+
"eslint-plugin-tsdoc": false
139144
}
140145
}
141146
},

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

+17-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { getPackageSubProperty, hasDependency, hasDevDependency } from "@anolila
33
import type { Linter } from "eslint";
44
import findUp from "find-up";
55
import { env } from "node:process";
6+
import { parse } from "semver";
67

78
import anolilabEslintConfig from "../../utils/eslint-config";
89
import { consoleLog } from "../../utils/loggers";
@@ -54,15 +55,25 @@ const hasJsxRuntime = (() => {
5455
return global.hasAnolilabEsLintConfigReactRuntimePath;
5556
})();
5657

57-
let reactVersion: string | undefined = getPackageSubProperty<string>("dependencies")("react");
58+
if (!global.anolilabEslintConfigReactVersion) {
59+
let reactVersion = getPackageSubProperty<string | undefined>("dependencies")("react");
5860

59-
if (reactVersion === undefined) {
60-
reactVersion = getPackageSubProperty<string | undefined>("devDependencies")("react");
61+
if (reactVersion === undefined) {
62+
reactVersion = getPackageSubProperty<string | undefined>("devDependencies")("react");
63+
}
64+
65+
if (reactVersion !== undefined) {
66+
const parsedVersion = parse(reactVersion);
67+
68+
if (parsedVersion !== null) {
69+
global.anolilabEslintConfigReactVersion = `${parsedVersion.major}.${parsedVersion.minor}`;
70+
}
71+
}
6172
}
6273

63-
if (reactVersion !== undefined && anolilabEslintConfig?.["info_on_found_react_version"] !== false) {
74+
if (global.anolilabEslintConfigReactVersion !== undefined && anolilabEslintConfig?.["info_on_found_react_version"] !== false) {
6475
consoleLog(
65-
`\n@anolilab/eslint-config found the version ${reactVersion} of react in your dependencies, this version ${reactVersion} will be used to setup the "eslint-plugin-react"\n`,
76+
`\n@anolilab/eslint-config found the version ${global.anolilabEslintConfigReactVersion} of react in your dependencies, this version ${global.anolilabEslintConfigReactVersion} will be used to setup the "eslint-plugin-react"\n`,
6677
);
6778
}
6879

@@ -93,7 +104,7 @@ const config: Linter.Config = {
93104
// The default value is "detect". Automatic detection works by loading the entire React library
94105
// into the linter's process, which is inefficient. It is recommended to specify the version
95106
// explicity.
96-
version: reactVersion ?? "detect",
107+
version: global.anolilabEslintConfigReactVersion ?? "detect",
97108
},
98109
propWrapperFunctions: [
99110
"forbidExtraProps", // https://www.npmjs.com/package/airbnb-prop-types

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ const config: Linter.Config = {
6060
overrides: [
6161
{
6262
files: ["*.ts", "*.mts", "*.cts", "*.tsx"],
63-
extends: ["plugin:import/typescript"],
63+
extends: [
64+
"plugin:import/typescript",
65+
// TODO: enable the rule when typescript-eslint 6.0.0 is released
66+
// "plugin:@typescript-eslint/recommended",
67+
// "plugin:@typescript-eslint/stylistic",
68+
// "plugin:@typescript-eslint/strict",
69+
],
6470
plugins: ["@typescript-eslint"],
6571
parser: "@typescript-eslint/parser",
6672
parserOptions: {

packages/eslint-config/src/global.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ declare global {
2929

3030
var anolilabEslintConfigReactPrettierRules: undefined | Linter.RulesRecord;
3131

32+
var anolilabEslintConfigReactVersion: undefined | string;
33+
3234
var anolilabEslintConfigTestingLibraryRuleSet: undefined | string;
3335

3436
var anolilabEslintConfigUnicornPrettierRules: undefined | Linter.RulesRecord;

packages/eslint-config/src/typescript-type-checking.ts

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import { createConfig } from "./utils/create-config";
66
const bestPracticesRules = bestPracticesConfig.rules as Linter.RulesRecord;
77

88
const config = createConfig("typescript", {
9+
// TODO: enable the rule when typescript-eslint 6.0.0 is released
10+
// extends: [
11+
// "plugin:@typescript-eslint/recommended-type-checked",
12+
// "plugin:@typescript-eslint/strict-type-checked",
13+
// "plugin:@typescript-eslint/stylistic-type-checked"
14+
// ],
915
rules: {
1016
// Disallows awaiting a value that is not a Thenable
1117
"@typescript-eslint/await-thenable": "error",

packages/eslint-config/tsup.config.ts

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { createConfig } from "../../tsup.config";
22

33
const config = createConfig({
44
format: "cjs",
5-
splitting: false,
65
});
76

87
export default config;

pnpm-lock.yaml

+6-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)