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

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