Skip to content

Commit f03b83c

Browse files
committed
chore: edit formatter options
1 parent e31c9f6 commit f03b83c

File tree

12 files changed

+111
-929
lines changed

12 files changed

+111
-929
lines changed

.vscode/settings.json

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
"eslint.experimental.useFlatConfig": true,
77
"editor.formatOnSave": false,
88
"eslint.validate": [
9-
"svelte",
10-
"astro",
119
"html",
1210
"css",
1311
"less",
@@ -20,11 +18,5 @@
2018
"toml"
2119
],
2220
"prettier.enable": false,
23-
"cSpell.words": [
24-
"antfu",
25-
"coderwyd",
26-
"rspack",
27-
"unocss"
28-
]
21+
"cSpell.words": ["antfu", "coderwyd", "rspack", "unocss"]
2922
}
30-

README.md

Lines changed: 12 additions & 229 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77
## Feature
88

99
- ✨ Single quotes, no semi
10-
- 🛠️ Auto fix for formatting (aimed to be used standalone **without** Prettier)
10+
- 🛠️ Auto fix for formatting
1111
- 🎯 Designed to work with TypeScript, Vue out-of-box
1212
- 🔍 Lints also for json, yaml, markdown
1313
- 🧩 Sorted imports, dangling commas
1414
- 🏆 Reasonable defaults, best practices, only one-line of config
1515
- 🚀 [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
1816

1917
## Usage
2018

@@ -30,18 +28,18 @@ With [`"type": "module"`](https://nodejs.org/api/packages.html#type) in `package
3028

3129
```js
3230
// eslint.config.js
33-
import coderwyd from '@coderwyd/eslint-config'
31+
import { defineConfig } from '@coderwyd/eslint-config'
3432

35-
export default coderwyd()
33+
export default defineConfig()
3634
```
3735

3836
With CJS:
3937

4038
```js
4139
// eslint.config.js
42-
const coderwyd = require('@coderwyd/eslint-config').default
40+
const { defineConfig } = require('@coderwyd/eslint-config')
4341

44-
module.exports = coderwyd()
42+
module.exports = defineConfig()
4543
```
4644

4745
> Note that `.eslintignore` no longer works in Flat config, see [customization](#customization) for more details.
@@ -80,237 +78,22 @@ Add the following settings to your `.vscode/settings.json`:
8078
"source.organizeImports": "never"
8179
},
8280

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-
9681
// Enable eslint for all supported languages
9782
"eslint.validate": [
98-
"javascript",
99-
"javascriptreact",
100-
"typescript",
101-
"typescriptreact",
102-
"vue",
10383
"html",
104-
"markdown",
84+
"css",
85+
"less",
86+
"scss",
10587
"json",
10688
"jsonc",
107-
"yaml"
89+
"yaml",
90+
"yml",
91+
"markdown",
92+
"toml"
10893
]
10994
}
11095
```
11196

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-
31497
### Lint Staged
31598

31699
If you want to apply lint and auto-fix before every commit, you can add the following to your `package.json`:

eslint.config.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
import 'tsx'
22
import { createRequire } from 'node:module'
33

4+
// eslint-disable-next-line antfu/no-import-dist
5+
import { defineConfig as defineConfig2 } from './dist/index.js'
6+
47
const require = createRequire(import.meta.url)
58

6-
const { defineConfig } = require('./src/index.ts')
9+
const { defineConfig: defineConfig1 } = require('./src/index.ts')
10+
11+
const useBuild = true
712

813
/** @type {import('./src/index.ts').defineConfig} */
14+
const defineConfig = useBuild ? defineConfig2 : defineConfig1
15+
916
export default defineConfig(
1017
{
1118
vue: true,
1219
react: false,
1320
typescript: true,
14-
ignores: ['fixtures', '_fixtures'],
21+
formatter: true,
1522
},
1623
{
1724
files: ['src/**/*.ts'],

example/css.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.abv {
2+
color: white;
3+
}

example/html.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!doctype html>
2+
<html class="no-js mY-ClAsS">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>My tITlE</title>
6+
<meta name="description" content="My CoNtEnT" />
7+
</head>
8+
<body>
9+
<p>
10+
Hello world!
11+
<br />
12+
This is HTML5 Boilerplate.
13+
</p>
14+
<script>
15+
window.ga = function () {
16+
ga.q.push(arguments)
17+
}
18+
ga.q = []
19+
ga.l = +new Date()
20+
ga('create', 'UA-XXXXX-Y', 'auto')
21+
ga('send', 'pageview')
22+
</script>
23+
<script
24+
src="https://www.google-analytics.com/analytics.js"
25+
async
26+
defer
27+
></script>
28+
</body>
29+
</html>

example/less.less

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.anv {
2+
color: red;
3+
.bbb {
4+
color: aliceblue;
5+
}
6+
}

example/scss.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.anv {
2+
color: red;
3+
.bbb {
4+
color: aliceblue;
5+
}
6+
}

0 commit comments

Comments
 (0)