@swissgeo/config-eslint 1.0.0-beta.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.
@@ -0,0 +1,12 @@
1
+ import defaultConfig from './index'
2
+
3
+ export default [
4
+ ...defaultConfig,
5
+ {
6
+ languageOptions: {
7
+ parserOptions: {
8
+ tsconfigRootDir: import.meta.dirname,
9
+ },
10
+ },
11
+ },
12
+ ]
package/index.ts ADDED
@@ -0,0 +1,240 @@
1
+ import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint'
2
+
3
+ import jsESLint from '@eslint/js'
4
+ import markdown from '@eslint/markdown'
5
+ import skipFormatting from '@vue/eslint-config-prettier/skip-formatting'
6
+ import { defineConfigWithVueTs, vueTsConfigs } from '@vue/eslint-config-typescript'
7
+ import pluginChaiFriendly from 'eslint-plugin-chai-friendly'
8
+ import pluginCypress from 'eslint-plugin-cypress/flat'
9
+ import mocha from 'eslint-plugin-mocha'
10
+ import perfectionist from 'eslint-plugin-perfectionist'
11
+ import pluginVue from 'eslint-plugin-vue'
12
+ import globals from 'globals'
13
+ import tsESLint, { plugin as tsESLintPlugin } from 'typescript-eslint'
14
+
15
+ type PartialRules = Partial<Record<string, FlatConfig.RuleEntry>>
16
+ type PartialConfig = Partial<FlatConfig.Config>
17
+
18
+ const noUnusedVarsRules: PartialRules = {
19
+ 'no-unused-vars': [
20
+ 'error',
21
+ {
22
+ argsIgnorePattern: '^_',
23
+ caughtErrorsIgnorePattern: '^_',
24
+ destructuredArrayIgnorePattern: '^_',
25
+ },
26
+ ],
27
+ '@typescript-eslint/no-unused-vars': [
28
+ 'error',
29
+ {
30
+ argsIgnorePattern: '^_',
31
+ caughtErrorsIgnorePattern: '^_',
32
+ destructuredArrayIgnorePattern: '^_',
33
+ },
34
+ ],
35
+ }
36
+
37
+ const standardTSRules: PartialRules = {
38
+ 'no-unused-vars': 'off',
39
+ '@typescript-eslint/no-unused-vars': [
40
+ 'error',
41
+ {
42
+ // as we are adding dispatcher reference in all our store action, but won't be using
43
+ // them directly in the action, we must ignore these unused variables too
44
+ argsIgnorePattern: '^(_|dispatcher)',
45
+ caughtErrorsIgnorePattern: '^_',
46
+ destructuredArrayIgnorePattern: '^_',
47
+ },
48
+ ],
49
+ '@typescript-eslint/consistent-type-exports': 'error',
50
+ '@typescript-eslint/no-import-type-side-effects': 'error',
51
+ }
52
+
53
+ const chaiFriendlyRules: PartialConfig = {
54
+ plugins: {
55
+ 'chai-friendly': pluginChaiFriendly,
56
+ },
57
+ rules: {
58
+ 'no-console': 'off',
59
+ 'no-prototype-builtins': 'off',
60
+ // see https://github.com/ihordiachenko/eslint-plugin-chai-friendly?tab=readme-ov-file#usage
61
+ 'no-unused-expressions': 'off', // disable original rule for JS
62
+ '@typescript-eslint/no-unused-expressions': 'off', // disable original rule for TS
63
+ 'chai-friendly/no-unused-expressions': 'error',
64
+ ...noUnusedVarsRules,
65
+ },
66
+ }
67
+
68
+ /**
69
+ * Generates a set of ESLint rules for Cypress tests. The root directory of the Cypress tests can be
70
+ * specified (the default value is 'tests/cypress/').
71
+ *
72
+ * @param cypressRootDir The root directory of the Cypress tests.
73
+ * @returns The set of ESLint rules for Cypress tests.
74
+ */
75
+ export function cypressConfig(cypressRootDir: string = 'tests/cypress/'): FlatConfig.ConfigArray {
76
+ return tsESLint.config([
77
+ {
78
+ files: [`${cypressRootDir}**/*.ts`, `${cypressRootDir}**/*.js`],
79
+ languageOptions: {
80
+ parserOptions: {
81
+ projectService: true,
82
+ tsconfigRootDir: import.meta.dirname,
83
+ },
84
+ },
85
+ rules: standardTSRules,
86
+ ...pluginCypress.configs.recommended,
87
+ ...chaiFriendlyRules,
88
+ },
89
+ ])
90
+ }
91
+
92
+ const allIgnores: string[] = [
93
+ '.gitignore',
94
+ '**/node_modules',
95
+ '**/.github',
96
+ '**/dist',
97
+ 'tsconfig.json',
98
+ '**/*.md',
99
+ '**/eslint.config.mts',
100
+ ]
101
+
102
+ export const vueConfig: FlatConfig.ConfigArray = defineConfigWithVueTs(
103
+ pluginVue.configs['flat/essential'],
104
+ vueTsConfigs.recommendedTypeCheckedOnly,
105
+ {
106
+ files: ['**/*.vue'],
107
+ plugins: {
108
+ '@typescript-eslint': tsESLintPlugin,
109
+ perfectionist,
110
+ },
111
+ rules: {
112
+ 'vue/html-indent': ['error', 4],
113
+ // TODO: switch to 'error' (or remove this line) after complete TS migration
114
+ 'vue/block-lang': 'off',
115
+ 'perfectionist/sort-imports': [
116
+ 'error',
117
+ { type: 'alphabetical', internalPattern: ['^@/.*'] },
118
+ ],
119
+ // Enforce consistent brace style for all control statements
120
+ curly: ['error', 'all'],
121
+ // Enforce opening brace on same line and closing brace on new line
122
+ 'brace-style': ['error', '1tbs', { allowSingleLine: false }],
123
+ ...noUnusedVarsRules,
124
+ },
125
+ }
126
+ )
127
+
128
+ export const unitTestsConfig: FlatConfig.ConfigArray = [
129
+ {
130
+ files: ['**/*.spec.{js,ts}', 'scripts/**.{js,ts}'],
131
+ ...chaiFriendlyRules,
132
+ },
133
+ ]
134
+
135
+ export const markdownConfig: FlatConfig.ConfigArray = [
136
+ {
137
+ files: ['**/*.md'],
138
+ plugins: {
139
+ markdown: markdown,
140
+ },
141
+ processor: 'markdown/markdown',
142
+ rules: {
143
+ 'no-irregular-whitespace': 'off',
144
+ 'no-undef': 'off',
145
+ },
146
+ },
147
+ ]
148
+
149
+ export const jsConfig: FlatConfig.ConfigArray = [
150
+ jsESLint.configs.recommended,
151
+ {
152
+ ignores: allIgnores,
153
+ },
154
+ {
155
+ files: ['**/*.js', '**/*.jsx'],
156
+ // no need to check our snippets
157
+ ignores: ['**/*.md'],
158
+ plugins: {
159
+ mocha,
160
+ 'chai-friendly': pluginChaiFriendly,
161
+ perfectionist,
162
+ '@typescript-eslint': tsESLintPlugin,
163
+ },
164
+ languageOptions: {
165
+ ecmaVersion: 'latest',
166
+
167
+ globals: {
168
+ ...globals.browser,
169
+ ...globals.vitest,
170
+ ...globals.node,
171
+ defineModel: 'readonly',
172
+ __APP_VERSION__: true,
173
+ __VITE_ENVIRONMENT__: true,
174
+ __CESIUM_STATIC_PATH__: true,
175
+ __IS_TESTING_WITH_CYPRESS__: true,
176
+ },
177
+
178
+ sourceType: 'module',
179
+ },
180
+ rules: {
181
+ eqeqeq: ['error', 'always'],
182
+ 'mocha/no-exclusive-tests': 'error',
183
+ 'no-console': 'error',
184
+ 'no-var': 'error',
185
+ 'perfectionist/sort-imports': [
186
+ 'error',
187
+ { type: 'alphabetical', internalPattern: ['^@/.*'] },
188
+ ],
189
+ // Enforce consistent brace style for all control statements
190
+ curly: ['error', 'all'],
191
+ // Enforce opening brace on same line and closing brace on new line
192
+ 'brace-style': ['error', '1tbs', { allowSingleLine: false }],
193
+ ...noUnusedVarsRules,
194
+ },
195
+ },
196
+ ...markdownConfig,
197
+ ...unitTestsConfig,
198
+ ...vueConfig,
199
+ // skip the formatting in the linting process
200
+ skipFormatting,
201
+ ]
202
+
203
+ const defaultConfig: FlatConfig.ConfigArray = tsESLint.config(
204
+ ...jsConfig,
205
+ tsESLint.configs.recommended,
206
+ ...markdownConfig,
207
+ ...vueConfig,
208
+ {
209
+ ignores: allIgnores,
210
+ },
211
+ {
212
+ files: ['**/*.ts', '**/*.tsx'],
213
+ // no need to check our snippets
214
+ ignores: ['**/*.md'],
215
+ plugins: { perfectionist },
216
+ languageOptions: {
217
+ parserOptions: {
218
+ projectService: true,
219
+ tsconfigRootDir: import.meta.dirname,
220
+ },
221
+ },
222
+ // switching to TypeScript unused var rule (instead of JS rule), so that no error is raised
223
+ // on unused param from abstract function arguments
224
+ rules: {
225
+ ...standardTSRules,
226
+ 'perfectionist/sort-imports': [
227
+ 'error',
228
+ { type: 'alphabetical', internalPattern: ['^@/.*'] },
229
+ ],
230
+ // Enforce consistent brace style for all control statements
231
+ curly: ['error', 'all'],
232
+ // Enforce opening brace on same line and closing brace on new line
233
+ 'brace-style': ['error', '1tbs', { allowSingleLine: false }],
234
+ },
235
+ },
236
+ // we have to declare that AFTER the TS specifics, our unit test rules from the JS config are otherwise ignored (when the tests are written in TS)
237
+ unitTestsConfig
238
+ )
239
+
240
+ export default defaultConfig
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@swissgeo/config-eslint",
3
+ "version": "1.0.0-beta.1",
4
+ "description": "Shared ESLint config for SWISSGEO projects.",
5
+ "license": "BSD-3-Clause",
6
+ "type": "module",
7
+ "main": "index.ts",
8
+ "scripts": {
9
+ "lint": "eslint --fix",
10
+ "lint:no-fix": "eslint",
11
+ "type-check": "tsc -p tsconfig.json"
12
+ },
13
+ "dependencies": {
14
+ "@eslint/js": "catalog:",
15
+ "@eslint/markdown": "catalog:",
16
+ "@typescript-eslint/utils": "catalog:",
17
+ "@vue/eslint-config-prettier": "catalog:",
18
+ "@vue/eslint-config-typescript": "catalog:",
19
+ "eslint-plugin-chai-friendly": "catalog:",
20
+ "eslint-plugin-cypress": "catalog:",
21
+ "eslint-plugin-mocha": "catalog:",
22
+ "eslint-plugin-perfectionist": "catalog:",
23
+ "eslint-plugin-prettier": "catalog:",
24
+ "eslint-plugin-vue": "catalog:",
25
+ "typescript-eslint": "catalog:"
26
+ },
27
+ "devDependencies": {
28
+ "@swissgeo/config-typescript": "workspace:*",
29
+ "globals": "catalog:",
30
+ "typescript": "catalog:"
31
+ },
32
+ "peerDependencies": {
33
+ "@swissgeo/config-prettier": "workspace:*",
34
+ "@swissgeo/config-stylelint": "workspace:*",
35
+ "eslint": "catalog:"
36
+ }
37
+ }
package/packages.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import type { Linter } from 'eslint'
2
+
3
+ import { FlatConfig } from '@typescript-eslint/utils/ts-eslint'
4
+
5
+ declare module 'eslint-plugin-chai-friendly' {
6
+ const plugin: FlatConfig.Plugin
7
+ export default plugin
8
+ }
9
+
10
+ declare module 'eslint-plugin-cypress/flat' {
11
+ const plugin: {
12
+ configs: {
13
+ recommended: Linter.Config
14
+ [key: string]: Linter.Config | undefined
15
+ }
16
+ }
17
+ export default plugin
18
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "@swissgeo/config-typescript/tsconfig.base.json",
3
+ "include": ["**/*.ts"]
4
+ }