@lqbach/eslint-config 0.7.0 → 0.8.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/CHANGELOG.md +15 -0
- package/dist/index.cjs +33 -346
- package/dist/index.d.cts +15 -11
- package/dist/index.d.ts +15 -11
- package/dist/index.js +66 -402
- package/package.json +10 -7
- package/src/index.ts +39 -3
- package/src/libs.ts +2 -2
- package/src/types.ts +18 -13
- package/test/astro.spec.ts +120 -0
package/src/index.ts
CHANGED
|
@@ -3,10 +3,12 @@ import globals from "globals"
|
|
|
3
3
|
import {
|
|
4
4
|
configPrettier,
|
|
5
5
|
jsConfig,
|
|
6
|
+
parserAstro,
|
|
6
7
|
parserJsonc,
|
|
7
8
|
parserTypeScript,
|
|
8
9
|
parserVue,
|
|
9
10
|
parserYaml,
|
|
11
|
+
pluginAstro,
|
|
10
12
|
pluginJsonc,
|
|
11
13
|
pluginNext,
|
|
12
14
|
pluginPerfectionist,
|
|
@@ -150,7 +152,8 @@ export default function config(params: ConfigParams = {}): Array<ConfigObject> {
|
|
|
150
152
|
"react-hooks": pluginReactHooks,
|
|
151
153
|
},
|
|
152
154
|
rules: {
|
|
153
|
-
|
|
155
|
+
"react-hooks/exhaustive-deps": "warn",
|
|
156
|
+
"react-hooks/rules-of-hooks": "error",
|
|
154
157
|
},
|
|
155
158
|
}
|
|
156
159
|
: {}
|
|
@@ -174,8 +177,8 @@ export default function config(params: ConfigParams = {}): Array<ConfigObject> {
|
|
|
174
177
|
processor: pluginVue.processors[".vue"],
|
|
175
178
|
rules: {
|
|
176
179
|
...pluginVue.configs["base"].rules,
|
|
177
|
-
...pluginVue.configs["
|
|
178
|
-
...pluginVue.configs["
|
|
180
|
+
...pluginVue.configs["essential"].rules,
|
|
181
|
+
...pluginVue.configs["strongly-recommended"].rules,
|
|
179
182
|
},
|
|
180
183
|
}
|
|
181
184
|
: {}
|
|
@@ -264,6 +267,38 @@ export default function config(params: ConfigParams = {}): Array<ConfigObject> {
|
|
|
264
267
|
}
|
|
265
268
|
: {}
|
|
266
269
|
|
|
270
|
+
// Astro Config
|
|
271
|
+
const astroConfig: ConfigObject =
|
|
272
|
+
(params.astro ?? false)
|
|
273
|
+
? {
|
|
274
|
+
files: ["**/*.astro"],
|
|
275
|
+
languageOptions: {
|
|
276
|
+
parser: parserAstro,
|
|
277
|
+
parserOptions: params.typescript
|
|
278
|
+
? {
|
|
279
|
+
extraFileExtensions: [".astro"],
|
|
280
|
+
parser: parserTypeScript,
|
|
281
|
+
sourceType: "module",
|
|
282
|
+
}
|
|
283
|
+
: {},
|
|
284
|
+
},
|
|
285
|
+
name: "lqbach/astro",
|
|
286
|
+
plugins: {
|
|
287
|
+
astro: pluginAstro,
|
|
288
|
+
},
|
|
289
|
+
rules: {
|
|
290
|
+
"astro/missing-client-only-directive-value": "error",
|
|
291
|
+
"astro/no-conflict-set-directives": "error",
|
|
292
|
+
"astro/no-deprecated-astro-canonicalurl": "error",
|
|
293
|
+
"astro/no-deprecated-astro-fetchcontent": "error",
|
|
294
|
+
"astro/no-deprecated-astro-resolve": "error",
|
|
295
|
+
"astro/no-deprecated-getentrybyslug": "error",
|
|
296
|
+
"astro/no-unused-define-vars-in-style": "error",
|
|
297
|
+
"astro/valid-compile": "error",
|
|
298
|
+
},
|
|
299
|
+
}
|
|
300
|
+
: {}
|
|
301
|
+
|
|
267
302
|
const prettierConfig: ConfigObject = configPrettier
|
|
268
303
|
|
|
269
304
|
let config: Array<ConfigObject> = []
|
|
@@ -274,6 +309,7 @@ export default function config(params: ConfigParams = {}): Array<ConfigObject> {
|
|
|
274
309
|
config.push(reactHooksConfig)
|
|
275
310
|
config.push(vueConfig)
|
|
276
311
|
config.push(nextConfig)
|
|
312
|
+
config.push(astroConfig)
|
|
277
313
|
config.push(yamlConfig)
|
|
278
314
|
config.push(...jsoncConfig)
|
|
279
315
|
config.push(perfectionistConfig)
|
package/src/libs.ts
CHANGED
|
@@ -6,7 +6,9 @@ export { default as jsConfig } from "@eslint/js"
|
|
|
6
6
|
export { default as pluginNext } from "@next/eslint-plugin-next"
|
|
7
7
|
export { default as pluginTypeScript } from "@typescript-eslint/eslint-plugin"
|
|
8
8
|
export { default as parserTypeScript } from "@typescript-eslint/parser"
|
|
9
|
+
export { default as parserAstro } from "astro-eslint-parser"
|
|
9
10
|
export { default as configPrettier } from "eslint-config-prettier"
|
|
11
|
+
export { default as pluginAstro } from "eslint-plugin-astro"
|
|
10
12
|
export { default as pluginJsonc } from "eslint-plugin-jsonc"
|
|
11
13
|
export { default as pluginPerfectionist } from "eslint-plugin-perfectionist"
|
|
12
14
|
export { default as pluginReact } from "eslint-plugin-react"
|
|
@@ -15,7 +17,5 @@ export { default as pluginUnusedImports } from "eslint-plugin-unused-imports"
|
|
|
15
17
|
export { default as pluginVue } from "eslint-plugin-vue"
|
|
16
18
|
export { default as pluginYaml } from "eslint-plugin-yml"
|
|
17
19
|
export { default as parserJsonc } from "jsonc-eslint-parser"
|
|
18
|
-
|
|
19
20
|
export { default as parserVue } from "vue-eslint-parser"
|
|
20
|
-
|
|
21
21
|
export { default as parserYaml } from "yaml-eslint-parser"
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,22 @@
|
|
|
1
|
+
export interface AstroConfigParams {
|
|
2
|
+
typescript?: boolean
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export interface ConfigObject {
|
|
6
|
+
files?: Array<string>
|
|
7
|
+
ignores?: Array<string>
|
|
8
|
+
languageOptions?: LanguageOptions
|
|
9
|
+
linterOptions?: LinterOptions
|
|
10
|
+
name?: string
|
|
11
|
+
plugins?: object
|
|
12
|
+
processor?: object
|
|
13
|
+
rules?: object
|
|
14
|
+
// eslint-disable-next-line
|
|
15
|
+
settings?: any
|
|
16
|
+
}
|
|
17
|
+
|
|
1
18
|
export interface ConfigParams {
|
|
19
|
+
astro?: AstroConfigParams | boolean
|
|
2
20
|
ignores?: Array<string>
|
|
3
21
|
json?: boolean
|
|
4
22
|
markdown?: boolean
|
|
@@ -23,19 +41,6 @@ export interface LinterOptions {
|
|
|
23
41
|
reportUnusedDisableDirectives?: boolean
|
|
24
42
|
}
|
|
25
43
|
|
|
26
|
-
export interface ConfigObject {
|
|
27
|
-
files?: Array<string>
|
|
28
|
-
ignores?: Array<string>
|
|
29
|
-
languageOptions?: LanguageOptions
|
|
30
|
-
linterOptions?: LinterOptions
|
|
31
|
-
name?: string
|
|
32
|
-
plugins?: object
|
|
33
|
-
processor?: object
|
|
34
|
-
rules?: object
|
|
35
|
-
// eslint-disable-next-line
|
|
36
|
-
settings?: any
|
|
37
|
-
}
|
|
38
|
-
|
|
39
44
|
export interface NextJSConfigParams {
|
|
40
45
|
rootDir?: string
|
|
41
46
|
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest"
|
|
2
|
+
|
|
3
|
+
import eslintConfig from "../src"
|
|
4
|
+
import { getConfigObjectByName } from "./utils"
|
|
5
|
+
|
|
6
|
+
const ASTRO_CONFIG_OBJECT_NAME = "lqbach/astro"
|
|
7
|
+
|
|
8
|
+
// test astro configuration
|
|
9
|
+
describe("test astro eslint configuration", () => {
|
|
10
|
+
describe("if astro parameter is not true", () => {
|
|
11
|
+
const config = eslintConfig({ astro: false })
|
|
12
|
+
|
|
13
|
+
test("should not have a configuration object lqbach/astro", () => {
|
|
14
|
+
expect(getConfigObjectByName(ASTRO_CONFIG_OBJECT_NAME, config)).toBe(
|
|
15
|
+
undefined,
|
|
16
|
+
)
|
|
17
|
+
})
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
describe("if astro parameter is true", () => {
|
|
21
|
+
const config = eslintConfig({ astro: true })
|
|
22
|
+
|
|
23
|
+
test("should have a configuration object lqbach/astro", () => {
|
|
24
|
+
expect(
|
|
25
|
+
getConfigObjectByName(ASTRO_CONFIG_OBJECT_NAME, config),
|
|
26
|
+
).toBeTruthy()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test("should target *.astro files", () => {
|
|
30
|
+
const astroConfig = getConfigObjectByName(
|
|
31
|
+
ASTRO_CONFIG_OBJECT_NAME,
|
|
32
|
+
config,
|
|
33
|
+
)
|
|
34
|
+
expect(astroConfig?.files).toEqual(["**/*.astro"])
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test("should include astro plugin", () => {
|
|
38
|
+
const astroConfig = getConfigObjectByName(
|
|
39
|
+
ASTRO_CONFIG_OBJECT_NAME,
|
|
40
|
+
config,
|
|
41
|
+
)
|
|
42
|
+
expect(astroConfig?.plugins).toHaveProperty("astro")
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test("should include astro recommended rules", () => {
|
|
46
|
+
const astroConfig = getConfigObjectByName(
|
|
47
|
+
ASTRO_CONFIG_OBJECT_NAME,
|
|
48
|
+
config,
|
|
49
|
+
)
|
|
50
|
+
expect(astroConfig?.rules).toBeDefined()
|
|
51
|
+
expect(Object.keys(astroConfig?.rules || {})).toContain(
|
|
52
|
+
"astro/no-conflict-set-directives",
|
|
53
|
+
)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test("should not have typescript parser options when typescript is not enabled", () => {
|
|
57
|
+
const astroConfig = getConfigObjectByName(
|
|
58
|
+
ASTRO_CONFIG_OBJECT_NAME,
|
|
59
|
+
config,
|
|
60
|
+
)
|
|
61
|
+
expect(astroConfig?.languageOptions?.parserOptions).toEqual({})
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
describe("if astro parameter is a config object", () => {
|
|
66
|
+
test("should have a configuration object lqbach/astro when typescript is enabled", () => {
|
|
67
|
+
const config = eslintConfig({
|
|
68
|
+
astro: { typescript: true },
|
|
69
|
+
typescript: true,
|
|
70
|
+
})
|
|
71
|
+
expect(
|
|
72
|
+
getConfigObjectByName(ASTRO_CONFIG_OBJECT_NAME, config),
|
|
73
|
+
).toBeTruthy()
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
test("should include typescript parser options when typescript is enabled", () => {
|
|
77
|
+
const config = eslintConfig({
|
|
78
|
+
astro: { typescript: true },
|
|
79
|
+
typescript: true,
|
|
80
|
+
})
|
|
81
|
+
const astroConfig = getConfigObjectByName(
|
|
82
|
+
ASTRO_CONFIG_OBJECT_NAME,
|
|
83
|
+
config,
|
|
84
|
+
)
|
|
85
|
+
expect(astroConfig?.languageOptions?.parserOptions).toEqual({
|
|
86
|
+
extraFileExtensions: [".astro"],
|
|
87
|
+
parser: expect.any(Object),
|
|
88
|
+
sourceType: "module",
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
test("should not include typescript parser options when typescript is disabled", () => {
|
|
93
|
+
const config = eslintConfig({
|
|
94
|
+
astro: { typescript: false },
|
|
95
|
+
typescript: false,
|
|
96
|
+
})
|
|
97
|
+
const astroConfig = getConfigObjectByName(
|
|
98
|
+
ASTRO_CONFIG_OBJECT_NAME,
|
|
99
|
+
config,
|
|
100
|
+
)
|
|
101
|
+
expect(astroConfig?.languageOptions?.parserOptions).toEqual({})
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
describe("default behavior", () => {
|
|
106
|
+
test("should not include astro config by default", () => {
|
|
107
|
+
const config = eslintConfig({})
|
|
108
|
+
expect(getConfigObjectByName(ASTRO_CONFIG_OBJECT_NAME, config)).toBe(
|
|
109
|
+
undefined,
|
|
110
|
+
)
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
test("should not include astro config when astro is undefined", () => {
|
|
114
|
+
const config = eslintConfig({ astro: undefined })
|
|
115
|
+
expect(getConfigObjectByName(ASTRO_CONFIG_OBJECT_NAME, config)).toBe(
|
|
116
|
+
undefined,
|
|
117
|
+
)
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
})
|