@itcase/lint 1.0.22 → 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.
@@ -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
- ## ESLint
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
- ## ESLint with MobX
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
- ## Stylelint
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
- ## Prettier
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
- ## git-hook
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
- const eslintStyleObjectsCustomGroups = {}
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
- const eslintStylePropsCustomGroups = {}
65
- eslintStyleProps.forEach((key) => (eslintStylePropsCustomGroups[key] = key))
66
-
67
- export { eslintStyleProps, eslintStylePropsCustomGroups }
65
+ export { eslintStyleProps }
package/eslint/index.js CHANGED
@@ -8,12 +8,22 @@ import eslintReact from 'eslint-plugin-react'
8
8
  import eslintReactHooks from 'eslint-plugin-react-hooks'
9
9
  import eslintTypeScript from 'typescript-eslint'
10
10
 
11
- import { eslintStyleObjects, eslintStyleObjectsCustomGroups } from './eslint.styleObjects.js'
12
- import { eslintStyleProps, eslintStylePropsCustomGroups } from './eslint.styleProps.js'
11
+ import {
12
+ sortClasses,
13
+ sortEnums,
14
+ sortInterfaces,
15
+ sortIntersectionTypes,
16
+ sortJSXProps,
17
+ sortMaps,
18
+ sortObjects,
19
+ sortObjectTypes,
20
+ sortUnionTypes,
21
+ } from './perfectionist/index.js'
13
22
 
14
23
  const eslintConfig = [
15
24
  eslintJs.configs.recommended,
16
25
  ...eslintTypeScript.configs.recommended,
26
+ ...eslintMarkdown.configs.recommended,
17
27
  eslintPluginPrettierRecommended,
18
28
 
19
29
  {
@@ -27,10 +37,12 @@ const eslintConfig = [
27
37
  {
28
38
  ignores: ['dist', 'node_modules', 'eslint.config.mjs'],
29
39
  },
40
+
30
41
  {
31
42
  files: ['**/*.json'],
32
43
  ...eslintJson.configs['recommended'],
33
44
  },
45
+
34
46
  {
35
47
  files: ['**/*.{js,jsx,mjs,cjs,ts,tsx}'],
36
48
  rules: {
@@ -42,7 +54,7 @@ const eslintConfig = [
42
54
  '@typescript-eslint/no-explicit-any': 'off',
43
55
  // Sometimes you need an empty one, for example when extends
44
56
  '@typescript-eslint/no-empty-object-type': 'off',
45
- "@typescript-eslint/no-unused-expressions": 'off',
57
+ '@typescript-eslint/no-unused-expressions': 'off',
46
58
 
47
59
  // react
48
60
  // TODO: make rule "react/prop-types" as error only for JS(x) files
@@ -59,154 +71,25 @@ const eslintConfig = [
59
71
  'object-shorthand': ['warn', 'consistent'],
60
72
 
61
73
  // Class
62
- 'perfectionist/sort-classes': [
63
- 'error',
64
- {
65
- type: 'natural',
66
- order: 'asc',
67
- groups: [
68
- 'top',
69
- 'index-signature',
70
- 'static-property',
71
- 'private-property',
72
- 'property',
73
- 'constructor',
74
- 'static-method',
75
- 'private-method',
76
- 'get-method',
77
- 'set-method',
78
- 'method',
79
- ],
80
- customGroups: [
81
- {
82
- groupName: 'top',
83
- elementNamePattern: 'id',
84
- },
85
- ],
86
- },
87
- ],
88
-
89
- // Objects
90
- 'perfectionist/sort-objects': [
91
- 'error',
92
- {
93
- type: 'natural',
94
- order: 'asc',
95
- groups: [
96
- 'isMobile',
97
- 'isTablet',
98
- 'isDesktop',
99
- 'id',
100
- 'children',
101
- ...eslintStyleObjects,
102
- 'device',
103
- 'is',
104
- 'unknown',
105
- 'callback',
106
- ],
107
- customGroups: {
108
- id: 'id',
109
- children: 'children',
110
- isMobile: 'isMobile*',
111
- isTablet: 'isTablet*',
112
- isDesktop: 'isDesktop*',
113
- ...eslintStyleObjectsCustomGroups,
114
- device: 'device',
115
- is: 'is*',
116
- callback: 'on*',
117
- },
118
- },
119
- ],
120
-
121
- // Props
122
- 'perfectionist/sort-jsx-props': [
123
- 'error',
124
- {
125
- type: 'natural',
126
- order: 'asc',
127
- groups: [
128
- 'className',
129
- 'key',
130
- 'ref',
131
- 'name',
132
- ...eslintStyleProps,
133
- 'shorthand',
134
- 'unknown',
135
- 'multiline',
136
- 'is',
137
- 'set',
138
- 'callback',
139
- ],
140
- customGroups: {
141
- className: 'className',
142
- key: 'key',
143
- ref: 'ref',
144
- name: 'name',
145
- ...eslintStylePropsCustomGroups,
146
- is: 'is*',
147
- callback: 'on*',
148
- set: ['set*'],
149
- },
150
- },
151
- ],
152
-
153
- // Types
154
- 'perfectionist/sort-object-types': [
155
- 'error',
156
- {
157
- type: 'natural',
158
- order: 'asc',
159
- groups: ['top'],
160
- customGroups: { top: 'id' },
161
- },
162
- ],
163
-
74
+ 'perfectionist/sort-classes': sortClasses,
75
+ // Enum
76
+ 'perfectionist/sort-enums': sortEnums,
164
77
  // Interfaces
165
- 'perfectionist/sort-interfaces': [
166
- 'error',
167
- {
168
- type: 'natural',
169
- order: 'asc',
170
- groups: ['top', 'unknown', 'is', 'callback', 'set'],
171
- customGroups: {
172
- top: ['id', 'Id'],
173
- is: 'is*',
174
- callback: 'on*',
175
- set: ['set*'],
176
- },
177
- },
178
- ],
179
-
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,
85
+ // Objects
86
+ 'perfectionist/sort-objects': sortObjects,
87
+ // Objects-types
88
+ 'perfectionist/sort-object-types': sortObjectTypes,
180
89
  // Union types
181
- 'perfectionist/sort-union-types': [
182
- 'error',
183
- {
184
- type: 'natural',
185
- order: 'asc',
186
- groups: [
187
- 'conditional',
188
- 'function',
189
- 'import',
190
- 'keyword',
191
- 'literal',
192
- 'named',
193
- 'object',
194
- 'operator',
195
- 'tuple',
196
- 'union',
197
- 'nullish',
198
- 'unknown',
199
- ],
200
- },
201
- ],
202
-
203
- // Maps, Enum, Intersection types
204
- 'perfectionist/sort-maps': ['error', { type: 'natural', order: 'asc' }],
205
- 'perfectionist/sort-enums': ['error', { type: 'natural', order: 'asc' }],
206
- 'perfectionist/sort-intersection-types': ['error', { type: 'natural', order: 'asc' }],
90
+ 'perfectionist/sort-union-types': sortUnionTypes,
207
91
  },
208
92
  },
209
- ...eslintMarkdown.configs.recommended,
210
93
  ]
211
94
 
212
95
  export default eslintConfig
@@ -0,0 +1,9 @@
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'
@@ -0,0 +1,28 @@
1
+ const sortClasses = [
2
+ 'error',
3
+ {
4
+ type: 'natural',
5
+ order: 'asc',
6
+ groups: [
7
+ 'top',
8
+ 'index-signature',
9
+ 'static-property',
10
+ 'private-property',
11
+ 'property',
12
+ 'constructor',
13
+ 'static-method',
14
+ 'private-method',
15
+ 'get-method',
16
+ 'set-method',
17
+ 'method',
18
+ ],
19
+ customGroups: [
20
+ {
21
+ groupName: 'top',
22
+ elementNamePattern: 'id',
23
+ },
24
+ ],
25
+ },
26
+ ]
27
+
28
+ export { sortClasses }
@@ -0,0 +1,3 @@
1
+ const sortEnums = ['error', { type: 'natural', order: 'asc' }]
2
+
3
+ export { sortEnums }
@@ -0,0 +1,24 @@
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
+
14
+ const sortInterfaces = [
15
+ 'error',
16
+ {
17
+ type: 'natural',
18
+ order: 'asc',
19
+ groups: groups,
20
+ customGroups: generateCustomGroups(groups, customRulesForGroups),
21
+ },
22
+ ]
23
+
24
+ export { sortInterfaces }
@@ -0,0 +1,3 @@
1
+ const sortIntersectionTypes = ['error', { type: 'natural', order: 'asc' }]
2
+
3
+ export { sortIntersectionTypes }
@@ -0,0 +1,36 @@
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
+ }
25
+
26
+ const sortJSXProps = [
27
+ 'error',
28
+ {
29
+ type: 'natural',
30
+ order: 'asc',
31
+ groups: groups,
32
+ customGroups: generateCustomGroups(groups, customRulesForGroups),
33
+ },
34
+ ]
35
+
36
+ export { sortJSXProps }
@@ -0,0 +1,3 @@
1
+ const sortMaps = ['error', { type: 'natural', order: 'asc' }]
2
+
3
+ export { sortMaps }
@@ -0,0 +1,19 @@
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
+
9
+ const sortObjectTypes = [
10
+ 'error',
11
+ {
12
+ type: 'natural',
13
+ order: 'asc',
14
+ groups: groups,
15
+ customGroups: generateCustomGroups(groups, customRulesForGroups),
16
+ },
17
+ ]
18
+
19
+ export { sortObjectTypes }
@@ -0,0 +1,37 @@
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
+ }
26
+
27
+ const sortObjects = [
28
+ 'error',
29
+ {
30
+ type: 'natural',
31
+ order: 'asc',
32
+ groups: groups,
33
+ customGroups: generateCustomGroups(groups, customRulesForGroups),
34
+ },
35
+ ]
36
+
37
+ export { sortObjects }
@@ -0,0 +1,22 @@
1
+ const sortUnionTypes = [
2
+ 'error',
3
+ {
4
+ type: 'natural',
5
+ order: 'asc',
6
+ groups: [
7
+ 'conditional',
8
+ 'function',
9
+ 'import',
10
+ 'keyword',
11
+ 'literal',
12
+ 'named',
13
+ 'object',
14
+ 'operator',
15
+ 'tuple',
16
+ 'union',
17
+ 'nullish',
18
+ 'unknown',
19
+ ],
20
+ },
21
+ ]
22
+ export { sortUnionTypes }
@@ -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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itcase/lint",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "author": "ITCase",
5
5
  "description": "Code style linter configuration presets",
6
6
  "engines": {
@@ -20,7 +20,10 @@
20
20
  "files": [
21
21
  "eslint",
22
22
  "eslint/mobx",
23
+ "perfectionist",
23
24
  "prettier",
25
+ "react-native",
26
+ "storybook",
24
27
  "stylelint",
25
28
  "README.md"
26
29
  ],