@kristijorgji/eslint-config-typescript 0.0.1 → 0.0.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.
- package/README.md +57 -18
- package/__tests__/__utils/data.ts +32 -0
- package/__tests__/config.test.ts +17 -0
- package/__tests__/data/fixtures/1/expected.json +241 -0
- package/__tests__/data/fixtures/1/file.txt +9 -0
- package/index.cjs +103 -0
- package/jest-setup.ts +0 -0
- package/jest.config.ts +44 -0
- package/package.json +29 -14
- package/tsconfig.json +13 -0
- package/index.js +0 -60
package/README.md
CHANGED
|
@@ -1,34 +1,73 @@
|
|
|
1
1
|
# @kristijorgji/eslint-config-typescript
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
If you
|
|
3
|
+
A general-purpose ESLint and Prettier configuration for TypeScript projects (non-browser environments).
|
|
4
|
+
If you need rules specific to React, Next.js, or other frameworks, you can extend or override these rules after including this config.
|
|
5
5
|
|
|
6
|
+
# Table of Contents
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
- [Requirements](#requirements)
|
|
9
|
+
- [Installation](#installation)
|
|
10
|
+
- [Usage](#usage)
|
|
11
|
+
- [Configuration](#configuration)
|
|
12
|
+
- [Development](#development)
|
|
13
|
+
- [License](#license)
|
|
14
|
+
|
|
15
|
+
## Requirements
|
|
16
|
+
|
|
17
|
+
- ESLint version **>= 8.21.0** with support for Flat Config.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
Install the package and peer dependencies using:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
11
24
|
yarn add --dev @kristijorgji/eslint-config-typescript@latest
|
|
12
25
|
```
|
|
13
26
|
|
|
14
|
-
|
|
27
|
+
> **Note:**
|
|
28
|
+
> When migrating from an older ESLint setup, please remove conflicting or duplicate dependencies first, for example:
|
|
29
|
+
> `yarn remove eslint prettier @typescript-eslint/eslint-plugin`
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
### Configuration
|
|
34
|
+
|
|
35
|
+
For ESLint **>= 9.x**, use `FlatCompat.extends` for compatibility.
|
|
36
|
+
|
|
37
|
+
Example `eslint.config.js`:
|
|
15
38
|
|
|
16
|
-
### Config
|
|
17
|
-
Add the following to your `.eslintrc.js`:
|
|
18
39
|
```js
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
40
|
+
const { FlatCompat } = require('@eslint/eslintrc');
|
|
41
|
+
const js = require('@eslint/js');
|
|
42
|
+
const { defineConfig } = require('eslint/config');
|
|
43
|
+
|
|
44
|
+
const compat = new FlatCompat({
|
|
45
|
+
baseDirectory: __dirname,
|
|
46
|
+
recommendedConfig: js.configs.recommended,
|
|
47
|
+
allConfig: js.configs.all,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
module.exports = defineConfig([
|
|
51
|
+
{
|
|
52
|
+
files: ['src/**/*.ts', '__tests__/**/*.ts'],
|
|
53
|
+
extends: compat.extends('@kristijorgji/eslint-config-typescript'),
|
|
54
|
+
},
|
|
55
|
+
]);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Development
|
|
59
|
+
|
|
60
|
+
Learn more about creating custom ESLint configs here:
|
|
61
|
+
[ESLint Shareable Configs Guide](https://eslint.org/docs/developer-guide/shareable-configs)
|
|
62
|
+
|
|
63
|
+
To develop locally, you can link your local package using:
|
|
22
64
|
|
|
65
|
+
```bash
|
|
66
|
+
yarn add --dev /path/to/local/eslint-config-typescript
|
|
23
67
|
```
|
|
24
68
|
|
|
25
|
-
|
|
26
|
-
More info on how to develop your custom eslint config can be found here: https://eslint.org/docs/developer-guide/shareable-configs
|
|
69
|
+
> You need to run this command after every change to your local plugin.
|
|
27
70
|
|
|
28
|
-
To develop locally you can install with `yarn add --dev pathtolocalfile` example
|
|
29
|
-
`yarn add --dev /Users/kristi.jorgji/Desktop/fl-lite/eslint-config-typescript`
|
|
30
|
-
|
|
31
|
-
You need to run the above command after every plugin change.
|
|
32
71
|
## License
|
|
33
72
|
|
|
34
73
|
[MIT](LICENSE)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
|
|
4
|
+
import Callsite from 'callsite';
|
|
5
|
+
|
|
6
|
+
const fixturesPath = (name: string, ext = '.json'): string => {
|
|
7
|
+
const _ext = getExt(name);
|
|
8
|
+
return path.resolve(__dirname, `../data/fixtures/${name}${_ext.length !== 0 ? '' : ext}`);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const rawFixture = (name: string): string => {
|
|
12
|
+
return fs.readFileSync(fixturesPath(name)).toString();
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const rawLocalFixture = (name: string, ext = '.json'): string => {
|
|
16
|
+
const _ext = getExt(name);
|
|
17
|
+
const fpath = `${path.dirname(Callsite()[2].getFileName())}/fixtures/${name}${_ext.length !== 0 ? '' : ext}`;
|
|
18
|
+
return fs.readFileSync(fpath).toString();
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const readLocalFixture = <T>(name: string): T => {
|
|
22
|
+
return JSON.parse(rawLocalFixture(name)) as unknown as T;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const readFixture = <T>(name: string): T => {
|
|
26
|
+
return JSON.parse(rawFixture(name)) as unknown as T;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
function getExt(filename: string): string {
|
|
30
|
+
const t = path.extname(filename || '').split('.');
|
|
31
|
+
return t[t.length - 1];
|
|
32
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FlatESLint } from 'eslint/use-at-your-own-risk';
|
|
2
|
+
import {rawFixture, readFixture} from "./__utils/data";
|
|
3
|
+
|
|
4
|
+
describe('eslint config', () => {
|
|
5
|
+
it('should lint a basic TypeScript file without errors', async () => {
|
|
6
|
+
const eslint = new FlatESLint({
|
|
7
|
+
overrideConfigFile: './index.cjs',
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const results = await eslint.lintText(rawFixture('1/file.txt'), { filePath: 'test.ts' });
|
|
11
|
+
const expected = await readFixture('1/expected.json');
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
expected[0].filePath = `${process.cwd()}/test.ts`
|
|
14
|
+
|
|
15
|
+
expect(results).toEqual(expected)
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"filePath": "/Users/kristi.jorgji/Desktop/libs/eslint-config-typescript/test.ts",
|
|
4
|
+
"messages": [
|
|
5
|
+
{
|
|
6
|
+
"ruleId": "@typescript-eslint/no-unused-vars",
|
|
7
|
+
"severity": 2,
|
|
8
|
+
"message": "'bip39' is defined but never used. Allowed unused vars must match /^_/u.",
|
|
9
|
+
"line": 1,
|
|
10
|
+
"column": 13,
|
|
11
|
+
"nodeType": null,
|
|
12
|
+
"messageId": "unusedVar",
|
|
13
|
+
"endLine": 1,
|
|
14
|
+
"endColumn": 18
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"ruleId": "import/no-unresolved",
|
|
18
|
+
"severity": 2,
|
|
19
|
+
"message": "Unable to resolve path to module 'bip39'.",
|
|
20
|
+
"line": 1,
|
|
21
|
+
"column": 24,
|
|
22
|
+
"nodeType": "Literal",
|
|
23
|
+
"endLine": 1,
|
|
24
|
+
"endColumn": 31
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"ruleId": "@typescript-eslint/no-unused-vars",
|
|
28
|
+
"severity": 2,
|
|
29
|
+
"message": "'bs58' is defined but never used. Allowed unused vars must match /^_/u.",
|
|
30
|
+
"line": 2,
|
|
31
|
+
"column": 8,
|
|
32
|
+
"nodeType": null,
|
|
33
|
+
"messageId": "unusedVar",
|
|
34
|
+
"endLine": 2,
|
|
35
|
+
"endColumn": 12
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"ruleId": "import/no-unresolved",
|
|
39
|
+
"severity": 2,
|
|
40
|
+
"message": "Unable to resolve path to module 'bs58'.",
|
|
41
|
+
"line": 2,
|
|
42
|
+
"column": 18,
|
|
43
|
+
"nodeType": "Literal",
|
|
44
|
+
"endLine": 2,
|
|
45
|
+
"endColumn": 24
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"ruleId": "import/order",
|
|
49
|
+
"severity": 2,
|
|
50
|
+
"message": "There should be at least one empty line between import groups",
|
|
51
|
+
"line": 3,
|
|
52
|
+
"column": 1,
|
|
53
|
+
"nodeType": "ImportDeclaration",
|
|
54
|
+
"endLine": 3,
|
|
55
|
+
"endColumn": 43,
|
|
56
|
+
"fix": {
|
|
57
|
+
"range": [
|
|
58
|
+
99,
|
|
59
|
+
99
|
|
60
|
+
],
|
|
61
|
+
"text": "\n"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"ruleId": "@typescript-eslint/no-unused-vars",
|
|
66
|
+
"severity": 2,
|
|
67
|
+
"message": "'ed25519' is defined but never used. Allowed unused vars must match /^_/u.",
|
|
68
|
+
"line": 3,
|
|
69
|
+
"column": 13,
|
|
70
|
+
"nodeType": null,
|
|
71
|
+
"messageId": "unusedVar",
|
|
72
|
+
"endLine": 3,
|
|
73
|
+
"endColumn": 20
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"ruleId": "import/no-unresolved",
|
|
77
|
+
"severity": 2,
|
|
78
|
+
"message": "Unable to resolve path to module 'ed25519-hd-key'.",
|
|
79
|
+
"line": 3,
|
|
80
|
+
"column": 26,
|
|
81
|
+
"nodeType": "Literal",
|
|
82
|
+
"endLine": 3,
|
|
83
|
+
"endColumn": 42
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"ruleId": "prettier/prettier",
|
|
87
|
+
"severity": 2,
|
|
88
|
+
"message": "Replace `z,·x,·c` with `·z,·x,·c·`",
|
|
89
|
+
"line": 4,
|
|
90
|
+
"column": 9,
|
|
91
|
+
"nodeType": null,
|
|
92
|
+
"messageId": "replace",
|
|
93
|
+
"endLine": 4,
|
|
94
|
+
"endColumn": 16,
|
|
95
|
+
"fix": {
|
|
96
|
+
"range": [
|
|
97
|
+
108,
|
|
98
|
+
115
|
|
99
|
+
],
|
|
100
|
+
"text": " z, x, c "
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"ruleId": "@typescript-eslint/no-unused-vars",
|
|
105
|
+
"severity": 2,
|
|
106
|
+
"message": "'z' is defined but never used. Allowed unused vars must match /^_/u.",
|
|
107
|
+
"line": 4,
|
|
108
|
+
"column": 9,
|
|
109
|
+
"nodeType": null,
|
|
110
|
+
"messageId": "unusedVar",
|
|
111
|
+
"endLine": 4,
|
|
112
|
+
"endColumn": 10
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"ruleId": "sort-imports",
|
|
116
|
+
"severity": 2,
|
|
117
|
+
"message": "Member 'x' of the import declaration should be sorted alphabetically.",
|
|
118
|
+
"line": 4,
|
|
119
|
+
"column": 12,
|
|
120
|
+
"nodeType": "ImportSpecifier",
|
|
121
|
+
"messageId": "sortMembersAlphabetically",
|
|
122
|
+
"endLine": 4,
|
|
123
|
+
"endColumn": 13,
|
|
124
|
+
"fix": {
|
|
125
|
+
"range": [
|
|
126
|
+
108,
|
|
127
|
+
115
|
|
128
|
+
],
|
|
129
|
+
"text": "c, x, z"
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"ruleId": "@typescript-eslint/no-unused-vars",
|
|
134
|
+
"severity": 2,
|
|
135
|
+
"message": "'c' is defined but never used. Allowed unused vars must match /^_/u.",
|
|
136
|
+
"line": 4,
|
|
137
|
+
"column": 15,
|
|
138
|
+
"nodeType": null,
|
|
139
|
+
"messageId": "unusedVar",
|
|
140
|
+
"endLine": 4,
|
|
141
|
+
"endColumn": 16
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"ruleId": "import/no-unresolved",
|
|
145
|
+
"severity": 2,
|
|
146
|
+
"message": "Unable to resolve path to module './a'.",
|
|
147
|
+
"line": 4,
|
|
148
|
+
"column": 23,
|
|
149
|
+
"nodeType": "Literal",
|
|
150
|
+
"endLine": 4,
|
|
151
|
+
"endColumn": 28
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"ruleId": "no-redeclare",
|
|
155
|
+
"severity": 2,
|
|
156
|
+
"message": "'x' is already defined.",
|
|
157
|
+
"line": 6,
|
|
158
|
+
"column": 7,
|
|
159
|
+
"nodeType": "Identifier",
|
|
160
|
+
"messageId": "redeclared",
|
|
161
|
+
"endLine": 6,
|
|
162
|
+
"endColumn": 16
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
"ruleId": "no-import-assign",
|
|
166
|
+
"severity": 2,
|
|
167
|
+
"message": "'x' is read-only.",
|
|
168
|
+
"line": 6,
|
|
169
|
+
"column": 7,
|
|
170
|
+
"nodeType": "Identifier",
|
|
171
|
+
"messageId": "readonly",
|
|
172
|
+
"endLine": 6,
|
|
173
|
+
"endColumn": 16
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
"ruleId": "prettier/prettier",
|
|
177
|
+
"severity": 2,
|
|
178
|
+
"message": "Delete `····`",
|
|
179
|
+
"line": 7,
|
|
180
|
+
"column": 1,
|
|
181
|
+
"nodeType": null,
|
|
182
|
+
"messageId": "delete",
|
|
183
|
+
"endLine": 7,
|
|
184
|
+
"endColumn": 5,
|
|
185
|
+
"fix": {
|
|
186
|
+
"range": [
|
|
187
|
+
151,
|
|
188
|
+
155
|
|
189
|
+
],
|
|
190
|
+
"text": ""
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
"ruleId": "@typescript-eslint/no-unused-vars",
|
|
195
|
+
"severity": 2,
|
|
196
|
+
"message": "'d' is assigned a value but never used. Allowed unused vars must match /^_/u.",
|
|
197
|
+
"line": 9,
|
|
198
|
+
"column": 5,
|
|
199
|
+
"nodeType": null,
|
|
200
|
+
"messageId": "unusedVar",
|
|
201
|
+
"endLine": 9,
|
|
202
|
+
"endColumn": 6
|
|
203
|
+
}
|
|
204
|
+
],
|
|
205
|
+
"suppressedMessages": [],
|
|
206
|
+
"errorCount": 16,
|
|
207
|
+
"fatalErrorCount": 0,
|
|
208
|
+
"warningCount": 0,
|
|
209
|
+
"fixableErrorCount": 4,
|
|
210
|
+
"fixableWarningCount": 0,
|
|
211
|
+
"source": "import * as bip39 from 'bip39';\nimport bs58 from 'bs58';\nimport * as ed25519 from 'ed25519-hd-key';\nimport {z, x, c} from './a';\n\nconst x: number = 5;\n console.log(x);\n\nlet d = 2;\n",
|
|
212
|
+
"usedDeprecatedRules": [
|
|
213
|
+
{
|
|
214
|
+
"ruleId": "quotes",
|
|
215
|
+
"replacedBy": [
|
|
216
|
+
"@stylistic/js/quotes"
|
|
217
|
+
],
|
|
218
|
+
"info": {
|
|
219
|
+
"message": "Formatting rules are being moved out of ESLint core.",
|
|
220
|
+
"url": "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
|
221
|
+
"deprecatedSince": "8.53.0",
|
|
222
|
+
"availableUntil": "10.0.0",
|
|
223
|
+
"replacedBy": [
|
|
224
|
+
{
|
|
225
|
+
"message": "ESLint Stylistic now maintains deprecated stylistic core rules.",
|
|
226
|
+
"url": "https://eslint.style/guide/migration",
|
|
227
|
+
"plugin": {
|
|
228
|
+
"name": "@stylistic/eslint-plugin-js",
|
|
229
|
+
"url": "https://eslint.style/packages/js"
|
|
230
|
+
},
|
|
231
|
+
"rule": {
|
|
232
|
+
"name": "quotes",
|
|
233
|
+
"url": "https://eslint.style/rules/js/quotes"
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
]
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
]
|
|
240
|
+
}
|
|
241
|
+
]
|
package/index.cjs
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
const globals = require('globals');
|
|
2
|
+
const js = require('@eslint/js');
|
|
3
|
+
const importPlugin = require('eslint-plugin-import');
|
|
4
|
+
const tseslint = require('@typescript-eslint/eslint-plugin');
|
|
5
|
+
const parser = require('@typescript-eslint/parser');
|
|
6
|
+
const prettierPlugin = require('eslint-plugin-prettier');
|
|
7
|
+
|
|
8
|
+
module.exports = [
|
|
9
|
+
{
|
|
10
|
+
files: ['**/*.ts'],
|
|
11
|
+
languageOptions: {
|
|
12
|
+
parser,
|
|
13
|
+
ecmaVersion: 'latest',
|
|
14
|
+
sourceType: 'module',
|
|
15
|
+
globals: {
|
|
16
|
+
...globals.node,
|
|
17
|
+
...globals.jest,
|
|
18
|
+
...globals.es2021,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
plugins: {
|
|
22
|
+
'@typescript-eslint': tseslint,
|
|
23
|
+
import: importPlugin,
|
|
24
|
+
prettier: prettierPlugin,
|
|
25
|
+
},
|
|
26
|
+
settings: {
|
|
27
|
+
'import/resolver': {
|
|
28
|
+
typescript: {
|
|
29
|
+
// always try to resolve types under `<root>@types` directory even it doesn't contain source code,
|
|
30
|
+
// this can help resolve things like `@types/node` correctly
|
|
31
|
+
alwaysTryTypes: true,
|
|
32
|
+
// optionally, you can specify project root if your tsconfig.json is not in the root
|
|
33
|
+
// project: './path/to/tsconfig.json',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
rules: {
|
|
38
|
+
...js.configs.recommended.rules,
|
|
39
|
+
'no-unused-vars': 'off',
|
|
40
|
+
...importPlugin.configs.recommended.rules,
|
|
41
|
+
...importPlugin.configs.typescript.rules,
|
|
42
|
+
'import/order': [
|
|
43
|
+
'error',
|
|
44
|
+
{
|
|
45
|
+
groups: ['builtin', 'external', 'internal', ['parent', 'sibling']],
|
|
46
|
+
'newlines-between': 'always',
|
|
47
|
+
alphabetize: {
|
|
48
|
+
order: 'asc',
|
|
49
|
+
caseInsensitive: true,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
'sort-imports': [
|
|
54
|
+
'error',
|
|
55
|
+
{
|
|
56
|
+
ignoreDeclarationSort: true,
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
'no-unmodified-loop-condition': 'error',
|
|
60
|
+
'import/no-unresolved': 'error',
|
|
61
|
+
'import/no-extraneous-dependencies': [
|
|
62
|
+
'error',
|
|
63
|
+
{
|
|
64
|
+
devDependencies: ['{tests,__tests__,mocks,__mocks__}/**/*.ts'],
|
|
65
|
+
bundledDependencies: true,
|
|
66
|
+
optionalDependencies: false,
|
|
67
|
+
peerDependencies: false,
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
// typescript-eslint rules
|
|
71
|
+
'@typescript-eslint/no-explicit-any': 'error',
|
|
72
|
+
'@typescript-eslint/no-unused-vars': [
|
|
73
|
+
'error',
|
|
74
|
+
{
|
|
75
|
+
args: 'all',
|
|
76
|
+
argsIgnorePattern: '^_',
|
|
77
|
+
caughtErrors: 'all',
|
|
78
|
+
caughtErrorsIgnorePattern: '^_',
|
|
79
|
+
destructuredArrayIgnorePattern: '^_',
|
|
80
|
+
varsIgnorePattern: '^_',
|
|
81
|
+
ignoreRestSiblings: true,
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
// stylistic rules
|
|
85
|
+
quotes: ['error', 'single'],
|
|
86
|
+
'object-shorthand': 'off',
|
|
87
|
+
'prettier/prettier': [
|
|
88
|
+
'error',
|
|
89
|
+
{
|
|
90
|
+
arrowParens: 'avoid',
|
|
91
|
+
bracketSpacing: true,
|
|
92
|
+
printWidth: 120,
|
|
93
|
+
semi: true,
|
|
94
|
+
singleQuote: true,
|
|
95
|
+
tabWidth: 4,
|
|
96
|
+
trailingComma: 'all',
|
|
97
|
+
useTabs: false,
|
|
98
|
+
endOfLine: 'lf',
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
];
|
package/jest-setup.ts
ADDED
|
File without changes
|
package/jest.config.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
process.env.TZ = 'UTC';
|
|
2
|
+
|
|
3
|
+
const TS_CONFIG_PATH = './tsconfig.json';
|
|
4
|
+
const SRC_PATH = '<rootDir>';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
testEnvironment: 'node',
|
|
8
|
+
preset: 'ts-jest',
|
|
9
|
+
setupFilesAfterEnv: ['<rootDir>/jest-setup.ts'],
|
|
10
|
+
testMatch: ['**/__tests__/**/*.test.ts'],
|
|
11
|
+
collectCoverage: true,
|
|
12
|
+
collectCoverageFrom: [
|
|
13
|
+
'src/**/*.{js,jsx,ts,tsx}',
|
|
14
|
+
'!**/__mocks__/**',
|
|
15
|
+
'!<rootDir>/node_modules/',
|
|
16
|
+
],
|
|
17
|
+
coverageThreshold: {
|
|
18
|
+
global: {
|
|
19
|
+
statements: 49,
|
|
20
|
+
branches: 50,
|
|
21
|
+
functions: 40,
|
|
22
|
+
lines: 45,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
moduleNameMapper: {
|
|
26
|
+
...makeModuleNameMapper(SRC_PATH, TS_CONFIG_PATH),
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function makeModuleNameMapper(srcPath: string, tsconfigPath: string) {
|
|
31
|
+
// Get paths from tsconfig
|
|
32
|
+
const { paths } = require(tsconfigPath).compilerOptions;
|
|
33
|
+
|
|
34
|
+
const aliases: Record<string, string> = {};
|
|
35
|
+
|
|
36
|
+
// Iterate over paths and convert them into moduleNameMapper format
|
|
37
|
+
Object.keys(paths || {}).forEach(item => {
|
|
38
|
+
const key = item.replace('/*', '/(.*)');
|
|
39
|
+
const path = paths[item][0].replace('/*', '/$1');
|
|
40
|
+
aliases[key] = srcPath + '/' + path;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return aliases;
|
|
44
|
+
}
|
package/package.json
CHANGED
|
@@ -1,28 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kristijorgji/eslint-config-typescript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "eslint config for typescript based projects",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "index.cjs",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "NODE_OPTIONS='--experimental-vm-modules' jest"
|
|
12
|
+
},
|
|
9
13
|
"dependencies": {
|
|
10
|
-
"@
|
|
11
|
-
"@
|
|
12
|
-
"eslint": "^8.
|
|
13
|
-
"eslint
|
|
14
|
-
"eslint
|
|
15
|
-
"eslint-
|
|
16
|
-
"eslint-
|
|
17
|
-
"eslint-
|
|
18
|
-
"eslint-plugin-
|
|
19
|
-
"eslint-plugin-
|
|
20
|
-
"
|
|
14
|
+
"@eslint/eslintrc": "^3.3.1",
|
|
15
|
+
"@eslint/js": "^9.27.0",
|
|
16
|
+
"@typescript-eslint/eslint-plugin": "^8.33.0",
|
|
17
|
+
"@typescript-eslint/parser": "^8.33.0",
|
|
18
|
+
"eslint": "^9.27.0",
|
|
19
|
+
"eslint-config-prettier": "^10.1.5",
|
|
20
|
+
"eslint-config-standard": "^17.1.0",
|
|
21
|
+
"eslint-import-resolver-typescript": "^4.4.1",
|
|
22
|
+
"eslint-plugin-import": "^2.31.0",
|
|
23
|
+
"eslint-plugin-prettier": "^5.4.0",
|
|
24
|
+
"globals": "^16.2.0",
|
|
25
|
+
"prettier": "3.5.3"
|
|
21
26
|
},
|
|
22
27
|
"keywords": [
|
|
23
28
|
"eslint",
|
|
24
29
|
"typescript"
|
|
25
30
|
],
|
|
26
31
|
"author": "kristijorgji",
|
|
27
|
-
"license": "MIT"
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/callsite": "^1.0.34",
|
|
35
|
+
"@types/jest": "^29.5.14",
|
|
36
|
+
"@types/node": "^22.15.24",
|
|
37
|
+
"callsite": "^1.0.0",
|
|
38
|
+
"jest": "^29.7.0",
|
|
39
|
+
"ts-jest": "^29.3.4",
|
|
40
|
+
"ts-node": "^10.9.2",
|
|
41
|
+
"typescript": "^5.8.3"
|
|
42
|
+
}
|
|
28
43
|
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowJs": true,
|
|
4
|
+
"esModuleInterop": true,
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"target": "ES2020",
|
|
7
|
+
"module": "CommonJS",
|
|
8
|
+
"types": ["node", "jest"],
|
|
9
|
+
"strict": true,
|
|
10
|
+
"resolveJsonModule": true
|
|
11
|
+
},
|
|
12
|
+
"include": ["__tests__/**/*.ts"]
|
|
13
|
+
}
|
package/index.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
env: {
|
|
3
|
-
browser: true,
|
|
4
|
-
es2021: true,
|
|
5
|
-
jest: true,
|
|
6
|
-
node: true,
|
|
7
|
-
},
|
|
8
|
-
extends: ['standard', 'eslint:recommended', 'prettier', 'plugin:import/recommended', 'plugin:import/typescript'],
|
|
9
|
-
parser: '@typescript-eslint/parser',
|
|
10
|
-
plugins: ['@typescript-eslint', 'eslint-plugin-prettier', 'eslint-plugin-import'],
|
|
11
|
-
rules: {
|
|
12
|
-
'import/order': [
|
|
13
|
-
'error',
|
|
14
|
-
{
|
|
15
|
-
groups: ['builtin', 'external', 'internal', ['parent', 'sibling']],
|
|
16
|
-
'newlines-between': 'always',
|
|
17
|
-
alphabetize: {
|
|
18
|
-
order: 'asc',
|
|
19
|
-
caseInsensitive: true,
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
],
|
|
23
|
-
'sort-imports': [
|
|
24
|
-
'error',
|
|
25
|
-
{
|
|
26
|
-
ignoreDeclarationSort: true,
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
'import/no-unresolved': [
|
|
30
|
-
'error',
|
|
31
|
-
],
|
|
32
|
-
'import/no-extraneous-dependencies': [
|
|
33
|
-
'error',
|
|
34
|
-
{
|
|
35
|
-
devDependencies: ['{tests,__tests__,mocks,__mocks__}/**/*.ts'],
|
|
36
|
-
bundledDependencies: true,
|
|
37
|
-
optionalDependencies: false,
|
|
38
|
-
peerDependencies: false,
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
'@typescript-eslint/no-explicit-any': 'error',
|
|
42
|
-
quotes: ['error', 'single'],
|
|
43
|
-
'@typescript-eslint/no-unused-vars': 'error',
|
|
44
|
-
'object-shorthand': 'off',
|
|
45
|
-
'prettier/prettier': [
|
|
46
|
-
'error',
|
|
47
|
-
{
|
|
48
|
-
arrowParens: 'avoid',
|
|
49
|
-
bracketSpacing: true,
|
|
50
|
-
printWidth: 120,
|
|
51
|
-
semi: true,
|
|
52
|
-
singleQuote: true,
|
|
53
|
-
tabWidth: 4,
|
|
54
|
-
trailingComma: 'all',
|
|
55
|
-
useTabs: false,
|
|
56
|
-
endOfLine: "lf"
|
|
57
|
-
},
|
|
58
|
-
],
|
|
59
|
-
},
|
|
60
|
-
};
|