@coderwyd/eslint-config 1.1.1 → 2.0.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
@@ -7,14 +7,13 @@
7
7
  ## Feature
8
8
 
9
9
  - ✨ Single quotes, no semi
10
- - 🛠️ Auto fix for formatting (aimed to be used standalone **without** Prettier)
10
+ - 🛠️ Auto fix for formatting
11
11
  - 🎯 Designed to work with TypeScript, Vue out-of-box
12
- - 🔍 Lints also for json, yaml, markdown
12
+ - 🔍 Lints also for json
13
13
  - 🧩 Sorted imports, dangling commas
14
14
  - 🏆 Reasonable defaults, best practices, only one-line of config
15
15
  - 🚀 [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new), compose easily!
16
- - 🎨 Using [ESLint Stylistic](https://github.com/eslint-stylistic/eslint-stylistic)
17
- - 📖 **Style principle**: Minimal for reading, stable for diff, consistent
16
+ - 🎨 Use ESlint and Prettier to format HTML, CSS, LESS, SCSS, YAML, TOML, Markdown.
18
17
 
19
18
  ## Usage
20
19
 
@@ -30,18 +29,18 @@ With [`"type": "module"`](https://nodejs.org/api/packages.html#type) in `package
30
29
 
31
30
  ```js
32
31
  // eslint.config.js
33
- import coderwyd from '@coderwyd/eslint-config'
32
+ import { defineConfig } from '@coderwyd/eslint-config'
34
33
 
35
- export default coderwyd()
34
+ export default defineConfig()
36
35
  ```
37
36
 
38
37
  With CJS:
39
38
 
40
39
  ```js
41
40
  // eslint.config.js
42
- const coderwyd = require('@coderwyd/eslint-config').default
41
+ const { defineConfig } = require('@coderwyd/eslint-config')
43
42
 
44
- module.exports = coderwyd()
43
+ module.exports = defineConfig()
45
44
  ```
46
45
 
47
46
  > Note that `.eslintignore` no longer works in Flat config, see [customization](#customization) for more details.
@@ -80,237 +79,22 @@ Add the following settings to your `.vscode/settings.json`:
80
79
  "source.organizeImports": "never"
81
80
  },
82
81
 
83
- // Silent the stylistic rules in you IDE, but still auto fix them
84
- "eslint.rules.customizations": [
85
- { "rule": "style/*", "severity": "off" },
86
- { "rule": "*-indent", "severity": "off" },
87
- { "rule": "*-spacing", "severity": "off" },
88
- { "rule": "*-spaces", "severity": "off" },
89
- { "rule": "*-order", "severity": "off" },
90
- { "rule": "*-dangle", "severity": "off" },
91
- { "rule": "*-newline", "severity": "off" },
92
- { "rule": "*quotes", "severity": "off" },
93
- { "rule": "*semi", "severity": "off" }
94
- ],
95
-
96
82
  // Enable eslint for all supported languages
97
83
  "eslint.validate": [
98
- "javascript",
99
- "javascriptreact",
100
- "typescript",
101
- "typescriptreact",
102
- "vue",
103
84
  "html",
104
- "markdown",
85
+ "css",
86
+ "less",
87
+ "scss",
105
88
  "json",
106
89
  "jsonc",
107
- "yaml"
90
+ "yaml",
91
+ "yml",
92
+ "markdown",
93
+ "toml"
108
94
  ]
109
95
  }
110
96
  ```
111
97
 
112
- ## Customization
113
-
114
- Since v1.0, we migrated to [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new). It provides a much better organization and composition.
115
-
116
- Normally you only need to import the `coderwyd` preset:
117
-
118
- ```js
119
- // eslint.config.js
120
- import coderwyd from '@coderwyd/eslint-config'
121
-
122
- export default coderwyd()
123
- ```
124
-
125
- And that's it! Or you can configure each integration individually, for example:
126
-
127
- ```js
128
- // eslint.config.js
129
- import coderwyd from '@coderwyd/eslint-config'
130
-
131
- export default coderwyd({
132
- stylistic: true, // enable stylistic formatting rules
133
- typescript: true,
134
- vue: true,
135
- jsonc: false, // disable jsonc support
136
- yaml: false,
137
-
138
- // `.eslintignore` is no longer supported in Flat config, use `ignores` instead
139
- ignores: [
140
- './fixtures',
141
- // ...globs
142
- ]
143
- })
144
- ```
145
-
146
- The `coderwyd` factory function also accepts any number of arbitrary custom config overrides:
147
-
148
- ```js
149
- // eslint.config.js
150
- import coderwyd from '@coderwyd/eslint-config'
151
-
152
- export default coderwyd(
153
- {
154
- // Configures for coderwyd's config
155
- },
156
-
157
- // From the second arguments they are ESLint Flat Configs
158
- // you can have multiple configs
159
- {
160
- files: ['**/*.ts'],
161
- rules: {},
162
- },
163
- {
164
- rules: {},
165
- },
166
- )
167
- ```
168
-
169
- Going more advanced, you can also import fine-grained configs and compose them as you wish:
170
-
171
- ```js
172
- // eslint.config.js
173
- import {
174
- astro,
175
- comments,
176
- ignores,
177
- imports,
178
- javascript,
179
- jsdoc,
180
- jsonc,
181
- markdown,
182
- node,
183
- react,
184
- sortPackageJson,
185
- sortTsconfig,
186
- stylistic,
187
- typescript,
188
- unicorn,
189
- vue,
190
- yaml,
191
- } from '@coderwyd/eslint-config'
192
-
193
- export default [
194
- ...astro(),
195
- ...react(),
196
- ...ignores(),
197
- ...javascript(),
198
- ...comments(),
199
- ...node(),
200
- ...jsdoc(),
201
- ...imports(),
202
- ...unicorn(),
203
- ...typescript(),
204
- ...stylistic(),
205
- ...vue(),
206
- ...jsonc(),
207
- ...yaml(),
208
- ...markdown(),
209
- ]
210
- ```
211
-
212
- Check out the [configs](https://github.com/coderwyd/eslint-config/blob/main/src/configs) and [factory](https://github.com/coderwyd/eslint-config/blob/main/src/factory.ts) for more details.
213
-
214
- ## Plugins Renaming
215
-
216
- Since flat config requires us to explicitly provide the plugin names (instead of mandatory convention from npm package name), we renamed some plugins to make overall scope more consistent and easier to write.
217
-
218
- | New Prefix | Original Prefix | Source Plugin |
219
- | --- | --- | --- |
220
- | `import/*` | `i/*` | [eslint-plugin-i](https://github.com/un-es/eslint-plugin-i) |
221
- | `node/*` | `n/*` | [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) |
222
- | `yaml/*` | `yml/*` | [eslint-plugin-yml](https://github.com/ota-meshi/eslint-plugin-yml) |
223
- | `ts/*` | `@typescript-eslint/*` | [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) |
224
- | `style/*` | `@stylistic/*` | [@stylistic/eslint-plugin](https://github.com/eslint-stylistic/eslint-stylistic) |
225
- | `test/*` | `vitest/*` | [eslint-plugin-vitest](https://github.com/veritem/eslint-plugin-vitest) |
226
- | `test/*` | `no-only-tests/*` | [eslint-plugin-no-only-tests](https://github.com/levibuzolic/eslint-plugin-no-only-tests) |
227
-
228
- When you want to override rules, or disable them inline, you need to update to the new prefix:
229
-
230
- ```diff
231
- -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
232
- +// eslint-disable-next-line ts/consistent-type-definitions
233
- type foo = { bar: 2 }
234
- ```
235
-
236
- ### Rules Overrides
237
-
238
- 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:
239
-
240
- ```js
241
- // eslint.config.js
242
- import coderwyd from '@coderwyd/eslint-config'
243
-
244
- export default coderwyd(
245
- {
246
- // Enable stylistic formatting rules
247
- // stylistic: true,
248
-
249
- // Or customize the stylistic rules
250
- stylistic: {
251
- indent: 2, // 4, or 'tab'
252
- quotes: 'single', // or 'double'
253
- },
254
-
255
- // TypeScript and Vue are auto-detected, you can also explicitly enable them:
256
- typescript: true,
257
- vue: true,
258
-
259
- // Disable jsonc and yaml support
260
- jsonc: false,
261
- yaml: false,
262
- },
263
- {
264
- // Remember to specify the file glob here, otherwise it might cause the vue plugin to handle non-vue files
265
- files: ['**/*.vue'],
266
- rules: {
267
- 'vue/operator-linebreak': ['error', 'before'],
268
- },
269
- },
270
- {
271
- // Without `files`, they are general rules for all files
272
- rules: {
273
- 'style/semi': ['error', 'never'],
274
- },
275
- }
276
- )
277
- ```
278
-
279
- We also provided an `overrides` options to make it easier:
280
-
281
- ```js
282
- // eslint.config.js
283
- import coderwyd from '@coderwyd/eslint-config'
284
-
285
- export default coderwyd({
286
- overrides: {
287
- vue: {
288
- 'vue/operator-linebreak': ['error', 'before'],
289
- },
290
- typescript: {
291
- 'ts/consistent-type-definitions': ['error', 'interface'],
292
- },
293
- yaml: {},
294
- // ...
295
- }
296
- })
297
- ```
298
-
299
- ### Type Aware Rules
300
-
301
- You can optionally enable the [type aware rules](https://typescript-eslint.io/linting/typed-linting/) by passing the options object to the `typescript` config:
302
-
303
- ```js
304
- // eslint.config.js
305
- import coderwyd from '@coderwyd/eslint-config'
306
-
307
- export default coderwyd({
308
- typescript: {
309
- tsconfigPath: 'tsconfig.json',
310
- },
311
- })
312
- ```
313
-
314
98
  ### Lint Staged
315
99
 
316
100
  If you want to apply lint and auto-fix before every commit, you can add the following to your `package.json`:
package/dist/cli.cjs CHANGED
@@ -46,32 +46,30 @@ var import_parse_gitignore = __toESM(require("parse-gitignore"), 1);
46
46
  var import_picocolors = __toESM(require("picocolors"), 1);
47
47
 
48
48
  // package.json
49
- var version = "1.1.1";
49
+ var version = "2.0.0";
50
50
  var devDependencies = {
51
- "@antfu/ni": "^0.21.10",
52
- "@stylistic/eslint-plugin-migrate": "^1.4.0",
53
- "@types/eslint": "^8.44.7",
51
+ "@antfu/ni": "^0.21.12",
52
+ "@types/eslint": "^8.56.0",
54
53
  "@types/fs-extra": "^11.0.4",
55
- "@types/node": "^20.9.4",
54
+ "@types/node": "^20.10.5",
56
55
  "@types/prompts": "^2.4.9",
57
56
  "@types/yargs": "^17.0.32",
58
- "@unocss/eslint-plugin": "^0.57.7",
59
- bumpp: "^9.2.0",
60
- eslint: "^8.54.0",
61
- "eslint-flat-config-viewer": "^0.1.3",
57
+ "@unocss/eslint-plugin": "^0.58.2",
58
+ bumpp: "^9.2.1",
59
+ eslint: "^8.56.0",
60
+ "eslint-flat-config-viewer": "^0.1.4",
62
61
  "eslint-plugin-react": "^7.33.2",
63
62
  "eslint-plugin-react-hooks": "^4.6.0",
64
- "eslint-plugin-react-refresh": "^0.4.4",
63
+ "eslint-plugin-react-refresh": "^0.4.5",
65
64
  esno: "^4.0.0",
66
65
  execa: "^8.0.1",
67
66
  "fast-glob": "^3.3.2",
68
- "fs-extra": "^11.1.1",
69
- "lint-staged": "^15.1.0",
67
+ "fs-extra": "^11.2.0",
68
+ "lint-staged": "^15.2.0",
70
69
  rimraf: "^5.0.5",
71
70
  "simple-git-hooks": "^2.9.0",
72
71
  tsup: "^8.0.1",
73
- typescript: "^5.3.2",
74
- vitest: "^0.34.6"
72
+ typescript: "^5.3.3"
75
73
  };
76
74
 
77
75
  // src/cli/constants.ts
@@ -94,31 +92,20 @@ var vscodeSettingsString = `
94
92
  "source.organizeImports": "never"
95
93
  },
96
94
 
97
- // Silent the stylistic rules in you IDE, but still auto fix them
98
- "eslint.rules.customizations": [
99
- { "rule": "style/*", "severity": "off" },
100
- { "rule": "*-indent", "severity": "off" },
101
- { "rule": "*-spacing", "severity": "off" },
102
- { "rule": "*-spaces", "severity": "off" },
103
- { "rule": "*-order", "severity": "off" },
104
- { "rule": "*-dangle", "severity": "off" },
105
- { "rule": "*-newline", "severity": "off" },
106
- { "rule": "*quotes", "severity": "off" },
107
- { "rule": "*semi", "severity": "off" }
108
- ],
109
-
110
95
  // Enable eslint for all supported languages
111
96
  "eslint.validate": [
112
- "javascript",
113
- "javascriptreact",
114
- "typescript",
115
- "typescriptreact",
116
- "vue",
97
+ "svelte",
98
+ "astro",
117
99
  "html",
118
- "markdown",
100
+ "css",
101
+ "less",
102
+ "scss",
119
103
  "json",
120
104
  "jsonc",
121
- "yaml"
105
+ "yaml",
106
+ "yml",
107
+ "markdown",
108
+ "toml"
122
109
  ]
123
110
  `;
124
111
 
@@ -142,11 +129,23 @@ async function run(options = {}) {
142
129
  const pathPackageJSON = import_node_path.default.join(cwd, "package.json");
143
130
  const pathESLintIngore = import_node_path.default.join(cwd, ".eslintignore");
144
131
  if (import_node_fs.default.existsSync(pathFlatConfig)) {
145
- console.log(import_picocolors2.default.yellow(`${WARN} eslint.config.js already exists, migration wizard exited.`));
146
- return;
132
+ console.log(
133
+ import_picocolors2.default.yellow(
134
+ `${WARN} eslint.config.js already exists, migration wizard exited.`
135
+ )
136
+ );
137
+ return import_node_process.default.exit(1);
138
+ }
139
+ if (!SKIP_GIT_CHECK && !isGitClean()) {
140
+ const { confirmed } = await (0, import_prompts.default)({
141
+ initial: false,
142
+ message: "There are uncommitted changes in the current repository, are you sure to continue?",
143
+ name: "confirmed",
144
+ type: "confirm"
145
+ });
146
+ if (!confirmed)
147
+ return import_node_process.default.exit(1);
147
148
  }
148
- if (!SKIP_GIT_CHECK && !isGitClean())
149
- throw new Error("There are uncommitted changes in the current repository, please commit them and try again");
150
149
  console.log(import_picocolors2.default.cyan(`${ARROW} bumping @coderwyd/eslint-config to v${version}`));
151
150
  const pkgContent = await import_promises.default.readFile(pathPackageJSON, "utf-8");
152
151
  const pkg = JSON.parse(pkgContent);
@@ -166,24 +165,26 @@ async function run(options = {}) {
166
165
  if (glob.type === "ignore")
167
166
  eslintIgnores.push(...glob.patterns);
168
167
  else if (glob.type === "unignore")
169
- eslintIgnores.push(...glob.patterns.map((pattern) => `!${pattern}`));
168
+ eslintIgnores.push(
169
+ ...glob.patterns.map((pattern) => `!${pattern}`)
170
+ );
170
171
  }
171
172
  }
172
173
  let eslintConfigContent = "";
173
174
  const coderwydConfig = `${eslintIgnores.length ? `ignores: ${JSON.stringify(eslintIgnores)}` : ""}`;
174
175
  if (pkg.type === "module") {
175
176
  eslintConfigContent = `
176
- import coderwyd from '@coderwyd/eslint-config'
177
+ import { defineConfig } from '@coderwyd/eslint-config'
177
178
 
178
- export default coderwyd({
179
+ export default defineConfig({
179
180
  ${coderwydConfig}
180
181
  })
181
182
  `.trimStart();
182
183
  } else {
183
184
  eslintConfigContent = `
184
- const coderwyd = require('@coderwyd/eslint-config').default
185
+ const { defineConfig } = require('@coderwyd/eslint-config')
185
186
 
186
- module.exports = coderwyd({
187
+ module.exports = defineConfig({
187
188
  ${coderwydConfig}
188
189
  })
189
190
  `.trimStart();
@@ -205,22 +206,25 @@ ${coderwydConfig}
205
206
  };
206
207
  if (!SKIP_PROMPT) {
207
208
  try {
208
- promptResult = await (0, import_prompts.default)({
209
- initial: true,
210
- message: "Update .vscode/settings.json for better VS Code experience?",
211
- name: "updateVscodeSettings",
212
- type: "confirm"
213
- }, {
214
- onCancel: () => {
215
- throw new Error(`Cancelled`);
209
+ promptResult = await (0, import_prompts.default)(
210
+ {
211
+ initial: true,
212
+ message: "Update .vscode/settings.json for better VS Code experience?",
213
+ name: "updateVscodeSettings",
214
+ type: "confirm"
215
+ },
216
+ {
217
+ onCancel: () => {
218
+ throw new Error(`Cancelled`);
219
+ }
216
220
  }
217
- });
221
+ );
218
222
  } catch (cancelled) {
219
223
  console.log(cancelled.message);
220
224
  return;
221
225
  }
222
226
  }
223
- if (promptResult?.updateVscodeSettings ?? true) {
227
+ if ((promptResult == null ? void 0 : promptResult.updateVscodeSettings) ?? true) {
224
228
  const dotVscodePath = import_node_path.default.join(cwd, ".vscode");
225
229
  const settingsPath = import_node_path.default.join(dotVscodePath, "settings.json");
226
230
  if (!import_node_fs.default.existsSync(dotVscodePath))
@@ -240,8 +244,10 @@ ${coderwydConfig}
240
244
  }
241
245
  }
242
246
  console.log(import_picocolors2.default.green(`${CHECK} migration completed`));
243
- console.log(`Now you can update the dependencies and run ${import_picocolors2.default.blue("eslint . --fix")}
244
- `);
247
+ console.log(
248
+ `Now you can update the dependencies and run ${import_picocolors2.default.blue("eslint . --fix")}
249
+ `
250
+ );
245
251
  }
246
252
 
247
253
  // src/cli/index.ts
@@ -252,7 +258,11 @@ ${import_picocolors3.default.green(`@coderwyd/eslint-config `)}${import_picocolo
252
258
  var instance = (0, import_yargs.default)((0, import_helpers.hideBin)(import_node_process2.default.argv)).scriptName("@coderwyd/eslint-config").usage("").command(
253
259
  "*",
254
260
  "Run the initialization or migration",
255
- (args) => args.option("yes", { alias: "y", description: "Skip prompts and use default values", type: "boolean" }).help(),
261
+ (args) => args.option("yes", {
262
+ alias: "y",
263
+ description: "Skip prompts and use default values",
264
+ type: "boolean"
265
+ }).help(),
256
266
  async (args) => {
257
267
  header();
258
268
  console.log();