@itcase/lint 1.0.23 → 1.0.24
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 → README.md} +62 -5
- package/eslint/eslint.styleObjects.js +2 -5
- package/eslint/eslint.styleProps.js +2 -4
- package/eslint/index.js +14 -11
- package/eslint/perfectionist/index.js +9 -21
- package/eslint/perfectionist/sortInterfaces.js +15 -7
- package/eslint/perfectionist/sortJSXProps.js +26 -24
- package/eslint/perfectionist/sortObjectTypes.js +10 -2
- package/eslint/perfectionist/sortObjects.js +27 -24
- package/eslint/utils/generateCustomGroups.js +11 -0
- package/package.json +1 -1
package/{readme.md → README.md}
RENAMED
|
@@ -8,9 +8,43 @@ Presets of linter configurations
|
|
|
8
8
|
$ npm i -D @itcase/lint eslint stylelint prettier
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
## Setting up sorting configuration
|
|
12
|
+
|
|
13
|
+
The sorting configuration is located in the `perfectionist` folder along the path: `eslint/perfectionist`.
|
|
14
|
+
|
|
15
|
+
Example: Setting up sortJSXProps
|
|
16
|
+
|
|
17
|
+
Sorting rules are defined in eslint/perfectionist/sortJSXProps.js.
|
|
18
|
+
|
|
19
|
+
Here's how to set up the order and rules:
|
|
20
|
+
|
|
21
|
+
1. `groups`:
|
|
22
|
+
|
|
23
|
+
- This array defines the order in which the props will be sorted.
|
|
24
|
+
- Add the prop names in the order you want them to be.
|
|
25
|
+
|
|
26
|
+
2. `customRulesForGroups`:
|
|
27
|
+
|
|
28
|
+
- If the prop sort order depends on the template (rather than the exact name), set up the rule here.
|
|
29
|
+
|
|
30
|
+
- For example:
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
const groups = [
|
|
34
|
+
'className',
|
|
35
|
+
'key',
|
|
36
|
+
// ...
|
|
37
|
+
'callback',
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
const customRulesForGroups = {
|
|
41
|
+
callback: 'on*',
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
11
45
|
## Usage
|
|
12
46
|
|
|
13
|
-
|
|
47
|
+
### ESLint
|
|
14
48
|
|
|
15
49
|
Create a `eslint.config.mjs` configuration file in the root of your project with the following content:
|
|
16
50
|
|
|
@@ -20,7 +54,7 @@ import eslint from '@itcase/lint/eslint/index.js'
|
|
|
20
54
|
export default eslint
|
|
21
55
|
```
|
|
22
56
|
|
|
23
|
-
|
|
57
|
+
### ESLint with MobX
|
|
24
58
|
|
|
25
59
|
Create a `eslint.config.mjs` configuration file in the root of your project with the following content:
|
|
26
60
|
|
|
@@ -31,7 +65,30 @@ import eslintMobx from '@itcase/lint/eslint/mobx/index.js'
|
|
|
31
65
|
export default [...eslint, ...eslintMobx]
|
|
32
66
|
```
|
|
33
67
|
|
|
34
|
-
|
|
68
|
+
### ESLint with React Native
|
|
69
|
+
|
|
70
|
+
Create a `eslint.config.mjs` configuration file in the root of your project with the following content:
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
import eslint from '@itcase/lint/eslint/index.js'
|
|
74
|
+
import eslintReactNative from '@itcase/lint/eslint/react-native/index.js'
|
|
75
|
+
|
|
76
|
+
export default [...eslint, ...eslintReactNative]
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### ESLint with MobX, React Native
|
|
80
|
+
|
|
81
|
+
Create a `eslint.config.mjs` configuration file in the root of your project with the following content:
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
import eslint from '@itcase/lint/eslint/index.js'
|
|
85
|
+
import eslintMobx from '@itcase/lint/eslint/mobx/index.js'
|
|
86
|
+
import eslintReactNative from '@itcase/lint/eslint/react-native/index.js'
|
|
87
|
+
|
|
88
|
+
export default [...eslint, ...eslintMobx, ...eslintReactNative]
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Stylelint
|
|
35
92
|
|
|
36
93
|
Create a `eslint.config.mjs` configuration file in the root of your project with the following content:
|
|
37
94
|
|
|
@@ -41,7 +98,7 @@ export default {
|
|
|
41
98
|
}
|
|
42
99
|
```
|
|
43
100
|
|
|
44
|
-
|
|
101
|
+
### Prettier
|
|
45
102
|
|
|
46
103
|
Create a `prettier.config.mjs` configuration file in the root of your project with the following content:
|
|
47
104
|
|
|
@@ -51,7 +108,7 @@ import prettier from '@itcase/lint/prettier/index.js'
|
|
|
51
108
|
export default prettier
|
|
52
109
|
```
|
|
53
110
|
|
|
54
|
-
|
|
111
|
+
### git-hook
|
|
55
112
|
|
|
56
113
|
1. Use `husky` and `lint-staged`
|
|
57
114
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// In what order they are written, that’s how they will be sorted
|
|
2
|
+
// В каком порядке они записаны, так они и будут отсортированы
|
|
2
3
|
const eslintStyleObjects = [
|
|
3
4
|
// Size and positioning
|
|
4
5
|
// Размер и позиционирование
|
|
@@ -118,8 +119,4 @@ const eslintStyleObjects = [
|
|
|
118
119
|
'cursor',
|
|
119
120
|
]
|
|
120
121
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
eslintStyleObjects.forEach((key) => (eslintStyleObjectsCustomGroups[key] = key))
|
|
124
|
-
|
|
125
|
-
export { eslintStyleObjects, eslintStyleObjectsCustomGroups }
|
|
122
|
+
export { eslintStyleObjects }
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// In what order they are written, that’s how they will be sorted
|
|
2
|
+
// В каком порядке они записаны, так они и будут отсортированы
|
|
2
3
|
const eslintStyleProps = [
|
|
3
4
|
'width',
|
|
4
5
|
'height',
|
|
@@ -61,7 +62,4 @@ const eslintStyleProps = [
|
|
|
61
62
|
'cursor',
|
|
62
63
|
]
|
|
63
64
|
|
|
64
|
-
|
|
65
|
-
eslintStyleProps.forEach((key) => (eslintStylePropsCustomGroups[key] = key))
|
|
66
|
-
|
|
67
|
-
export { eslintStyleProps, eslintStylePropsCustomGroups }
|
|
65
|
+
export { eslintStyleProps }
|
package/eslint/index.js
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
const eslintConfig = [
|
|
24
24
|
eslintJs.configs.recommended,
|
|
25
25
|
...eslintTypeScript.configs.recommended,
|
|
26
|
+
...eslintMarkdown.configs.recommended,
|
|
26
27
|
eslintPluginPrettierRecommended,
|
|
27
28
|
|
|
28
29
|
{
|
|
@@ -36,10 +37,12 @@ const eslintConfig = [
|
|
|
36
37
|
{
|
|
37
38
|
ignores: ['dist', 'node_modules', 'eslint.config.mjs'],
|
|
38
39
|
},
|
|
40
|
+
|
|
39
41
|
{
|
|
40
42
|
files: ['**/*.json'],
|
|
41
43
|
...eslintJson.configs['recommended'],
|
|
42
44
|
},
|
|
45
|
+
|
|
43
46
|
{
|
|
44
47
|
files: ['**/*.{js,jsx,mjs,cjs,ts,tsx}'],
|
|
45
48
|
rules: {
|
|
@@ -69,24 +72,24 @@ const eslintConfig = [
|
|
|
69
72
|
|
|
70
73
|
// Class
|
|
71
74
|
'perfectionist/sort-classes': sortClasses,
|
|
75
|
+
// Enum
|
|
76
|
+
'perfectionist/sort-enums': sortEnums,
|
|
77
|
+
// Interfaces
|
|
78
|
+
'perfectionist/sort-interfaces': sortInterfaces,
|
|
79
|
+
// Intersection types
|
|
80
|
+
'perfectionist/sort-intersection-types': sortIntersectionTypes,
|
|
81
|
+
// JSX props
|
|
82
|
+
'perfectionist/sort-jsx-props': sortJSXProps,
|
|
83
|
+
// Maps
|
|
84
|
+
'perfectionist/sort-maps': sortMaps,
|
|
72
85
|
// Objects
|
|
73
86
|
'perfectionist/sort-objects': sortObjects,
|
|
87
|
+
// Objects-types
|
|
74
88
|
'perfectionist/sort-object-types': sortObjectTypes,
|
|
75
|
-
// Props
|
|
76
|
-
'perfectionist/sort-jsx-props': sortJSXProps,
|
|
77
|
-
// Interfaces
|
|
78
|
-
'perfectionist/sort-interfaces': sortInterfaces,
|
|
79
|
-
|
|
80
89
|
// Union types
|
|
81
90
|
'perfectionist/sort-union-types': sortUnionTypes,
|
|
82
|
-
|
|
83
|
-
// Maps, Enum, Intersection types
|
|
84
|
-
'perfectionist/sort-maps': sortMaps,
|
|
85
|
-
'perfectionist/sort-enums': sortEnums,
|
|
86
|
-
'perfectionist/sort-intersection-types': sortIntersectionTypes,
|
|
87
91
|
},
|
|
88
92
|
},
|
|
89
|
-
...eslintMarkdown.configs.recommended,
|
|
90
93
|
]
|
|
91
94
|
|
|
92
95
|
export default eslintConfig
|
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export {
|
|
12
|
-
sortClasses,
|
|
13
|
-
sortEnums,
|
|
14
|
-
sortInterfaces,
|
|
15
|
-
sortIntersectionTypes,
|
|
16
|
-
sortJSXProps,
|
|
17
|
-
sortMaps,
|
|
18
|
-
sortObjects,
|
|
19
|
-
sortObjectTypes,
|
|
20
|
-
sortUnionTypes,
|
|
21
|
-
}
|
|
1
|
+
export { sortClasses } from './sortClasses.js'
|
|
2
|
+
export { sortEnums } from './sortEnums.js'
|
|
3
|
+
export { sortInterfaces } from './sortInterfaces.js'
|
|
4
|
+
export { sortIntersectionTypes } from './sortIntersectionTypes.js'
|
|
5
|
+
export { sortJSXProps } from './sortJSXProps.js'
|
|
6
|
+
export { sortMaps } from './sortMaps.js'
|
|
7
|
+
export { sortObjects } from './sortObjects.js'
|
|
8
|
+
export { sortObjectTypes } from './sortObjectTypes.js'
|
|
9
|
+
export { sortUnionTypes } from './sortUnionTypes.js'
|
|
@@ -1,15 +1,23 @@
|
|
|
1
|
+
import { generateCustomGroups } from '../utils/generateCustomGroups.js'
|
|
2
|
+
|
|
3
|
+
// In what order they are written, that’s how they will be sorted
|
|
4
|
+
// В каком порядке они записаны, так они и будут отсортированы
|
|
5
|
+
const groups = ['top', 'unknown', 'is', 'callback', 'set']
|
|
6
|
+
|
|
7
|
+
const customRulesForGroups = {
|
|
8
|
+
top: ['id', 'Id'],
|
|
9
|
+
is: 'is*',
|
|
10
|
+
callback: 'on*',
|
|
11
|
+
set: ['set*'],
|
|
12
|
+
}
|
|
13
|
+
|
|
1
14
|
const sortInterfaces = [
|
|
2
15
|
'error',
|
|
3
16
|
{
|
|
4
17
|
type: 'natural',
|
|
5
18
|
order: 'asc',
|
|
6
|
-
groups:
|
|
7
|
-
customGroups:
|
|
8
|
-
top: ['id', 'Id'],
|
|
9
|
-
is: 'is*',
|
|
10
|
-
callback: 'on*',
|
|
11
|
-
set: ['set*'],
|
|
12
|
-
},
|
|
19
|
+
groups: groups,
|
|
20
|
+
customGroups: generateCustomGroups(groups, customRulesForGroups),
|
|
13
21
|
},
|
|
14
22
|
]
|
|
15
23
|
|
|
@@ -1,33 +1,35 @@
|
|
|
1
|
-
import { eslintStyleProps
|
|
1
|
+
import { eslintStyleProps } from './../eslint.styleProps.js'
|
|
2
|
+
import { generateCustomGroups } from './../utils/generateCustomGroups.js'
|
|
3
|
+
|
|
4
|
+
// In what order they are written, that’s how they will be sorted
|
|
5
|
+
// В каком порядке они записаны, так они и будут отсортированы
|
|
6
|
+
const groups = [
|
|
7
|
+
'className',
|
|
8
|
+
'key',
|
|
9
|
+
'ref',
|
|
10
|
+
'name',
|
|
11
|
+
...eslintStyleProps,
|
|
12
|
+
'shorthand',
|
|
13
|
+
'unknown',
|
|
14
|
+
'multiline',
|
|
15
|
+
'is',
|
|
16
|
+
'set',
|
|
17
|
+
'callback',
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
const customRulesForGroups = {
|
|
21
|
+
is: 'is*',
|
|
22
|
+
callback: 'on*',
|
|
23
|
+
set: ['set*'],
|
|
24
|
+
}
|
|
2
25
|
|
|
3
26
|
const sortJSXProps = [
|
|
4
27
|
'error',
|
|
5
28
|
{
|
|
6
29
|
type: 'natural',
|
|
7
30
|
order: 'asc',
|
|
8
|
-
groups:
|
|
9
|
-
|
|
10
|
-
'key',
|
|
11
|
-
'ref',
|
|
12
|
-
'name',
|
|
13
|
-
...eslintStyleProps,
|
|
14
|
-
'shorthand',
|
|
15
|
-
'unknown',
|
|
16
|
-
'multiline',
|
|
17
|
-
'is',
|
|
18
|
-
'set',
|
|
19
|
-
'callback',
|
|
20
|
-
],
|
|
21
|
-
customGroups: {
|
|
22
|
-
className: 'className',
|
|
23
|
-
key: 'key',
|
|
24
|
-
ref: 'ref',
|
|
25
|
-
name: 'name',
|
|
26
|
-
...eslintStylePropsCustomGroups,
|
|
27
|
-
is: 'is*',
|
|
28
|
-
callback: 'on*',
|
|
29
|
-
set: ['set*'],
|
|
30
|
-
},
|
|
31
|
+
groups: groups,
|
|
32
|
+
customGroups: generateCustomGroups(groups, customRulesForGroups),
|
|
31
33
|
},
|
|
32
34
|
]
|
|
33
35
|
|
|
@@ -1,10 +1,18 @@
|
|
|
1
|
+
import { generateCustomGroups } from '../utils/generateCustomGroups.js'
|
|
2
|
+
|
|
3
|
+
// In what order they are written, that’s how they will be sorted
|
|
4
|
+
// В каком порядке они записаны, так они и будут отсортированы
|
|
5
|
+
const groups = ['id']
|
|
6
|
+
|
|
7
|
+
const customRulesForGroups = {}
|
|
8
|
+
|
|
1
9
|
const sortObjectTypes = [
|
|
2
10
|
'error',
|
|
3
11
|
{
|
|
4
12
|
type: 'natural',
|
|
5
13
|
order: 'asc',
|
|
6
|
-
groups:
|
|
7
|
-
customGroups:
|
|
14
|
+
groups: groups,
|
|
15
|
+
customGroups: generateCustomGroups(groups, customRulesForGroups),
|
|
8
16
|
},
|
|
9
17
|
]
|
|
10
18
|
|
|
@@ -1,33 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { generateCustomGroups } from '../utils/generateCustomGroups.js'
|
|
2
|
+
import { eslintStyleObjects } from './../eslint.styleObjects.js'
|
|
3
|
+
|
|
4
|
+
// In what order they are written, that’s how they will be sorted
|
|
5
|
+
// В каком порядке они записаны, так они и будут отсортированы
|
|
6
|
+
const groups = [
|
|
7
|
+
'isMobile',
|
|
8
|
+
'isTablet',
|
|
9
|
+
'isDesktop',
|
|
10
|
+
'id',
|
|
11
|
+
'children',
|
|
12
|
+
...eslintStyleObjects,
|
|
13
|
+
'device',
|
|
14
|
+
'is',
|
|
15
|
+
'unknown',
|
|
16
|
+
'callback',
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
const customRulesForGroups = {
|
|
20
|
+
isMobile: 'isMobile*',
|
|
21
|
+
isTablet: 'isTablet*',
|
|
22
|
+
isDesktop: 'isDesktop*',
|
|
23
|
+
is: 'is*',
|
|
24
|
+
callback: 'on*',
|
|
25
|
+
}
|
|
2
26
|
|
|
3
27
|
const sortObjects = [
|
|
4
28
|
'error',
|
|
5
29
|
{
|
|
6
30
|
type: 'natural',
|
|
7
31
|
order: 'asc',
|
|
8
|
-
groups:
|
|
9
|
-
|
|
10
|
-
'isTablet',
|
|
11
|
-
'isDesktop',
|
|
12
|
-
'id',
|
|
13
|
-
'children',
|
|
14
|
-
...eslintStyleObjects,
|
|
15
|
-
'device',
|
|
16
|
-
'is',
|
|
17
|
-
'unknown',
|
|
18
|
-
'callback',
|
|
19
|
-
],
|
|
20
|
-
customGroups: {
|
|
21
|
-
id: 'id',
|
|
22
|
-
children: 'children',
|
|
23
|
-
isMobile: 'isMobile*',
|
|
24
|
-
isTablet: 'isTablet*',
|
|
25
|
-
isDesktop: 'isDesktop*',
|
|
26
|
-
...eslintStyleObjectsCustomGroups,
|
|
27
|
-
device: 'device',
|
|
28
|
-
is: 'is*',
|
|
29
|
-
callback: 'on*',
|
|
30
|
-
},
|
|
32
|
+
groups: groups,
|
|
33
|
+
customGroups: generateCustomGroups(groups, customRulesForGroups),
|
|
31
34
|
},
|
|
32
35
|
]
|
|
33
36
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const generateCustomGroups = (groups, customRulesForGroups = {}) => {
|
|
2
|
+
const defaultRulesForGroups = groups.reduce((acc, group) => {
|
|
3
|
+
acc[group] = group
|
|
4
|
+
return acc
|
|
5
|
+
}, {})
|
|
6
|
+
|
|
7
|
+
return {
|
|
8
|
+
...defaultRulesForGroups,
|
|
9
|
+
...customRulesForGroups,
|
|
10
|
+
}
|
|
11
|
+
}
|