@timobechtel/style 1.4.0 → 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 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`
@@ -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
+ });
@@ -78,5 +78,7 @@ module.exports = defineConfig({
78
78
  varsIgnorePattern: '^_',
79
79
  },
80
80
  ],
81
+ // Disallow expressions where the operation doesn't affect the value
82
+ 'no-constant-binary-expression': 'error',
81
83
  },
82
84
  });
@@ -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.4.0",
3
+ "version": "1.5.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.53.0",
14
- "prettier": "^3.0.3",
15
- "semantic-release": "^22.0.7",
16
- "typescript": "^5.2.2"
13
+ "eslint": "^8.54.0",
14
+ "prettier": "^3.1.0",
15
+ "semantic-release": "^22.0.8",
16
+ "typescript": "^5.3.2"
17
17
  },
18
18
  "peerDependencies": {
19
- "eslint": "^8.53.0",
20
- "prettier": "^3.0.3",
21
- "semantic-release": "^22.0.7",
22
- "typescript": "^5.2.2"
19
+ "eslint": "^8.54.0",
20
+ "prettier": "^3.1.0",
21
+ "semantic-release": "^22.0.8",
22
+ "typescript": "^5.3.2"
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": "^6.10.0",
28
- "@typescript-eslint/parser": "^6.10.0",
27
+ "@typescript-eslint/eslint-plugin": "^6.12.0",
28
+ "@typescript-eslint/parser": "^6.12.0",
29
29
  "eslint-config-prettier": "^9.0.0",
30
- "eslint-define-config": "^1.24.1",
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
  }