@viclafouch/eslint-config-viclafouch 4.1.1 → 4.1.2
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 +7 -14
- package/imports.js +7 -0
- package/package.json +16 -15
- package/rules/imports.js +26 -0
- package/rules/sort-imports.js +0 -62
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ These are the ESLint and Prettier settings for a Next.js project ⚡️
|
|
|
15
15
|
- [Add the typescript eslint config](#add-the-typescript-eslint-config)
|
|
16
16
|
- [Better typing](#better-typing)
|
|
17
17
|
- [Scripts](#scripts-1)
|
|
18
|
-
- [
|
|
18
|
+
- [If you want to enable imports sorting](#if-you-want-to-enable-imports-sorting)
|
|
19
19
|
- [If you use Next.js](#if-you-use-nextjs)
|
|
20
20
|
- [If you use React.js](#if-you-use-reactjs)
|
|
21
21
|
- [If you want to use Prettier](#if-you-want-to-use-prettier)
|
|
@@ -152,24 +152,16 @@ You can add two scripts to your package.json to lint and/or fix your code:
|
|
|
152
152
|
}
|
|
153
153
|
```
|
|
154
154
|
|
|
155
|
-
##
|
|
155
|
+
## If you want to enable imports sorting
|
|
156
156
|
|
|
157
157
|
If you want to sort your imports using your alias at the same time from your `jsonfig.json` or `tsconfig.json` file.
|
|
158
158
|
|
|
159
|
-
1. Import the `sortImports` function from the config in your `.eslintrc.js` file:
|
|
160
|
-
|
|
161
|
-
```js
|
|
162
|
-
const {
|
|
163
|
-
sortImports
|
|
164
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
165
|
-
} = require('@viclafouch/eslint-config-viclafouch/rules/sort-imports')
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
2. Include the function in your `overrides` array like this:
|
|
169
|
-
|
|
170
159
|
```js
|
|
171
160
|
{
|
|
172
|
-
|
|
161
|
+
extends: [
|
|
162
|
+
'@viclafouch/eslint-config-viclafouch',
|
|
163
|
+
'@viclafouch/eslint-config-viclafouch/imports'
|
|
164
|
+
]
|
|
173
165
|
}
|
|
174
166
|
```
|
|
175
167
|
|
|
@@ -209,6 +201,7 @@ Be sure to add the prettier config at the end of your `extends` array.
|
|
|
209
201
|
{
|
|
210
202
|
extends: [
|
|
211
203
|
'@viclafouch/eslint-config-viclafouch',
|
|
204
|
+
'@viclafouch/eslint-config-viclafouch/imports',
|
|
212
205
|
'@viclafouch/eslint-config-viclafouch/react',
|
|
213
206
|
'@viclafouch/eslint-config-viclafouch/hooks',
|
|
214
207
|
'@viclafouch/eslint-config-viclafouch/prettier' // be sure to be the last
|
package/imports.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viclafouch/eslint-config-viclafouch",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.2",
|
|
4
4
|
"description": "ESLint and Prettier Config from Victor de la Fouchardiere",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -29,27 +29,28 @@
|
|
|
29
29
|
"typescript": "^5.1.6"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
+
"@babel/core": "^7.22.10",
|
|
33
|
+
"@babel/eslint-parser": "^7.22.10",
|
|
34
|
+
"@next/eslint-plugin-next": "^13.4.13",
|
|
35
|
+
"@rushstack/eslint-patch": "^1.3.3",
|
|
32
36
|
"@total-typescript/ts-reset": "^0.4.2",
|
|
33
|
-
"
|
|
34
|
-
"@
|
|
35
|
-
"
|
|
36
|
-
"@next/eslint-plugin-next": "^13.4.12",
|
|
37
|
-
"@rushstack/eslint-patch": "^1.3.2",
|
|
38
|
-
"@typescript-eslint/eslint-plugin": "^6.2.0",
|
|
39
|
-
"@typescript-eslint/parser": "^6.2.0",
|
|
37
|
+
"@typescript-eslint/eslint-plugin": "^6.3.0",
|
|
38
|
+
"@typescript-eslint/parser": "^6.3.0",
|
|
39
|
+
"app-root-path": "^3.1.0",
|
|
40
40
|
"babel-loader": "^9.1.3",
|
|
41
|
-
"eslint": "^8.
|
|
42
|
-
"eslint-config-prettier": "^
|
|
43
|
-
"eslint-plugin-import": "^2.
|
|
41
|
+
"eslint": "^8.46.0",
|
|
42
|
+
"eslint-config-prettier": "^9.0.0",
|
|
43
|
+
"eslint-plugin-import": "^2.28.0",
|
|
44
44
|
"eslint-plugin-jsx-a11y": "^6.7.1",
|
|
45
45
|
"eslint-plugin-prettier": "^5.0.0",
|
|
46
46
|
"eslint-plugin-promise": "^6.1.1",
|
|
47
|
-
"eslint-plugin-react": "^7.33.
|
|
47
|
+
"eslint-plugin-react": "^7.33.1",
|
|
48
48
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
49
49
|
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
50
|
-
"eslint-plugin-testing-library": "^5.11.
|
|
51
|
-
"
|
|
52
|
-
"
|
|
50
|
+
"eslint-plugin-testing-library": "^5.11.1",
|
|
51
|
+
"get-tsconfig": "^4.6.2",
|
|
52
|
+
"prettier": "^3.0.1",
|
|
53
|
+
"typescript": "^5.1.6"
|
|
53
54
|
},
|
|
54
55
|
"scripts": {
|
|
55
56
|
"lint": "eslint .",
|
package/rules/imports.js
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
const { getTsconfig } = require('get-tsconfig')
|
|
2
|
+
const appRoot = require('app-root-path')
|
|
3
|
+
|
|
4
|
+
function extractPaths(paths) {
|
|
5
|
+
return Object.keys(paths).map((key) => {
|
|
6
|
+
return key.split('/')[0]
|
|
7
|
+
})
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const tsConfig = getTsconfig(appRoot.path, 'tsconfig.json')
|
|
11
|
+
const jsConfig = getTsconfig(appRoot.path, 'jsconfig.json')
|
|
12
|
+
|
|
13
|
+
let pathsNames = []
|
|
14
|
+
|
|
15
|
+
if (tsConfig && tsConfig.config.compilerOptions.paths) {
|
|
16
|
+
pathsNames = extractPaths(tsConfig.config.compilerOptions.paths)
|
|
17
|
+
} else if (jsConfig && jsConfig.config.compilerOptions.paths) {
|
|
18
|
+
pathsNames = extractPaths(jsConfig.config.compilerOptions.paths)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @type {import("eslint").Linter.Config}
|
|
23
|
+
*/
|
|
1
24
|
module.exports = {
|
|
2
25
|
parserOptions: {
|
|
3
26
|
sourceType: 'module'
|
|
@@ -26,6 +49,9 @@ module.exports = {
|
|
|
26
49
|
// Anything that starts with a letter
|
|
27
50
|
// e.g: import Downshift from 'downshift'
|
|
28
51
|
'^[a-z]',
|
|
52
|
+
// Anything that starts with an alias (see jsconfig.json)
|
|
53
|
+
// e.g: import ListDropdown from '@shared/components/ListDropdown'
|
|
54
|
+
`^(${pathsNames.join('|')})(/.*|$)`,
|
|
29
55
|
// Anything that starts with @
|
|
30
56
|
// e.g: import { yupResolver } from '@hookform/resolvers/yup'
|
|
31
57
|
'^@',
|
package/rules/sort-imports.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
const { getTsconfig } = require('get-tsconfig')
|
|
2
|
-
|
|
3
|
-
function extractPaths(paths) {
|
|
4
|
-
return Object.keys(paths).map((key) => {
|
|
5
|
-
return key.split('/')[0]
|
|
6
|
-
})
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
module.exports = {
|
|
10
|
-
sortImports: (path) => {
|
|
11
|
-
const tsConfig = getTsconfig(path, 'tsconfig.json')
|
|
12
|
-
const jsConfig = getTsconfig(path, 'jsconfig.json')
|
|
13
|
-
|
|
14
|
-
let pathsNames = []
|
|
15
|
-
|
|
16
|
-
if (tsConfig && tsConfig.config.compilerOptions.paths) {
|
|
17
|
-
pathsNames = extractPaths(tsConfig.config.compilerOptions.paths)
|
|
18
|
-
} else if (jsConfig && jsConfig.config.compilerOptions.paths) {
|
|
19
|
-
pathsNames = extractPaths(jsConfig.config.compilerOptions.paths)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return {
|
|
23
|
-
files: ['*.ts?(x)', '*.js?(x)'],
|
|
24
|
-
rules: {
|
|
25
|
-
'simple-import-sort/imports': [
|
|
26
|
-
'error',
|
|
27
|
-
{
|
|
28
|
-
groups: [
|
|
29
|
-
[
|
|
30
|
-
// Anything that starts with react
|
|
31
|
-
// e.g: import { useState } from 'react'
|
|
32
|
-
// e.g: import { useFela } from 'react-fela'
|
|
33
|
-
'^react',
|
|
34
|
-
// Anything that starts with next
|
|
35
|
-
// e.g: import { useRouter } from 'next/router'
|
|
36
|
-
'^next',
|
|
37
|
-
// Anything that starts with a letter
|
|
38
|
-
// e.g: import Downshift from 'downshift'
|
|
39
|
-
'^[a-z]',
|
|
40
|
-
// Anything that starts with an alias (see jsconfig.json)
|
|
41
|
-
// e.g: import ListDropdown from '@shared/components/ListDropdown'
|
|
42
|
-
`^(${pathsNames.join('|')})(/.*|$)`,
|
|
43
|
-
// Anything that starts with @
|
|
44
|
-
// e.g: import { yupResolver } from '@hookform/resolvers/yup'
|
|
45
|
-
'^@',
|
|
46
|
-
// Anything that starts with a dot
|
|
47
|
-
// e.g: import { matchIsDate } from './utils/date
|
|
48
|
-
'^\\.',
|
|
49
|
-
// Side effect imports from lib
|
|
50
|
-
// e.g: import 'react-toastify/dist/ReactToastify.css'
|
|
51
|
-
'^\\u0000',
|
|
52
|
-
// Side effect import that starts with a dot
|
|
53
|
-
// e.g: import './setup-config'
|
|
54
|
-
'^\\u0000\\.'
|
|
55
|
-
]
|
|
56
|
-
]
|
|
57
|
-
}
|
|
58
|
-
]
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|