@timobechtel/style 1.4.1 → 1.6.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/core.cjs +10 -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/eslint/rules/typescript.cjs +7 -0
- package/package.json +17 -15
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/core.cjs
CHANGED
|
@@ -45,5 +45,15 @@ module.exports = defineConfig({
|
|
|
45
45
|
require.resolve('./rules/typescript.cjs'),
|
|
46
46
|
],
|
|
47
47
|
},
|
|
48
|
+
{
|
|
49
|
+
files: ['*.test.ts?(x)', '*.spec.ts?(x)'],
|
|
50
|
+
rules: {
|
|
51
|
+
// ts-expect-error makes sense for tests
|
|
52
|
+
'@typescript-eslint/ban-ts-comment': [
|
|
53
|
+
'off',
|
|
54
|
+
{ 'ts-expect-error': 'off' },
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
},
|
|
48
58
|
],
|
|
49
59
|
});
|
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
|
+
});
|
|
@@ -95,5 +95,12 @@ module.exports = defineConfig({
|
|
|
95
95
|
// While I'd prefer using types over interfaces, there are a lot of cases
|
|
96
96
|
// where interfaces are needed, e.g. merging declarations and this rule is too strict.
|
|
97
97
|
'@typescript-eslint/consistent-type-definitions': 'off',
|
|
98
|
+
// while using property signatures provides better typechecking,
|
|
99
|
+
// method signatures provide better hinting in the editor.
|
|
100
|
+
// (different color for methods vs properties)
|
|
101
|
+
'@typescript-eslint/method-signature-style': 'off',
|
|
102
|
+
// There are cases where using the index signature is more descriptive
|
|
103
|
+
// as the index can be named
|
|
104
|
+
'@typescript-eslint/consistent-indexed-object-style': 'off',
|
|
98
105
|
},
|
|
99
106
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@timobechtel/style",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"bin",
|
|
@@ -10,26 +10,28 @@
|
|
|
10
10
|
"tsconfig"
|
|
11
11
|
],
|
|
12
12
|
"devDependencies": {
|
|
13
|
-
"eslint": "^8.
|
|
14
|
-
"prettier": "^3.
|
|
15
|
-
"semantic-release": "^
|
|
16
|
-
"typescript": "^5.3
|
|
13
|
+
"eslint": "^8.57.0",
|
|
14
|
+
"prettier": "^3.2.5",
|
|
15
|
+
"semantic-release": "^23.0.5",
|
|
16
|
+
"typescript": "^5.4.3"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
|
-
"eslint": "^8.
|
|
20
|
-
"prettier": "^3.
|
|
21
|
-
"semantic-release": "^
|
|
22
|
-
"typescript": "^5.3
|
|
19
|
+
"eslint": "^8.57.0",
|
|
20
|
+
"prettier": "^3.2.5",
|
|
21
|
+
"semantic-release": "^23.0.5",
|
|
22
|
+
"typescript": "^5.4.3"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@semantic-release/changelog": "^6.0.3",
|
|
26
26
|
"@semantic-release/git": "^10.0.1",
|
|
27
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
28
|
-
"@typescript-eslint/parser": "^
|
|
29
|
-
"eslint-config-prettier": "^9.
|
|
30
|
-
"eslint-define-config": "^2.
|
|
27
|
+
"@typescript-eslint/eslint-plugin": "^7.3.1",
|
|
28
|
+
"@typescript-eslint/parser": "^7.3.1",
|
|
29
|
+
"eslint-config-prettier": "^9.1.0",
|
|
30
|
+
"eslint-define-config": "^2.1.0",
|
|
31
31
|
"eslint-import-resolver-typescript": "^3.6.1",
|
|
32
|
-
"eslint-plugin-import": "^2.29.
|
|
33
|
-
"eslint-plugin-
|
|
32
|
+
"eslint-plugin-import": "^2.29.1",
|
|
33
|
+
"eslint-plugin-react": "^7.34.1",
|
|
34
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
35
|
+
"eslint-plugin-unicorn": "^51.0.1"
|
|
34
36
|
}
|
|
35
37
|
}
|