eslint-config-vylda-typescript 5.0.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/.editorconfig +12 -0
- package/.gitlab-ci.yml +13 -0
- package/.husky/pre-commit +1 -0
- package/.husky/pre-push +1 -0
- package/.vscode/extensions.json +8 -0
- package/.vscode/settings.json +6 -0
- package/Changelog.md +114 -0
- package/LICENSE +24 -0
- package/README.md +372 -0
- package/directory.mjs +3 -0
- package/empty.ts +0 -0
- package/eslint.config.mjs +81 -0
- package/index.d.ts +55 -0
- package/index.js +176 -0
- package/package.json +44 -0
- package/rules/defaultTs.mjs +654 -0
- package/rules/imports.mjs +119 -0
- package/rules/index.mjs +10 -0
- package/rules/off.mjs +64 -0
- package/rules/plus.mjs +22 -0
- package/rules/strictTs.mjs +115 -0
- package/rules/stylisticTs.mjs +495 -0
- package/rules/typescriptConfig.mjs +16 -0
- package/rules/vanillaConfig.mjs +26 -0
- package/rules/variablesTs.mjs +129 -0
- package/tsconfig.json +22 -0
package/.editorconfig
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# EditorConfig is awesome: http://EditorConfig.org
|
|
2
|
+
|
|
3
|
+
# top-most EditorConfig file
|
|
4
|
+
root = true
|
|
5
|
+
|
|
6
|
+
# Unix-style newlines with a newline ending every file
|
|
7
|
+
[*.{css,js,json,mjs,svg,ts,tsx}]
|
|
8
|
+
indent_style = space
|
|
9
|
+
end_of_line = lf
|
|
10
|
+
charset = utf-8
|
|
11
|
+
insert_final_newline = true
|
|
12
|
+
indent_size = 2
|
package/.gitlab-ci.yml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# You can override the included template(s) by including variable overrides
|
|
2
|
+
# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings
|
|
3
|
+
# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/pipeline/#customization
|
|
4
|
+
# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings
|
|
5
|
+
# Container Scanning customization: https://docs.gitlab.com/ee/user/application_security/container_scanning/#customizing-the-container-scanning-settings
|
|
6
|
+
# Note that environment variables can be set in several places
|
|
7
|
+
# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
|
|
8
|
+
stages:
|
|
9
|
+
- test
|
|
10
|
+
sast:
|
|
11
|
+
stage: test
|
|
12
|
+
include:
|
|
13
|
+
- template: Security/SAST.gitlab-ci.yml
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
npm test
|
package/.husky/pre-push
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
npm test
|
package/Changelog.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
All notable changes to this component will be documented in this file.
|
|
3
|
+
|
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [5.0.0] - 2025-08-30
|
|
8
|
+
### Added
|
|
9
|
+
- Rules
|
|
10
|
+
- @stylistic/indent [Vilda Lipold]
|
|
11
|
+
- eslint config specific rules [Vilda Lipold]
|
|
12
|
+
- inheriting defaultImportExtensions from vanilla package [Vilda Lipold]
|
|
13
|
+
- inheriting defaultImportResolverNodeExtensions from vanilla package [Vilda Lipold]
|
|
14
|
+
- export for non TS files and rule [Vilda Lipold]
|
|
15
|
+
### Fixed
|
|
16
|
+
- @stylistic/space-infix-ops types [Vilda Lipold]
|
|
17
|
+
- return back correct TS ruleset for mapFiles function [Vilda Lipold]
|
|
18
|
+
### Updated
|
|
19
|
+
- Packages [Vilda Lipold]
|
|
20
|
+
- Rules
|
|
21
|
+
- @stylistic/object-curly-newline [Vilda Lipold]
|
|
22
|
+
- @typescript-eslint/prefer-literal-enum-member [Vilda Lipold]
|
|
23
|
+
- @typescript-eslint/strict-boolean-expressions [Vilda Lipold]
|
|
24
|
+
|
|
25
|
+
## [4.1.0] - 2025-06-06
|
|
26
|
+
### Added
|
|
27
|
+
- index.d.ts file [Vilda Lipold]
|
|
28
|
+
### Updated
|
|
29
|
+
- Readme [Vilda Lipold]
|
|
30
|
+
- Rules
|
|
31
|
+
- @typescript-eslint/consistent-indexed-object-style [Vilda Lipold]
|
|
32
|
+
- Types for rules [Vilda Lipold]
|
|
33
|
+
|
|
34
|
+
## [4.0.3] - 2025-06-02
|
|
35
|
+
### Removed
|
|
36
|
+
- Ignores file [Vilda Lipold]
|
|
37
|
+
- Rules
|
|
38
|
+
- @typescript-eslint/typedef (deprecated) [Vilda Lipold]
|
|
39
|
+
### Updated
|
|
40
|
+
- Rules
|
|
41
|
+
- @typescript-eslint/array-type [Vilda Lipold]
|
|
42
|
+
- @typescript-eslint/no-magic-numbers [Vilda Lipold]
|
|
43
|
+
- @typescript-eslint/prefer-readonly-parameter-types [Vilda Lipold]
|
|
44
|
+
- @stylistic/type-annotation-spacing [Vilda Lipold]
|
|
45
|
+
- no-shadow [Vilda Lipold]
|
|
46
|
+
|
|
47
|
+
## [4.0.2] - 2025-05-26
|
|
48
|
+
### Updated
|
|
49
|
+
- Readme [Vilda Lipold]
|
|
50
|
+
|
|
51
|
+
## [4.0.1] - 2025-05-26
|
|
52
|
+
### Fixed
|
|
53
|
+
- main getConfig function [Vilda Lipold]
|
|
54
|
+
- Readme [Vilda Lipold]
|
|
55
|
+
|
|
56
|
+
## [4.0.0] - 2025-05-26
|
|
57
|
+
### Changed
|
|
58
|
+
- Refactored the package [Vilda Lipold]
|
|
59
|
+
|
|
60
|
+
## [3.0.0] - 2025-05-15
|
|
61
|
+
### Fixed
|
|
62
|
+
- Missing ts extension for resolver [Vilda Lipold]
|
|
63
|
+
### Changed
|
|
64
|
+
- Arrays with extensions (files, tsFiles, extensionsForResolver, extensionsWithImport) are now in options parameter [Vilda Lipold]
|
|
65
|
+
|
|
66
|
+
## [2.2.0] - 2025-05-13
|
|
67
|
+
### Added
|
|
68
|
+
- Config names [Vilda Lipold]
|
|
69
|
+
- Rules
|
|
70
|
+
- @typescript-eslint/no-unnecessary-type-conversion [Vilda Lipold]
|
|
71
|
+
### Updated
|
|
72
|
+
- Main config [Vilda Lipold]
|
|
73
|
+
- Packages [Vilda Lipold]
|
|
74
|
+
- Readme [Vilda Lipold]
|
|
75
|
+
- Rules
|
|
76
|
+
- @typescript-eslint/only-throw-error [Vilda Lipold]
|
|
77
|
+
|
|
78
|
+
## [2.1.1] - 2025-04-04
|
|
79
|
+
### Fixed
|
|
80
|
+
- Readme [Vilda Lipold]
|
|
81
|
+
|
|
82
|
+
## [2.1.0] - 2025-04-03
|
|
83
|
+
### Added
|
|
84
|
+
- Engines key to package.json [Vilda Lipold]
|
|
85
|
+
### Fixed
|
|
86
|
+
- Import rules [Vilda Lipold]
|
|
87
|
+
- Path to ts file [Vilda Lipold]
|
|
88
|
+
### Updated
|
|
89
|
+
- Better exports [Vilda Lipold]
|
|
90
|
+
- Rules order [Vilda Lipold]
|
|
91
|
+
|
|
92
|
+
## [2.0.0] - 2025-03-15
|
|
93
|
+
### Added
|
|
94
|
+
- Inherit from vanilla regiojet eslint [Vilda Lipold]
|
|
95
|
+
|
|
96
|
+
## [1.0.4] - 2025-02-01
|
|
97
|
+
### Added
|
|
98
|
+
- CI SAST vulnerabilities analyzer job [Vilda Lipold]
|
|
99
|
+
|
|
100
|
+
## [1.0.3] - 2025-01-20
|
|
101
|
+
### Fixed
|
|
102
|
+
- only ts files for TS rules [Vilda Lipold]
|
|
103
|
+
|
|
104
|
+
## [1.0.2] - 2025-01-15
|
|
105
|
+
### Fixed
|
|
106
|
+
- rules order [Vilda Lipold]
|
|
107
|
+
|
|
108
|
+
## [1.0.1] - 2025-01-15
|
|
109
|
+
### Changed
|
|
110
|
+
- no-extra-boolean-cast rule [Vilda Lipold]
|
|
111
|
+
|
|
112
|
+
## [1.0.0] - 2025-01-15
|
|
113
|
+
### Added
|
|
114
|
+
- First release [Vilda Lipold]
|
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Vilem Lipold <vilem.lipold@studentagency.cz>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person
|
|
6
|
+
obtaining a copy of this software and associated documentation
|
|
7
|
+
files (the "Software"), to deal in the Software without
|
|
8
|
+
restriction, including without limitation the rights to use,
|
|
9
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the
|
|
11
|
+
Software is furnished to do so, subject to the following
|
|
12
|
+
conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be
|
|
15
|
+
included in all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
19
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
21
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
22
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
23
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
24
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
# eslint-config-vylda-typescript
|
|
2
|
+
|
|
3
|
+
Enhances Regiojet's ESLint config with TypeScript support
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
### 1. Install dependencies
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install eslint eslint-import-resolver-typescript eslint-config-vylda-typescript --save-dev
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### 2. Configure ESLint
|
|
14
|
+
|
|
15
|
+
create `.eslint.config.mjs` file in project root
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
// eslint.config.mjs
|
|
19
|
+
import getConfig, { tsFiles } from "eslint-config-vylda-typescript";
|
|
20
|
+
|
|
21
|
+
const baseDir = import.meta.dirname;
|
|
22
|
+
|
|
23
|
+
const eslintConfig = [
|
|
24
|
+
...getConfig(baseDir),
|
|
25
|
+
{
|
|
26
|
+
files: tsFiles,
|
|
27
|
+
name: "my-rules",
|
|
28
|
+
rules: {
|
|
29
|
+
// Add custom rules here
|
|
30
|
+
},
|
|
31
|
+
settings: {
|
|
32
|
+
"import/resolver": {
|
|
33
|
+
alias: {
|
|
34
|
+
map: [
|
|
35
|
+
["@", "./src"],
|
|
36
|
+
["@assets", "./src/assets"],
|
|
37
|
+
["@utils", "./src/utils"],
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 3. Run ESLint
|
|
47
|
+
|
|
48
|
+
Open a terminal to the root of your project, and run the following command:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npx eslint .
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
or
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npx eslint ./src/
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
ESLint will lint all `.cjs`, `.js`, `.jsx`, `mjs` and `.ts` files within the current or `./src` folder , and output results to your terminal.
|
|
61
|
+
|
|
62
|
+
You can also get results in realtime inside most IDEs via a plugin.
|
|
63
|
+
|
|
64
|
+
## Customization
|
|
65
|
+
|
|
66
|
+
You can customize all rules with `rules` property in the `eslint.config.mjs` file.
|
|
67
|
+
You can also add custom rules to the `rules` property.
|
|
68
|
+
|
|
69
|
+
### Customize extensions for ESLint import rules
|
|
70
|
+
|
|
71
|
+
You can customize extensions for ESLint import rules by using getConfig function.
|
|
72
|
+
You can extend these default extensions and dependecies with your own extensions. It is used for import plugin settings, `import/extensions` and `import/no-extraneous-dependencies` rules.
|
|
73
|
+
|
|
74
|
+
### Default values
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
// default file pattern for all rules (https://eslint.org/docs/latest/use/configure/configuration-files#configuration-objects)
|
|
78
|
+
export const files = ["**/*.{cjs,cts,js,mjs,mts,ts}"];
|
|
79
|
+
|
|
80
|
+
// default file pattern for TypeScript rules only
|
|
81
|
+
export const tsFiles = ["**/*.{cts,mts,ts}"];
|
|
82
|
+
|
|
83
|
+
// default plugins used in this config
|
|
84
|
+
export const plugins = {
|
|
85
|
+
"@stylistic": stylisticPlugin,
|
|
86
|
+
"@typescript-eslint": tsESLint.configs.recommendedTypeCheckedOnly.plugins["@typescript-eslint"],
|
|
87
|
+
import: importPlugin,
|
|
88
|
+
n: nodePlugin,
|
|
89
|
+
perfectionist,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// default value for import/extension module settings (https://github.com/import-js/eslint-plugin-import?tab=readme-ov-file#importextensions)
|
|
93
|
+
export const defaultImportExtensions = [".js", ".mjs", ".mts", ".ts"];
|
|
94
|
+
|
|
95
|
+
// default value for import/resolver settings with node resolution (https://github.com/import-js/eslint-plugin-import?tab=readme-ov-file#resolvers)
|
|
96
|
+
export const defaultImportResolverNodeExtensions = [
|
|
97
|
+
".js",
|
|
98
|
+
".json",
|
|
99
|
+
".mjs",
|
|
100
|
+
".mts",
|
|
101
|
+
".svg",
|
|
102
|
+
".ts",
|
|
103
|
+
];
|
|
104
|
+
|
|
105
|
+
// default value for import/extensions rule granular option (https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/extensions.md#rule-details)
|
|
106
|
+
export const defaultImportExtensionsRuleGranularOption = {
|
|
107
|
+
js: "never",
|
|
108
|
+
json: "always",
|
|
109
|
+
svg: "always",
|
|
110
|
+
ts: "never",
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// default value for import/no-extraneous-dependencies rule devDependencies option (https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-extraneous-dependencies.md#rule-details)
|
|
114
|
+
export const defaultImportNoExtraneousDependenciesDevDependencies = [
|
|
115
|
+
'espree',
|
|
116
|
+
"test/**",
|
|
117
|
+
"tests/**",
|
|
118
|
+
"spec/**",
|
|
119
|
+
'@testing-library/**',
|
|
120
|
+
"**/__tests__/**",
|
|
121
|
+
"**/__mocks__/**",
|
|
122
|
+
"test.{js,jsx}",
|
|
123
|
+
"test.{ts,tsx}",
|
|
124
|
+
"test-*.{js,jsx}",
|
|
125
|
+
"test-*.{ts,tsx}",
|
|
126
|
+
"**/*{.,_}{test,spec}.{js,jsx}",
|
|
127
|
+
"**/*{.,_}{test,spec}.{ts,tsx}",
|
|
128
|
+
"**/jest.config.js",
|
|
129
|
+
"**/jest.config.ts",
|
|
130
|
+
"**/jest.setup.js",
|
|
131
|
+
"**/jest.setup.ts",
|
|
132
|
+
"**/vue.config.js",
|
|
133
|
+
"**/vue.config.ts",
|
|
134
|
+
"**/webpack.config.js",
|
|
135
|
+
"**/webpack.config.ts",
|
|
136
|
+
"**/webpack.config.*.js",
|
|
137
|
+
"**/webpack.config.*.ts",
|
|
138
|
+
"**/webpack.config.mjs",
|
|
139
|
+
"**/webpack.config.*.mjs",
|
|
140
|
+
"**/rollup.config.js",
|
|
141
|
+
"**/rollup.config.ts",
|
|
142
|
+
"**/rollup.config.*.js",
|
|
143
|
+
"**/rollup.config.*.ts",
|
|
144
|
+
"**/gulpfile.js",
|
|
145
|
+
"**/gulpfile.ts",
|
|
146
|
+
"**/gulpfile.*.js",
|
|
147
|
+
"**/gulpfile.*.ts",
|
|
148
|
+
"**/Gruntfile{,.js}",
|
|
149
|
+
"**/Gruntfile{,.ts}",
|
|
150
|
+
"**/protractor.conf.js",
|
|
151
|
+
"**/protractor.conf.ts",
|
|
152
|
+
"**/protractor.conf.*.js",
|
|
153
|
+
"**/protractor.conf.*.ts",
|
|
154
|
+
"**/karma.conf.js",
|
|
155
|
+
"**/karma.conf.ts",
|
|
156
|
+
"**/eslint.config.mjs",
|
|
157
|
+
"./rules/*.mjs",
|
|
158
|
+
"**/vitest.config.mjs",
|
|
159
|
+
"**/vitestSetup.mjs",
|
|
160
|
+
"**/tailwind.config.mjs",
|
|
161
|
+
"**/vite.config.js",
|
|
162
|
+
"**/vite.config.ts",
|
|
163
|
+
"**/vite.config.mjs",
|
|
164
|
+
"**/vite.config.*.js",
|
|
165
|
+
"**/vite.config.*.ts",
|
|
166
|
+
"**/vite.config*.mjs",
|
|
167
|
+
];
|
|
168
|
+
|
|
169
|
+
// files that are not parsed by typescript parser (js configs)
|
|
170
|
+
export const nonTsConfigFiles = ['eslint.config.mjs'];
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
All default values are optional and can be overridden in the `eslint.config.mjs` file.
|
|
174
|
+
|
|
175
|
+
### Example of ESLint config with custom extensions
|
|
176
|
+
|
|
177
|
+
```javascript
|
|
178
|
+
// eslint.config.mjs
|
|
179
|
+
import
|
|
180
|
+
getConfig,
|
|
181
|
+
{
|
|
182
|
+
defaultImportExtensions,
|
|
183
|
+
defaultImportExtensionsRuleGranularOption,
|
|
184
|
+
defaultImportResolverNodeExtensions,
|
|
185
|
+
defaultImportNoExtraneousDependenciesDevDependencies,
|
|
186
|
+
files as defaultFiles,
|
|
187
|
+
tsFiles as defaultTsFiles,
|
|
188
|
+
plugins as defaultPlugins,
|
|
189
|
+
} from 'eslint-config-vylda-typescript';
|
|
190
|
+
import myPlugin from 'path-to-my-plugin';
|
|
191
|
+
|
|
192
|
+
const baseDir = import.meta.dirname;
|
|
193
|
+
|
|
194
|
+
const importExtensions = [
|
|
195
|
+
...defaultImportExtensions,
|
|
196
|
+
'.jsm',
|
|
197
|
+
'.tsm',
|
|
198
|
+
];
|
|
199
|
+
|
|
200
|
+
const importExtensionsRuleGranularOption = {
|
|
201
|
+
...defaultImportExtensionsRuleGranularOption,
|
|
202
|
+
jsm: 'never',
|
|
203
|
+
tsm: 'never',
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const importResolverNodeExtensions = [
|
|
207
|
+
...defaultImportResolverNodeExtensions,
|
|
208
|
+
'.jsm',
|
|
209
|
+
'.tsm',
|
|
210
|
+
];
|
|
211
|
+
|
|
212
|
+
const importNoExtraneousDependenciesDevDependencies = [
|
|
213
|
+
...defaultImportNoExtraneousDependenciesDevDependencies,
|
|
214
|
+
'**/my-plugin.jsm',
|
|
215
|
+
];
|
|
216
|
+
|
|
217
|
+
const files = [
|
|
218
|
+
...defaultFiles,
|
|
219
|
+
'**/*.jsm',
|
|
220
|
+
'**/*.tsm',
|
|
221
|
+
];
|
|
222
|
+
|
|
223
|
+
const plugins = {
|
|
224
|
+
...defaultPlugins,
|
|
225
|
+
'my/plugin': myPlugin,
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
const tsFiles = [
|
|
229
|
+
...defaultTsFiles,
|
|
230
|
+
'**/*.tsm',
|
|
231
|
+
];
|
|
232
|
+
|
|
233
|
+
const rjConfig = getConfig(
|
|
234
|
+
baseDir,
|
|
235
|
+
{
|
|
236
|
+
files,
|
|
237
|
+
importExtensions,
|
|
238
|
+
importExtensionsRuleGranularOption,
|
|
239
|
+
importResolverNodeExtensions,
|
|
240
|
+
importNoExtraneousDependenciesDevDependencies
|
|
241
|
+
plugins,
|
|
242
|
+
tsFiles,
|
|
243
|
+
},
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
const config = [
|
|
247
|
+
...rjConfig,
|
|
248
|
+
{
|
|
249
|
+
files,
|
|
250
|
+
name: 'my/plugin',
|
|
251
|
+
rules: {
|
|
252
|
+
"my/plugin/rule": "error",
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
];
|
|
256
|
+
|
|
257
|
+
export default config;
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## Partial ESLint config
|
|
261
|
+
You can also use the package as a partial ESLint config. This is useful if you want to use only some of the rules from the package.
|
|
262
|
+
|
|
263
|
+
If you can use import plugin, you must use `getImportConfig` function to get the config for the import plugin and import `plugins` object.
|
|
264
|
+
This function uses the same default values as the package, except `files` and `plugins` in option object.
|
|
265
|
+
|
|
266
|
+
```javascript
|
|
267
|
+
// eslint.config.mjs
|
|
268
|
+
import {
|
|
269
|
+
barrels, barrelsFiles, bestPractices, defaultTs, es6, getImportConfig,
|
|
270
|
+
getLanguageOptions, files, ignores, mapFiles, nonTsConfigFiles,
|
|
271
|
+
nonTsConfigFilesRule, plugins,
|
|
272
|
+
} from 'eslint-config-vylda-typescript';
|
|
273
|
+
|
|
274
|
+
const baseDir = import.meta.dirname;
|
|
275
|
+
|
|
276
|
+
const configs = [
|
|
277
|
+
bestPractices,
|
|
278
|
+
defaultTs,
|
|
279
|
+
es6,
|
|
280
|
+
// you can add custom options object to the function getConfig
|
|
281
|
+
// optional parameters: importExtensions, importExtensionsRuleGranularOption, importResolverNodeExtensions,importNoExtraneousDependenciesDevDependencies
|
|
282
|
+
getImportConfig(baseDir);
|
|
283
|
+
];
|
|
284
|
+
|
|
285
|
+
const configWithFiles = mapFiles(configs, files);
|
|
286
|
+
const barrelsWithFiles = mapFiles(barrels, barrelsFiles);
|
|
287
|
+
|
|
288
|
+
const myNonTsFiles = [
|
|
289
|
+
...nonTsConfigFiles,
|
|
290
|
+
'vitest.config.js',
|
|
291
|
+
];
|
|
292
|
+
|
|
293
|
+
consz myNonTsFilesRule = {
|
|
294
|
+
...nonTsConfigFilesRule,
|
|
295
|
+
files: myNonTsFiles,
|
|
296
|
+
},
|
|
297
|
+
|
|
298
|
+
const config = [
|
|
299
|
+
{
|
|
300
|
+
languageOptions: getLanguageOptions(baseDir),
|
|
301
|
+
name: 'typescript-eslint/base',
|
|
302
|
+
plugins,
|
|
303
|
+
},
|
|
304
|
+
...configWithFiles,
|
|
305
|
+
...barrelsWithFiles,
|
|
306
|
+
...ignores,
|
|
307
|
+
{
|
|
308
|
+
files,
|
|
309
|
+
name: 'typescript-eslint/custom-rules',
|
|
310
|
+
rules: {
|
|
311
|
+
"no-console": "warn",
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
myNonTsFilesRule,
|
|
315
|
+
]
|
|
316
|
+
|
|
317
|
+
export default config;
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## What you can import from this package
|
|
321
|
+
|
|
322
|
+
All rules are without `files` property, so you can use them as a partial ESLint config.
|
|
323
|
+
You can use `files` property to specify the files for the rule.
|
|
324
|
+
You can also use `mapFiles` function to map files for all rules.
|
|
325
|
+
|
|
326
|
+
- `default getConfig` - default helper for getting ESLint config with custom options ([source](./index.js#L72))
|
|
327
|
+
- `barrels` - ESLint config with rules for barrel files ([source](https://gitlab.com/Vylda/eslint-config-vylda-vanilla/-/blob/main/rules/barrels.mjs), [documentation](https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/prefer-default-export.md))
|
|
328
|
+
- `barrelsFiles` - default file patterns for barrel files ([default values](./eslint.config.mjs#L8), [documentation](https://eslint.org/docs/latest/use/configure/configuration-files#configuration-objects))
|
|
329
|
+
- `bestPractices` - ESLint config with rules for best practices ([source](https://gitlab.com/Vylda/eslint-config-vylda-vanilla/-/blob/main/rules/best-practices.mjs), [documentation (js)](https://eslint.org/docs/latest/rules), [documentation (stylistic)](https://eslint.style/packages/js#rules))
|
|
330
|
+
- `constants` - Constants used for some rules ([source](https://gitlab.com/Vylda/eslint-config-vylda-vanilla/-/blob/main/rules/constants.mjs), [documentation](https://eslint.org/docs/latest/rules))
|
|
331
|
+
- `customs` - ESLint config with my custom rules ([source](https://gitlab.com/Vylda/eslint-config-vylda-vanilla/-/blob/main/rules/customs.mjs))
|
|
332
|
+
- `defaultImportExtensions` - default value for import/extension module settings ([default values](./rules/imports.mjs#L34), [documentation](https://github.com/import-js/eslint-plugin-import?tab=readme-ov-file#importextensions))
|
|
333
|
+
- `defaultImportExtensionsRuleGranularOption` - default value for import/resolver settings with node resolution ([default values](./rules/imports.mjs#L35), [documentation](https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/extensions.md#rule-details))
|
|
334
|
+
- `defaultImportNoExtraneousDependenciesDevDependencies` - default value for import/extensions rule granular option ([default values](./rules/imports.mjs#L40), [documentation](https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-extraneous-dependencies.md#rule-details))
|
|
335
|
+
- `defaultImportResolverNodeExtensions` - default value for import/no-extraneous-dependencies rule devDependencies option ([default values](./rules/imports.mjs#L39), [documentation](https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/extensions.md#rule-details))
|
|
336
|
+
- `defaultTs` - ESLint config with rules for TypeScript ([source](./rules/defaultTs.mjs), [documentation](https://typescript-eslint.io/rules/))
|
|
337
|
+
- `errors` - ESLint config with rules for errors ([source](https://gitlab.com/Vylda/eslint-config-vylda-vanilla/-/blob/main/rules/errors.mjs), [documentation](https://eslint.org/docs/latest/rules))
|
|
338
|
+
- `es6` - ESLint config with rules for ES6 ([source](https://gitlab.com/Vylda/eslint-config-vylda-vanilla/-/blob/main/rules/es6.mjs), [documentation (js)](https://eslint.org/docs/latest/rules), [documentation (stylistic)](https://eslint.style/packages/js#rules))
|
|
339
|
+
- `files` - default file pattern for all rules ([default values](./eslint.config.mjs#L9), [documentation](https://eslint.org/docs/latest/use/configure/configuration-files#configuration-objects))
|
|
340
|
+
- `getImportConfig` - function to get ESLint config for import plugin ([source](./rules/imports.mjs#L52))
|
|
341
|
+
- `getLanguageOptions` - ESLint helper for ESLint language options with Typescript support ([source](./eslint.config.mjs#L36))
|
|
342
|
+
- `ignores` - ESLint config with global ignored folder patterns ([default values](https://gitlab.com/Vylda/eslint-config-vylda-vanilla/-/blob/main/ignores.mjs#L4), [documentation](https://eslint.org/docs/latest/use/configure/ignore#ignoring-files))
|
|
343
|
+
- `mapFiles` - helper function to map files for all configs ([source](https://gitlab.com/Vylda/eslint-config-vylda-vanilla/-/blob/main/mapFiles.mjs))
|
|
344
|
+
- `node` - ESLint config with rules for Node.js ([source](https://gitlab.com/Vylda/eslint-config-vylda-vanilla/-/blob/main/rules/node.mjs), [documentation](https://github.com/eslint-community/eslint-plugin-n?tab=readme-ov-file#-rules))
|
|
345
|
+
- `nonTsConfigFiles` - Array of non typescript files for nonTsConfigFilesRule
|
|
346
|
+
- `nonTsConfigFilesRule` - ESLint rule for non-TypeScript files
|
|
347
|
+
- `perfectionist` - ESLint config with rules for perfectionist ([source](https://gitlab.com/Vylda/eslint-config-vylda-vanilla/-/blob/main/rules/perfectionist.mjs), [documentation](https://perfectionist.dev/rules))
|
|
348
|
+
- `plugins` - default plugins used in this config ([source](./eslint.config.mjs#L26))
|
|
349
|
+
- `plus` - ESLint config with rules for extended rules ([source](./rules/plus.mjs), [documentation](https://eslint.style/packages/plus))
|
|
350
|
+
- `strict` - ESLint config with rules for strict mode ([source](https://gitlab.com/Vylda/eslint-config-vylda-vanilla/-/blob/main/rules/strict.mjs))
|
|
351
|
+
- `stylistic` - ESLint config with stylistic rules ([source](https://gitlab.com/Vylda/eslint-config-vylda-vanilla/-/blob/main/rules/stylistic.mjs))
|
|
352
|
+
- `tsConfig` - ESLint config with rules for TypeScript configuration ([source](./rules/typescriptConfig.mjs))
|
|
353
|
+
- `tsFiles` - default file pattern for TypeScript rules only ([default values](./eslint.config.mjs#L10), [documentation](https://eslint.org/docs/latest/use/configure/configuration-files#configuration-objects))
|
|
354
|
+
- `tsPlugins` - default Typescript plugins only used in this config ([source](./eslint.config.mjs#L22))
|
|
355
|
+
- `tsStrict` - ESLint config with rules for strict TypeScript mode ([source](./rules/strictTs.mjs), [documentation](https://typescript-eslint.io/rules/))
|
|
356
|
+
- `tsStylistic` - ESLint config with Typescript stylistic rules ([source](./rules/stylisticTs.mjs), [documentation](https://eslint.style/packages/ts))
|
|
357
|
+
- `tsVariables` - ESLint config with typescript variables rules (extends from `variables ) ([source](./rules/variablesTs.mjs), [documentation](https://eslint.org/docs/latest/rules))
|
|
358
|
+
- `vanillaConfigs` - Eslint configuration for vanilla javascript only (without import rules) ([source](./index.js#L115))
|
|
359
|
+
- `vanillaPlugins` - default plugins used in this config for vanilla javascript ([source](https://gitlab.com/Vylda/eslint-config-vylda-vanilla/-/blob/main/eslint.config.mjs#L17))
|
|
360
|
+
- `variables` - ESLint config with rules for vanilla variables ([source](https://gitlab.com/Vylda/eslint-config-vylda-vanilla/-/blob/main/rules/variables.mjs))
|
|
361
|
+
|
|
362
|
+
## Additional Documentation
|
|
363
|
+
|
|
364
|
+
- [Changelog.md](Changelog.md)
|
|
365
|
+
|
|
366
|
+
## Credits
|
|
367
|
+
|
|
368
|
+
Authored and maintained by Vilda Lipold ([dovolena.cz](https://dovolena.cz), [studentagency.cz](https://studentagency.cz), [regiojethotels.cz](https://regiojethotels.cz), [jazykovepobyty.cz](https://jazykovepobyty.cz) and more)
|
|
369
|
+
|
|
370
|
+
## License
|
|
371
|
+
|
|
372
|
+
Open source [licensed as MIT](LICENSE).
|
package/directory.mjs
ADDED
package/empty.ts
ADDED
|
File without changes
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {
|
|
2
|
+
barrels, ignores, mapFiles, plugins as vanillaPlugins,
|
|
3
|
+
} from 'eslint-config-vylda-vanilla';
|
|
4
|
+
import * as espree from 'espree';
|
|
5
|
+
import tsESLint from 'typescript-eslint';
|
|
6
|
+
import baseDir from './directory.mjs';
|
|
7
|
+
import { getVanillaConfig, tsConfig } from './rules/index.mjs';
|
|
8
|
+
|
|
9
|
+
export const barrelsFiles = ['**/index.{js,mjs,mts,ts}'];
|
|
10
|
+
export const files = ['**/*.{cjs,cts,js,mjs,mts,ts}'];
|
|
11
|
+
export const tsFiles = ['**/*.{cts,mts,ts}'];
|
|
12
|
+
export const nonTsConfigFiles = ['**/eslint.config.mjs'];
|
|
13
|
+
|
|
14
|
+
const [{
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
languageOptions: recommendedLanguageOptions,
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
plugins: recommendedTsPlugins,
|
|
19
|
+
}] = tsESLint.configs.recommendedTypeCheckedOnly;
|
|
20
|
+
|
|
21
|
+
const tsPlugin = recommendedTsPlugins?.['@typescript-eslint'];
|
|
22
|
+
|
|
23
|
+
if (!!tsPlugin && 'configs' in tsPlugin) {
|
|
24
|
+
delete tsPlugin.configs;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const tsPlugins = {
|
|
28
|
+
'@typescript-eslint': tsPlugin,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const plugins = {
|
|
32
|
+
...vanillaPlugins,
|
|
33
|
+
...tsPlugins,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Returns language options for ESLint with typescript
|
|
38
|
+
* @param {string} dir - base directory for tsconfig.json
|
|
39
|
+
* @returns Object
|
|
40
|
+
*/
|
|
41
|
+
export const getLanguageOptions = (dir) => ({
|
|
42
|
+
...recommendedLanguageOptions,
|
|
43
|
+
ecmaVersion: 'latest',
|
|
44
|
+
parserOptions: {
|
|
45
|
+
projectService: true,
|
|
46
|
+
tsconfigRootDir: dir,
|
|
47
|
+
},
|
|
48
|
+
sourceType: 'module',
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const configsWithFiles = mapFiles(getVanillaConfig(baseDir), files);
|
|
52
|
+
const configsWithTsFiles = mapFiles(tsConfig, tsFiles);
|
|
53
|
+
|
|
54
|
+
const barrelsWithFiles = mapFiles(barrels, barrelsFiles);
|
|
55
|
+
|
|
56
|
+
export const nonTsConfigFilesRule = {
|
|
57
|
+
files: nonTsConfigFiles,
|
|
58
|
+
languageOptions: {
|
|
59
|
+
parser: espree,
|
|
60
|
+
parserOptions: {
|
|
61
|
+
ecmaVersion: 'latest',
|
|
62
|
+
sourceType: 'module',
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
name: 'Eslint config file specific typescript language options',
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const config = [
|
|
69
|
+
{
|
|
70
|
+
languageOptions: getLanguageOptions(baseDir),
|
|
71
|
+
name: 'typescript-eslint/base',
|
|
72
|
+
plugins,
|
|
73
|
+
},
|
|
74
|
+
...configsWithFiles,
|
|
75
|
+
...configsWithTsFiles,
|
|
76
|
+
...barrelsWithFiles,
|
|
77
|
+
...ignores,
|
|
78
|
+
nonTsConfigFilesRule,
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
export default config;
|