@cronos-labs/ui 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/eslintConfig.d.ts +17 -0
- package/dist/config/eslintConfig.js +52 -23
- package/package.json +1 -1
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
export interface ReactEslintConfigOptions {
|
|
2
2
|
ignores?: string[];
|
|
3
|
+
/**
|
|
4
|
+
* Globs, relative to `tsconfigRootDir`, for files that belong to no
|
|
5
|
+
* tsconfig but should still be linted — config files at the repo root, and
|
|
6
|
+
* build scripts under `scripts/`. typescript-eslint reads this from inside
|
|
7
|
+
* `projectService`, so passing it as a sibling silently does nothing.
|
|
8
|
+
*/
|
|
3
9
|
allowDefaultProject?: string[];
|
|
10
|
+
/**
|
|
11
|
+
* Globs for plain Node files — build scripts, codegen — that should be
|
|
12
|
+
* linted but are not part of the React app: Node globals instead of
|
|
13
|
+
* browser, and no type-aware rules, since they have no types to check and
|
|
14
|
+
* every value reads as `any`. Defaults to none, so a consumer opts in.
|
|
15
|
+
*
|
|
16
|
+
* These are folded into `allowDefaultProject`, which typescript-eslint
|
|
17
|
+
* refuses to match with `**` — use a single-level glob such as
|
|
18
|
+
* `scripts/*.mjs`.
|
|
19
|
+
*/
|
|
20
|
+
nodeScripts?: string[];
|
|
4
21
|
tsconfigRootDir: string;
|
|
5
22
|
}
|
|
6
23
|
export declare const createReactEslintConfig: (options: ReactEslintConfigOptions) => import("typescript-eslint").FlatConfig.ConfigArray;
|
|
@@ -4,28 +4,57 @@ import tseslint from 'typescript-eslint';
|
|
|
4
4
|
import reactHooks from 'eslint-plugin-react-hooks';
|
|
5
5
|
import reactRefresh from 'eslint-plugin-react-refresh';
|
|
6
6
|
import eslintConfigPrettier from 'eslint-config-prettier';
|
|
7
|
-
export const createReactEslintConfig = (options) =>
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
export const createReactEslintConfig = (options) => {
|
|
8
|
+
// Node scripts are outside every tsconfig by definition, so they need to be
|
|
9
|
+
// in the default-project allowlist as well as having type-aware rules off.
|
|
10
|
+
// Folding that in here means a consumer names them once.
|
|
11
|
+
const allowDefaultProject = [
|
|
12
|
+
...(options.allowDefaultProject ?? ['*.{js,mjs,cjs,ts}']),
|
|
13
|
+
...(options.nodeScripts ?? []),
|
|
14
|
+
];
|
|
15
|
+
return tseslint.config({
|
|
16
|
+
ignores: options.ignores ?? ['dist', 'coverage', 'node_modules', 'eslint.config.mjs'],
|
|
17
|
+
}, js.configs.recommended, ...tseslint.configs.recommendedTypeChecked, ...tseslint.configs.stylisticTypeChecked, {
|
|
18
|
+
languageOptions: {
|
|
19
|
+
ecmaVersion: 2023,
|
|
20
|
+
globals: {
|
|
21
|
+
...globals.browser,
|
|
22
|
+
},
|
|
23
|
+
parserOptions: {
|
|
24
|
+
// `allowDefaultProject` is an option *of* the project service, not a
|
|
25
|
+
// sibling of it. Passing `projectService: true` alongside it left
|
|
26
|
+
// the allowlist unread, so any file outside a tsconfig was simply
|
|
27
|
+
// skipped rather than linted.
|
|
28
|
+
projectService: {
|
|
29
|
+
allowDefaultProject,
|
|
30
|
+
},
|
|
31
|
+
tsconfigRootDir: options.tsconfigRootDir,
|
|
32
|
+
},
|
|
14
33
|
},
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
tsconfigRootDir: options.tsconfigRootDir,
|
|
34
|
+
plugins: {
|
|
35
|
+
'react-hooks': reactHooks,
|
|
36
|
+
'react-refresh': reactRefresh,
|
|
19
37
|
},
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
38
|
+
rules: {
|
|
39
|
+
...reactHooks.configs.recommended.rules,
|
|
40
|
+
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
|
|
41
|
+
'@typescript-eslint/no-explicit-any': 'error',
|
|
42
|
+
'@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports' }],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
// Plain Node files, opted into by the consumer. Type-aware rules are
|
|
46
|
+
// switched off for them with typescript-eslint's own
|
|
47
|
+
// `disableTypeChecked`: a .mjs build script has no types, so every value
|
|
48
|
+
// reads as `any` and the unsafe-* rules fire on correct code.
|
|
49
|
+
...(options.nodeScripts?.length
|
|
50
|
+
? [
|
|
51
|
+
{
|
|
52
|
+
files: options.nodeScripts,
|
|
53
|
+
...tseslint.configs.disableTypeChecked,
|
|
54
|
+
languageOptions: {
|
|
55
|
+
globals: { ...globals.node },
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
]
|
|
59
|
+
: []), eslintConfigPrettier);
|
|
60
|
+
};
|
package/package.json
CHANGED