@curev/eslint-config 0.2.1 → 0.3.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.
Files changed (103) hide show
  1. package/.eslintignore +1 -0
  2. package/.github/workflows/release.yml +37 -0
  3. package/.vscode/settings.json +36 -0
  4. package/CHANGELOG.md +740 -0
  5. package/README.md +70 -0
  6. package/eslint.config.ts +3 -0
  7. package/fixtures/input/css.css +10 -0
  8. package/fixtures/input/html.html +17 -0
  9. package/fixtures/input/javascript.js +69 -0
  10. package/fixtures/input/jsx.jsx +27 -0
  11. package/fixtures/input/markdown.md +34 -0
  12. package/fixtures/input/svelte.svelte +8 -0
  13. package/fixtures/input/toml.toml +23 -0
  14. package/fixtures/input/tsx.tsx +32 -0
  15. package/fixtures/input/typescript.ts +84 -0
  16. package/fixtures/input/vue-ts.vue +35 -0
  17. package/fixtures/input/vue.vue +27 -0
  18. package/fixtures/output/all/javascript.js +72 -0
  19. package/fixtures/output/all/jsx.jsx +26 -0
  20. package/fixtures/output/all/markdown.md +33 -0
  21. package/fixtures/output/all/svelte.svelte +8 -0
  22. package/fixtures/output/all/toml.toml +23 -0
  23. package/fixtures/output/all/tsx.tsx +32 -0
  24. package/fixtures/output/all/typescript.ts +83 -0
  25. package/fixtures/output/all/vue-ts.vue +35 -0
  26. package/fixtures/output/all/vue.vue +24 -0
  27. package/fixtures/output/js/javascript.js +72 -0
  28. package/fixtures/output/js/markdown.md +33 -0
  29. package/fixtures/output/js/toml.toml +23 -0
  30. package/fixtures/output/no-markdown-with-formatters/javascript.js +72 -0
  31. package/fixtures/output/no-markdown-with-formatters/jsx.jsx +24 -0
  32. package/fixtures/output/no-markdown-with-formatters/markdown.md +33 -0
  33. package/fixtures/output/no-markdown-with-formatters/toml.toml +23 -0
  34. package/fixtures/output/no-markdown-with-formatters/tsx.tsx +23 -0
  35. package/fixtures/output/no-markdown-with-formatters/typescript.ts +83 -0
  36. package/fixtures/output/no-style/javascript.js +72 -0
  37. package/fixtures/output/no-style/jsx.jsx +21 -0
  38. package/fixtures/output/no-style/toml.toml +23 -0
  39. package/fixtures/output/no-style/typescript.ts +80 -0
  40. package/fixtures/output/no-style/vue-ts.vue +35 -0
  41. package/fixtures/output/no-style/vue.vue +24 -0
  42. package/fixtures/output/tab-double-quotes/javascript.js +72 -0
  43. package/fixtures/output/tab-double-quotes/jsx.jsx +26 -0
  44. package/fixtures/output/tab-double-quotes/markdown.md +33 -0
  45. package/fixtures/output/tab-double-quotes/toml.toml +23 -0
  46. package/fixtures/output/tab-double-quotes/tsx.tsx +32 -0
  47. package/fixtures/output/tab-double-quotes/typescript.ts +83 -0
  48. package/fixtures/output/tab-double-quotes/vue-ts.vue +35 -0
  49. package/fixtures/output/tab-double-quotes/vue.vue +24 -0
  50. package/fixtures/output/ts-override/javascript.js +72 -0
  51. package/fixtures/output/ts-override/jsx.jsx +26 -0
  52. package/fixtures/output/ts-override/markdown.md +33 -0
  53. package/fixtures/output/ts-override/toml.toml +23 -0
  54. package/fixtures/output/ts-override/tsx.tsx +32 -0
  55. package/fixtures/output/ts-override/typescript.ts +83 -0
  56. package/fixtures/output/ts-override/vue-ts.vue +35 -0
  57. package/fixtures/output/ts-override/vue.vue +24 -0
  58. package/fixtures/output/with-formatters/css.css +11 -0
  59. package/fixtures/output/with-formatters/html.html +28 -0
  60. package/fixtures/output/with-formatters/javascript.js +72 -0
  61. package/fixtures/output/with-formatters/jsx.jsx +26 -0
  62. package/fixtures/output/with-formatters/markdown.md +34 -0
  63. package/fixtures/output/with-formatters/toml.toml +23 -0
  64. package/fixtures/output/with-formatters/tsx.tsx +32 -0
  65. package/fixtures/output/with-formatters/typescript.ts +83 -0
  66. package/fixtures/output/with-formatters/vue-ts.vue +38 -0
  67. package/fixtures/output/with-formatters/vue.vue +24 -0
  68. package/package.json +130 -12
  69. package/src/configs/comments.ts +19 -0
  70. package/src/configs/formatters.ts +187 -0
  71. package/src/configs/ignores.ts +10 -0
  72. package/src/configs/imports.ts +46 -0
  73. package/src/configs/index.ts +21 -0
  74. package/src/configs/javascript.ts +277 -0
  75. package/src/configs/jsdoc.ts +41 -0
  76. package/src/configs/jsonc.ts +86 -0
  77. package/src/configs/markdown.ts +110 -0
  78. package/src/configs/node.ts +24 -0
  79. package/src/configs/perfectionist.ts +18 -0
  80. package/src/configs/react.ts +111 -0
  81. package/src/configs/sort.ts +223 -0
  82. package/src/configs/stylistic.ts +52 -0
  83. package/src/configs/svelte.ts +107 -0
  84. package/src/configs/test.ts +54 -0
  85. package/src/configs/toml.ts +72 -0
  86. package/src/configs/typescript.ts +171 -0
  87. package/src/configs/unicorn.ts +41 -0
  88. package/src/configs/unocss.ts +43 -0
  89. package/src/configs/vue.ts +170 -0
  90. package/src/configs/yaml.ts +72 -0
  91. package/src/factory.ts +255 -0
  92. package/src/globs.ts +81 -0
  93. package/src/index.ts +9 -0
  94. package/src/plugins.ts +10 -0
  95. package/src/stub.d.ts +3 -0
  96. package/src/types.ts +364 -0
  97. package/src/utils.ts +76 -0
  98. package/src/vender/prettier-types.ts +136 -0
  99. package/test/cli.spec.ts +90 -0
  100. package/test/fixtures.test.ts +127 -0
  101. package/tsconfig.json +17 -0
  102. package/tsup.config.ts +8 -0
  103. package/index.js +0 -5
@@ -0,0 +1,110 @@
1
+ import { mergeProcessors, processorPassThrough } from "eslint-merge-processors";
2
+ import type { FlatConfigItem, OptionsComponentExts, OptionsFiles, OptionsOverrides } from "../types";
3
+ import { GLOB_MARKDOWN, GLOB_MARKDOWN_CODE, GLOB_MARKDOWN_IN_MARKDOWN } from "../globs";
4
+ import { interopDefault, parserPlain } from "../utils";
5
+
6
+ export async function markdown(
7
+ options: OptionsFiles & OptionsComponentExts & OptionsOverrides = {}
8
+ ): Promise<FlatConfigItem[]> {
9
+ const {
10
+ componentExts = [],
11
+ files = [GLOB_MARKDOWN],
12
+ overrides = {}
13
+ } = options;
14
+
15
+ // @ts-expect-error missing types
16
+ const markdown = await interopDefault(import("eslint-plugin-markdown"));
17
+
18
+ return [
19
+ {
20
+ name: "curev:markdown:setup",
21
+ plugins: {
22
+ markdown
23
+ }
24
+ },
25
+ {
26
+ files,
27
+ ignores: [GLOB_MARKDOWN_IN_MARKDOWN],
28
+ name: "curev:markdown:processor",
29
+ // `eslint-plugin-markdown` only creates virtual files for code blocks,
30
+ // but not the markdown file itself. We use `eslint-merge-processors` to
31
+ // add a pass-through processor for the markdown file itself.
32
+ processor: mergeProcessors([
33
+ markdown.processors.markdown,
34
+ processorPassThrough
35
+ ])
36
+ },
37
+ {
38
+ files,
39
+ languageOptions: {
40
+ parser: parserPlain
41
+ },
42
+ name: "curev:markdown:parser"
43
+ },
44
+ {
45
+ files: [
46
+ GLOB_MARKDOWN_CODE,
47
+ ...componentExts.map(ext => `${GLOB_MARKDOWN}/**/*.${ext}`)
48
+ ],
49
+ languageOptions: {
50
+ parserOptions: {
51
+ ecmaFeatures: {
52
+ impliedStrict: true
53
+ }
54
+ }
55
+ },
56
+ name: "curev:markdown:disables",
57
+ rules: {
58
+ "import/newline-after-import": "off",
59
+
60
+ "no-alert": "off",
61
+ "no-console": "off",
62
+ "no-labels": "off",
63
+ "no-lone-blocks": "off",
64
+ "no-restricted-syntax": "off",
65
+ "no-undef": "off",
66
+ "no-unused-expressions": "off",
67
+ "no-unused-labels": "off",
68
+ "no-unused-vars": "off",
69
+
70
+ "node/prefer-global/process": "off",
71
+ "style/comma-dangle": "off",
72
+
73
+ "style/eol-last": "off",
74
+ "ts/consistent-type-imports": "off",
75
+ "ts/no-namespace": "off",
76
+ "ts/no-redeclare": "off",
77
+ "ts/no-require-imports": "off",
78
+ "ts/no-unused-vars": "off",
79
+ "ts/no-use-before-define": "off",
80
+ "ts/no-var-requires": "off",
81
+
82
+ "unicode-bom": "off",
83
+ "unused-imports/no-unused-imports": "off",
84
+ "unused-imports/no-unused-vars": "off",
85
+
86
+ // Type aware rules
87
+ ...{
88
+ "ts/await-thenable": "off",
89
+ "ts/dot-notation": "off",
90
+ "ts/no-floating-promises": "off",
91
+ "ts/no-for-in-array": "off",
92
+ "ts/no-implied-eval": "off",
93
+ "ts/no-misused-promises": "off",
94
+ "ts/no-throw-literal": "off",
95
+ "ts/no-unnecessary-type-assertion": "off",
96
+ "ts/no-unsafe-argument": "off",
97
+ "ts/no-unsafe-assignment": "off",
98
+ "ts/no-unsafe-call": "off",
99
+ "ts/no-unsafe-member-access": "off",
100
+ "ts/no-unsafe-return": "off",
101
+ "ts/restrict-plus-operands": "off",
102
+ "ts/restrict-template-expressions": "off",
103
+ "ts/unbound-method": "off"
104
+ },
105
+
106
+ ...overrides
107
+ }
108
+ }
109
+ ];
110
+ }
@@ -0,0 +1,24 @@
1
+ import type { FlatConfigItem } from "../types";
2
+ import { pluginNode } from "../plugins";
3
+
4
+ export async function node(): Promise<FlatConfigItem[]> {
5
+ return [
6
+ {
7
+ name: "curev:node",
8
+ plugins: {
9
+ node: pluginNode
10
+ },
11
+ rules: {
12
+ "node/handle-callback-err": ["error", "^(err|error)$"],
13
+ "node/no-deprecated-api": "error",
14
+ "node/no-exports-assign": "error",
15
+ "node/no-new-require": "error",
16
+ "node/no-path-concat": "error",
17
+ "node/prefer-global/buffer": ["error", "never"],
18
+ "node/prefer-global/process": ["error", "never"],
19
+ "node/process-exit-as-throw": "error",
20
+ "node/no-callback-literal": "error"
21
+ }
22
+ }
23
+ ];
24
+ }
@@ -0,0 +1,18 @@
1
+ import type { FlatConfigItem } from "../types";
2
+ import { pluginPerfectionist } from "../plugins";
3
+
4
+ /**
5
+ * Optional perfectionist plugin for props and items sorting.
6
+ *
7
+ * @see https://github.com/azat-io/eslint-plugin-perfectionist
8
+ */
9
+ export async function perfectionist(): Promise<FlatConfigItem[]> {
10
+ return [
11
+ {
12
+ name: "curev:perfectionist",
13
+ plugins: {
14
+ perfectionist: pluginPerfectionist
15
+ }
16
+ }
17
+ ];
18
+ }
@@ -0,0 +1,111 @@
1
+ import { isPackageExists } from "local-pkg";
2
+ import { ensurePackages, interopDefault } from "../utils";
3
+ import type { FlatConfigItem, OptionsFiles, OptionsHasTypeScript, OptionsOverrides } from "../types";
4
+ import { GLOB_JSX, GLOB_TSX } from "../globs";
5
+
6
+ // react refresh
7
+ const ReactRefreshAllowConstantExportPackages = [
8
+ "vite"
9
+ ];
10
+
11
+ export async function react(
12
+ options: OptionsHasTypeScript & OptionsOverrides & OptionsFiles = {}
13
+ ): Promise<FlatConfigItem[]> {
14
+ const {
15
+ files = [GLOB_JSX, GLOB_TSX],
16
+ overrides = {},
17
+ typescript = true
18
+ } = options;
19
+
20
+ await ensurePackages([
21
+ "eslint-plugin-react",
22
+ "eslint-plugin-react-hooks",
23
+ "eslint-plugin-react-refresh"
24
+ ]);
25
+
26
+ const [
27
+ pluginReact,
28
+ pluginReactHooks,
29
+ pluginReactRefresh
30
+ ] = await Promise.all([
31
+ interopDefault(import("eslint-plugin-react")),
32
+ interopDefault(import("eslint-plugin-react-hooks")),
33
+ interopDefault(import("eslint-plugin-react-refresh"))
34
+ ] as const);
35
+
36
+ const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some(
37
+ i => isPackageExists(i)
38
+ );
39
+
40
+ return [
41
+ {
42
+ name: "curev:react:setup",
43
+ plugins: {
44
+ "react": pluginReact,
45
+ "react-hooks": pluginReactHooks,
46
+ "react-refresh": pluginReactRefresh
47
+ },
48
+ settings: {
49
+ react: {
50
+ version: "detect"
51
+ }
52
+ }
53
+ },
54
+ {
55
+ files,
56
+ languageOptions: {
57
+ parserOptions: {
58
+ ecmaFeatures: {
59
+ jsx: true
60
+ }
61
+ }
62
+ },
63
+ name: "curev:react:rules",
64
+ rules: {
65
+ // recommended rules react-hooks
66
+ "react-hooks/exhaustive-deps": "warn",
67
+ "react-hooks/rules-of-hooks": "error",
68
+
69
+ // react refresh
70
+ "react-refresh/only-export-components": [
71
+ "warn",
72
+ { allowConstantExport: isAllowConstantExport }
73
+ ],
74
+
75
+ // recommended rules react
76
+ "react/display-name": "error",
77
+ "react/jsx-key": "error",
78
+ "react/jsx-no-comment-textnodes": "error",
79
+ "react/jsx-no-duplicate-props": "error",
80
+ "react/jsx-no-target-blank": "error",
81
+ "react/jsx-no-undef": "error",
82
+ "react/jsx-uses-react": "error",
83
+ "react/jsx-uses-vars": "error",
84
+ "react/no-children-prop": "error",
85
+ "react/no-danger-with-children": "error",
86
+ "react/no-deprecated": "error",
87
+ "react/no-direct-mutation-state": "error",
88
+ "react/no-find-dom-node": "error",
89
+ "react/no-is-mounted": "error",
90
+ "react/no-render-return-value": "error",
91
+ "react/no-string-refs": "error",
92
+ "react/no-unescaped-entities": "error",
93
+ "react/no-unknown-property": "error",
94
+ "react/no-unsafe": "off",
95
+ "react/prop-types": "error",
96
+ "react/react-in-jsx-scope": "off",
97
+ "react/require-render-return": "error",
98
+
99
+ ...typescript
100
+ ? {
101
+ "react/jsx-no-undef": "off",
102
+ "react/prop-type": "off"
103
+ }
104
+ : {},
105
+
106
+ // overrides
107
+ ...overrides
108
+ }
109
+ }
110
+ ];
111
+ }
@@ -0,0 +1,223 @@
1
+ import type { FlatConfigItem } from "../types";
2
+
3
+ /**
4
+ * Sort package.json
5
+ *
6
+ * Requires `jsonc` config
7
+ */
8
+ export async function sortPackageJson(): Promise<FlatConfigItem[]> {
9
+ return [
10
+ {
11
+ files: ["**/package.json"],
12
+ name: "curev:sort-package-json",
13
+ rules: {
14
+ "jsonc/sort-array-values": [
15
+ "error",
16
+ {
17
+ order: { type: "asc" },
18
+ pathPattern: "^files$"
19
+ }
20
+ ],
21
+ "jsonc/sort-keys": [
22
+ "error",
23
+ {
24
+ order: [
25
+ "publisher",
26
+ "name",
27
+ "displayName",
28
+ "type",
29
+ "version",
30
+ "private",
31
+ "packageManager",
32
+ "description",
33
+ "author",
34
+ "license",
35
+ "funding",
36
+ "homepage",
37
+ "repository",
38
+ "bugs",
39
+ "keywords",
40
+ "categories",
41
+ "sideEffects",
42
+ "exports",
43
+ "main",
44
+ "module",
45
+ "unpkg",
46
+ "jsdelivr",
47
+ "types",
48
+ "typesVersions",
49
+ "bin",
50
+ "icon",
51
+ "files",
52
+ "engines",
53
+ "activationEvents",
54
+ "contributes",
55
+ "scripts",
56
+ "peerDependencies",
57
+ "peerDependenciesMeta",
58
+ "dependencies",
59
+ "optionalDependencies",
60
+ "devDependencies",
61
+ "pnpm",
62
+ "overrides",
63
+ "resolutions",
64
+ "husky",
65
+ "simple-git-hooks",
66
+ "lint-staged",
67
+ "eslintConfig"
68
+ ],
69
+ pathPattern: "^$"
70
+ },
71
+ {
72
+ order: { type: "asc" },
73
+ pathPattern: "^(?:dev|peer|optional|bundled)?[Dd]ependencies(Meta)?$"
74
+ },
75
+ {
76
+ order: { type: "asc" },
77
+ pathPattern: "^(?:resolutions|overrides|pnpm.overrides)$"
78
+ },
79
+ {
80
+ order: [
81
+ "types",
82
+ "import",
83
+ "require",
84
+ "default"
85
+ ],
86
+ pathPattern: "^exports.*$"
87
+ }
88
+ ]
89
+ }
90
+ }
91
+ ];
92
+ }
93
+ /**
94
+ * Sort tsconfig.json
95
+ *
96
+ * Requires `jsonc` config
97
+ */
98
+
99
+ export function sortTsconfig(): FlatConfigItem[] {
100
+ return [
101
+ {
102
+ files: ["**/tsconfig.json", "**/tsconfig.*.json"],
103
+ name: "curev:sort-tsconfig",
104
+ rules: {
105
+ "jsonc/sort-keys": [
106
+ "error",
107
+ {
108
+ order: [
109
+ "extends",
110
+ "compilerOptions",
111
+ "references",
112
+ "files",
113
+ "include",
114
+ "exclude"
115
+ ],
116
+ pathPattern: "^$"
117
+ },
118
+ {
119
+ order: [
120
+ /* Projects */
121
+ "incremental",
122
+ "composite",
123
+ "tsBuildInfoFile",
124
+ "disableSourceOfProjectReferenceRedirect",
125
+ "disableSolutionSearching",
126
+ "disableReferencedProjectLoad",
127
+ /* Language and Environment */
128
+ "target",
129
+ "jsx",
130
+ "jsxFactory",
131
+ "jsxFragmentFactory",
132
+ "jsxImportSource",
133
+ "lib",
134
+ "moduleDetection",
135
+ "noLib",
136
+ "reactNamespace",
137
+ "useDefineForClassFields",
138
+ "emitDecoratorMetadata",
139
+ "experimentalDecorators",
140
+ /* Modules */
141
+ "baseUrl",
142
+ "rootDir",
143
+ "rootDirs",
144
+ "customConditions",
145
+ "module",
146
+ "moduleResolution",
147
+ "moduleSuffixes",
148
+ "noResolve",
149
+ "paths",
150
+ "resolveJsonModule",
151
+ "resolvePackageJsonExports",
152
+ "resolvePackageJsonImports",
153
+ "typeRoots",
154
+ "types",
155
+ "allowArbitraryExtensions",
156
+ "allowImportingTsExtensions",
157
+ "allowUmdGlobalAccess",
158
+ /* JavaScript Support */
159
+ "allowJs",
160
+ "checkJs",
161
+ "maxNodeModuleJsDepth",
162
+ /* Type Checking */
163
+ "strict",
164
+ "strictBindCallApply",
165
+ "strictFunctionTypes",
166
+ "strictNullChecks",
167
+ "strictPropertyInitialization",
168
+ "allowUnreachableCode",
169
+ "allowUnusedLabels",
170
+ "alwaysStrict",
171
+ "exactOptionalPropertyTypes",
172
+ "noFallthroughCasesInSwitch",
173
+ "noImplicitAny",
174
+ "noImplicitOverride",
175
+ "noImplicitReturns",
176
+ "noImplicitThis",
177
+ "noPropertyAccessFromIndexSignature",
178
+ "noUncheckedIndexedAccess",
179
+ "noUnusedLocals",
180
+ "noUnusedParameters",
181
+ "useUnknownInCatchVariables",
182
+ /* Emit */
183
+ "declaration",
184
+ "declarationDir",
185
+ "declarationMap",
186
+ "downlevelIteration",
187
+ "emitBOM",
188
+ "emitDeclarationOnly",
189
+ "importHelpers",
190
+ "importsNotUsedAsValues",
191
+ "inlineSourceMap",
192
+ "inlineSources",
193
+ "mapRoot",
194
+ "newLine",
195
+ "noEmit",
196
+ "noEmitHelpers",
197
+ "noEmitOnError",
198
+ "outDir",
199
+ "outFile",
200
+ "preserveConstEnums",
201
+ "preserveValueImports",
202
+ "removeComments",
203
+ "sourceMap",
204
+ "sourceRoot",
205
+ "stripInternal",
206
+ /* Interop Constraints */
207
+ "allowSyntheticDefaultImports",
208
+ "esModuleInterop",
209
+ "forceConsistentCasingInFileNames",
210
+ "isolatedModules",
211
+ "preserveSymlinks",
212
+ "verbatimModuleSyntax",
213
+ /* Completeness */
214
+ "skipDefaultLibCheck",
215
+ "skipLibCheck"
216
+ ],
217
+ pathPattern: "^compilerOptions$"
218
+ }
219
+ ]
220
+ }
221
+ }
222
+ ];
223
+ }
@@ -0,0 +1,52 @@
1
+ import { interopDefault } from "../utils";
2
+ import type { FlatConfigItem, OptionsOverrides, StylisticConfig } from "../types";
3
+ import { pluginAntfu } from "../plugins";
4
+
5
+ export const StylisticConfigDefaults: StylisticConfig = {
6
+ indent: 2,
7
+ jsx: true,
8
+ quotes: "double",
9
+ semi: true,
10
+ braceStyle: "1tbs",
11
+ commaDangle: "never"
12
+ };
13
+
14
+ export async function stylistic(
15
+ options: StylisticConfig & OptionsOverrides = {}
16
+ ): Promise<FlatConfigItem[]> {
17
+ const mergeOptions = {
18
+ ...StylisticConfigDefaults,
19
+ ...options
20
+ };
21
+
22
+ const { overrides = {} } = mergeOptions;
23
+
24
+ const pluginStylistic = await interopDefault(import("@stylistic/eslint-plugin"));
25
+
26
+ const config = pluginStylistic.configs.customize({
27
+ flat: true,
28
+ pluginName: "style",
29
+ ...mergeOptions
30
+ });
31
+
32
+ return [
33
+ {
34
+ name: "curev:stylistic",
35
+ plugins: {
36
+ curev: pluginAntfu,
37
+ style: pluginStylistic
38
+ },
39
+ rules: {
40
+ ...config.rules,
41
+
42
+ "antfu/consistent-list-newline": "error",
43
+ "antfu/if-newline": "error",
44
+ "antfu/top-level-function": "error",
45
+ "semi-spacing": ["error", { before: false, after: true }],
46
+ "style/brace-style": ["error", "1tbs", { allowSingleLine: true }],
47
+ "curly": ["error", "all"],
48
+ ...overrides
49
+ }
50
+ }
51
+ ];
52
+ }
@@ -0,0 +1,107 @@
1
+ import { ensurePackages, interopDefault } from "../utils";
2
+ import type { FlatConfigItem, OptionsFiles, OptionsHasTypeScript, OptionsOverrides, OptionsStylistic } from "../types";
3
+ import { GLOB_SVELTE } from "../globs";
4
+
5
+ export async function svelte(
6
+ options: OptionsHasTypeScript & OptionsOverrides & OptionsStylistic & OptionsFiles = {}
7
+ ): Promise<FlatConfigItem[]> {
8
+ const {
9
+ files = [GLOB_SVELTE],
10
+ overrides = {},
11
+ stylistic = true
12
+ } = options;
13
+
14
+ const {
15
+ indent = 2,
16
+ quotes = "single"
17
+ } = typeof stylistic === "boolean" ? {} : stylistic;
18
+
19
+ await ensurePackages([
20
+ "eslint-plugin-svelte"
21
+ ]);
22
+
23
+ const [
24
+ pluginSvelte,
25
+ parserSvelte
26
+ ] = await Promise.all([
27
+ interopDefault(import("eslint-plugin-svelte")),
28
+ interopDefault(import("svelte-eslint-parser"))
29
+ ] as const);
30
+
31
+ return [
32
+ {
33
+ name: "curev:svelte:setup",
34
+ plugins: {
35
+ svelte: pluginSvelte
36
+ }
37
+ },
38
+ {
39
+ files,
40
+ languageOptions: {
41
+ parser: parserSvelte,
42
+ parserOptions: {
43
+ extraFileExtensions: [".svelte"],
44
+ parser: options.typescript
45
+ ? await interopDefault(import("@typescript-eslint/parser")) as any
46
+ : null
47
+ }
48
+ },
49
+ name: "curev:svelte:rules",
50
+ processor: pluginSvelte.processors[".svelte"],
51
+ rules: {
52
+ "import/no-mutable-exports": "off",
53
+ "no-undef": "off", // incompatible with most recent (attribute-form) generic types RFC
54
+ "no-unused-vars": ["error", {
55
+ args: "none",
56
+ caughtErrors: "none",
57
+ ignoreRestSiblings: true,
58
+ vars: "all",
59
+ varsIgnorePattern: "^\\$\\$Props$"
60
+ }],
61
+
62
+ "svelte/comment-directive": "error",
63
+ "svelte/no-at-debug-tags": "warn",
64
+ "svelte/no-at-html-tags": "error",
65
+ "svelte/no-dupe-else-if-blocks": "error",
66
+ "svelte/no-dupe-style-properties": "error",
67
+ "svelte/no-dupe-use-directives": "error",
68
+ "svelte/no-dynamic-slot-name": "error",
69
+ "svelte/no-export-load-in-svelte-module-in-kit-pages": "error",
70
+ "svelte/no-inner-declarations": "error",
71
+ "svelte/no-not-function-handler": "error",
72
+ "svelte/no-object-in-text-mustaches": "error",
73
+ "svelte/no-reactive-functions": "error",
74
+ "svelte/no-reactive-literals": "error",
75
+ "svelte/no-shorthand-style-property-overrides": "error",
76
+ "svelte/no-unknown-style-directive-property": "error",
77
+ "svelte/no-unused-svelte-ignore": "error",
78
+ "svelte/no-useless-mustaches": "error",
79
+ "svelte/require-store-callbacks-use-set-param": "error",
80
+ "svelte/system": "error",
81
+ "svelte/valid-compile": "error",
82
+ "svelte/valid-each-key": "error",
83
+
84
+ "unused-imports/no-unused-vars": [
85
+ "error",
86
+ { args: "after-used", argsIgnorePattern: "^_", vars: "all", varsIgnorePattern: "^(_|\\$\\$Props$)" }
87
+ ],
88
+
89
+ ...stylistic
90
+ ? {
91
+ "style/no-trailing-spaces": "off", // superseded by svelte/no-trailing-spaces
92
+ "svelte/derived-has-same-inputs-outputs": "error",
93
+ "svelte/html-closing-bracket-spacing": "error",
94
+ "svelte/html-quotes": ["error", { prefer: quotes }],
95
+ "svelte/indent": ["error", { alignAttributesVertically: true, indent }],
96
+ "svelte/mustache-spacing": "error",
97
+ "svelte/no-spaces-around-equal-signs-in-attribute": "error",
98
+ "svelte/no-trailing-spaces": "error",
99
+ "svelte/spaced-html-comment": "error"
100
+ }
101
+ : {},
102
+
103
+ ...overrides
104
+ }
105
+ }
106
+ ];
107
+ }