js-style-kit 0.5.3 → 0.6.1
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 +169 -357
- package/dist/index.d.ts +4 -1
- package/dist/index.js +84 -87
- package/dist/index.js.map +1 -1
- package/package.json +33 -32
package/README.md
CHANGED
|
@@ -7,49 +7,21 @@ A zero-configuration style guide for ESLint and Prettier that provides sensible
|
|
|
7
7
|
[](https://www.npmjs.com/package/js-style-kit)
|
|
8
8
|
[](https://opensource.org/licenses/MIT)
|
|
9
9
|
[](https://codecov.io/gh/drake-nathan/js-style-kit)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
- ✅
|
|
17
|
-
- ✅
|
|
18
|
-
- ✅
|
|
19
|
-
- ✅
|
|
20
|
-
|
|
21
|
-
### Configs Included
|
|
22
|
-
|
|
23
|
-
> **Note:** All configs are optional and can be disabled or configured.
|
|
24
|
-
|
|
25
|
-
- ESlint
|
|
26
|
-
- Base config - Tweaked version of "recommended" config
|
|
27
|
-
- typescript-eslint - Falls somewhere between "recommended" and "strict"
|
|
28
|
-
- eslint-plugin-perfectionist - automatically sort all imports, objects, props, etc.
|
|
29
|
-
- eslint-plugin-import-x - faster version of eslint-plugin-import
|
|
30
|
-
- eslint-plugin-unicorn - enforce consistent file names (kebab-case will save you so many headaches)
|
|
31
|
-
- eslint-plugin-react - React rules
|
|
32
|
-
- eslint-plugin-react-hooks - React hooks rules
|
|
33
|
-
- eslint-plugin-react-refresh - React Fast Refresh validation for Vite
|
|
34
|
-
- eslint-plugin-nextjs - Next.js rules
|
|
35
|
-
- eslint-plugin-storybook - Storybook rules
|
|
36
|
-
- eslint-plugin-turbo - Turborepo rules
|
|
37
|
-
- eslint-plugin-jest - Jest rules
|
|
38
|
-
- eslint-plugin-vitest - Vitest rules
|
|
39
|
-
- Prettier
|
|
40
|
-
- Default config
|
|
41
|
-
- prettier-plugin-css-order
|
|
42
|
-
- prettier-plugin-curly
|
|
43
|
-
- prettier-plugin-packagejson
|
|
44
|
-
- prettier-plugin-sort-json
|
|
45
|
-
- prettier-plugin-tailwindcss
|
|
46
|
-
|
|
47
|
-
> **Note:** This is very much a work in progress. I want to know what configuration changes you make, so please open an issue!
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- ✅ **Batteries included** - ESLint, Prettier, and all plugins bundled (no peer dependency headaches)
|
|
14
|
+
- ✅ **ESLint v9** flat config format
|
|
15
|
+
- ✅ **TypeScript** first with automatic project detection
|
|
16
|
+
- ✅ **Framework support** - React, Next.js, Vite, Remix, React Router
|
|
17
|
+
- ✅ **Auto-sorting** - Imports, objects, properties, and more
|
|
18
|
+
- ✅ **Smart defaults** - All rules configured as warnings (not errors)
|
|
19
|
+
- ✅ **Highly configurable** - Enable only what you need, what you don't use is left out of the config for efficiency
|
|
20
|
+
- ✅ **ESM-only** - For modern JavaScript projects
|
|
48
21
|
|
|
49
22
|
## Requirements
|
|
50
23
|
|
|
51
24
|
- Node.js v20.11.0 or higher
|
|
52
|
-
- TypeScript (for TypeScript projects, not bundled)
|
|
53
25
|
|
|
54
26
|
## Installation
|
|
55
27
|
|
|
@@ -63,426 +35,266 @@ pnpm add js-style-kit --save-dev
|
|
|
63
35
|
bun add js-style-kit --dev
|
|
64
36
|
```
|
|
65
37
|
|
|
66
|
-
##
|
|
67
|
-
|
|
68
|
-
### ESLint Usage
|
|
38
|
+
## Quick Start
|
|
69
39
|
|
|
70
|
-
|
|
40
|
+
### Option 1: CLI (Recommended)
|
|
71
41
|
|
|
72
|
-
|
|
73
|
-
import { eslintConfig } from "js-style-kit";
|
|
42
|
+
The fastest way to get started is with our CLI tool:
|
|
74
43
|
|
|
75
|
-
|
|
44
|
+
```bash
|
|
45
|
+
npx js-style-kit init
|
|
76
46
|
```
|
|
77
47
|
|
|
78
|
-
|
|
48
|
+
This will:
|
|
79
49
|
|
|
80
|
-
|
|
50
|
+
1. Install dependencies
|
|
51
|
+
2. Create `style-kit.config.js`, `eslint.config.js`, and `prettier.config.js`
|
|
52
|
+
3. Add npm scripts to your `package.json`
|
|
53
|
+
4. Configure VS Code settings
|
|
81
54
|
|
|
82
|
-
|
|
83
|
-
{
|
|
84
|
-
"scripts": {
|
|
85
|
-
"lint": "eslint . --max-warnings 0",
|
|
86
|
-
"lint:fix": "eslint . --fix --max-warnings 0"
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
```
|
|
55
|
+
[→ Learn more about the CLI](./bin/README.md)
|
|
90
56
|
|
|
91
|
-
|
|
57
|
+
### Option 2: Manual Setup
|
|
92
58
|
|
|
93
|
-
|
|
59
|
+
#### ESLint
|
|
94
60
|
|
|
95
|
-
|
|
61
|
+
Create `eslint.config.js` (or `eslint.config.mjs` if not using `"type": "module"`):
|
|
96
62
|
|
|
97
63
|
```js
|
|
64
|
+
// @ts-check
|
|
98
65
|
import { eslintConfig } from "js-style-kit";
|
|
99
66
|
|
|
100
|
-
export default eslintConfig(
|
|
101
|
-
// All options shown with their default values
|
|
102
|
-
functionStyle: "arrow", // Controls function style: "arrow", "declaration", "expression", or "off"
|
|
103
|
-
ignores: [], // Additional paths to ignore (node_modules and dist already excluded)
|
|
104
|
-
importPlugin: true, // Whether to include import plugin rules
|
|
105
|
-
jsdoc: { requireJsdoc: false }, // JSDoc configuration or false to disable
|
|
106
|
-
react: false, // Whether to include React rules, see below for options
|
|
107
|
-
rules: {}, // Custom rules to override or configure specific ESLint rules
|
|
108
|
-
sorting: true, // Whether to include sorting rules from Perfectionist
|
|
109
|
-
storybook: false, // Whether to include Storybook rules
|
|
110
|
-
testing: {
|
|
111
|
-
/* see Testing Configuration section */
|
|
112
|
-
}, // Testing configuration or false to disable
|
|
113
|
-
turbo: false, // Whether to include Turborepo rules
|
|
114
|
-
typescript: true, // Boolean or string path to tsconfig.json
|
|
115
|
-
unicorn: true, // Whether to include Unicorn rules
|
|
116
|
-
});
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
#### Function Style Configuration
|
|
120
|
-
|
|
121
|
-
Controls how functions should be written. Some configurations are auto-fixable, but some require manual adjustment.
|
|
122
|
-
|
|
123
|
-
```js
|
|
124
|
-
// Enforce arrow functions (default)
|
|
125
|
-
functionStyle: "arrow";
|
|
126
|
-
|
|
127
|
-
// Enforce function declarations
|
|
128
|
-
functionStyle: "declaration";
|
|
129
|
-
|
|
130
|
-
// Enforce function expressions
|
|
131
|
-
functionStyle: "expression";
|
|
132
|
-
|
|
133
|
-
// Disable function style enforcement
|
|
134
|
-
functionStyle: "off";
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
#### TypeScript Configuration
|
|
138
|
-
|
|
139
|
-
TypeScript support is enabled by default. You can:
|
|
140
|
-
|
|
141
|
-
```js
|
|
142
|
-
// Enable with automatic project detection
|
|
143
|
-
typescript: true;
|
|
144
|
-
|
|
145
|
-
// Disable TypeScript rules
|
|
146
|
-
typescript: false;
|
|
147
|
-
|
|
148
|
-
// Specify path to your tsconfig.json
|
|
149
|
-
typescript: "./tsconfig.json";
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
#### Import Plugin Configuration
|
|
153
|
-
|
|
154
|
-
The import plugin rules are enabled by default. These rules help maintain proper import/export syntax and detect issues with imports.
|
|
155
|
-
|
|
156
|
-
```js
|
|
157
|
-
// Enable import plugin (default)
|
|
158
|
-
importPlugin: true;
|
|
159
|
-
|
|
160
|
-
// Disable import plugin
|
|
161
|
-
importPlugin: false;
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
#### Custom Rules Configuration
|
|
165
|
-
|
|
166
|
-
You can override or configure specific ESLint rules using the `rules` option:
|
|
167
|
-
|
|
168
|
-
```js
|
|
169
|
-
// Add custom rule configurations
|
|
170
|
-
rules: {
|
|
171
|
-
// Format is the same as standard ESLint rule configuration
|
|
172
|
-
"no-console": ["error", { allow: ["warn", "error"] }],
|
|
173
|
-
"@typescript-eslint/no-explicit-any": "off",
|
|
174
|
-
// Any valid ESLint rule can be configured here
|
|
175
|
-
}
|
|
67
|
+
export default eslintConfig();
|
|
176
68
|
```
|
|
177
69
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
React support is disabled by default.
|
|
70
|
+
Add scripts to `package.json`:
|
|
181
71
|
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
reactRefresh: false, // Controls React Fast Refresh validation
|
|
189
|
-
framework: "next" // "next", "vite", "none", "remix", or "react-router" to control related configurations
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"scripts": {
|
|
75
|
+
"lint": "eslint . --max-warnings=0 --cache",
|
|
76
|
+
"lint:fix": "eslint . --fix --max-warnings=0 --cache"
|
|
77
|
+
}
|
|
190
78
|
}
|
|
191
|
-
// Using the framework option configures related features:
|
|
192
|
-
// - "next": Includes Next.js config, excludes React Refresh by default
|
|
193
|
-
// - "vite" or "none": Includes React Refresh by default, excludes Next.js
|
|
194
|
-
// - "remix" or "react-router": Excludes both Next.js and React Refresh (these frameworks handle their own refresh logic)
|
|
195
|
-
// - The reactRefresh property can override the framework-based behavior
|
|
196
79
|
```
|
|
197
80
|
|
|
198
|
-
|
|
81
|
+
> **Note:** The `--max-warnings=0` flag is important since all rules are warnings by default.
|
|
199
82
|
|
|
200
|
-
|
|
83
|
+
#### Prettier
|
|
201
84
|
|
|
202
|
-
|
|
203
|
-
// Disable testing rules
|
|
204
|
-
testing: false;
|
|
205
|
-
|
|
206
|
-
// Customize testing rules
|
|
207
|
-
testing: {
|
|
208
|
-
filenamePattern: "test", // "test" or "spec" for filename patterns
|
|
209
|
-
files: ["**/*.{test,spec}.{ts,tsx,js,jsx}"], // File patterns to match
|
|
210
|
-
formattingRules: true, // Whether to include formatting rules
|
|
211
|
-
framework: "vitest", // "vitest" or "jest"
|
|
212
|
-
itOrTest: "it", // Whether to use "it" or "test" as the test function
|
|
213
|
-
};
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
#### JSDoc Configuration
|
|
217
|
-
|
|
218
|
-
JSDoc validation is enabled by default, but requirement rules are off:
|
|
85
|
+
Create `prettier.config.js` (or `prettier.config.mjs` if not using `"type": "module"`):
|
|
219
86
|
|
|
220
87
|
```js
|
|
221
|
-
//
|
|
222
|
-
|
|
88
|
+
// @ts-check
|
|
89
|
+
import { prettierConfig } from "js-style-kit";
|
|
223
90
|
|
|
224
|
-
|
|
225
|
-
jsdoc: {
|
|
226
|
-
requireJsdoc: true;
|
|
227
|
-
}
|
|
91
|
+
export default prettierConfig();
|
|
228
92
|
```
|
|
229
93
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
Testing support is enabled by default with Vitest configuration. You can customize it or disable it completely:
|
|
94
|
+
Add scripts to `package.json`:
|
|
233
95
|
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
filenamePattern: "spec", // "test" (.test, default) or "spec" (.spec)
|
|
241
|
-
files: ["**/*.{test,spec}.{ts,tsx,js,jsx}"], // Override file patterns
|
|
242
|
-
formattingRules: true, // Whether to include formatting rules like padding around blocks
|
|
243
|
-
framework: "vitest", // "vitest" (default), "jest", "node", or "bun"
|
|
244
|
-
itOrTest: "test", // "it" (default) or "test"
|
|
96
|
+
```json
|
|
97
|
+
{
|
|
98
|
+
"scripts": {
|
|
99
|
+
"format": "prettier . --write --cache",
|
|
100
|
+
"format:check": "prettier . --check --cache"
|
|
101
|
+
}
|
|
245
102
|
}
|
|
246
103
|
```
|
|
247
104
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
Sorting/organization rules from the Perfectionist plugin are enabled by default:
|
|
251
|
-
|
|
252
|
-
```js
|
|
253
|
-
// Disable sorting rules
|
|
254
|
-
sorting: false;
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
#### Storybook Configuration
|
|
105
|
+
## Configuration
|
|
258
106
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
```js
|
|
262
|
-
// Enable Storybook rules
|
|
263
|
-
storybook: true;
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
When enabled, this configuration:
|
|
267
|
-
|
|
268
|
-
- Applies best practices for Storybook files (_.stories._ and _.story._)
|
|
269
|
-
- Includes rules for Storybook configuration files (.storybook/main.\*)
|
|
270
|
-
- Ensures the .storybook directory is not ignored by ESLint (adds a negation pattern to ignores)
|
|
271
|
-
|
|
272
|
-
### Adding Custom ESLint Configurations
|
|
273
|
-
|
|
274
|
-
You can extend the base configuration by providing additional ESLint config objects as rest parameters:
|
|
107
|
+
### ESLint Options
|
|
275
108
|
|
|
276
109
|
```js
|
|
277
110
|
import { eslintConfig } from "js-style-kit";
|
|
278
111
|
|
|
279
112
|
export default eslintConfig(
|
|
280
113
|
{
|
|
281
|
-
//
|
|
282
|
-
typescript:
|
|
283
|
-
react:
|
|
114
|
+
// Core options
|
|
115
|
+
typescript: true, // Boolean or path to tsconfig.json
|
|
116
|
+
react: false, // React support (see React config docs)
|
|
117
|
+
functionStyle: "arrow", // "arrow" | "declaration" | "expression" | "off"
|
|
118
|
+
|
|
119
|
+
// Plugin toggles
|
|
120
|
+
importPlugin: true, // Import/export validation
|
|
121
|
+
sorting: true, // Auto-sort imports, objects, etc.
|
|
122
|
+
unicorn: true, // Enforce file naming and best practices
|
|
123
|
+
jsdoc: { requireJsdoc: false }, // JSDoc validation
|
|
124
|
+
|
|
125
|
+
// Framework & tools
|
|
126
|
+
query: false, // TanStack Query rules
|
|
127
|
+
testing: { framework: "vitest" }, // Test framework config
|
|
128
|
+
storybook: false, // Storybook rules
|
|
129
|
+
turbo: false, // Turborepo rules
|
|
130
|
+
|
|
131
|
+
// Advanced
|
|
132
|
+
ignores: [], // Additional ignore patterns
|
|
133
|
+
rules: {}, // Custom rule overrides
|
|
284
134
|
},
|
|
285
|
-
// Additional
|
|
135
|
+
// Additional ESLint config objects
|
|
286
136
|
{
|
|
287
137
|
name: "custom-globals",
|
|
288
138
|
languageOptions: {
|
|
289
139
|
globals: {
|
|
290
140
|
process: "readonly",
|
|
291
|
-
__dirname: "readonly",
|
|
292
141
|
},
|
|
293
142
|
},
|
|
294
143
|
},
|
|
295
|
-
{
|
|
296
|
-
name: "custom-rules",
|
|
297
|
-
rules: {
|
|
298
|
-
// Override or add specific rules
|
|
299
|
-
"no-console": ["error", { allow: ["warn", "error"] }],
|
|
300
|
-
"max-len": ["warn", { code: 100 }],
|
|
301
|
-
quotes: ["error", "single"],
|
|
302
|
-
},
|
|
303
|
-
},
|
|
304
|
-
// Add as many additional configs as needed
|
|
305
144
|
);
|
|
306
145
|
```
|
|
307
146
|
|
|
308
|
-
|
|
147
|
+
### Configuration Guides
|
|
309
148
|
|
|
310
|
-
|
|
149
|
+
Each configuration has detailed documentation:
|
|
311
150
|
|
|
312
|
-
|
|
151
|
+
- **Core Configs**
|
|
152
|
+
- [Base ESLint Rules](./src/eslint/base/README.md)
|
|
153
|
+
- [TypeScript](./src/eslint/typescript/README.md)
|
|
154
|
+
- [Sorting (Perfectionist)](./src/eslint/perfectionist/README.md)
|
|
155
|
+
- [Import Plugin](./src/eslint/import/README.md)
|
|
156
|
+
- [Unicorn](./src/eslint/unicorn/README.md)
|
|
313
157
|
|
|
314
|
-
|
|
315
|
-
|
|
158
|
+
- **Framework Configs**
|
|
159
|
+
- [React](./src/eslint/react/README.md) - React, hooks, compiler, and refresh support
|
|
160
|
+
- [TanStack Query](./src/eslint/query/README.md) - Query best practices
|
|
316
161
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
Setup your `package.json` commands:
|
|
162
|
+
- **Tool Configs**
|
|
163
|
+
- [Testing](./src/eslint/testing/README.md) - Vitest, Jest, Bun, Node
|
|
164
|
+
- [JSDoc](./src/eslint/jsdoc/README.md) - Documentation validation
|
|
165
|
+
- [Storybook](./src/eslint/storybook/README.md) - Component story rules
|
|
166
|
+
- [Turborepo](./src/eslint/turbo/README.md) - Monorepo rules
|
|
323
167
|
|
|
324
|
-
|
|
325
|
-
{
|
|
326
|
-
"scripts": {
|
|
327
|
-
"format": "prettier --write .",
|
|
328
|
-
"format:check": "prettier --check ." // run this one in your CI
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
### Prettier Configuration
|
|
334
|
-
|
|
335
|
-
The `prettierConfig()` function accepts a configuration object with the following options:
|
|
168
|
+
### Prettier Options
|
|
336
169
|
|
|
337
170
|
```js
|
|
338
171
|
import { prettierConfig } from "js-style-kit";
|
|
339
172
|
|
|
340
173
|
export default prettierConfig({
|
|
341
|
-
//
|
|
342
|
-
cssOrderPlugin: true, //
|
|
343
|
-
curlyPlugin: true, //
|
|
344
|
-
jsonSortPlugin: true, //
|
|
345
|
-
packageJsonPlugin: true, //
|
|
346
|
-
tailwindPlugin: false, //
|
|
347
|
-
|
|
348
|
-
|
|
174
|
+
// Plugin options
|
|
175
|
+
cssOrderPlugin: true, // Sort CSS properties
|
|
176
|
+
curlyPlugin: true, // Enforce curly braces
|
|
177
|
+
jsonSortPlugin: true, // Sort JSON keys
|
|
178
|
+
packageJsonPlugin: true, // Sort package.json
|
|
179
|
+
tailwindPlugin: false, // Boolean, path to global css file, or config object
|
|
180
|
+
parser: "oxc", // "oxc" (faster) or "default"
|
|
181
|
+
|
|
182
|
+
// Standard Prettier options
|
|
349
183
|
printWidth: 80,
|
|
350
184
|
tabWidth: 2,
|
|
351
|
-
//
|
|
185
|
+
// ... any Prettier option
|
|
352
186
|
});
|
|
353
187
|
```
|
|
354
188
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
Tailwind CSS formatting is disabled by default. You can enable it in different ways:
|
|
358
|
-
|
|
359
|
-
```js
|
|
360
|
-
// Enable Tailwind with default utility functions (clsx, cva, cn)
|
|
361
|
-
tailwindPlugin: true
|
|
362
|
-
|
|
363
|
-
// Enable Tailwind with custom utility functions
|
|
364
|
-
tailwindPlugin: ["clsx", "cva", "cn", "myCustomFunction"]
|
|
365
|
-
|
|
366
|
-
// Enable Tailwind with custom options
|
|
367
|
-
tailwindPlugin: {
|
|
368
|
-
tailwindFunctions: ["clsx", "cva", "myCustomFunction"],
|
|
369
|
-
tailwindAttributes: ["tw"]
|
|
370
|
-
}
|
|
371
|
-
```
|
|
189
|
+
[→ Full Prettier documentation](./src/prettier/README.md)
|
|
372
190
|
|
|
373
|
-
|
|
191
|
+
## Framework Examples
|
|
374
192
|
|
|
375
|
-
|
|
193
|
+
### React with Next.js
|
|
376
194
|
|
|
377
195
|
```js
|
|
378
|
-
|
|
379
|
-
cssOrderPlugin: false;
|
|
380
|
-
```
|
|
381
|
-
|
|
382
|
-
#### Curly Braces Enforcement
|
|
383
|
-
|
|
384
|
-
The curly braces plugin is disabled by default. It enforces consistent use of curly braces for all control flow statements (`if`, `for`, `while`, etc.), even for single-line statements. This is equivalent to ESLint's `curly` rule with the `all` option, but applied at the Prettier formatting level:
|
|
385
|
-
|
|
386
|
-
```diff
|
|
387
|
-
- if (abc) def;
|
|
388
|
-
+ if (abc) {
|
|
389
|
-
+ def;
|
|
390
|
-
+ }
|
|
391
|
-
```
|
|
392
|
-
|
|
393
|
-
You can disable it:
|
|
196
|
+
import { eslintConfig } from "js-style-kit";
|
|
394
197
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
198
|
+
export default eslintConfig({
|
|
199
|
+
typescript: "./tsconfig.json",
|
|
200
|
+
react: {
|
|
201
|
+
framework: "next",
|
|
202
|
+
reactCompiler: true, // React 19 compiler rules (enabled by default)
|
|
203
|
+
},
|
|
204
|
+
testing: {
|
|
205
|
+
framework: "vitest",
|
|
206
|
+
itOrTest: "it",
|
|
207
|
+
},
|
|
208
|
+
});
|
|
398
209
|
```
|
|
399
210
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
The JSON sorting plugin is enabled by default. You can disable it or configure it:
|
|
211
|
+
### React with Vite
|
|
403
212
|
|
|
404
213
|
```js
|
|
405
|
-
|
|
406
|
-
jsonSortPlugin: false;
|
|
214
|
+
import { eslintConfig } from "js-style-kit";
|
|
407
215
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
}
|
|
216
|
+
export default eslintConfig({
|
|
217
|
+
react: {
|
|
218
|
+
framework: "vite",
|
|
219
|
+
reactRefresh: true, // Fast Refresh validation (enabled by default with vite)
|
|
220
|
+
},
|
|
221
|
+
testing: { framework: "vitest" },
|
|
222
|
+
});
|
|
413
223
|
```
|
|
414
224
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
You can pass any standard Prettier options directly:
|
|
225
|
+
### TypeScript Library
|
|
418
226
|
|
|
419
227
|
```js
|
|
420
|
-
import {
|
|
421
|
-
|
|
422
|
-
export default prettierConfig({
|
|
423
|
-
// Enable Tailwind
|
|
424
|
-
tailwindPlugin: true,
|
|
228
|
+
import { eslintConfig } from "js-style-kit";
|
|
425
229
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
semi: true,
|
|
431
|
-
singleQuote: false,
|
|
432
|
-
trailingComma: "all",
|
|
433
|
-
bracketSpacing: true,
|
|
434
|
-
endOfLine: "lf",
|
|
230
|
+
export default eslintConfig({
|
|
231
|
+
typescript: "./tsconfig.json",
|
|
232
|
+
jsdoc: { requireJsdoc: true }, // Enforce JSDoc for public APIs
|
|
233
|
+
testing: { framework: "bun" },
|
|
435
234
|
});
|
|
436
235
|
```
|
|
437
236
|
|
|
438
|
-
##
|
|
439
|
-
|
|
440
|
-
Here's a complete example with both ESLint and Prettier configurations:
|
|
237
|
+
## Adding Custom Rules
|
|
441
238
|
|
|
442
|
-
|
|
239
|
+
You can override any rule or add custom configurations. If you disable a rule in the `rules` object, it will be removed from the config for efficiency.
|
|
443
240
|
|
|
444
241
|
```js
|
|
445
242
|
import { eslintConfig } from "js-style-kit";
|
|
446
243
|
|
|
447
244
|
export default eslintConfig(
|
|
448
245
|
{
|
|
449
|
-
typescript:
|
|
246
|
+
typescript: true,
|
|
450
247
|
react: true,
|
|
451
|
-
jsdoc: { requireJsdoc: true },
|
|
452
|
-
functionStyle: "arrow",
|
|
453
|
-
// Use the built-in rules parameter for custom rules
|
|
454
248
|
rules: {
|
|
249
|
+
// Override built-in rules
|
|
455
250
|
"no-console": ["error", { allow: ["warn", "error"] }],
|
|
456
|
-
|
|
457
|
-
// Configure testing
|
|
458
|
-
testing: {
|
|
459
|
-
framework: "jest",
|
|
460
|
-
itOrTest: "test",
|
|
251
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
461
252
|
},
|
|
462
253
|
},
|
|
463
|
-
//
|
|
254
|
+
// Additional ESLint config objects
|
|
464
255
|
{
|
|
465
|
-
name: "
|
|
466
|
-
|
|
467
|
-
|
|
256
|
+
name: "custom-globals",
|
|
257
|
+
languageOptions: {
|
|
258
|
+
globals: {
|
|
259
|
+
process: "readonly",
|
|
260
|
+
},
|
|
468
261
|
},
|
|
469
262
|
},
|
|
470
263
|
);
|
|
471
264
|
```
|
|
472
265
|
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
266
|
+
## What's Included
|
|
267
|
+
|
|
268
|
+
### ESLint Plugins
|
|
269
|
+
|
|
270
|
+
- [`typescript-eslint`](https://typescript-eslint.io) - TypeScript linting
|
|
271
|
+
- [`eslint-plugin-perfectionist`](https://perfectionist.dev) - Auto-sorting
|
|
272
|
+
- [`eslint-plugin-import-x`](https://www.npmjs.com/package/eslint-plugin-import-x) - Import/export validation
|
|
273
|
+
- [`eslint-plugin-unicorn`](https://www.npmjs.com/package/eslint-plugin-unicorn) - Best practices & naming
|
|
274
|
+
- [`eslint-plugin-react`](https://www.npmjs.com/package/eslint-plugin-react) - React rules
|
|
275
|
+
- [`eslint-plugin-react-hooks`](https://www.npmjs.com/package/eslint-plugin-react-hooks) - React hooks rules
|
|
276
|
+
- [`eslint-plugin-react-refresh`](https://www.npmjs.com/package/eslint-plugin-react-refresh) - Fast Refresh validation
|
|
277
|
+
- [`eslint-plugin-nextjs`](../eslint-plugin-nextjs/README.md) - My fork of the Next.js plugin
|
|
278
|
+
- [`@tanstack/eslint-plugin-query`](https://tanstack.com/query/v4/docs/eslint/eslint-plugin-query) - TanStack Query rules
|
|
279
|
+
- [`eslint-plugin-jsdoc`](https://www.npmjs.com/package/eslint-plugin-jsdoc) - JSDoc validation
|
|
280
|
+
- [`eslint-plugin-storybook`](https://www.npmjs.com/package/eslint-plugin-storybook) - Storybook rules
|
|
281
|
+
- [`eslint-plugin-turbo`](https://www.npmjs.com/package/eslint-plugin-turbo) - Turborepo rules
|
|
282
|
+
- [`eslint-plugin-vitest`](https://www.npmjs.com/package/eslint-plugin-vitest) - Vitest rules
|
|
283
|
+
- [`eslint-plugin-jest`](https://www.npmjs.com/package/eslint-plugin-jest) - Jest rules
|
|
284
|
+
|
|
285
|
+
### Prettier Plugins
|
|
286
|
+
|
|
287
|
+
- [`prettier-plugin-css-order`](https://www.npmjs.com/package/prettier-plugin-css-order) - CSS property ordering
|
|
288
|
+
- [`prettier-plugin-curly`](https://www.npmjs.com/package/prettier-plugin-curly) - Curly brace enforcement
|
|
289
|
+
- [`prettier-plugin-packagejson`](https://www.npmjs.com/package/prettier-plugin-packagejson) - package.json sorting
|
|
290
|
+
- [`prettier-plugin-sort-json`](https://www.npmjs.com/package/prettier-plugin-sort-json) - JSON sorting
|
|
291
|
+
- [`prettier-plugin-tailwindcss`](https://www.npmjs.com/package/prettier-plugin-tailwindcss) - Tailwind class sorting
|
|
292
|
+
- [`@prettier/plugin-oxc`](https://www.npmjs.com/package/@prettier/plugin-oxc) - Faster parser (optional)
|
|
485
293
|
|
|
486
294
|
## License
|
|
487
295
|
|
|
488
296
|
MIT
|
|
297
|
+
|
|
298
|
+
---
|
|
299
|
+
|
|
300
|
+
**Note:** This is a work in progress. Please [open an issue](https://github.com/drake-nathan/js-style-kit/issues) if you have suggestions or find any problems!
|
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ declare const configNames: {
|
|
|
18
18
|
readonly nextjs: "nextjs";
|
|
19
19
|
readonly perfectionist: "perfectionist";
|
|
20
20
|
readonly preferArrowFunction: "prefer-arrow-function";
|
|
21
|
+
readonly query: "@tanstack/query";
|
|
21
22
|
readonly react: "react";
|
|
22
23
|
readonly reactRefresh: "react-refresh";
|
|
23
24
|
readonly storybook: "storybook:stories";
|
|
@@ -52,6 +53,7 @@ interface EslintConfigOptions {
|
|
|
52
53
|
jsdoc?: false | {
|
|
53
54
|
requireJsdoc?: boolean;
|
|
54
55
|
};
|
|
56
|
+
query?: boolean;
|
|
55
57
|
react?: boolean | {
|
|
56
58
|
framework?: "next" | "none" | "react-router" | "remix" | "vite";
|
|
57
59
|
reactCompiler?: boolean;
|
|
@@ -73,6 +75,7 @@ interface EslintConfigOptions {
|
|
|
73
75
|
* @param options.ignores - Additional paths to ignore. Already excludes `node_modules` and `dist`.
|
|
74
76
|
* @param options.importPlugin - Whether to include the import plugin. Defaults to true.
|
|
75
77
|
* @param options.jsdoc - Whether to include JSDoc rules. Set to false to disable, or provide an object to configure.
|
|
78
|
+
* @param options.query - Whether to include TanStack Query rules.
|
|
76
79
|
* @param options.react - Whether to include React, React hooks, and React compiler rules.
|
|
77
80
|
* Can specify framework as "next", "none", "react-router", "remix", or "vite" to control related configs:
|
|
78
81
|
* - "next": Includes Next.js config, excludes React Refresh.
|
|
@@ -94,7 +97,7 @@ interface EslintConfigOptions {
|
|
|
94
97
|
* @param additionalConfigs - Additional ESLint config objects to be merged into the final configuration.
|
|
95
98
|
* @returns An array of ESLint configuration objects.
|
|
96
99
|
*/
|
|
97
|
-
declare const eslintConfig: ({ functionStyle, ignores, importPlugin, jsdoc, react, rules, sorting, storybook, testing, turbo, typescript, unicorn, }?: EslintConfigOptions, ...additionalConfigs: Linter.Config[]) => Linter.Config[];
|
|
100
|
+
declare const eslintConfig: ({ functionStyle, ignores, importPlugin, jsdoc, query, react, rules, sorting, storybook, testing, turbo, typescript, unicorn, }?: EslintConfigOptions, ...additionalConfigs: Linter.Config[]) => Linter.Config[];
|
|
98
101
|
|
|
99
102
|
interface PrettierConfigOptions extends Config {
|
|
100
103
|
cssOrderPlugin?: boolean;
|