@zayne-labs/eslint-config 0.0.0 → 0.0.2

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
@@ -1,50 +1,572 @@
1
- # Create Ts Library
1
+ # @zayne-labs/eslint-config
2
2
 
3
- This is an opinionated starter template for creating a library with TypeScript.
3
+ - Reasonable defaults, best practices, only one line of config
4
+ - Designed to work with TypeScript, JSX, Vue, JSON, YAML, Toml, Markdown, etc. Out-of-box.
5
+ - Opinionated, but [very customizable](#customization)
6
+ - [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new), compose easily!
7
+ - Optional [React](#react), [Svelte](#svelte), [TailwindCSS](#tailwindcss), [Astro](#astro), [Solid](#solid) support
8
+ - Respects `.gitignore` by default
9
+ - Requires ESLint v9.5.0+
4
10
 
5
11
 
6
12
  ## Usage
7
13
 
8
- To use this template, simply click the green `Use this template` button at the top right of this repo, or just fork and clone it if you prefer.
9
-
10
- ## Tooling available
11
- - Eslint plugins for linting (customizable)
12
- - Prettier for formatting
13
- - [TSUP](https://github.com/egoist/tsup) for bundling
14
- - [@zayne-labs/tsconfig](https://github.com/zayne-labs/tsconfig) for relevant tsconfig presets
15
- - [Changesets](https://github.com/changesets/changesets) (Both cli and github action which must be installed on the repo) for versioning, publishing, release notes and changelogs
16
- - [publint](https://github.com/bluwy/publint) and [@arethetypeswrong/cli](https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/packages/cli/README.md) for validating package.json and checking for proper package types resolutions respectively.
17
- - [size-limit](https://github.com/ai/size-limit) for bundle size analysis and management
18
- - [lint-staged](https://github.com/lint-staged/lint-staged) for lint and types checks on staged files and [husky](https://github.com/typicode/husky) for running lint-staged before any commit and before push if you prefer
19
- - [pkg.pr.new](https://pkg-pr-new) for continuous testing of packages on every commit before publishing to npm.
20
- - Various github workflows for:
21
- - Linting on ci
22
- - Automatic publishing via changesets
23
- - Formatting on ci via [autofix.ci](https://autofix.ci/)
24
- - Labeling issues
25
- - Issue assignment
26
- - Continuous release testing via pkg.pr.new github action, etc.
27
-
28
- ## Setup
29
-
30
- - Click the `Use this template` button.
31
- - Create a new repository with it.
32
- - Install the necessary github applications and bots on your repo namely:
33
- - [aufofix app](https://github.com/marketplace/autofix-ci) for running automatic code fixes
34
- - [changesets bot](https://github.com/apps/changeset-bot) for checking if there are any changesets contained in PRs
35
- - [pkg.pr.new app](https://github.com/apps/pkg-pr-new) for continuous testing of packages
36
- - Create npm token [here](https://docs.npmjs.com/creating-and-viewing-access-tokens) (Skip if you already have it handy).
37
- - Add it as a [secret to your repository](https://docs.github.com/en/codespaces/managing-codespaces-for-your-organization/managing-development-environment-secrets-for-your-repository-or-organization#adding-secrets-for-a-repository) (or at the organization level if you have one), using the name `"NPM_TOKEN"`.
38
- - Install the dependencies using `pnpm install`.
39
- - Edit the package.json file, and replace any of these: `[*]`, with the appropriate names relevant to your lib (Did this cuz comments aren't allowed in json files).
40
- - Lint your changes by running some of the `lint:*` scripts in the package.json.
41
- - Commit and push your changes.
42
-
43
- ## To publish a new version
44
- - Create a changeset via `pnpm changeset` command
45
- - Follow the prompts
46
- - Push to github
47
- - Wait for the changeset action to finish and if it's successful, you should see a pr created by the changeset bot
48
- - Merging it will lead to the version bump, release and publishing of the package
14
+ ### Manual Install
49
15
 
16
+ If you prefer to set up manually:
50
17
 
18
+ ```bash
19
+ pnpm add -D eslint @zayne-labs/eslint-config
20
+ ```
21
+
22
+ And create `eslint.config.js` in your project root:
23
+
24
+ ```js
25
+ // eslint.config.js
26
+ import zayne from '@zayne-labs/eslint-config'
27
+
28
+ export default zayne()
29
+ ```
30
+
31
+ <details>
32
+ <summary>
33
+ Combined with legacy config:
34
+ </summary>
35
+
36
+ If you still use some configs from the legacy eslintrc format, you can use the [`@eslint/eslintrc`](https://www.npmjs.com/package/@eslint/eslintrc) package to convert them to the flat config.
37
+
38
+ ```js
39
+ // eslint.config.mjs
40
+ import zayne from '@zayne-labs/eslint-config'
41
+ import { FlatCompat } from '@eslint/eslintrc'
42
+
43
+ const compat = new FlatCompat()
44
+
45
+ export default zayne(
46
+ {
47
+ ignores: [],
48
+ },
49
+
50
+ // Legacy config
51
+ [
52
+ ...compat.config({
53
+ extends: [
54
+ 'eslint:recommended',
55
+ // Other extends...
56
+ ],
57
+ }),
58
+
59
+ // Other flat configs...
60
+ ]
61
+
62
+ )
63
+ ```
64
+
65
+ > Note that `.eslintignore` no longer works in Flat config, see [customization](#customization) for more details.
66
+
67
+ </details>
68
+
69
+ ### Add script for package.json
70
+
71
+ For example:
72
+
73
+ ```json
74
+ {
75
+ "scripts": {
76
+ "lint:eslint": "eslint .",
77
+ "lint:eslint-fix": "eslint . --fix"
78
+ }
79
+ }
80
+ ```
81
+
82
+ ## IDE Support (auto fix on save)
83
+
84
+ <details>
85
+ <summary>🟦 VS Code support</summary>
86
+
87
+ <br>
88
+
89
+ Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
90
+
91
+ Add the following settings to your `.vscode/settings.json`:
92
+
93
+ ```jsonc
94
+ {
95
+ // Auto fix
96
+ "editor.codeActionsOnSave": {
97
+ "source.fixAll.eslint": "explicit",
98
+ "source.organizeImports": "never"
99
+ },
100
+
101
+ // Enable eslint for all supported languages
102
+ "eslint.validate": [
103
+ "javascript",
104
+ "javascriptreact",
105
+ "typescript",
106
+ "typescriptreact",
107
+ "vue",
108
+ "html",
109
+ "markdown",
110
+ "json",
111
+ "jsonc",
112
+ "yaml",
113
+ "toml",
114
+ "xml",
115
+ "gql",
116
+ "graphql",
117
+ "astro",
118
+ "svelte",
119
+ "css",
120
+ "less",
121
+ "scss",
122
+ "pcss",
123
+ "postcss"
124
+ ]
125
+ }
126
+ ```
127
+
128
+ </details>
129
+
130
+ <details>
131
+ <summary>🟩 Neovim Support</summary>
132
+
133
+ <br>
134
+
135
+ Update your configuration to use the following:
136
+
137
+ ```lua
138
+ local lspconfig = require('lspconfig')
139
+ -- Enable eslint for all supported languages
140
+ lspconfig.eslint.setup(
141
+ {
142
+ filetypes = {
143
+ "javascript",
144
+ "javascriptreact",
145
+ "javascript.jsx",
146
+ "typescript",
147
+ "typescriptreact",
148
+ "typescript.tsx",
149
+ "vue",
150
+ "html",
151
+ "markdown",
152
+ "json",
153
+ "jsonc",
154
+ "yaml",
155
+ "toml",
156
+ "xml",
157
+ "gql",
158
+ "graphql",
159
+ "astro",
160
+ "svelte",
161
+ "css",
162
+ "less",
163
+ "scss",
164
+ "pcss",
165
+ "postcss"
166
+ },
167
+ }
168
+ )
169
+ ```
170
+
171
+ ### Neovim format on save
172
+
173
+ There's few ways you can achieve format on save in neovim:
174
+
175
+ - `nvim-lspconfig` has a `EslintFixAll` command predefined, you can create a autocmd to call this command after saving file.
176
+
177
+ ```lua
178
+ lspconfig.eslint.setup({
179
+ --- ...
180
+ on_attach = function(client, bufnr)
181
+ vim.api.nvim_create_autocmd("BufWritePre", {
182
+ buffer = bufnr,
183
+ command = "EslintFixAll",
184
+ })
185
+ end,
186
+ })
187
+ ```
188
+
189
+ - Use [conform.nvim](https://github.com/stevearc/conform.nvim).
190
+ - Use [none-ls](https://github.com/nvimtools/none-ls.nvim)
191
+ - Use [nvim-lint](https://github.com/mfussenegger/nvim-lint)
192
+
193
+ </details>
194
+
195
+ ## Customization
196
+
197
+ Normally you only need to import the `zayne` preset:
198
+
199
+ ```js
200
+ // eslint.config.js
201
+ import zayne from '@zayne-labs/eslint-config'
202
+
203
+ export default zayne()
204
+ ```
205
+
206
+ And that's it! Or you can configure each integration individually, for example:
207
+
208
+ ```js
209
+ // eslint.config.js
210
+ import zayne from '@zayne-labs/eslint-config'
211
+
212
+ export default zayne({
213
+ // Enable stylistic formatting rules
214
+ stylistic: true,
215
+
216
+ // TypeScript is autodetected, you can also explicitly enable it:
217
+ typescript: true,
218
+
219
+ // Disable jsonc and yaml support
220
+ jsonc: false,
221
+ yaml: false,
222
+
223
+ // `.eslintignore` is no longer supported in Flat config, use `ignores` instead
224
+ ignores: [
225
+ 'build/**',
226
+ // ...globs
227
+ ]
228
+ })
229
+ ```
230
+
231
+ The `zayne` factory function also accepts an array of arbitrary custom config overrides as the second argument:
232
+
233
+ ```js
234
+ // eslint.config.js
235
+ import zayne from '@zayne-labs/eslint-config'
236
+
237
+ export default zayne(
238
+ {
239
+ // Configures for zayne labs' config
240
+ },
241
+
242
+ // The second arguments is an array of ESLint Configs
243
+ [ {
244
+ files: ['**/*.ts'],
245
+ rules: {},
246
+ },
247
+ {
248
+ rules: {},
249
+ }],
250
+ )
251
+ ```
252
+
253
+ Going more advanced, you can also import fine-grained configs and compose them as you wish:
254
+
255
+ <details>
256
+ <summary>Advanced Example</summary>
257
+
258
+ We wouldn't recommend using this style in general unless you know exactly what they are doing, as there are shared options between configs and might need extra care to make them consistent.
259
+
260
+ ```js
261
+ // eslint.config.js
262
+ import {
263
+ combine,
264
+ comments,
265
+ ignores,
266
+ imports,
267
+ javascript,
268
+ jsdoc,
269
+ jsonc,
270
+ markdown,
271
+ node,
272
+ sortPackageJson,
273
+ sortTsconfig,
274
+ stylistic,
275
+ toml,
276
+ typescript,
277
+ unicorn,
278
+ vue,
279
+ yaml,
280
+ } from '@zayne-labs/eslint-config'
281
+
282
+ export default combine(
283
+ ignores(),
284
+ javascript(/* Options */),
285
+ comments(),
286
+ node(),
287
+ jsdoc(),
288
+ imports(),
289
+ unicorn(),
290
+ typescript(/* Options */),
291
+ stylistic(),
292
+ vue(),
293
+ jsonc(),
294
+ yaml(),
295
+ toml(),
296
+ markdown(),
297
+ )
298
+ ```
299
+
300
+ </details>
301
+
302
+ Check out the [configs](https://github.com/zayne-labs/eslint-config/blob/main/src/configs) and [factory](https://github.com/zayne-labs/eslint-config/blob/main/src/factory.ts) for more details.
303
+
304
+ > Thanks to [zayne/eslint-config](https://github.com/zayne/eslint-config) for the inspiration and reference.
305
+
306
+ ### Plugins Renaming
307
+
308
+ Since flat config requires us to explicitly provide the plugin names (instead of the mandatory convention from npm package name), we renamed some plugins to make the overall scope more consistent and easier to write.
309
+
310
+ | New Prefix | Original Prefix | Source Plugin |
311
+ | ---------- | ---------------------- | ------------------------------------------------------------------------------------------ |
312
+ | `import/*` | `import-x/*` | [eslint-plugin-import-x](https://github.com/un-es/eslint-plugin-import-x) |
313
+ | `node/*` | `n/*` | [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) |
314
+ | `yaml/*` | `yml/*` | [eslint-plugin-yml](https://github.com/ota-meshi/eslint-plugin-yml) |
315
+ | `ts-eslint/*` | `@typescript-eslint/*` | [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) |
316
+ | `stylistic/*` | `@stylistic/*` | [@stylistic/eslint-plugin](https://github.com/eslint-stylistic/eslint-stylistic) |
317
+
318
+ When you want to override rules, or disable them inline, you need to update to the new prefix:
319
+
320
+ ```diff
321
+ -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
322
+ +// eslint-disable-next-line ts/consistent-type-definitions
323
+ type foo = { bar: 2 }
324
+ ```
325
+
326
+
327
+ <details>
328
+ <summary>Change back to original prefix</summary>
329
+
330
+ If you really want to use the original prefix, you can revert the plugin renaming by:
331
+
332
+ ```ts
333
+ import zayne from '@zayne-labs/eslint-config'
334
+
335
+ export default zayne()
336
+ .renamePlugins({
337
+ "ts-eslint": '@typescript-eslint',
338
+ // ...
339
+ })
340
+ ```
341
+
342
+ </details>
343
+
344
+ ### Rules Overrides
345
+
346
+ Certain rules would only be enabled in specific files, for example, `ts/*` rules would only be enabled in `.ts` files and `vue/*` rules would only be enabled in `.vue` files. If you want to override the rules, you need to specify the file extension:
347
+
348
+ ```js
349
+ // eslint.config.js
350
+ import zayne from '@zayne-labs/eslint-config'
351
+
352
+ export default zayne(
353
+ {
354
+ vue: true,
355
+ typescript: true
356
+ },
357
+ {
358
+ // Remember to specify the file glob here, otherwise it might cause the vue plugin to handle non-vue files
359
+ files: ['**/*.vue'],
360
+ rules: {
361
+ 'vue/operator-linebreak': ['error', 'before'],
362
+ },
363
+ },
364
+ {
365
+ // Without `files`, they are general rules for all files
366
+ rules: {
367
+ 'stylistic/semi': ['error', 'never'],
368
+ },
369
+ }
370
+ )
371
+ ```
372
+
373
+ We also provided the `overrides` options in each integration to make it easier:
374
+
375
+ ```js
376
+ // eslint.config.js
377
+ import zayne from '@zayne-labs/eslint-config'
378
+
379
+ export default zayne({
380
+ vue: {
381
+ overrides: {
382
+ 'vue/operator-linebreak': ['error', 'before'],
383
+ },
384
+ },
385
+ typescript: {
386
+ overrides: {
387
+ 'ts/consistent-type-definitions': ['error', 'interface'],
388
+ },
389
+ },
390
+ yaml: {
391
+ overrides: {
392
+ // ...
393
+ },
394
+ },
395
+ })
396
+ ```
397
+
398
+ ### Config Composer
399
+
400
+ The factory function `zayne()` returns a [`FlatConfigComposer` object from `eslint-flat-config-utils`](https://github.com/zayne/eslint-flat-config-utils#composer) where you can chain the methods to compose the config even more flexibly.
401
+
402
+ ```js
403
+ // eslint.config.js
404
+ import zayne from '@zayne-labs/eslint-config'
405
+
406
+ export default zayne()
407
+ .prepend(
408
+ // some configs before the main config
409
+ )
410
+ // overrides any named configs
411
+ .override(
412
+ 'zayne/imports',
413
+ {
414
+ rules: {
415
+ 'import/order': ['error', { 'newlines-between': 'always' }],
416
+ }
417
+ }
418
+ )
419
+ // rename plugin prefixes
420
+ .renamePlugins({
421
+ 'old-prefix': 'new-prefix',
422
+ // ...
423
+ })
424
+ // ...
425
+ ```
426
+
427
+
428
+ #### React
429
+
430
+ To enable React support, you need to explicitly turn it on:
431
+
432
+ ```js
433
+ // eslint.config.js
434
+ import zayne from '@zayne-labs/eslint-config'
435
+
436
+ export default zayne({
437
+ react: true,
438
+ })
439
+ ```
440
+
441
+ Running `npx eslint` should prompt you to install the required dependencies, otherwise, you can install them manually:
442
+
443
+ ```bash
444
+ npm i -D @eslint-react/eslint-plugin eslint-plugin-react-hooks eslint-plugin-react-refresh
445
+ ```
446
+
447
+ #### Svelte
448
+
449
+ To enable svelte support, you need to explicitly turn it on:
450
+
451
+ ```js
452
+ // eslint.config.js
453
+ import zayne from '@zayne-labs/eslint-config'
454
+
455
+ export default zayne({
456
+ svelte: true,
457
+ })
458
+ ```
459
+
460
+ Running `npx eslint` should prompt you to install the required dependencies, otherwise, you can install them manually:
461
+
462
+ ```bash
463
+ npm i -D eslint-plugin-svelte
464
+ ```
465
+
466
+ #### Astro
467
+
468
+ To enable astro support, you need to explicitly turn it on:
469
+
470
+ ```js
471
+ // eslint.config.js
472
+ import zayne from '@zayne-labs/eslint-config'
473
+
474
+ export default zayne({
475
+ astro: true,
476
+ })
477
+ ```
478
+
479
+ Running `npx eslint` should prompt you to install the required dependencies, otherwise, you can install them manually:
480
+
481
+ ```bash
482
+ npm i -D eslint-plugin-astro
483
+ ```
484
+
485
+ #### Solid
486
+
487
+ To enable Solid support, you need to explicitly turn it on:
488
+
489
+ ```js
490
+ // eslint.config.js
491
+ import zayne from '@zayne-labs/eslint-config'
492
+
493
+ export default zayne({
494
+ solid: true,
495
+ })
496
+ ```
497
+
498
+ Running `npx eslint` should prompt you to install the required dependencies, otherwise, you can install them manually:
499
+
500
+ ```bash
501
+ npm i -D eslint-plugin-solid
502
+ ```
503
+
504
+ #### tailwindcss
505
+
506
+ To enable Tailwindcss support, you need to explicitly turn it on:
507
+
508
+ ```js
509
+ // eslint.config.js
510
+ import zayne from '@zayne-labs/eslint-config'
511
+
512
+ export default zayne({
513
+ tailwindcss: true,
514
+ })
515
+ ```
516
+
517
+ Running `npx eslint` should prompt you to install the required dependencies, otherwise, you can install them manually:
518
+
519
+ ```bash
520
+ npm i -D eslint-plugin-tailwindcss
521
+ ```
522
+
523
+
524
+ ### Type Aware Rules
525
+
526
+ You can optionally enable the [type aware rules](https://typescript-eslint.io/linting/typed-linting/) by passing the options object to the `typescript` config:
527
+
528
+ ```js
529
+ // eslint.config.js
530
+ import zayne from '@zayne-labs/eslint-config'
531
+
532
+ export default zayne({
533
+ typescript: {
534
+ tsconfigPath: 'tsconfig.json',
535
+ },
536
+ })
537
+ ```
538
+
539
+
540
+ ## View what rules are enabled
541
+
542
+ Eslint config inspecctor is visual tool to help you view what rules are enabled in your project and apply them to what files, [@eslint/config-inspector](https://github.com/eslint/config-inspector).
543
+ It was built by the legendary Anthony Fu.
544
+
545
+ Go to your project root that contains `eslint.config.js` and run:
546
+
547
+ ```bash
548
+ npx @eslint/config-inspector
549
+ ```
550
+
551
+ ## Versioning Policy
552
+
553
+ This project follows [Semantic Versioning](https://semver.org/) for releases. However, since this is just a config and involves opinions and many moving parts, we don't treat rules changes as breaking changes.
554
+
555
+ ### Changes Considered as Breaking Changes
556
+
557
+ - Node.js version requirement changes
558
+ - Huge refactors that might break the config
559
+ - Plugins made major changes that might break the config
560
+ - Changes that might affect most of the codebases
561
+
562
+ ### Changes Considered as Non-breaking Changes
563
+
564
+ - Enable/disable rules and plugins (that might become stricter)
565
+ - Rules options changes
566
+ - Version bumps of dependencies
567
+
568
+ ## FAQ
569
+
570
+ ### I prefer XXX...
571
+
572
+ Sure, you can configure and override rules locally in your project to fit your needs. If that still does not work for you, you can always fork this repo and maintain your own.