@codfish/eslint-config 0.0.0-PR-124--8ec70e4 → 0.0.0-PR-124--5ec5040
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 +106 -75
- package/index.js +1 -5
- package/package.json +2 -3
- package/rules/jest.js +0 -1
- package/rules/vitest.js +0 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @codfish/eslint-config
|
|
2
2
|
|
|
3
|
-
> Modern ESLint configuration with TypeScript, React/Next.js,
|
|
4
|
-
>
|
|
3
|
+
> Modern ESLint configuration with TypeScript, React/Next.js, YAML, Testing Library, and testing framework support using
|
|
4
|
+
> ESLint v9+ flat config format.
|
|
5
5
|
|
|
6
6
|
[](http://npm.im/@codfish/eslint-config)
|
|
7
7
|
[](http://npm-stat.com/charts.html?package=@codfish/eslint-config&from=2015-08-01)
|
|
@@ -9,24 +9,23 @@
|
|
|
9
9
|
[](https://github.com/semantic-release/semantic-release)
|
|
10
10
|
[](http://commitizen.github.io/cz-cli/)
|
|
11
11
|
|
|
12
|
+
<!-- prettier-ignore-start -->
|
|
12
13
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
13
14
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
14
15
|
## Table of Contents
|
|
15
16
|
|
|
16
17
|
- [Features](#features)
|
|
17
|
-
- [Automatic Configuration](#automatic-configuration)
|
|
18
|
-
- [Opinionated Highlights](#opinionated-highlights)
|
|
19
18
|
- [Installation](#installation)
|
|
20
19
|
- [Usage](#usage)
|
|
21
|
-
- [
|
|
22
|
-
- [dApps Configuration](#dapps-configuration)
|
|
20
|
+
- [Opinionated Highlights](#opinionated-highlights)
|
|
23
21
|
- [Prettier Configuration](#prettier-configuration)
|
|
22
|
+
- [Use in combination with prettier-plugin-tailwindcss](#use-in-combination-with-prettier-plugin-tailwindcss)
|
|
24
23
|
- [Example scripts](#example-scripts)
|
|
25
24
|
- [Commitlint Configuration](#commitlint-configuration)
|
|
26
|
-
- [Known issues](#known-issues)
|
|
27
25
|
- [Migration from Legacy Config](#migration-from-legacy-config)
|
|
28
26
|
|
|
29
27
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
|
28
|
+
<!-- prettier-ignore-end -->
|
|
30
29
|
|
|
31
30
|
## Features
|
|
32
31
|
|
|
@@ -37,58 +36,12 @@
|
|
|
37
36
|
- **Next.js support**: Automatically configures Next.js official plugin linting rules when detected
|
|
38
37
|
- **Test framework agnostic**: Supports Jest and Vitest with automatic detection
|
|
39
38
|
- **Testing Library integration**: Automatically includes Testing Library rules for test files
|
|
40
|
-
- **Tailwind CSS support**: Automatically configures Tailwind CSS linting when detected
|
|
41
39
|
- **YAML/YML support**: Built-in linting for YAML configuration files
|
|
42
40
|
- **Prettier integration**: Built-in Prettier configuration with conflict resolution via eslint-config-prettier
|
|
43
41
|
- **ESM architecture**: Built with ECMAScript modules and full TypeScript typing
|
|
44
42
|
- **Docker support**: Optional configuration for dockerized applications
|
|
45
43
|
- **Blockchain/dApp support**: Optional configuration for decentralized applications
|
|
46
44
|
|
|
47
|
-
### Automatic Configuration
|
|
48
|
-
|
|
49
|
-
The config automatically detects and configures:
|
|
50
|
-
|
|
51
|
-
- **React**: Includes React, React Hooks, and JSX a11y rules when `react` is installed
|
|
52
|
-
- **Next.js**: Includes Next.js recommended and Core Web Vitals rules when `next` is detected
|
|
53
|
-
- **Jest**: Configures Jest-specific rules when `jest` is found in dependencies
|
|
54
|
-
- **Vitest**: Configures Vitest-specific rules when `vitest` is detected
|
|
55
|
-
- **Testing Library**: Automatically adds Testing Library rules for test files in Jest/Vitest projects
|
|
56
|
-
- **Tailwind CSS**: Includes Tailwind CSS linting rules when `tailwindcss` is detected
|
|
57
|
-
- **YAML files**: Always includes YAML/YML file linting support
|
|
58
|
-
- **Prettier**: Loads your project's Prettier config or falls back to [my defaults](./prettier.js)
|
|
59
|
-
|
|
60
|
-
### Opinionated Highlights
|
|
61
|
-
|
|
62
|
-
This configuration includes some opinionated settings that you might want to customize for your project:
|
|
63
|
-
|
|
64
|
-
**Prettier/Formatting:**
|
|
65
|
-
|
|
66
|
-
- **Semicolons**: Enforces semicolons (`;`)
|
|
67
|
-
- **120 character line width**: Wider than the common 80/100 - you might prefer shorter lines
|
|
68
|
-
- **2-space indentation**: Uses 2 spaces for tabs
|
|
69
|
-
- **Single quotes**: Prefers `'single'` over `"double"` quotes
|
|
70
|
-
- **Trailing commas**: Adds trailing commas everywhere
|
|
71
|
-
- **Arrow parentheses**: Avoids parens around single args (`x => x` not `(x) => x`)
|
|
72
|
-
|
|
73
|
-
**ESLint Rules:**
|
|
74
|
-
|
|
75
|
-
- **Import sorting**: Enforces automatic import organization with specific grouping rules
|
|
76
|
-
- **Lodash restrictions**: Requires direct imports (`import get from 'lodash-es/get'`) instead of full lodash
|
|
77
|
-
- **React hooks deps**: Disables `exhaustive-deps` rule - you might want this stricter
|
|
78
|
-
- **Console statements**: Disallows `console.log` in regular code (only allowed in test files) - some teams prefer
|
|
79
|
-
warnings instead of errors
|
|
80
|
-
- **Next.js rules**: Enforces Next.js best practices and Core Web Vitals optimization
|
|
81
|
-
- **Tailwind class sorting**: Automatically sorts Tailwind classes (can break dynamic class builds - see Known Issues)
|
|
82
|
-
- **Testing Library rules**: Enforces Testing Library best practices in test files
|
|
83
|
-
|
|
84
|
-
**File Ignores:**
|
|
85
|
-
|
|
86
|
-
- Ignores common build directories (`.next`, `coverage`, `.vercel`, etc.)
|
|
87
|
-
- Includes `.github` and `.vitepress` folders (not ignored like most configs)
|
|
88
|
-
|
|
89
|
-
See the [configuration examples below](#usage) for instructions on overriding these settings to match your team's
|
|
90
|
-
preferences.
|
|
91
|
-
|
|
92
45
|
## Installation
|
|
93
46
|
|
|
94
47
|
Install the package and required peer dependencies:
|
|
@@ -122,7 +75,41 @@ export default defineConfig(
|
|
|
122
75
|
> [!IMPORTANT] If you get ES module errors, you may need to set the `type` field in your `package.json` to `module` or
|
|
123
76
|
> rename your config file to `eslint.config.mjs`.
|
|
124
77
|
|
|
125
|
-
|
|
78
|
+
**Using extends and targetting all files:**
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
import codfish from '@codfish/eslint-config';
|
|
82
|
+
|
|
83
|
+
export default defineConfig({
|
|
84
|
+
extends: [codfish],
|
|
85
|
+
rules: {
|
|
86
|
+
// temporary
|
|
87
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**Using extends and targetting specific files:**
|
|
93
|
+
|
|
94
|
+
> [!WARNING]
|
|
95
|
+
>
|
|
96
|
+
> **Not recommended.** This will prevent it from using the `files` specified in the main config, so rules around test
|
|
97
|
+
> files, yml files, etc. will not be applied.
|
|
98
|
+
|
|
99
|
+
```js
|
|
100
|
+
import codfish from '@codfish/eslint-config';
|
|
101
|
+
|
|
102
|
+
export default defineConfig({
|
|
103
|
+
files: ['**/*.{js,jsx,ts,tsx}'],
|
|
104
|
+
extends: [codfish],
|
|
105
|
+
rules: {
|
|
106
|
+
// temporary
|
|
107
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**Not using the `defineConfig` function, just spread the config object:**
|
|
126
113
|
|
|
127
114
|
```js
|
|
128
115
|
import codfish from '@codfish/eslint-config';
|
|
@@ -179,9 +166,6 @@ export default defineConfig(
|
|
|
179
166
|
{
|
|
180
167
|
files: ['**/*.{js,jsx,ts,tsx}'],
|
|
181
168
|
rules: {
|
|
182
|
-
// Customize Tailwind CSS rules
|
|
183
|
-
'tailwindcss/classnames-order': 'warn',
|
|
184
|
-
'tailwindcss/no-custom-classname': 'off',
|
|
185
169
|
// Customize Next.js rules
|
|
186
170
|
'@next/next/no-img-element': 'warn',
|
|
187
171
|
'@next/next/no-html-link-for-pages': 'off',
|
|
@@ -190,7 +174,7 @@ export default defineConfig(
|
|
|
190
174
|
);
|
|
191
175
|
```
|
|
192
176
|
|
|
193
|
-
|
|
177
|
+
**Docker Configuration:**
|
|
194
178
|
|
|
195
179
|
For projects leveraging Docker containers, you may want to disable import resolution errors for `node_modules` if
|
|
196
180
|
packages are only available in the container but you're running the linter locally.
|
|
@@ -209,17 +193,24 @@ export default defineConfig(
|
|
|
209
193
|
);
|
|
210
194
|
```
|
|
211
195
|
|
|
212
|
-
|
|
196
|
+
**dApps Configuration:**
|
|
213
197
|
|
|
214
198
|
For decentralized applications that use build artifacts and blockchain globals, use the specialized dApp config. This
|
|
215
199
|
config will set some globals as well as ignore missing build artifact imports. While you obviously need those to run
|
|
216
200
|
your app, sometimes you might want to run the linter in a ci/cd environment and build artifacts might not be present.
|
|
217
201
|
|
|
218
|
-
You can also directly import the Prettier config:
|
|
219
|
-
|
|
220
202
|
```js
|
|
221
|
-
import
|
|
222
|
-
|
|
203
|
+
import codfish from '@codfish/eslint-config';
|
|
204
|
+
import dapp from '@codfish/eslint-config/dapp';
|
|
205
|
+
|
|
206
|
+
export default defineConfig(
|
|
207
|
+
codfish,
|
|
208
|
+
dapp,
|
|
209
|
+
|
|
210
|
+
{
|
|
211
|
+
// Your app-specific overrides
|
|
212
|
+
},
|
|
213
|
+
);
|
|
223
214
|
```
|
|
224
215
|
|
|
225
216
|
The dApp configuration provides:
|
|
@@ -228,6 +219,37 @@ The dApp configuration provides:
|
|
|
228
219
|
- Import resolution handling for smart contract build artifacts
|
|
229
220
|
- Relaxed rules for generated contract files
|
|
230
221
|
|
|
222
|
+
### Opinionated Highlights
|
|
223
|
+
|
|
224
|
+
This configuration includes some opinionated settings that you might want to customize for your project:
|
|
225
|
+
|
|
226
|
+
**Prettier/Formatting:**
|
|
227
|
+
|
|
228
|
+
- **Semicolons**: Enforces semicolons (`;`)
|
|
229
|
+
- **120 character line width**: Wider than the common 80/100 - you might prefer shorter lines
|
|
230
|
+
- **2-space indentation**: Uses 2 spaces for tabs
|
|
231
|
+
- **Single quotes**: Prefers `'single'` over `"double"` quotes
|
|
232
|
+
- **Trailing commas**: Adds trailing commas everywhere
|
|
233
|
+
- **Arrow parentheses**: Avoids parens around single args (`x => x` not `(x) => x`)
|
|
234
|
+
|
|
235
|
+
**ESLint Rules:**
|
|
236
|
+
|
|
237
|
+
- **Import sorting**: Enforces automatic import organization with specific grouping rules
|
|
238
|
+
- **Lodash restrictions**: Requires direct imports (`import get from 'lodash-es/get'`) instead of full lodash
|
|
239
|
+
- **React hooks deps**: Disables `exhaustive-deps` rule - you might want this stricter
|
|
240
|
+
- **Console statements**: Disallows `console.log` in regular code (only allowed in test files) - some teams prefer
|
|
241
|
+
warnings instead of errors
|
|
242
|
+
- **Next.js rules**: Enforces Next.js best practices and Core Web Vitals optimization
|
|
243
|
+
- **Testing Library rules**: Enforces Testing Library best practices in test files
|
|
244
|
+
|
|
245
|
+
**File Ignores:**
|
|
246
|
+
|
|
247
|
+
- Ignores common build directories (`.next`, `coverage`, `.vercel`, etc.)
|
|
248
|
+
- Includes `.github` and `.vitepress` folders (not ignored like most configs)
|
|
249
|
+
|
|
250
|
+
See the [configuration examples below](#usage) for instructions on overriding these settings to match your team's
|
|
251
|
+
preferences.
|
|
252
|
+
|
|
231
253
|
## Prettier Configuration
|
|
232
254
|
|
|
233
255
|
**Prettier is included and runs automatically** through ESLint for JavaScript, TypeScript, JSX, and TSX files using the
|
|
@@ -291,6 +313,27 @@ export default {
|
|
|
291
313
|
};
|
|
292
314
|
```
|
|
293
315
|
|
|
316
|
+
### Use in combination with prettier-plugin-tailwindcss
|
|
317
|
+
|
|
318
|
+
```sh
|
|
319
|
+
npm i -D eslint@9 @codfish/eslint-config prettier-plugin-tailwindcss
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
```js
|
|
323
|
+
// prettier.config.js
|
|
324
|
+
|
|
325
|
+
import codfishPrettier from '@codfish/eslint-config/prettier';
|
|
326
|
+
import tailwindcss from 'prettier-plugin-tailwindcss';
|
|
327
|
+
|
|
328
|
+
/** @type {import('prettier').Config & import('prettier-plugin-tailwindcss').PluginOptions} */
|
|
329
|
+
export default {
|
|
330
|
+
...codfishPrettier,
|
|
331
|
+
plugins: ['prettier-plugin-tailwindcss'],
|
|
332
|
+
tailwindStylesheet: './src/styles/app.css',
|
|
333
|
+
tailwindFunctions: ['clsx'], // optional
|
|
334
|
+
};
|
|
335
|
+
```
|
|
336
|
+
|
|
294
337
|
## Example scripts
|
|
295
338
|
|
|
296
339
|
Optionally, you can add these scripts to your `package.json` for common linting workflows:
|
|
@@ -388,18 +431,6 @@ jobs:
|
|
|
388
431
|
--verbose
|
|
389
432
|
```
|
|
390
433
|
|
|
391
|
-
## Known issues
|
|
392
|
-
|
|
393
|
-
> https://github.com/francoismassart/eslint-plugin-tailwindcss/issues/149
|
|
394
|
-
|
|
395
|
-
When building dynamic classes, the auto sorting of tailwind classes can break things so beware.
|
|
396
|
-
|
|
397
|
-
To avoid this happening you can re-wrap the dynamic class expression like so:
|
|
398
|
-
|
|
399
|
-
```vue-html
|
|
400
|
-
class="`p-0 ${`tw-border-${accentColor}`}`"
|
|
401
|
-
```
|
|
402
|
-
|
|
403
434
|
## Migration from Legacy Config
|
|
404
435
|
|
|
405
436
|
If you're upgrading from an older version that used Airbnb presets:
|
package/index.js
CHANGED
|
@@ -2,7 +2,6 @@ import js from '@eslint/js';
|
|
|
2
2
|
import { defineConfig } from 'eslint/config';
|
|
3
3
|
import prettier from 'eslint-plugin-prettier/recommended';
|
|
4
4
|
import simpleImportSortPlugin from 'eslint-plugin-simple-import-sort';
|
|
5
|
-
import tailwindPlugin from 'eslint-plugin-tailwindcss';
|
|
6
5
|
import ymlPlugin from 'eslint-plugin-yml';
|
|
7
6
|
import globals from 'globals';
|
|
8
7
|
import tseslint from 'typescript-eslint';
|
|
@@ -18,7 +17,7 @@ const useBuiltinPrettierConfig = !hasLocalConfig('prettier');
|
|
|
18
17
|
|
|
19
18
|
/**
|
|
20
19
|
* Modern ESLint configuration with dynamic feature detection
|
|
21
|
-
* Supports TypeScript, React, Jest, Vitest, Prettier, YAML,
|
|
20
|
+
* Supports TypeScript, React, Jest, Vitest, Prettier, YAML, and Next.js
|
|
22
21
|
*/
|
|
23
22
|
export default defineConfig([
|
|
24
23
|
// Base JavaScript configuration
|
|
@@ -150,9 +149,6 @@ export default defineConfig([
|
|
|
150
149
|
// React configuration (dynamic)
|
|
151
150
|
ifAnyDep('react', reactConfig, []),
|
|
152
151
|
|
|
153
|
-
// Tailwind CSS configuration (dynamic)
|
|
154
|
-
ifAnyDep('tailwindcss', tailwindPlugin.configs['flat/recommended'], []),
|
|
155
|
-
|
|
156
152
|
// Jest OR Vitest configuration (dynamic)
|
|
157
153
|
ifAnyDep('jest', jestConfig, []),
|
|
158
154
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codfish/eslint-config",
|
|
3
|
-
"version": "0.0.0-PR-124--
|
|
3
|
+
"version": "0.0.0-PR-124--5ec5040",
|
|
4
4
|
"description": "Modern ESLint configuration with TypeScript, React, and testing framework support.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"dev": "tsc --watch",
|
|
48
48
|
"type-check": "tsc --noEmit",
|
|
49
49
|
"lint": "eslint .",
|
|
50
|
-
"fix": "prettier --write \"**/*.{json,css,scss,md}\" && npm run lint -- --fix",
|
|
50
|
+
"fix": "prettier --write \"**/*.{json,css,scss,md}\" --config ./prettier.js && npm run lint -- --fix",
|
|
51
51
|
"prepublishOnly": "npm run build",
|
|
52
52
|
"prepare": "husky"
|
|
53
53
|
},
|
|
@@ -64,7 +64,6 @@
|
|
|
64
64
|
"eslint-plugin-react": "^7.37.5",
|
|
65
65
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
66
66
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
67
|
-
"eslint-plugin-tailwindcss": "^3.18.2",
|
|
68
67
|
"eslint-plugin-testing-library": "^7.1.0",
|
|
69
68
|
"eslint-plugin-yml": "^1.16.0",
|
|
70
69
|
"@next/eslint-plugin-next": "^15.1.6",
|
package/rules/jest.js
CHANGED