Skip to content

Commit 175c64b

Browse files
committedJun 22, 2023
fix: fixed react version finding, added 2 new logger settings
Signed-off-by: prisis <d.bannert@anolilab.de>
1 parent 64b2b07 commit 175c64b

File tree

3 files changed

+74
-18
lines changed

3 files changed

+74
-18
lines changed
 

‎packages/eslint-config/README.md

+36
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,42 @@ To disable the info, set the value to `false`.
259259
}
260260
```
261261

262+
#### info_on_testing_library_framework
263+
264+
Type: `boolean`
265+
266+
Default: `undefined`
267+
268+
To disable the info, set the value to `false`.
269+
270+
```json
271+
{
272+
"anolilab": {
273+
"eslint-config": {
274+
"info_on_testing_library_framework": false
275+
}
276+
}
277+
}
278+
```
279+
280+
#### info_on_found_react_version
281+
282+
Type: `boolean`
283+
284+
Default: `undefined`
285+
286+
To disable the info, set the value to `false`.
287+
288+
```json
289+
{
290+
"anolilab": {
291+
"eslint-config": {
292+
"info_on_found_react_version": false
293+
}
294+
}
295+
}
296+
```
297+
262298
### Let [Prettier](https://prettier.io/) handle style-related rules
263299

264300
Prettier is a code formatting tool that offers fewer options but is more professional than the style-related rules in ESLint.

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

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @see https://github.com/yannickcr/eslint-plugin-react
22
import { hasAnyDep, pkg } from "@anolilab/package-json-utils";
3+
import { getPackageSubProperty } from "@anolilab/package-json-utils/src";
34
import type { Linter } from "eslint";
45
import findUp from "find-up";
56
import { env } from "node:process";
@@ -67,8 +68,17 @@ const hasJsxRuntime = (() => {
6768
return global.hasAnolilabEsLintConfigReactRuntimePath;
6869
})();
6970

70-
const packageDependencies = pkg?.dependencies ?? {};
71-
const reactDependency = (packageDependencies?.["react"] ?? "").split(".");
71+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call
72+
let reactVersion: string | undefined = getPackageSubProperty<string>("dependencies")("react")
73+
74+
if (reactVersion === undefined) {
75+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call
76+
reactVersion = getPackageSubProperty<string | undefined>("devDependencies")("react");
77+
}
78+
79+
if (reactVersion !== undefined && anolilabEslintConfig?.["info_on_found_react_version"] !== false) {
80+
consoleLog(`\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`);
81+
}
7282

7383
const config: Linter.Config = {
7484
overrides: [
@@ -97,7 +107,7 @@ const config: Linter.Config = {
97107
// The default value is "detect". Automatic detection works by loading the entire React library
98108
// into the linter's process, which is inefficient. It is recommended to specify the version
99109
// explicity.
100-
version: reactDependency[0] ? `${reactDependency[0]}.${reactDependency[1] ?? "0"}` : "detect",
110+
version: reactVersion ?? "detect",
101111
},
102112
propWrapperFunctions: [
103113
"forbidExtraProps", // https://www.npmjs.com/package/airbnb-prop-types

‎packages/eslint-config/src/config/plugins/testing-library.ts

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

44
import { consolePlugin } from "../../utils/loggers";
@@ -9,8 +9,18 @@ if (hasAnyDep(["react"])) {
99
ruleset = "react";
1010
}
1111

12+
let anolilabEslintConfig: { [key: string]: boolean | undefined } = {};
13+
14+
if (pkg) {
15+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
16+
anolilabEslintConfig = pkg?.["anolilab"]?.["eslint-config"];
17+
}
18+
19+
// Workaround VS Code trying to run this file twice!
1220
if (!global.hasAnolilabEsLintTestConfigLoaded) {
13-
consolePlugin(`testing-library/${ruleset}`);
21+
if (anolilabEslintConfig?.["info_on_testing_library_framework"] !== false) {
22+
consolePlugin(`testing-library/${ruleset}`);
23+
}
1424

1525
global.hasAnolilabEsLintTestConfigLoaded = true;
1626
}
@@ -19,19 +29,19 @@ const config: Linter.Config = {
1929
extends: [`plugin:testing-library/${ruleset}`],
2030
rules: {
2131
// Not included in jest/recommended
22-
"testing-library/await-fire-event": 0,
23-
"testing-library/consistent-data-testid": 0,
24-
"testing-library/no-debug": 0,
25-
"testing-library/no-dom-import": 0,
26-
"testing-library/no-manual-cleanup": 0,
27-
"testing-library/no-render-in-setup": 0,
28-
"testing-library/no-await-sync-events": 0,
29-
"testing-library/no-wait-for-empty-callback": 0,
30-
"testing-library/no-wait-for-snapshot": 0,
31-
"testing-library/prefer-explicit-assert": 0,
32-
"testing-library/prefer-presence-queries": 0,
33-
"testing-library/prefer-screen-queries": 0,
34-
"testing-library/prefer-wait-for": 0,
32+
"testing-library/await-fire-event": "off",
33+
"testing-library/consistent-data-testid": "off",
34+
"testing-library/no-debug": "off",
35+
"testing-library/no-dom-import": "off",
36+
"testing-library/no-manual-cleanup": "off",
37+
"testing-library/no-render-in-setup": "off",
38+
"testing-library/no-await-sync-events": "off",
39+
"testing-library/no-wait-for-empty-callback": "off",
40+
"testing-library/no-wait-for-snapshot": "off",
41+
"testing-library/prefer-explicit-assert": "off",
42+
"testing-library/prefer-presence-queries": "off",
43+
"testing-library/prefer-screen-queries": "off",
44+
"testing-library/prefer-wait-for": "off",
3545
},
3646
};
3747

0 commit comments

Comments
 (0)
Please sign in to comment.