@lincy/eslint-config 2.5.3 → 3.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019-PRESENT Anthony Fu<https://github.com/antfu>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,22 +1,253 @@
1
1
  # @lincy/eslint-config
2
2
 
3
- A set of opinionated ESLint (http://eslint.org) rules (all rules included) tailored for Vue.js projects
3
+ [![npm](https://img.shields.io/npm/v/@lincy/eslint-config?color=444&label=)](https://npmjs.com/package/@lincy/eslint-config)
4
4
 
5
- 自动区分vue2和vue3的规则
6
- 如果依赖安装了 typescript, 则自动应用 ts 的规则
7
- 如果依赖安装了 prettier, 则自动应用 prettier 的规则
5
+ - 单引号,无结尾分号
6
+ - 自动格式化
7
+ - 专为与 TypeScript、Vue(2/3) 一起使用而设计,开箱即用
8
+ - Lint 也适用于 json、yaml、markdown
9
+ - import导入排序, 对象字⾯量项尾逗号
10
+ - 合理的默认值,最佳实践,只需一行配置
11
+ - [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new)
12
+ - 使用 [ESLint Stylistic](https://github.com/eslint-stylistic/eslint-stylistic)
13
+ - **风格原则**: 读取最小,差异稳定
8
14
 
9
- Usage
15
+ ## Usage
10
16
 
11
- - pnpm install -D eslint @lincy/eslint-config
12
- - create a file named .eslintrc in your project:
17
+ ### Install
18
+
19
+ ```bash
20
+ pnpm add -D eslint @lincy/eslint-config
21
+ ```
22
+
23
+ ### Create config file
24
+
25
+ ```js
26
+ // eslint.config.js
27
+ import eslintConfig from '@lincy/eslint-config'
28
+
29
+ export default eslintConfig()
30
+ ```
31
+
32
+ > 通常您不需要`.eslintignore`,因为它已由预设提供。
33
+
34
+ ### Add script for package.json
35
+
36
+ For example:
37
+
38
+ ```json
39
+ {
40
+ "scripts": {
41
+ "lint": "eslint .",
42
+ "lint:fix": "eslint . --fix"
43
+ }
44
+ }
45
+ ```
46
+
47
+ ## VS Code support (auto fix)
48
+
49
+ 安装[VS Code ESLint扩展](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
50
+
51
+ 将以下设置添加到您的“settings.json”:
52
+
53
+ ```jsonc
54
+ {
55
+ // Enable the flat config support
56
+ "eslint.experimental.useFlatConfig": true,
57
+
58
+ // Disable the default formatter
59
+ "prettier.enable": false,
60
+ "editor.formatOnSave": false,
61
+
62
+ // Auto fix
63
+ "editor.codeActionsOnSave": {
64
+ "source.fixAll.eslint": true,
65
+ "source.organizeImports": false
66
+ },
67
+
68
+ // Silent the stylistic rules in you IDE, but still auto fix them
69
+ "eslint.rules.customizations": [
70
+ { "rule": "@stylistic/*", "severity": "off" },
71
+ { "rule": "*-indent", "severity": "off" },
72
+ { "rule": "*-spacing", "severity": "off" },
73
+ { "rule": "*-spaces", "severity": "off" },
74
+ { "rule": "*-order", "severity": "off" },
75
+ { "rule": "*-dangle", "severity": "off" },
76
+ { "rule": "*-newline", "severity": "off" },
77
+ { "rule": "*quotes", "severity": "off" },
78
+ { "rule": "*semi", "severity": "off" }
79
+ ],
80
+
81
+ // The following is optional.
82
+ // It's better to put under project setting `.vscode/settings.json`
83
+ // to avoid conflicts with working with different eslint configs
84
+ // that does not support all formats.
85
+ "eslint.validate": [
86
+ "javascript",
87
+ "javascriptreact",
88
+ "typescript",
89
+ "typescriptreact",
90
+ "vue",
91
+ "html",
92
+ "markdown",
93
+ "json",
94
+ "jsonc",
95
+ "yaml"
96
+ ]
97
+ }
98
+ ```
99
+
100
+ ## 定制化
101
+
102
+ 通常你只需要导入 `eslintConfig` 预设:
103
+
104
+ ```js
105
+ // eslint.config.js
106
+ import eslintConfig from '@lincy/eslint-config'
107
+
108
+ export default eslintConfig()
109
+ ```
110
+
111
+ 您可以单独配置每个功能,例如:
112
+
113
+ ```js
114
+ // eslint.config.js
115
+ import eslintConfig from '@lincy/eslint-config'
116
+
117
+ export default eslintConfig({
118
+ stylistic: true, // enable stylistic formatting rules
119
+ typescript: true,
120
+ vue: true,
121
+ jsonc: false,
122
+ yml: false,
123
+ })
124
+ ```
125
+
126
+ `eslintConfig` 工厂函数还接受任意数量的自定义配置覆盖:
127
+
128
+ ```js
129
+ // eslint.config.js
130
+ import eslintConfig from '@lincy/eslint-config'
131
+
132
+ export default eslintConfig(
133
+ {
134
+ // Configures for config
135
+ },
136
+
137
+ // From the second arguments they are ESLint Flat Configs
138
+ // you can have multiple configs
139
+ {
140
+ rules: {},
141
+ },
142
+ {
143
+ rules: {},
144
+ },
145
+ )
146
+ ```
147
+
148
+ 更高级的是,您还可以导入非常细粒度的配置并根据需要组合它们:
149
+
150
+ ```js
151
+ // eslint.config.js
152
+ import {
153
+ comments,
154
+ ignores,
155
+ imports,
156
+ javascript,
157
+ javascriptStylistic,
158
+ jsdoc,
159
+ jsonc,
160
+ markdown,
161
+ node,
162
+ sortPackageJson,
163
+ sortTsconfig,
164
+ typescript,
165
+ typescriptStylistic,
166
+ unicorn,
167
+ vue,
168
+ yml,
169
+ } from '@lincy/eslint-config'
170
+
171
+ export default [
172
+ ...ignores,
173
+ ...javascript(),
174
+ ...comments,
175
+ ...node,
176
+ ...jsdoc,
177
+ ...imports,
178
+ ...unicorn,
179
+ ...javascriptStylistic,
180
+
181
+ ...typescript(),
182
+ ...typescriptStylistic,
183
+
184
+ ...vue(),
185
+ ...jsonc,
186
+ ...yml,
187
+ ...markdown(),
188
+ ]
13
189
  ```
190
+
191
+ 查看 [configs](https://github.com/lincenying/eslint-config/blob/main/src/configs) 和 [factory](https://github.com/lincenying/eslint-config/blob/ main/src/factory.ts)了解更多详细信息。
192
+
193
+ > Thanks to [sxzz/eslint-config](https://github.com/sxzz/eslint-config) for the inspiration and reference.
194
+
195
+ ## Plugins Renaming
196
+
197
+ 由于平面配置支持显式提供了插件名称,因此我们重命名了一些插件以使它们更加一致并隐藏实现细节。
198
+
199
+ | Original Prefix | New Prefix | Source Plugin |
200
+ | --------------- | ---------- | ------------- |
201
+ | `i/*` | `import/*` | [eslint-plugin-i](https://github.com/un-es/eslint-plugin-i) |
202
+ | `n/*` | `node` | [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n)
203
+ | `@typescript-eslint/*` | `ts/*` | [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) |
204
+ | `@stylistic/js` | `style/*` | [@stylistic/eslint-plugin-js](https://github.com/eslint-stylistic/eslint-stylistic) |
205
+ | `@stylistic/ts` | `style-ts/` | [@stylistic/eslint-plugin-ts](https://github.com/eslint-stylistic/eslint-stylistic) |
206
+
207
+ 当您想要覆盖规则或内联禁用它们时,您需要更新到新的前缀:
208
+
209
+ ```diff
210
+ -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
211
+ +// eslint-disable-next-line ts/consistent-type-definitions
212
+ type foo = { bar: 2 }
213
+ ```
214
+
215
+ ### Type Aware Rules
216
+
217
+ 您可以选择通过将选项对象传递给“typescript”配置来启用[类型感知规则](https://typescript-eslint.io/linting/typed-linting/):
218
+
219
+ ```js
220
+ // eslint.config.js
221
+ import eslintConfig from '@lincy/eslint-config'
222
+
223
+ export default eslintConfig({
224
+ typescript: {
225
+ tsconfigPath: 'tsconfig.json',
226
+ },
227
+ })
228
+ ```
229
+
230
+ ### Lint Staged
231
+
232
+ 如果你想在每次提交之前应用 lint 和自动修复,你可以将以下内容添加到你的 `package.json` 中:
233
+
234
+ ```json
14
235
  {
15
- "extends": "@lincy"
16
- // Your overrides...
236
+ "simple-git-hooks": {
237
+ "pre-commit": "pnpm lint-staged"
238
+ },
239
+ "lint-staged": {
240
+ "*": "eslint --fix"
241
+ }
17
242
  }
18
243
  ```
19
244
 
20
- License
245
+ 然后
246
+
247
+ ```bash
248
+ npm i -D lint-staged simple-git-hooks
249
+ ```
250
+
251
+ ## License
21
252
 
22
- MIT
253
+ [MIT]
@@ -0,0 +1,149 @@
1
+ import { FlatESLintConfigItem } from 'eslint-define-config';
2
+ export { default as pluginAntfu } from 'eslint-plugin-antfu';
3
+ export { default as pluginComments } from 'eslint-plugin-eslint-comments';
4
+ export { default as pluginImport } from 'eslint-plugin-i';
5
+ export { default as pluginJsdoc } from 'eslint-plugin-jsdoc';
6
+ export { default as pluginJsonc } from 'eslint-plugin-jsonc';
7
+ export { default as pluginMarkdown } from 'eslint-plugin-markdown';
8
+ export { default as pluginNode } from 'eslint-plugin-n';
9
+ export { default as pluginStylisticJs } from '@stylistic/eslint-plugin-js';
10
+ export { default as pluginStylisticTs } from '@stylistic/eslint-plugin-ts';
11
+ export { default as pluginTs } from '@typescript-eslint/eslint-plugin';
12
+ export { default as pluginUnicorn } from 'eslint-plugin-unicorn';
13
+ export { default as pluginUnusedImports } from 'eslint-plugin-unused-imports';
14
+ export { default as pluginVue } from 'eslint-plugin-vue';
15
+ export { default as pluginYml } from 'eslint-plugin-yml';
16
+ export { default as pluginNoOnlyTests } from 'eslint-plugin-no-only-tests';
17
+ export { default as parserTs } from '@typescript-eslint/parser';
18
+ export { default as parserVue } from 'vue-eslint-parser';
19
+ export { default as parserYml } from 'yaml-eslint-parser';
20
+ export { default as parserJsonc } from 'jsonc-eslint-parser';
21
+
22
+ interface OptionsComponentExts {
23
+ /**
24
+ * Additional extensions for components.
25
+ *
26
+ * @example ['vue']
27
+ * @default []
28
+ */
29
+ componentExts?: string[];
30
+ }
31
+ interface OptionsTypeScriptWithLanguageServer {
32
+ tsconfigPath: string;
33
+ tsconfigRootDir?: string;
34
+ }
35
+ interface OptionsHasTypeScript {
36
+ typescript?: boolean;
37
+ }
38
+ interface OptionsIsInEditor {
39
+ isInEditor?: boolean;
40
+ }
41
+ interface OptionsConfig {
42
+ /**
43
+ * Enable TypeScript support.
44
+ *
45
+ * Passing an object to enable TypeScript Language Server support.
46
+ *
47
+ * @default auto-detect based on the dependencies
48
+ */
49
+ typescript?: boolean | OptionsTypeScriptWithLanguageServer;
50
+ /**
51
+ * Enable test support.
52
+ *
53
+ * @default true
54
+ */
55
+ test?: boolean;
56
+ /**
57
+ * Enable Vue support.
58
+ *
59
+ * @default auto-detect based on the dependencies
60
+ */
61
+ vue?: boolean;
62
+ /**
63
+ * Enable JSONC support.
64
+ *
65
+ * @default true
66
+ */
67
+ jsonc?: boolean;
68
+ /**
69
+ * Enable YAML support.
70
+ *
71
+ * @default true
72
+ */
73
+ yaml?: boolean;
74
+ /**
75
+ * Enable Markdown support.
76
+ *
77
+ * @default true
78
+ */
79
+ markdown?: boolean;
80
+ /**
81
+ * Enable stylistic rules.
82
+ *
83
+ * @default true
84
+ */
85
+ stylistic?: boolean;
86
+ /**
87
+ * Control to disable some rules in editors.
88
+ * @default auto-detect based on the process.env
89
+ */
90
+ isInEditor?: boolean;
91
+ }
92
+
93
+ /**
94
+ * Construct an array of ESLint flat config items.
95
+ */
96
+ declare function factoryFunc(options?: OptionsConfig, ...userConfigs: (FlatESLintConfigItem | FlatESLintConfigItem[])[]): FlatESLintConfigItem[];
97
+
98
+ declare const comments: FlatESLintConfigItem[];
99
+
100
+ declare const ignores: FlatESLintConfigItem[];
101
+
102
+ declare const imports: FlatESLintConfigItem[];
103
+
104
+ declare function javascript(options?: OptionsIsInEditor): FlatESLintConfigItem[];
105
+
106
+ declare const jsdoc: FlatESLintConfigItem[];
107
+
108
+ declare const jsonc: FlatESLintConfigItem[];
109
+
110
+ declare function markdown(options?: OptionsComponentExts): FlatESLintConfigItem[];
111
+
112
+ declare const node: FlatESLintConfigItem[];
113
+
114
+ /**
115
+ * Sort package.json
116
+ *
117
+ * Requires `jsonc` config
118
+ */
119
+ declare const sortPackageJson: FlatESLintConfigItem[];
120
+ /**
121
+ * Sort tsconfig.json
122
+ *
123
+ * Requires `jsonc` config
124
+ */
125
+ declare const sortTsconfig: FlatESLintConfigItem[];
126
+
127
+ declare const javascriptStylistic: FlatESLintConfigItem[];
128
+ declare const typescriptStylistic: FlatESLintConfigItem[];
129
+
130
+ declare function typescript(options?: OptionsComponentExts): FlatESLintConfigItem[];
131
+ declare function typescriptWithLanguageServer(options: OptionsTypeScriptWithLanguageServer & OptionsComponentExts): FlatESLintConfigItem[];
132
+
133
+ declare const unicorn: FlatESLintConfigItem[];
134
+
135
+ declare function vue(options?: OptionsHasTypeScript): FlatESLintConfigItem[];
136
+
137
+ declare const yml: FlatESLintConfigItem[];
138
+
139
+ declare function test(options?: OptionsIsInEditor): FlatESLintConfigItem[];
140
+
141
+ /**
142
+ * Combine array and non-array configs into a single array.
143
+ */
144
+ declare function combine(...configs: (FlatESLintConfigItem | FlatESLintConfigItem[])[]): FlatESLintConfigItem[];
145
+ declare function renameRules(rules: Record<string, any>, from: string, to: string): {
146
+ [k: string]: any;
147
+ };
148
+
149
+ export { OptionsComponentExts, OptionsConfig, OptionsHasTypeScript, OptionsIsInEditor, OptionsTypeScriptWithLanguageServer, combine, comments, factoryFunc as default, factoryFunc, ignores, imports, javascript, javascriptStylistic, jsdoc, jsonc, markdown, node, renameRules, sortPackageJson, sortTsconfig, test, typescript, typescriptStylistic, typescriptWithLanguageServer, unicorn, vue, yml };