@codfish/eslint-config 12.0.0 → 12.1.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
@@ -48,8 +48,32 @@ Install the package and required peer dependencies:
48
48
 
49
49
  ```sh
50
50
  npm i -D eslint@9 @codfish/eslint-config
51
+
52
+ # Optionally, you can uninstall plugins or presets you don't need to manage anymore,
53
+ # @codfish/eslint-config includes them all.
54
+ npm uninstall typescript-eslint \
55
+ eslint-config-prettier \
56
+ eslint-plugin-jest \
57
+ eslint-plugin-jsx-a11y \
58
+ eslint-plugin-prettier \
59
+ eslint-plugin-react \
60
+ eslint-plugin-react-hooks \
61
+ eslint-plugin-simple-import-sort \
62
+ eslint-plugin-testing-library \
63
+ eslint-plugin-yml \
64
+ @next/eslint-plugin-next \
65
+ eslint-plugin-next \
66
+ commitlint \
67
+ @commitlint/cli \
68
+ @commitlint/config-conventional
51
69
  ```
52
70
 
71
+ > [!NOTE]
72
+ >
73
+ > Optionally, you can uninstall prettier as well. If you don't have prettier installed already but you want to format
74
+ > other file types (like Markdown, JSON, CSS, etc.), you can install it as a dev dependency: `npm i -D prettier`. Then
75
+ > you can use Prettier to format your non-JS files directly. Eslint will still run Prettier as an ESLint rule.
76
+
53
77
  ## Usage
54
78
 
55
79
  Create an `eslint.config.js` file in your project root:
@@ -255,14 +279,7 @@ preferences.
255
279
  **Prettier is included and runs automatically** through ESLint for JavaScript, TypeScript, JSX, and TSX files using the
256
280
  [built-in configuration](./prettier.js). **You don't need to install or configure Prettier separately** for basic usage.
257
281
 
258
- However, if you want to format other file types (like Markdown, JSON, CSS, or YAML) or run Prettier directly, you can
259
- install it as a dev dependency:
260
-
261
- ```sh
262
- npm i -D prettier
263
- ```
264
-
265
- You can then override the defaults by creating your own Prettier config file, or extend the built-in config:
282
+ You can then override the default config by creating your own Prettier config file, or extend the built-in config:
266
283
 
267
284
  **Option 1: Extend the built-in config (Recommended)**
268
285
 
@@ -322,12 +339,11 @@ npm i -D eslint@9 @codfish/eslint-config prettier-plugin-tailwindcss
322
339
  ```js
323
340
  // prettier.config.js
324
341
 
325
- import codfishPrettier from '@codfish/eslint-config/prettier';
326
- import tailwindcss from 'prettier-plugin-tailwindcss';
342
+ import codfish from '@codfish/eslint-config/prettier';
327
343
 
328
344
  /** @type {import('prettier').Config & import('prettier-plugin-tailwindcss').PluginOptions} */
329
345
  export default {
330
- ...codfishPrettier,
346
+ ...codfish,
331
347
  plugins: ['prettier-plugin-tailwindcss'],
332
348
  tailwindStylesheet: './src/styles/app.css',
333
349
  tailwindFunctions: ['clsx'], // optional
@@ -0,0 +1,3 @@
1
+ declare const _default: import("vite").UserConfig;
2
+ export default _default;
3
+ //# sourceMappingURL=vitest.config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vitest.config.d.ts","sourceRoot":"","sources":["../vitest.config.js"],"names":[],"mappings":""}
package/index.js CHANGED
@@ -20,12 +20,11 @@ const useBuiltinPrettierConfig = !hasLocalConfig('prettier');
20
20
  * Supports TypeScript, React, Jest, Vitest, Prettier, YAML, and Next.js
21
21
  */
22
22
  export default defineConfig([
23
- // Base JavaScript configuration
24
23
  js.configs.recommended,
25
24
 
26
25
  tseslint.configs.recommended,
27
26
 
28
- // Base configuration for all files
27
+ // Base opinionated rules
29
28
  {
30
29
  name: 'codfish/base',
31
30
 
@@ -44,6 +43,20 @@ export default defineConfig([
44
43
  },
45
44
 
46
45
  rules: {
46
+ // Error handling rules to enforce using the Error object
47
+ 'no-throw-literal': 'error',
48
+ 'prefer-promise-reject-errors': 'error',
49
+
50
+ // Asynchronous functions that don’t use await might not need to be asynchronous functions
51
+ // Usually result of refactoring, leads to misunderstanding/misusage
52
+ 'require-await': 'error',
53
+
54
+ // Disallow console statements in regular code (only allowed in test files)
55
+ 'no-console': 'error',
56
+
57
+ // Consolidate your imports
58
+ 'no-duplicate-imports': ['error', { includeExports: false }],
59
+
47
60
  // Custom Grouping: https://github.com/lydell/eslint-plugin-simple-import-sort#custom-grouping
48
61
  // Examples: https://github.com/lydell/eslint-plugin-simple-import-sort/blob/main/examples/.eslintrc.js
49
62
  'simple-import-sort/imports': [
@@ -91,6 +104,36 @@ export default defineConfig([
91
104
  },
92
105
  },
93
106
 
107
+ {
108
+ name: 'codfish/ts-overrides',
109
+
110
+ files: ['**/*.ts', '**/*.tsx'],
111
+
112
+ rules: {
113
+ '@typescript-eslint/no-empty-function': 'off',
114
+ '@typescript-eslint/naming-convention': [
115
+ 'error',
116
+ {
117
+ selector: ['interface', 'typeAlias'],
118
+ format: ['PascalCase'],
119
+ custom: {
120
+ regex: '^I[A-Z]', // prevent prefixing interfaces and type alias declarations with "I"
121
+ match: false,
122
+ },
123
+ },
124
+ ],
125
+ '@typescript-eslint/ban-ts-comment': [
126
+ 'error',
127
+ {
128
+ // If you need to use a ts comment, make sure you have a description.
129
+ 'ts-ignore': 'allow-with-description',
130
+ 'ts-expect-error': 'allow-with-description',
131
+ 'ts-nocheck': 'allow-with-description',
132
+ },
133
+ ],
134
+ },
135
+ },
136
+
94
137
  // Custom ignores
95
138
  {
96
139
  name: 'codfish/ignores',
@@ -146,6 +189,16 @@ export default defineConfig([
146
189
  ymlPlugin.configs['flat/standard'],
147
190
  ymlPlugin.configs['flat/prettier'], // handles conflicting rules with the yml plugin
148
191
 
192
+ {
193
+ name: 'codfish/github-yml-overrides',
194
+
195
+ files: ['.github/**/*.yml', '.github/**/*.yaml'],
196
+
197
+ rules: {
198
+ 'yml/no-empty-mapping-value': 'off', // somewhat common in github workflows
199
+ },
200
+ },
201
+
149
202
  // React configuration (dynamic)
150
203
  ifAnyDep('react', reactConfig, []),
151
204
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codfish/eslint-config",
3
- "version": "12.0.0",
3
+ "version": "12.1.0",
4
4
  "description": "Modern ESLint configuration with TypeScript, React, and testing framework support.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -48,6 +48,9 @@
48
48
  "type-check": "tsc --noEmit",
49
49
  "lint": "eslint .",
50
50
  "fix": "prettier --write \"**/*.{json,css,scss,md}\" --config ./prettier.js && npm run lint -- --fix",
51
+ "test": "vitest",
52
+ "test:watch": "vitest --watch",
53
+ "test:coverage": "vitest --coverage",
51
54
  "prepublishOnly": "npm run build",
52
55
  "prepare": "husky"
53
56
  },
@@ -78,7 +81,8 @@
78
81
  "eslint": "^9.35.0",
79
82
  "husky": "^9.1.7",
80
83
  "lint-staged": "^16.1.6",
81
- "typescript": "^5.9.2"
84
+ "typescript": "^5.9.2",
85
+ "vitest": "^1.0.0"
82
86
  },
83
87
  "engines": {
84
88
  "node": ">=20.0.0"
@@ -94,10 +98,11 @@
94
98
  "commitlint.js"
95
99
  ],
96
100
  "peerDependencies": {
97
- "eslint": ">= 9"
101
+ "eslint": ">= 9",
102
+ "prettier": ">= 3"
98
103
  },
99
104
  "peerDependenciesMeta": {
100
- "typescript": {
105
+ "prettier": {
101
106
  "optional": true
102
107
  }
103
108
  },
package/rules/react.js CHANGED
@@ -38,8 +38,8 @@ export default defineConfig([
38
38
  ifAnyDep(
39
39
  'next',
40
40
  {
41
- ...nextPlugin.flatConfig.recommended,
42
- ...nextPlugin.flatConfig.coreWebVitals,
41
+ ...(nextPlugin?.flatConfig?.recommended || {}),
42
+ ...(nextPlugin?.flatConfig?.coreWebVitals || {}),
43
43
 
44
44
  name: 'codfish/next',
45
45
  },