Skip to content

Commit a398383

Browse files
committedJun 21, 2023
fix: added option to disable the found react jsx-runtime info
Signed-off-by: prisis <d.bannert@anolilab.de>
1 parent 3e24be8 commit a398383

File tree

3 files changed

+52
-7
lines changed

3 files changed

+52
-7
lines changed
 

‎packages/eslint-config/README.md

+33-3
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,11 @@ Add this property to your package.json:
169169

170170
```json5
171171
{
172-
anolilab: {
172+
"anolilab": {
173173
"eslint-config": {
174174
// options
175-
},
176-
},
175+
}
176+
}
177177
}
178178
```
179179

@@ -211,6 +211,36 @@ Type: `boolean`
211211

212212
Default: `undefined`
213213

214+
To disable the warning, set the value to `false`.
215+
216+
```json
217+
{
218+
"anolilab": {
219+
"eslint-config": {
220+
"warn_on_unsupported_typescript_version": false
221+
}
222+
}
223+
}
224+
```
225+
226+
#### info_on_disabling_jsx_react_rule
227+
228+
Type: `boolean`
229+
230+
Default: `undefined`
231+
232+
To disable the info, set the value to `false`.
233+
234+
```json
235+
{
236+
"anolilab": {
237+
"eslint-config": {
238+
"info_on_disabling_jsx_react_rule": false
239+
}
240+
}
241+
}
242+
```
243+
214244
### Let [Prettier](https://prettier.io/) handle style-related rules
215245

216246
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

+17-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { hasAnyDep, pkg } from "@anolilab/package-json-utils";
33
import type { Linter } from "eslint";
44
import findUp from "find-up";
5+
import { env } from "node:process";
56

67
import { consoleLog } from "../../utils/loggers";
78
import styleConfig from "../style";
@@ -35,18 +36,32 @@ if (
3536
};
3637
}
3738

39+
let anolilabEslintConfig: { [key: string]: boolean | undefined } = {};
40+
41+
if (pkg) {
42+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
43+
anolilabEslintConfig = pkg?.["anolilab"]?.["eslint-config"];
44+
}
45+
3846
const hasJsxRuntime = (() => {
3947
// Workaround VS Code trying to run this file twice!
4048
if (!global.hasAnolilabEsLintConfigReactRuntimePath) {
4149
const reactPath = findUp.sync("node_modules/react/jsx-runtime.js");
50+
const isFile = typeof reactPath === "string";
51+
52+
let showLog: boolean = env["DISABLE_INFO_ON_DISABLING_JSX_REACT_RULE"] !== "true";
53+
54+
if (showLog && anolilabEslintConfig?.["info_on_disabling_jsx_react_rule"] !== undefined) {
55+
showLog = anolilabEslintConfig["info_on_disabling_jsx_react_rule"];
56+
}
4257

43-
if (typeof reactPath === "string") {
58+
if (showLog && isFile) {
4459
consoleLog(`\n@anolilab/eslint-config found react jsx-runtime. \n
4560
Following rules are disabled: "react/jsx-uses-react" and "react/react-in-jsx-scope".
4661
If you dont use the new react jsx-runtime in you project, please enable it manually.\n`);
4762
}
4863

49-
global.hasAnolilabEsLintConfigReactRuntimePath = typeof reactPath === "string";
64+
global.hasAnolilabEsLintConfigReactRuntimePath = isFile;
5065
}
5166

5267
return global.hasAnolilabEsLintConfigReactRuntimePath;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const importExtensions = importsRules["import/extensions"] as any[];
5454
const importNoExtraneousDependencies = importsRules["import/no-extraneous-dependencies"] as any[];
5555
const commaDangle = styleRules["comma-dangle"] as any[];
5656

57-
let anolilabEslintConfig: { [key: string]: false | undefined } = {};
57+
let anolilabEslintConfig: { [key: string]: boolean | undefined } = {};
5858

5959
if (pkg) {
6060
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
@@ -64,7 +64,7 @@ if (pkg) {
6464
let showUnsupportedTypeScriptVersionWarning: boolean = env["DISABLE_ESLINT_WARN_UNSUPPORTED_TYPESCRIPT_VERSION"] !== "true";
6565

6666
if (anolilabEslintConfig?.["warn_on_unsupported_typescript_version"] !== undefined) {
67-
showUnsupportedTypeScriptVersionWarning = anolilabEslintConfig?.["warn_on_unsupported_typescript_version"];
67+
showUnsupportedTypeScriptVersionWarning = anolilabEslintConfig["warn_on_unsupported_typescript_version"];
6868
}
6969

7070
const config: Linter.Config = {

0 commit comments

Comments
 (0)
Please sign in to comment.