@timobechtel/style 1.4.1 → 1.5.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/README.md +30 -0
- package/eslint/react.cjs +21 -0
- package/eslint/rules/base.cjs +2 -0
- package/eslint/rules/import.cjs +8 -0
- package/eslint/rules/react.cjs +90 -0
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -51,6 +51,36 @@ module.exports = {
|
|
|
51
51
|
};
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
+
#### React
|
|
55
|
+
|
|
56
|
+
Also add `require.resolve('@timobechtel/style/eslint/react.cjs')` to the `extends` array.
|
|
57
|
+
|
|
58
|
+
Example config:
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
const { resolve } = require('node:path');
|
|
62
|
+
|
|
63
|
+
const project = resolve(process.cwd(), 'tsconfig.json');
|
|
64
|
+
|
|
65
|
+
module.exports = {
|
|
66
|
+
root: true,
|
|
67
|
+
extends: [
|
|
68
|
+
require.resolve('@timobechtel/style/eslint/core.cjs'),
|
|
69
|
+
require.resolve('@timobechtel/style/eslint/react.cjs'),
|
|
70
|
+
],
|
|
71
|
+
parserOptions: {
|
|
72
|
+
project,
|
|
73
|
+
},
|
|
74
|
+
settings: {
|
|
75
|
+
'import/resolver': {
|
|
76
|
+
typescript: {
|
|
77
|
+
project,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
```
|
|
83
|
+
|
|
54
84
|
Note: You should disable `source.organizeImports` in your VSCode config, as this collides with the `import/order` rule.
|
|
55
85
|
|
|
56
86
|
Add the following to your VSCode config, e.g. `.vscode/settings.json`
|
package/eslint/react.cjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
const { defineConfig } = require('eslint-define-config');
|
|
3
|
+
|
|
4
|
+
module.exports = defineConfig({
|
|
5
|
+
extends: [
|
|
6
|
+
'plugin:react/recommended',
|
|
7
|
+
'plugin:react-hooks/recommended',
|
|
8
|
+
'plugin:import/react',
|
|
9
|
+
'prettier',
|
|
10
|
+
require.resolve('./rules/react.cjs'),
|
|
11
|
+
],
|
|
12
|
+
settings: {
|
|
13
|
+
react: {
|
|
14
|
+
version: 'detect',
|
|
15
|
+
},
|
|
16
|
+
linkComponents: [
|
|
17
|
+
// Components used as alternatives to <a> for linking, eg. <Link to={ url } />
|
|
18
|
+
'Link',
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
});
|
package/eslint/rules/base.cjs
CHANGED
package/eslint/rules/import.cjs
CHANGED
|
@@ -27,5 +27,13 @@ module.exports = defineConfig({
|
|
|
27
27
|
],
|
|
28
28
|
// allow default exports
|
|
29
29
|
'import/no-default-export': 'off',
|
|
30
|
+
/**
|
|
31
|
+
* These are enabled by `import/recommended`, but are better handled by
|
|
32
|
+
* TypeScript and @typescript-eslint.
|
|
33
|
+
*/
|
|
34
|
+
'import/default': 'off',
|
|
35
|
+
'import/export': 'off',
|
|
36
|
+
'import/namespace': 'off',
|
|
37
|
+
'import/no-unresolved': 'off',
|
|
30
38
|
},
|
|
31
39
|
});
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
const { defineConfig } = require('eslint-define-config');
|
|
3
|
+
|
|
4
|
+
module.exports = defineConfig({
|
|
5
|
+
rules: {
|
|
6
|
+
// We should prefer TypeScript over prop-types.
|
|
7
|
+
'react/prop-types': 'off',
|
|
8
|
+
// Disable requiring React to be imported, as this is no longer required.
|
|
9
|
+
'react/react-in-jsx-scope': 'off',
|
|
10
|
+
/**
|
|
11
|
+
* Require an explicit type when using button elements. Prevents common mistakes where `type="button"` is omitted on `<button>` elements.
|
|
12
|
+
*/
|
|
13
|
+
'react/button-has-type': 'error',
|
|
14
|
+
/**
|
|
15
|
+
* Require consistent function type for function components.
|
|
16
|
+
*/
|
|
17
|
+
'react/function-component-definition': 'warn',
|
|
18
|
+
/**
|
|
19
|
+
* Require destructuring and symmetric naming of `useState` hook value and setter variables.
|
|
20
|
+
*/
|
|
21
|
+
'react/hook-use-state': 'warn',
|
|
22
|
+
/**
|
|
23
|
+
* Require consistent boolean attributes notation in JSX.
|
|
24
|
+
*/
|
|
25
|
+
'react/jsx-boolean-value': 'warn',
|
|
26
|
+
/**
|
|
27
|
+
* Disallow unnecessary curly braces in JSX props and children.
|
|
28
|
+
*/
|
|
29
|
+
'react/jsx-curly-brace-presence': [
|
|
30
|
+
'warn',
|
|
31
|
+
{
|
|
32
|
+
props: 'never',
|
|
33
|
+
children: 'ignore',
|
|
34
|
+
propElementValues: 'always',
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
/**
|
|
38
|
+
* Require using shorthand form for React fragments, unless required.
|
|
39
|
+
*/
|
|
40
|
+
'react/jsx-fragments': 'warn',
|
|
41
|
+
/**
|
|
42
|
+
* Prevent problematic leaked values from being rendered.
|
|
43
|
+
*/
|
|
44
|
+
'react/jsx-no-leaked-render': 'error',
|
|
45
|
+
/**
|
|
46
|
+
* Prevents usage of unsafe `target='_blank'`.
|
|
47
|
+
*
|
|
48
|
+
* This rule is a part of `react/recommended`, but modified to
|
|
49
|
+
* enable allowReferrer.
|
|
50
|
+
*/
|
|
51
|
+
'react/jsx-no-target-blank': [
|
|
52
|
+
'error',
|
|
53
|
+
{
|
|
54
|
+
allowReferrer: true,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
/**
|
|
58
|
+
* Disallow empty React fragments.
|
|
59
|
+
*/
|
|
60
|
+
'react/jsx-no-useless-fragment': ['warn', { allowExpressions: true }],
|
|
61
|
+
/**
|
|
62
|
+
* Require the use of PascalCase for user-defined JSX components.
|
|
63
|
+
*/
|
|
64
|
+
'react/jsx-pascal-case': 'warn',
|
|
65
|
+
/**
|
|
66
|
+
* Require props to be sorted alphabetically.
|
|
67
|
+
*/
|
|
68
|
+
'react/jsx-sort-props': [
|
|
69
|
+
'warn',
|
|
70
|
+
{
|
|
71
|
+
// list callbacks after all other props
|
|
72
|
+
callbacksLast: true,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
/**
|
|
76
|
+
* Disallow creating unstable components inside components.
|
|
77
|
+
*/
|
|
78
|
+
'react/no-unstable-nested-components': 'error',
|
|
79
|
+
/**
|
|
80
|
+
* Disallow closing tags for components without children.
|
|
81
|
+
*/
|
|
82
|
+
'react/self-closing-comp': 'warn',
|
|
83
|
+
/**
|
|
84
|
+
* Enforce exhaustive dependencies in `useEffect` and `useCallback` hooks.
|
|
85
|
+
*/
|
|
86
|
+
'react-hooks/exhaustive-deps': 'error',
|
|
87
|
+
// prefer destructuring props
|
|
88
|
+
'react/destructuring-assignment': ['warn', 'always'],
|
|
89
|
+
},
|
|
90
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@timobechtel/style",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"bin",
|
|
@@ -30,6 +30,8 @@
|
|
|
30
30
|
"eslint-define-config": "^2.0.0",
|
|
31
31
|
"eslint-import-resolver-typescript": "^3.6.1",
|
|
32
32
|
"eslint-plugin-import": "^2.29.0",
|
|
33
|
+
"eslint-plugin-react": "^7.33.2",
|
|
34
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
33
35
|
"eslint-plugin-unicorn": "^49.0.0"
|
|
34
36
|
}
|
|
35
37
|
}
|