@swissgeo/config-eslint 1.0.0-beta.1 → 1.0.0-beta.3

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