@lqbach/eslint-config 0.7.0 → 0.8.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/src/libs.ts CHANGED
@@ -7,6 +7,7 @@ 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
9
  export { default as configPrettier } from "eslint-config-prettier"
10
+ export { default as pluginAstro } from "eslint-plugin-astro"
10
11
  export { default as pluginJsonc } from "eslint-plugin-jsonc"
11
12
  export { default as pluginPerfectionist } from "eslint-plugin-perfectionist"
12
13
  export { default as pluginReact } from "eslint-plugin-react"
@@ -15,7 +16,5 @@ export { default as pluginUnusedImports } from "eslint-plugin-unused-imports"
15
16
  export { default as pluginVue } from "eslint-plugin-vue"
16
17
  export { default as pluginYaml } from "eslint-plugin-yml"
17
18
  export { default as parserJsonc } from "jsonc-eslint-parser"
18
-
19
19
  export { default as parserVue } from "vue-eslint-parser"
20
-
21
20
  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
+ })