@vitus-labs/tools-lint 0.46.0 → 1.0.1-alpha.1

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.
@@ -1,305 +1,306 @@
1
- import { merge, omit, filter, isEmpty } from 'lodash';
1
+ import { merge, omit, filter, isEmpty } from 'lodash-es';
2
2
 
3
- const loadTsProjects = (projects) => projects.map((item) => `${item}/**/*/tsconfig.json`);
4
- const loadPlugins = (options) => {
5
- const RESULT = ['@typescript-eslint'];
6
- if (options.import)
7
- RESULT.push('import');
8
- if (options.react)
9
- RESULT.push('react');
10
- if (options.a11y)
11
- RESULT.push('jsx-a11y');
12
- if (options.graphql)
13
- RESULT.push('graphql');
14
- if (options.markdown)
15
- RESULT.push('markdown');
16
- if (options.jest)
17
- RESULT.push('jest');
18
- if (options.prettier)
19
- RESULT.push('prettier');
20
- return RESULT;
21
- };
22
- const loadExtendsConfigs = (options) => {
23
- const RESULT = ['eslint:recommended'];
24
- if (options.import)
25
- RESULT.push('plugin:import/recommended', 'plugin:import/typescript');
26
- RESULT.push('plugin:@typescript-eslint/eslint-recommended', 'plugin:@typescript-eslint/recommended', 'airbnb');
27
- if (options.react)
28
- RESULT.push('plugin:react/recommended', 'plugin:react-hooks/recommended');
29
- if (options.a11y)
30
- RESULT.push('plugin:jsx-a11y/recommended');
31
- if (options.prettier)
32
- RESULT.push('plugin:prettier/recommended', 'prettier');
33
- if (options.jest)
34
- RESULT.push('plugin:jest/all');
35
- return RESULT;
36
- };
3
+ const loadTsProjects = (projects) => projects.map((item) => `${item}/**/*/tsconfig.json`);
4
+ const loadPlugins = (options) => {
5
+ const RESULT = ['@typescript-eslint'];
6
+ if (options.import)
7
+ RESULT.push('import');
8
+ if (options.react)
9
+ RESULT.push('react');
10
+ if (options.a11y)
11
+ RESULT.push('jsx-a11y');
12
+ if (options.graphql)
13
+ RESULT.push('graphql');
14
+ if (options.markdown)
15
+ RESULT.push('markdown');
16
+ if (options.jest)
17
+ RESULT.push('jest');
18
+ if (options.prettier)
19
+ RESULT.push('prettier');
20
+ return RESULT;
21
+ };
22
+ const loadExtendsConfigs = (options) => {
23
+ const RESULT = ['eslint:recommended'];
24
+ if (options.import)
25
+ RESULT.push('plugin:import/recommended', 'plugin:import/typescript');
26
+ RESULT.push('plugin:@typescript-eslint/recommended-type-checked', 'plugin:@typescript-eslint/stylistic-type-checked', 'airbnb');
27
+ if (options.react)
28
+ RESULT.push('plugin:react/recommended', 'plugin:react-hooks/recommended');
29
+ if (options.a11y)
30
+ RESULT.push('plugin:jsx-a11y/recommended');
31
+ if (options.prettier)
32
+ RESULT.push('plugin:prettier/recommended', 'prettier');
33
+ if (options.jest)
34
+ RESULT.push('plugin:jest/all');
35
+ return RESULT;
36
+ };
37
37
  const extendObject = (condition, object = {}) => (condition ? object : {});
38
38
 
39
- const createEslint = (options) => ({ rootPath = './', projects = ['packages', 'apps', 'tools', 'features'], extensions = [], graphqlClient = undefined, scope, config, } = {}) => {
40
- const defaultOptions = {
41
- react: true,
42
- typescript: true,
43
- import: true,
44
- a11y: true,
45
- prettier: true,
46
- markdown: true,
47
- graphql: false,
48
- jest: false,
49
- };
50
- const finalOptions = merge(defaultOptions, options);
51
- const optionsConfig = omit(finalOptions, 'jest');
52
- const extensionsConfig = [
53
- '.js',
54
- '.jsx',
55
- '.ts',
56
- '.tsx',
57
- '.d.ts',
58
- ...extensions,
59
- ];
60
- const tsProjects = loadTsProjects(projects);
61
- const pluginsConfig = loadPlugins(optionsConfig);
62
- const extendsConfig = loadExtendsConfigs(optionsConfig);
63
- const OVERRIDES = [
64
- // --------------------------------------------------
65
- // SCRIPTS
66
- // --------------------------------------------------
67
- {
68
- files: ['**/bin/*.js'],
69
- rules: {
70
- '@typescript-eslint/no-var-requires': 'off',
71
- 'no-console': 'off',
72
- ...extendObject(finalOptions.import, {
73
- 'import/no-extraneous-dependencies': [
74
- 'error',
75
- {
76
- peerDependencies: true,
77
- },
78
- ],
79
- }),
80
- },
81
- },
82
- // --------------------------------------------------
83
- // STORIES of STORYBOOK
84
- // --------------------------------------------------
85
- {
86
- files: [
87
- '**/__stories__/**',
88
- '*.stories.*',
89
- '*stories.*',
90
- '*.storyOf.*',
91
- ],
92
- rules: {
93
- '@typescript-eslint/explicit-module-boundary-types': 'off',
94
- 'no-console': 'off',
95
- ...extendObject(finalOptions.import, {
96
- 'import/no-extraneous-dependencies': [
97
- 'error',
98
- {
99
- devDependencies: true,
100
- optionalDependencies: true,
101
- peerDependencies: true,
102
- },
103
- ],
104
- }),
105
- },
106
- },
107
- // --------------------------------------------------
108
- // MARKDOWN
109
- // --------------------------------------------------
110
- extendObject(finalOptions.markdown, {
111
- files: ['**/*.md', '**/*.mdx'],
112
- processor: 'markdown/markdown',
113
- }),
114
- // --------------------------------------------------
115
- // CONFIGURATION FILES
116
- // --------------------------------------------------
117
- {
118
- files: [
119
- '.eslintrc.js',
120
- '*.eslintrc.js',
121
- '*.eslintrc.*.js',
122
- '*.config.js',
123
- '.babelrc.js',
124
- ],
125
- rules: {
126
- '@typescript-eslint/no-var-requires': 'off',
127
- ...extendObject(finalOptions.import, {
128
- 'import/no-extraneous-dependencies': [
129
- 'error',
130
- {
131
- devDependencies: true,
132
- optionalDependencies: true,
133
- peerDependencies: true,
134
- },
135
- ],
136
- }),
137
- },
138
- },
139
- // --------------------------------------------------
140
- // TESTS
141
- // --------------------------------------------------
142
- extendObject(finalOptions.jest, {
143
- files: ['**/__tests__/**', '**/__specs__/**', '*.spec.*', '*.test.*'],
144
- plugins: loadPlugins(optionsConfig),
145
- env: {
146
- 'jest/globals': true,
147
- },
148
- extends: loadExtendsConfigs(optionsConfig),
149
- settings: {
150
- jest: {
151
- version: 27,
152
- },
153
- },
154
- rules: {
155
- '@typescript-eslint/explicit-module-boundary-types': 'off',
156
- 'no-console': 'off',
157
- ...extendObject(finalOptions.import, {
158
- 'import/no-extraneous-dependencies': [
159
- 'error',
160
- {
161
- devDependencies: true,
162
- optionalDependencies: true,
163
- peerDependencies: true,
164
- },
165
- ],
166
- }),
167
- },
168
- }),
169
- ];
170
- const CONFIG = {
171
- root: true,
172
- env: {
173
- browser: true,
174
- node: true,
175
- es2022: true,
176
- },
177
- globals: {
178
- __NODE__: true,
179
- __WEB__: true,
180
- __BROWSER__: true,
181
- __NATIVE__: true,
182
- __CLIENT__: true,
183
- },
184
- parser: '@typescript-eslint/parser',
185
- plugins: pluginsConfig,
186
- parserOptions: {
187
- tsconfigRootDir: rootPath,
188
- project: ['tsconfig.json', ...tsProjects],
189
- ecmaFeatures: {
190
- jsx: true,
191
- },
192
- ecmaVersion: 'latest',
193
- sourceType: 'module',
194
- },
195
- extends: extendsConfig,
196
- settings: {
197
- ...extendObject(finalOptions.import, {
198
- 'import/extensions': extensionsConfig,
199
- 'import/parsers': {
200
- '@typescript-eslint/parser': ['.ts', '.tsx'],
201
- },
202
- 'import/resolver': {
203
- node: {
204
- extensions: extensionsConfig,
205
- },
206
- ...extendObject(finalOptions.typescript, {
207
- typescript: {
208
- alwaysTryTypes: true,
209
- project: [...tsProjects, 'tsconfig.json'],
210
- },
211
- }),
212
- },
213
- ...extendObject(!!scope, { 'import/internal-regex': scope }),
214
- }),
215
- },
216
- rules: {
217
- 'no-unused-vars': 'off',
218
- 'no-useless-constructor': 'off',
219
- 'no-shadow': 'off',
220
- 'no-use-before-define': 'off',
221
- 'no-param-reassign': [
222
- 'error',
223
- { props: true, ignorePropertyModificationsFor: ['self'] },
224
- ],
225
- ...extendObject(finalOptions.typescript, {
226
- '@typescript-eslint/no-explicit-any': 'off',
227
- '@typescript-eslint/no-useless-constructor': 'error',
228
- '@typescript-eslint/explicit-function-return-type': 'off',
229
- '@typescript-eslint/no-unused-vars': 'error',
230
- '@typescript-eslint/member-delimiter-style': [
231
- 2,
232
- {
233
- multiline: {
234
- delimiter: 'none',
235
- requireLast: false,
236
- },
237
- singleline: {
238
- delimiter: 'semi',
239
- requireLast: false,
240
- },
241
- },
242
- ],
243
- }),
244
- // --------------------------------------------------
245
- // IMPORT rules
246
- // --------------------------------------------------
247
- ...extendObject(finalOptions.import, {
248
- 'import/extensions': [
249
- 'error',
250
- 'ignorePackages',
251
- {
252
- js: 'never',
253
- jsx: 'never',
254
- ts: 'never',
255
- tsx: 'never',
256
- },
257
- ],
258
- }),
259
- // --------------------------------------------------
260
- // REACT rules
261
- // --------------------------------------------------
262
- ...extendObject(finalOptions.react, {
263
- 'react/require-default-props': 'off',
264
- 'react/prop-types': 'off',
265
- 'react/jsx-props-no-spreading': 'off',
266
- 'react/function-component-definition': 'off',
267
- 'react/jsx-filename-extension': [1, { extensions: extensionsConfig }],
268
- }),
269
- // --------------------------------------------------
270
- // GRAPHQL rules
271
- // --------------------------------------------------
272
- ...extendObject(finalOptions.graphql, {
273
- 'graphql/template-strings': [
274
- 'error',
275
- {
276
- // Import default settings for your GraphQL client. Supported values:
277
- // 'apollo', 'relay', 'lokka', 'fraql', 'literal'
278
- env: graphqlClient || 'literal',
279
- // no need to specify schema here, it will be automatically determined using .graphqlconfig
280
- },
281
- ],
282
- }),
283
- // --------------------------------------------------
284
- // PRETTIER rules
285
- // --------------------------------------------------
286
- ...extendObject(finalOptions.prettier, {
287
- 'prettier/prettier': 'error',
288
- }),
289
- },
290
- overrides: filter(OVERRIDES, (item) => !isEmpty(item)),
291
- };
292
- return merge(CONFIG, config);
293
- };
39
+ const createEslint = (options) => ({ rootPath = './', projects = ['packages', 'apps', 'tools', 'features'], extensions = [], graphqlClient = undefined, scope, config, } = {}) => {
40
+ const defaultOptions = {
41
+ react: true,
42
+ typescript: true,
43
+ import: true,
44
+ a11y: true,
45
+ prettier: true,
46
+ markdown: true,
47
+ graphql: false,
48
+ jest: false,
49
+ };
50
+ const finalOptions = merge(defaultOptions, options);
51
+ const optionsConfig = omit(finalOptions, 'jest');
52
+ const extensionsConfig = [
53
+ '.js',
54
+ '.jsx',
55
+ '.ts',
56
+ '.tsx',
57
+ '.d.ts',
58
+ ...extensions,
59
+ ];
60
+ const tsProjects = loadTsProjects(projects);
61
+ const pluginsConfig = loadPlugins(optionsConfig);
62
+ const extendsConfig = loadExtendsConfigs(optionsConfig);
63
+ const OVERRIDES = [
64
+ // --------------------------------------------------
65
+ // SCRIPTS
66
+ // --------------------------------------------------
67
+ {
68
+ files: ['**/bin/*.js'],
69
+ rules: {
70
+ '@typescript-eslint/no-var-requires': 'off',
71
+ 'no-console': 'off',
72
+ ...extendObject(finalOptions.import, {
73
+ 'import/no-extraneous-dependencies': [
74
+ 'error',
75
+ {
76
+ peerDependencies: true,
77
+ },
78
+ ],
79
+ }),
80
+ },
81
+ },
82
+ // --------------------------------------------------
83
+ // STORIES of STORYBOOK
84
+ // --------------------------------------------------
85
+ {
86
+ files: [
87
+ '**/__stories__/**',
88
+ '*.stories.*',
89
+ '*stories.*',
90
+ '*.storyOf.*',
91
+ ],
92
+ rules: {
93
+ '@typescript-eslint/explicit-module-boundary-types': 'off',
94
+ 'no-console': 'off',
95
+ ...extendObject(finalOptions.import, {
96
+ 'import/no-extraneous-dependencies': [
97
+ 'error',
98
+ {
99
+ devDependencies: true,
100
+ optionalDependencies: true,
101
+ peerDependencies: true,
102
+ },
103
+ ],
104
+ }),
105
+ },
106
+ },
107
+ // --------------------------------------------------
108
+ // MARKDOWN
109
+ // --------------------------------------------------
110
+ extendObject(finalOptions.markdown, {
111
+ files: ['**/*.md', '**/*.mdx'],
112
+ processor: 'markdown/markdown',
113
+ }),
114
+ // --------------------------------------------------
115
+ // CONFIGURATION FILES
116
+ // --------------------------------------------------
117
+ {
118
+ files: [
119
+ '.eslintrc.js',
120
+ '*.eslintrc.js',
121
+ '*.eslintrc.*.js',
122
+ '*.config.js',
123
+ '.babelrc.js',
124
+ ],
125
+ rules: {
126
+ '@typescript-eslint/no-var-requires': 'off',
127
+ ...extendObject(finalOptions.import, {
128
+ 'import/no-extraneous-dependencies': [
129
+ 'error',
130
+ {
131
+ devDependencies: true,
132
+ optionalDependencies: true,
133
+ peerDependencies: true,
134
+ },
135
+ ],
136
+ }),
137
+ },
138
+ },
139
+ // --------------------------------------------------
140
+ // TESTS
141
+ // --------------------------------------------------
142
+ extendObject(finalOptions.jest, {
143
+ files: ['**/__tests__/**', '**/__specs__/**', '*.spec.*', '*.test.*'],
144
+ plugins: loadPlugins(optionsConfig),
145
+ env: {
146
+ 'jest/globals': true,
147
+ },
148
+ extends: loadExtendsConfigs(optionsConfig),
149
+ settings: {
150
+ jest: {
151
+ version: 27,
152
+ },
153
+ },
154
+ rules: {
155
+ '@typescript-eslint/explicit-module-boundary-types': 'off',
156
+ 'no-console': 'off',
157
+ ...extendObject(finalOptions.import, {
158
+ 'import/no-extraneous-dependencies': [
159
+ 'error',
160
+ {
161
+ devDependencies: true,
162
+ optionalDependencies: true,
163
+ peerDependencies: true,
164
+ },
165
+ ],
166
+ }),
167
+ },
168
+ }),
169
+ ];
170
+ const CONFIG = {
171
+ root: true,
172
+ env: {
173
+ browser: true,
174
+ node: true,
175
+ es2022: true,
176
+ },
177
+ globals: {
178
+ false: true,
179
+ true: true,
180
+ false: true,
181
+ false: true,
182
+ false: true,
183
+ },
184
+ parser: '@typescript-eslint/parser',
185
+ plugins: pluginsConfig,
186
+ parserOptions: {
187
+ tsconfigRootDir: rootPath,
188
+ project: true,
189
+ ecmaFeatures: {
190
+ jsx: true,
191
+ },
192
+ ecmaVersion: 'latest',
193
+ sourceType: 'module',
194
+ },
195
+ extends: extendsConfig,
196
+ settings: {
197
+ ...extendObject(finalOptions.import, {
198
+ 'import/extensions': extensionsConfig,
199
+ 'import/parsers': {
200
+ '@typescript-eslint/parser': ['.ts', '.tsx'],
201
+ },
202
+ 'import/resolver': {
203
+ node: {
204
+ extensions: extensionsConfig,
205
+ },
206
+ ...extendObject(finalOptions.typescript, {
207
+ typescript: {
208
+ alwaysTryTypes: true,
209
+ project: [...tsProjects, 'tsconfig.json'],
210
+ },
211
+ }),
212
+ },
213
+ ...extendObject(!!scope, { 'import/internal-regex': scope }),
214
+ }),
215
+ },
216
+ rules: {
217
+ 'no-unused-vars': 'off',
218
+ 'no-useless-constructor': 'off',
219
+ 'no-shadow': 'off',
220
+ 'no-use-before-define': 'off',
221
+ 'no-param-reassign': [
222
+ 'error',
223
+ { props: true, ignorePropertyModificationsFor: ['self'] },
224
+ ],
225
+ ...extendObject(finalOptions.typescript, {
226
+ '@typescript-eslint/no-explicit-any': 'off',
227
+ '@typescript-eslint/no-useless-constructor': 'error',
228
+ '@typescript-eslint/explicit-function-return-type': 'off',
229
+ '@typescript-eslint/no-unused-vars': 'error',
230
+ '@typescript-eslint/member-delimiter-style': [
231
+ 2,
232
+ {
233
+ multiline: {
234
+ delimiter: 'none',
235
+ requireLast: false,
236
+ },
237
+ singleline: {
238
+ delimiter: 'semi',
239
+ requireLast: false,
240
+ },
241
+ },
242
+ ],
243
+ }),
244
+ // --------------------------------------------------
245
+ // IMPORT rules
246
+ // --------------------------------------------------
247
+ ...extendObject(finalOptions.import, {
248
+ 'import/prefer-default-export': 'off',
249
+ 'import/extensions': [
250
+ 'error',
251
+ 'ignorePackages',
252
+ {
253
+ js: 'never',
254
+ jsx: 'never',
255
+ ts: 'never',
256
+ tsx: 'never',
257
+ },
258
+ ],
259
+ }),
260
+ // --------------------------------------------------
261
+ // REACT rules
262
+ // --------------------------------------------------
263
+ ...extendObject(finalOptions.react, {
264
+ 'react/require-default-props': 'off',
265
+ 'react/prop-types': 'off',
266
+ 'react/jsx-props-no-spreading': 'off',
267
+ 'react/function-component-definition': 'off',
268
+ 'react/jsx-filename-extension': [1, { extensions: extensionsConfig }],
269
+ }),
270
+ // --------------------------------------------------
271
+ // GRAPHQL rules
272
+ // --------------------------------------------------
273
+ ...extendObject(finalOptions.graphql, {
274
+ 'graphql/template-strings': [
275
+ 'error',
276
+ {
277
+ // Import default settings for your GraphQL client. Supported values:
278
+ // 'apollo', 'relay', 'lokka', 'fraql', 'literal'
279
+ env: graphqlClient || 'literal',
280
+ // no need to specify schema here, it will be automatically determined using .graphqlconfig
281
+ },
282
+ ],
283
+ }),
284
+ // --------------------------------------------------
285
+ // PRETTIER rules
286
+ // --------------------------------------------------
287
+ ...extendObject(finalOptions.prettier, {
288
+ 'prettier/prettier': 'error',
289
+ }),
290
+ },
291
+ overrides: filter(OVERRIDES, (item) => !isEmpty(item)),
292
+ };
293
+ return merge(CONFIG, config);
294
+ };
294
295
  var index = createEslint()();
295
296
 
296
- var styles = {
297
- processors: ['stylelint-processor-styled-components'],
298
- extends: [
299
- 'stylelint-config-recommended',
300
- 'stylelint-config-styled-components',
301
- 'stylelint-config-prettier',
302
- ],
297
+ var styles = {
298
+ processors: ['stylelint-processor-styled-components'],
299
+ extends: [
300
+ 'stylelint-config-recommended',
301
+ 'stylelint-config-styled-components',
302
+ 'stylelint-config-prettier',
303
+ ],
303
304
  };
304
305
 
305
306
  export { createEslint, index as eslint, styles };