@kristijorgji/eslint-config-react-typescript 0.0.1 → 2.0.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/LICENSE +1 -1
- package/README.md +54 -22
- package/dist/create-react-config.d.ts +25 -0
- package/dist/create-react-config.d.ts.map +1 -0
- package/dist/create-react-config.js +112 -0
- package/dist/create-react-config.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx-props.d.ts +22 -0
- package/dist/jsx-props.d.ts.map +1 -0
- package/dist/jsx-props.js +37 -0
- package/dist/jsx-props.js.map +1 -0
- package/dist/shared.d.ts +9 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +50 -0
- package/dist/shared.js.map +1 -0
- package/package.json +84 -19
- package/index.js +0 -60
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,38 +1,70 @@
|
|
|
1
1
|
# @kristijorgji/eslint-config-react-typescript
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Flat ESLint config factory for React + TypeScript apps. Builds on
|
|
4
|
+
[`@kristijorgji/eslint-config-typescript`](https://www.npmjs.com/package/@kristijorgji/eslint-config-typescript)
|
|
5
|
+
with `variant: 'vite' | 'next'`.
|
|
4
6
|
|
|
5
|
-
##
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# Vite + Storybook example
|
|
11
|
+
pnpm add -D @kristijorgji/eslint-config-react-typescript \
|
|
12
|
+
eslint typescript prettier \
|
|
13
|
+
eslint-plugin-react-x eslint-plugin-react-dom eslint-plugin-storybook
|
|
6
14
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
15
|
+
# Next example
|
|
16
|
+
pnpm add -D @kristijorgji/eslint-config-react-typescript \
|
|
17
|
+
eslint typescript prettier \
|
|
18
|
+
eslint-plugin-react @next/eslint-plugin-next
|
|
11
19
|
```
|
|
12
20
|
|
|
13
|
-
|
|
21
|
+
Framework plugins are **optional peers** — only install what your variant needs.
|
|
22
|
+
`eslint-plugin-perfectionist` is a **dependency** of this package (JSX prop order).
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
14
25
|
|
|
15
|
-
### Config
|
|
16
|
-
Add the following to your `.eslintrc.js`:
|
|
17
26
|
```js
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
27
|
+
// eslint.config.js
|
|
28
|
+
import { createReactConfig } from '@kristijorgji/eslint-config-react-typescript';
|
|
21
29
|
|
|
30
|
+
export default await createReactConfig({
|
|
31
|
+
variant: 'vite',
|
|
32
|
+
tsconfigRootDir: import.meta.dirname,
|
|
33
|
+
storybook: true,
|
|
34
|
+
prettier: 'prettierrc',
|
|
35
|
+
});
|
|
22
36
|
```
|
|
23
37
|
|
|
24
|
-
|
|
25
|
-
|
|
38
|
+
### Options
|
|
39
|
+
|
|
40
|
+
| Option | Description |
|
|
41
|
+
| --- | --- |
|
|
42
|
+
| `variant` | `'vite'` or `'next'` (required) |
|
|
43
|
+
| `tsconfigRootDir` | Required for type-aware rules |
|
|
44
|
+
| `storybook` | Vite only — Storybook flat recommended |
|
|
45
|
+
| `a11y` | Optional `eslint-plugin-jsx-a11y` |
|
|
46
|
+
| `jsxProps` | Options for `perfectionist/sort-jsx-props` (shallow merge); `false` disables |
|
|
47
|
+
| plus | All `createTypescriptConfig` options (`prettier`, `importOrder`, `sortImports`, …) |
|
|
26
48
|
|
|
27
|
-
|
|
28
|
-
`yarn add --dev /Users/kristi.jorgji/Desktop/fl-lite/eslint-config-react-typescript`
|
|
29
|
-
|
|
30
|
-
You need to run the above command after every plugin change.
|
|
49
|
+
### Shared React rules
|
|
31
50
|
|
|
32
|
-
|
|
51
|
+
- `eslint-plugin-react-hooks` / `react-refresh`
|
|
52
|
+
- `perfectionist/sort-jsx-props` (ranked identity props, then unknown, callbacks last)
|
|
53
|
+
- `kj/no-single-export-barrel`
|
|
54
|
+
- `componentExtraction()` (`kj/no-multi-comp` + line limits, warn)
|
|
33
55
|
|
|
34
|
-
|
|
56
|
+
### Standalone JSX prop config
|
|
35
57
|
|
|
36
|
-
|
|
58
|
+
Consumers with a custom React preset (for example React Native) can compose without
|
|
59
|
+
the full factory:
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
import { createJsxPropsConfig } from '@kristijorgji/eslint-config-react-typescript';
|
|
63
|
+
|
|
64
|
+
export default [
|
|
65
|
+
createJsxPropsConfig(),
|
|
66
|
+
];
|
|
67
|
+
```
|
|
37
68
|
|
|
38
|
-
|
|
69
|
+
Rewritten from the legacy `eslint-config-react-app` shareable config
|
|
70
|
+
([`8c090ded`](https://github.com/kristijorgji/eslint-config-react-typescript/commit/8c090ded195c4c957cee7e24b3b5b024ad6120f9)) — not a port of that lineage.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type CreateTypescriptConfigOptions } from '@kristijorgji/eslint-config-typescript';
|
|
2
|
+
import type { Linter } from 'eslint';
|
|
3
|
+
import type { SortJsxPropsOptions } from './jsx-props.js';
|
|
4
|
+
export type ReactConfigVariant = 'vite' | 'next';
|
|
5
|
+
export interface CreateReactConfigOptions extends CreateTypescriptConfigOptions {
|
|
6
|
+
/** Framework variant. Required. */
|
|
7
|
+
variant: ReactConfigVariant;
|
|
8
|
+
/** Directory containing the consumer's `tsconfig.json`. Required for typed rules. */
|
|
9
|
+
tsconfigRootDir: string;
|
|
10
|
+
/** Include Storybook flat recommended (vite variant). Defaults to false. */
|
|
11
|
+
storybook?: boolean;
|
|
12
|
+
/** Include `eslint-plugin-jsx-a11y` recommended. Defaults to false. */
|
|
13
|
+
a11y?: boolean;
|
|
14
|
+
/** Extra ignores passed to `componentExtraction`. */
|
|
15
|
+
extractionIgnores?: string[];
|
|
16
|
+
/** `false` disables JSX prop sorting; an object shallow-merges over package defaults. */
|
|
17
|
+
jsxProps?: false | SortJsxPropsOptions;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Flat ESLint config factory for React TypeScript apps.
|
|
21
|
+
*
|
|
22
|
+
* Async so framework plugins can be optional peers loaded via dynamic `import()`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function createReactConfig(options: CreateReactConfigOptions): Promise<Linter.Config[]>;
|
|
25
|
+
//# sourceMappingURL=create-react-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-react-config.d.ts","sourceRoot":"","sources":["../src/create-react-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,6BAA6B,EACnC,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE7C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAG1D,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,MAAM,CAAC;AAEjD,MAAM,WAAW,wBAAyB,SAAQ,6BAA6B;IAC7E,mCAAmC;IACnC,OAAO,EAAE,kBAAkB,CAAC;IAC5B,qFAAqF;IACrF,eAAe,EAAE,MAAM,CAAC;IACxB,4EAA4E;IAC5E,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,uEAAuE;IACvE,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,qDAAqD;IACrD,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,yFAAyF;IACzF,QAAQ,CAAC,EAAE,KAAK,GAAG,mBAAmB,CAAC;CACxC;AA6GD;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CA6B1B"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { createTypescriptConfig, } from '@kristijorgji/eslint-config-typescript';
|
|
2
|
+
import { createSharedReactConfigs } from './shared.js';
|
|
3
|
+
function asPlugin(mod) {
|
|
4
|
+
const resolved = mod;
|
|
5
|
+
if (resolved && typeof resolved === 'object' && 'default' in resolved && resolved.default) {
|
|
6
|
+
return resolved.default;
|
|
7
|
+
}
|
|
8
|
+
return resolved;
|
|
9
|
+
}
|
|
10
|
+
function pluginConfigs(plugin) {
|
|
11
|
+
return (plugin.configs ?? {});
|
|
12
|
+
}
|
|
13
|
+
function rulesFrom(value) {
|
|
14
|
+
if (value && typeof value === 'object' && 'rules' in value) {
|
|
15
|
+
return (value.rules ?? {});
|
|
16
|
+
}
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
async function loadVitePlugins(options) {
|
|
20
|
+
const configs = [];
|
|
21
|
+
const reactX = asPlugin(await import('eslint-plugin-react-x'));
|
|
22
|
+
const reactDom = asPlugin(await import('eslint-plugin-react-dom'));
|
|
23
|
+
const reactXConfigs = pluginConfigs(reactX);
|
|
24
|
+
const reactDomConfigs = pluginConfigs(reactDom);
|
|
25
|
+
configs.push({
|
|
26
|
+
files: ['**/*.{ts,tsx}'],
|
|
27
|
+
plugins: {
|
|
28
|
+
'react-x': reactX,
|
|
29
|
+
'react-dom': reactDom,
|
|
30
|
+
},
|
|
31
|
+
rules: {
|
|
32
|
+
...rulesFrom(reactXConfigs['recommended-typescript']),
|
|
33
|
+
...rulesFrom(reactDomConfigs.recommended),
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
if (options.storybook) {
|
|
37
|
+
const storybook = asPlugin(await import('eslint-plugin-storybook'));
|
|
38
|
+
const flat = pluginConfigs(storybook)['flat/recommended'];
|
|
39
|
+
if (Array.isArray(flat)) {
|
|
40
|
+
configs.push(...flat);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (options.a11y) {
|
|
44
|
+
configs.push(await loadA11yConfig());
|
|
45
|
+
}
|
|
46
|
+
return configs;
|
|
47
|
+
}
|
|
48
|
+
async function loadNextPlugins(options) {
|
|
49
|
+
const configs = [];
|
|
50
|
+
const react = asPlugin(await import('eslint-plugin-react'));
|
|
51
|
+
const nextPlugin = asPlugin(await import('@next/eslint-plugin-next'));
|
|
52
|
+
const reactConfigs = pluginConfigs(react);
|
|
53
|
+
const flat = (reactConfigs.flat ?? {});
|
|
54
|
+
const nextConfigs = pluginConfigs(nextPlugin);
|
|
55
|
+
configs.push({
|
|
56
|
+
plugins: { react },
|
|
57
|
+
settings: { react: { version: 'detect' } },
|
|
58
|
+
rules: {
|
|
59
|
+
...rulesFrom(flat.recommended),
|
|
60
|
+
...rulesFrom(flat['jsx-runtime']),
|
|
61
|
+
'react/prop-types': 'off',
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
configs.push({
|
|
65
|
+
plugins: { '@next/next': nextPlugin },
|
|
66
|
+
rules: {
|
|
67
|
+
...rulesFrom(nextConfigs.recommended),
|
|
68
|
+
...rulesFrom(nextConfigs['core-web-vitals']),
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
if (options.a11y) {
|
|
72
|
+
configs.push(await loadA11yConfig());
|
|
73
|
+
}
|
|
74
|
+
return configs;
|
|
75
|
+
}
|
|
76
|
+
async function loadA11yConfig() {
|
|
77
|
+
const jsxA11y = asPlugin(await import('eslint-plugin-jsx-a11y'));
|
|
78
|
+
const flatConfigs = jsxA11y
|
|
79
|
+
.flatConfigs;
|
|
80
|
+
return {
|
|
81
|
+
files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
|
|
82
|
+
plugins: { 'jsx-a11y': jsxA11y },
|
|
83
|
+
rules: { ...rulesFrom(flatConfigs?.recommended) },
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Flat ESLint config factory for React TypeScript apps.
|
|
88
|
+
*
|
|
89
|
+
* Async so framework plugins can be optional peers loaded via dynamic `import()`.
|
|
90
|
+
*/
|
|
91
|
+
export async function createReactConfig(options) {
|
|
92
|
+
const { variant, tsconfigRootDir, storybook = false, a11y = false, extractionIgnores, jsxProps, ...tsOptions } = options;
|
|
93
|
+
const configs = [
|
|
94
|
+
...createTypescriptConfig({
|
|
95
|
+
...tsOptions,
|
|
96
|
+
tsconfigRootDir,
|
|
97
|
+
}),
|
|
98
|
+
...createSharedReactConfigs({ extractionIgnores, jsxProps }),
|
|
99
|
+
];
|
|
100
|
+
if (variant === 'vite') {
|
|
101
|
+
configs.push(...(await loadVitePlugins({ storybook, a11y })));
|
|
102
|
+
}
|
|
103
|
+
else if (variant === 'next') {
|
|
104
|
+
configs.push(...(await loadNextPlugins({ a11y })));
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
const _exhaustive = variant;
|
|
108
|
+
throw new Error(`Unknown React config variant: ${String(_exhaustive)}`);
|
|
109
|
+
}
|
|
110
|
+
return configs;
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=create-react-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-react-config.js","sourceRoot":"","sources":["../src/create-react-config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,GAEvB,MAAM,wCAAwC,CAAC;AAIhD,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAqBvD,SAAS,QAAQ,CAAC,GAAY;IAC5B,MAAM,QAAQ,GAAG,GAAsC,CAAC;IACxD,IAAI,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,SAAS,IAAI,QAAQ,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;QAC1F,OAAO,QAAQ,CAAC,OAAoB,CAAC;IACvC,CAAC;IACD,OAAO,QAAqB,CAAC;AAC/B,CAAC;AAED,SAAS,aAAa,CAAC,MAAiB;IACtC,OAAO,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,CAA4B,CAAC;AAC3D,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,IAAI,KAAK,EAAE,CAAC;QAC3D,OAAO,CAAE,KAAwC,CAAC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f,OAAO;QACL,KAAK,EAAE,CAAC,wCAAwC,CAAC;QACjD,OAAO,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE;QAChC,KAAK,EAAE,EAAE,GAAG,SAAS,CAAC,WAAW,EAAE,WAAW,CAAC,EAAE;KAClD,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAAiC;IAEjC,MAAM,EACJ,OAAO,EACP,eAAe,EACf,SAAS,GAAG,KAAK,EACjB,IAAI,GAAG,KAAK,EACZ,iBAAiB,EACjB,QAAQ,EACR,GAAG,SAAS,EACb,GAAG,OAAO,CAAC;IAEZ,MAAM,OAAO,GAAoB;QAC/B,GAAG,sBAAsB,CAAC;YACxB,GAAG,SAAS;YACZ,eAAe;SAChB,CAAC;QACF,GAAG,wBAAwB,CAAC,EAAE,iBAAiB,EAAE,QAAQ,EAAE,CAAC;KAC7D,CAAC;IAEF,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;QACvB,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,eAAe,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAChE,CAAC;SAAM,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;QAC9B,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,eAAe,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IACrD,CAAC;SAAM,CAAC;QACN,MAAM,WAAW,GAAU,OAAO,CAAC;QACnC,MAAM,IAAI,KAAK,CAAC,iCAAiC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createReactConfig, type CreateReactConfigOptions, type ReactConfigVariant, } from './create-react-config.js';
|
|
2
|
+
export { createJsxPropsConfig, defaultJsxPropsOptions, type SortJsxPropsCustomGroup, type SortJsxPropsOptions, } from './jsx-props.js';
|
|
3
|
+
export { createSharedReactConfigs } from './shared.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,KAAK,wBAAwB,EAC7B,KAAK,kBAAkB,GACxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,GACzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,GAGlB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,oBAAoB,EACpB,sBAAsB,GAGvB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Linter } from 'eslint';
|
|
2
|
+
export interface SortJsxPropsCustomGroup {
|
|
3
|
+
groupName: string;
|
|
4
|
+
elementNamePattern?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface SortJsxPropsOptions {
|
|
7
|
+
type?: 'alphabetical' | 'natural' | 'line-length' | 'unsorted';
|
|
8
|
+
order?: 'asc' | 'desc';
|
|
9
|
+
ignoreCase?: boolean;
|
|
10
|
+
groups?: (string | string[])[];
|
|
11
|
+
customGroups?: SortJsxPropsCustomGroup[];
|
|
12
|
+
partitionByNewLine?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** JSX prop order: ranked identity props first, then unknown props, callbacks last. */
|
|
15
|
+
export declare const defaultJsxPropsOptions: SortJsxPropsOptions;
|
|
16
|
+
/**
|
|
17
|
+
* Standalone flat-config block for JSX prop order. Exported so consumers with their
|
|
18
|
+
* own React preset (for example React Native) can compose it without the full factory.
|
|
19
|
+
* Top-level option keys shallow-merge over {@link defaultJsxPropsOptions} (arrays replace).
|
|
20
|
+
*/
|
|
21
|
+
export declare function createJsxPropsConfig(options?: SortJsxPropsOptions): Linter.Config;
|
|
22
|
+
//# sourceMappingURL=jsx-props.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx-props.d.ts","sourceRoot":"","sources":["../src/jsx-props.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGrC,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,CAAC,EAAE,cAAc,GAAG,SAAS,GAAG,aAAa,GAAG,UAAU,CAAC;IAC/D,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE,CAAC;IAC/B,YAAY,CAAC,EAAE,uBAAuB,EAAE,CAAC;IACzC,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,uFAAuF;AACvF,eAAO,MAAM,sBAAsB,EAAE,mBAapC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,MAAM,CAAC,MAAM,CAcjF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import perfectionist from 'eslint-plugin-perfectionist';
|
|
2
|
+
/** JSX prop order: ranked identity props first, then unknown props, callbacks last. */
|
|
3
|
+
export const defaultJsxPropsOptions = {
|
|
4
|
+
type: 'alphabetical',
|
|
5
|
+
order: 'asc',
|
|
6
|
+
ignoreCase: true,
|
|
7
|
+
groups: ['testid', 'key', 'ref', 'id', 'name', 'unknown', 'callback'],
|
|
8
|
+
customGroups: [
|
|
9
|
+
{ groupName: 'testid', elementNamePattern: '^(data-testid|testID)$' },
|
|
10
|
+
{ groupName: 'key', elementNamePattern: '^key$' },
|
|
11
|
+
{ groupName: 'ref', elementNamePattern: '^ref$' },
|
|
12
|
+
{ groupName: 'id', elementNamePattern: '^id$' },
|
|
13
|
+
{ groupName: 'name', elementNamePattern: '^name$' },
|
|
14
|
+
{ groupName: 'callback', elementNamePattern: '^on.+' },
|
|
15
|
+
],
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Standalone flat-config block for JSX prop order. Exported so consumers with their
|
|
19
|
+
* own React preset (for example React Native) can compose it without the full factory.
|
|
20
|
+
* Top-level option keys shallow-merge over {@link defaultJsxPropsOptions} (arrays replace).
|
|
21
|
+
*/
|
|
22
|
+
export function createJsxPropsConfig(options) {
|
|
23
|
+
return {
|
|
24
|
+
files: ['**/*.{ts,tsx}'],
|
|
25
|
+
plugins: { perfectionist },
|
|
26
|
+
rules: {
|
|
27
|
+
'perfectionist/sort-jsx-props': [
|
|
28
|
+
'error',
|
|
29
|
+
{
|
|
30
|
+
...defaultJsxPropsOptions,
|
|
31
|
+
...options,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=jsx-props.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx-props.js","sourceRoot":"","sources":["../src/jsx-props.ts"],"names":[],"mappings":"AACA,OAAO,aAAa,MAAM,6BAA6B,CAAC;AAgBxD,uFAAuF;AACvF,MAAM,CAAC,MAAM,sBAAsB,GAAwB;IACzD,IAAI,EAAE,cAAc;IACpB,KAAK,EAAE,KAAK;IACZ,UAAU,EAAE,IAAI;IAChB,MAAM,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,CAAC;IACrE,YAAY,EAAE;QACZ,EAAE,SAAS,EAAE,QAAQ,EAAE,kBAAkB,EAAE,wBAAwB,EAAE;QACrE,EAAE,SAAS,EAAE,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE;QACjD,EAAE,SAAS,EAAE,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE;QACjD,EAAE,SAAS,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,EAAE;QAC/C,EAAE,SAAS,EAAE,MAAM,EAAE,kBAAkB,EAAE,QAAQ,EAAE;QACnD,EAAE,SAAS,EAAE,UAAU,EAAE,kBAAkB,EAAE,OAAO,EAAE;KACvD;CACF,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAA6B;IAChE,OAAO;QACL,KAAK,EAAE,CAAC,eAAe,CAAC;QACxB,OAAO,EAAE,EAAE,aAAa,EAAE;QAC1B,KAAK,EAAE;YACL,8BAA8B,EAAE;gBAC9B,OAAO;gBACP;oBACE,GAAG,sBAAsB;oBACzB,GAAG,OAAO;iBACX;aACF;SACF;KACF,CAAC;AACJ,CAAC"}
|
package/dist/shared.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Linter } from 'eslint';
|
|
2
|
+
import { type SortJsxPropsOptions } from './jsx-props.js';
|
|
3
|
+
/** Shared React core: hooks, refresh, kj barrel/extraction rules, browser globals, JSX prop order. */
|
|
4
|
+
export declare function createSharedReactConfigs(options?: {
|
|
5
|
+
extractionIgnores?: string[];
|
|
6
|
+
/** `false` disables JSX prop sorting; an object shallow-merges over package defaults. */
|
|
7
|
+
jsxProps?: false | SortJsxPropsOptions;
|
|
8
|
+
}): Linter.Config[];
|
|
9
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAKrC,OAAO,EAAwB,KAAK,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAEhF,sGAAsG;AACtG,wBAAgB,wBAAwB,CAAC,OAAO,CAAC,EAAE;IACjD,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,yFAAyF;IACzF,QAAQ,CAAC,EAAE,KAAK,GAAG,mBAAmB,CAAC;CACxC,GAAG,MAAM,CAAC,MAAM,EAAE,CA6ClB"}
|
package/dist/shared.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { componentExtraction, plugin as kjPlugin } from '@kristijorgji/eslint-plugin';
|
|
2
|
+
import reactHooks from 'eslint-plugin-react-hooks';
|
|
3
|
+
import reactRefresh from 'eslint-plugin-react-refresh';
|
|
4
|
+
import globals from 'globals';
|
|
5
|
+
import { createJsxPropsConfig } from './jsx-props.js';
|
|
6
|
+
/** Shared React core: hooks, refresh, kj barrel/extraction rules, browser globals, JSX prop order. */
|
|
7
|
+
export function createSharedReactConfigs(options) {
|
|
8
|
+
const extractionIgnores = options?.extractionIgnores ?? [
|
|
9
|
+
'**/components/ui/**',
|
|
10
|
+
'**/*.test.tsx',
|
|
11
|
+
'**/*.stories.tsx',
|
|
12
|
+
'**/*.test.ts',
|
|
13
|
+
'**/*.stories.ts',
|
|
14
|
+
];
|
|
15
|
+
const configs = [
|
|
16
|
+
{
|
|
17
|
+
files: ['**/*.{ts,tsx}'],
|
|
18
|
+
languageOptions: {
|
|
19
|
+
globals: {
|
|
20
|
+
...globals.browser,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
plugins: {
|
|
26
|
+
'react-hooks': reactHooks,
|
|
27
|
+
'react-refresh': reactRefresh,
|
|
28
|
+
},
|
|
29
|
+
rules: {
|
|
30
|
+
...reactHooks.configs.recommended.rules,
|
|
31
|
+
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
files: ['**/*.{ts,tsx}'],
|
|
36
|
+
plugins: { kj: kjPlugin },
|
|
37
|
+
rules: {
|
|
38
|
+
'kj/no-single-export-barrel': 'error',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
...componentExtraction({
|
|
42
|
+
ignores: extractionIgnores,
|
|
43
|
+
}),
|
|
44
|
+
];
|
|
45
|
+
if (options?.jsxProps !== false) {
|
|
46
|
+
configs.push(createJsxPropsConfig(options?.jsxProps));
|
|
47
|
+
}
|
|
48
|
+
return configs;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,IAAI,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEtF,OAAO,UAAU,MAAM,2BAA2B,CAAC;AACnD,OAAO,YAAY,MAAM,6BAA6B,CAAC;AACvD,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAE,oBAAoB,EAA4B,MAAM,gBAAgB,CAAC;AAEhF,sGAAsG;AACtG,MAAM,UAAU,wBAAwB,CAAC,OAIxC;IACC,MAAM,iBAAiB,GAAG,OAAO,EAAE,iBAAiB,IAAI;QACtD,qBAAqB;QACrB,eAAe;QACf,kBAAkB;QAClB,cAAc;QACd,iBAAiB;KAClB,CAAC;IAEF,MAAM,OAAO,GAAoB;QAC/B;YACE,KAAK,EAAE,CAAC,eAAe,CAAC;YACxB,eAAe,EAAE;gBACf,OAAO,EAAE;oBACP,GAAG,OAAO,CAAC,OAAO;iBACnB;aACF;SACF;QACD;YACE,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU;gBACzB,eAAe,EAAE,YAAY;aAC9B;YACD,KAAK,EAAE;gBACL,GAAG,UAAU,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK;gBACvC,sCAAsC,EAAE,CAAC,MAAM,EAAE,EAAE,mBAAmB,EAAE,IAAI,EAAE,CAAC;aAChF;SACF;QACD;YACE,KAAK,EAAE,CAAC,eAAe,CAAC;YACxB,OAAO,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE;YACzB,KAAK,EAAE;gBACL,4BAA4B,EAAE,OAAO;aACtC;SACF;QACD,GAAG,mBAAmB,CAAC;YACrB,OAAO,EAAE,iBAAiB;SAC3B,CAAC;KACH,CAAC;IAEF,IAAI,OAAO,EAAE,QAAQ,KAAK,KAAK,EAAE,CAAC;QAChC,OAAO,CAAC,IAAI,CAAC,oBAAoB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,24 +1,89 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kristijorgji/eslint-config-react-typescript",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Flat ESLint React TypeScript config factory (vite | next) on @kristijorgji/eslint-config-typescript",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "kristijorgji",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=22.16.0"
|
|
10
|
+
},
|
|
5
11
|
"publishConfig": {
|
|
6
|
-
"access": "public"
|
|
12
|
+
"access": "public",
|
|
13
|
+
"provenance": true
|
|
7
14
|
},
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
"eslint-config-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"react",
|
|
18
|
-
"typescript",
|
|
19
|
-
"eslint",
|
|
20
|
-
"prettier"
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/kristijorgji/js-devkit.git",
|
|
18
|
+
"directory": "packages/eslint-config-react-typescript"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"README.md",
|
|
23
|
+
"LICENSE"
|
|
21
24
|
],
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@next/eslint-plugin-next": "^15 || ^16",
|
|
34
|
+
"eslint": "^9 || ^10",
|
|
35
|
+
"eslint-plugin-jsx-a11y": "^6",
|
|
36
|
+
"eslint-plugin-react": "^7",
|
|
37
|
+
"eslint-plugin-react-dom": "^1 || ^2",
|
|
38
|
+
"eslint-plugin-react-x": "^1 || ^2",
|
|
39
|
+
"eslint-plugin-storybook": "^0 || ^9 || ^10",
|
|
40
|
+
"prettier": "^3",
|
|
41
|
+
"typescript": "^5 || ^6"
|
|
42
|
+
},
|
|
43
|
+
"peerDependenciesMeta": {
|
|
44
|
+
"@next/eslint-plugin-next": {
|
|
45
|
+
"optional": true
|
|
46
|
+
},
|
|
47
|
+
"eslint-plugin-jsx-a11y": {
|
|
48
|
+
"optional": true
|
|
49
|
+
},
|
|
50
|
+
"eslint-plugin-react": {
|
|
51
|
+
"optional": true
|
|
52
|
+
},
|
|
53
|
+
"eslint-plugin-react-dom": {
|
|
54
|
+
"optional": true
|
|
55
|
+
},
|
|
56
|
+
"eslint-plugin-react-x": {
|
|
57
|
+
"optional": true
|
|
58
|
+
},
|
|
59
|
+
"eslint-plugin-storybook": {
|
|
60
|
+
"optional": true
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"dependencies": {
|
|
64
|
+
"eslint-plugin-perfectionist": "^4.15.0",
|
|
65
|
+
"eslint-plugin-react-hooks": "^5",
|
|
66
|
+
"eslint-plugin-react-refresh": "^0.4",
|
|
67
|
+
"globals": "^17",
|
|
68
|
+
"@kristijorgji/eslint-config-typescript": "^1.1.0",
|
|
69
|
+
"@kristijorgji/eslint-plugin": "^0.2.0"
|
|
70
|
+
},
|
|
71
|
+
"devDependencies": {
|
|
72
|
+
"@next/eslint-plugin-next": "^16",
|
|
73
|
+
"@types/node": "^26",
|
|
74
|
+
"eslint": "^10",
|
|
75
|
+
"eslint-plugin-react": "^7",
|
|
76
|
+
"eslint-plugin-react-dom": "^5",
|
|
77
|
+
"eslint-plugin-react-x": "^5",
|
|
78
|
+
"eslint-plugin-storybook": "^9",
|
|
79
|
+
"prettier": "^3",
|
|
80
|
+
"typescript": "^5",
|
|
81
|
+
"vitest": "^4"
|
|
82
|
+
},
|
|
83
|
+
"scripts": {
|
|
84
|
+
"build": "tsc -p tsconfig.json",
|
|
85
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
86
|
+
"test": "vitest run",
|
|
87
|
+
"test:watch": "vitest"
|
|
88
|
+
}
|
|
89
|
+
}
|
package/index.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
extends: [
|
|
3
|
-
'react-app',
|
|
4
|
-
'eslint:recommended',
|
|
5
|
-
'plugin:@typescript-eslint/recommended',
|
|
6
|
-
'plugin:import/errors',
|
|
7
|
-
'plugin:import/warnings',
|
|
8
|
-
'plugin:import/typescript',
|
|
9
|
-
'plugin:prettier/recommended',
|
|
10
|
-
],
|
|
11
|
-
rules: {
|
|
12
|
-
'prettier/prettier': [
|
|
13
|
-
'error',
|
|
14
|
-
{
|
|
15
|
-
semi: true,
|
|
16
|
-
trailingComma: 'es5',
|
|
17
|
-
singleQuote: true,
|
|
18
|
-
printWidth: 120,
|
|
19
|
-
tabWidth: 4,
|
|
20
|
-
useTabs: false,
|
|
21
|
-
bracketSpacing: true,
|
|
22
|
-
arrowParens: 'avoid',
|
|
23
|
-
endOfLine: "lf"
|
|
24
|
-
},
|
|
25
|
-
],
|
|
26
|
-
'import/no-anonymous-default-export': 'off',
|
|
27
|
-
'@typescript-eslint/ban-ts-comment': 'off',
|
|
28
|
-
'@typescript-eslint/no-non-null-assertion': 'warn',
|
|
29
|
-
'import/order': [
|
|
30
|
-
'error',
|
|
31
|
-
{
|
|
32
|
-
groups: ['builtin', 'external', 'internal', ['parent', 'sibling']],
|
|
33
|
-
pathGroups: [
|
|
34
|
-
{
|
|
35
|
-
pattern: 'react',
|
|
36
|
-
group: 'external',
|
|
37
|
-
position: 'before',
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
pattern: '@/**',
|
|
41
|
-
group: 'external',
|
|
42
|
-
position: 'after',
|
|
43
|
-
},
|
|
44
|
-
],
|
|
45
|
-
pathGroupsExcludedImportTypes: ['react'],
|
|
46
|
-
'newlines-between': 'always',
|
|
47
|
-
alphabetize: {
|
|
48
|
-
order: 'asc',
|
|
49
|
-
caseInsensitive: true,
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
'sort-imports': [
|
|
54
|
-
'error',
|
|
55
|
-
{
|
|
56
|
-
ignoreDeclarationSort: true,
|
|
57
|
-
},
|
|
58
|
-
],
|
|
59
|
-
},
|
|
60
|
-
};
|