@itcase/lint 1.1.74 → 1.1.78

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.
Files changed (61) hide show
  1. package/dist/eslint/customPlugins/dataTestIdPlugin/constants.d.ts +33 -0
  2. package/dist/eslint/customPlugins/dataTestIdPlugin/example.d.ts +1 -0
  3. package/dist/eslint/customPlugins/dataTestIdPlugin/extra.d.ts +12 -0
  4. package/dist/eslint/customPlugins/dataTestIdPlugin/plugin.d.ts +40 -0
  5. package/dist/eslint/customPlugins/dataTestIdPlugin/rule.d.ts +5 -0
  6. package/dist/eslint/customPlugins/dataTestIdPlugin/rule.test.d.ts +1 -0
  7. package/dist/eslint/customPlugins/dataTestIdPlugin/ruleVisitors.d.ts +3 -0
  8. package/dist/eslint/customPlugins/dataTestIdPlugin/utils.d.ts +18 -0
  9. package/dist/eslint/index.d.ts +2 -0
  10. package/dist/eslint/mobx/index.d.ts +16 -0
  11. package/dist/eslint/mobx.js +20 -0
  12. package/dist/eslint/perfectionist/index.d.ts +11 -0
  13. package/dist/eslint/perfectionist/sort/customGroup.d.ts +105 -0
  14. package/dist/eslint/perfectionist/sort/props.d.ts +2 -0
  15. package/dist/eslint/perfectionist/sortClasses.d.ts +10 -0
  16. package/dist/eslint/perfectionist/sortEnums.d.ts +5 -0
  17. package/dist/eslint/perfectionist/sortExports.d.ts +15 -0
  18. package/dist/eslint/perfectionist/sortInterfaces.d.ts +10 -0
  19. package/dist/eslint/perfectionist/sortIntersectionTypes.d.ts +5 -0
  20. package/dist/eslint/perfectionist/sortJSXProps.d.ts +10 -0
  21. package/dist/eslint/perfectionist/sortMaps.d.ts +5 -0
  22. package/dist/eslint/perfectionist/sortNamedExports.d.ts +16 -0
  23. package/dist/eslint/perfectionist/sortObjectTypes.d.ts +10 -0
  24. package/dist/eslint/perfectionist/sortObjects.d.ts +23 -0
  25. package/dist/eslint/perfectionist/sortUnionTypes.d.ts +6 -0
  26. package/dist/eslint/perfectionist.js +30 -0
  27. package/dist/eslint/react-native.js +22 -0
  28. package/dist/eslint/storybook/index.d.ts +408 -0
  29. package/dist/eslint/storybook.js +10 -0
  30. package/dist/eslint/utils.d.ts +3 -0
  31. package/dist/eslint.js +342 -0
  32. package/dist/prettier/index.d.ts +15 -0
  33. package/dist/prettier/react-native/index.d.ts +9 -0
  34. package/dist/prettier/react-native.js +68 -0
  35. package/dist/prettier.js +34 -0
  36. package/dist/sortUnionTypes_rTLrktP3.js +619 -0
  37. package/dist/stylelint/index.d.ts +85 -0
  38. package/dist/stylelint.js +249 -0
  39. package/package.json +44 -18
  40. package/eslint/index.js +0 -108
  41. package/eslint/mobx/index.js +0 -18
  42. package/eslint/perfectionist/index.js +0 -11
  43. package/eslint/perfectionist/sort/customGroup.js +0 -118
  44. package/eslint/perfectionist/sort/props.js +0 -355
  45. package/eslint/perfectionist/sortClasses.js +0 -28
  46. package/eslint/perfectionist/sortEnums.js +0 -3
  47. package/eslint/perfectionist/sortExports.js +0 -17
  48. package/eslint/perfectionist/sortInterfaces.js +0 -38
  49. package/eslint/perfectionist/sortIntersectionTypes.js +0 -3
  50. package/eslint/perfectionist/sortJSXProps.js +0 -30
  51. package/eslint/perfectionist/sortMaps.js +0 -3
  52. package/eslint/perfectionist/sortNamedExports.js +0 -18
  53. package/eslint/perfectionist/sortObjectTypes.js +0 -32
  54. package/eslint/perfectionist/sortObjects.js +0 -44
  55. package/eslint/perfectionist/sortUnionTypes.js +0 -22
  56. package/eslint/react-native/index.js +0 -20
  57. package/eslint/storybook/index.js +0 -8
  58. package/eslint/utils.js +0 -25
  59. package/prettier/index.js +0 -32
  60. package/prettier/react-native/index.js +0 -66
  61. package/stylelint/index.js +0 -248
package/dist/eslint.js ADDED
@@ -0,0 +1,342 @@
1
+ import { fixupPluginRules } from '@eslint/compat';
2
+ import eslintJs from '@eslint/js';
3
+ import eslintMarkdown from '@eslint/markdown';
4
+ import eslintHtml from 'eslint-plugin-html';
5
+ import eslintImport from 'eslint-plugin-import';
6
+ import eslintJson from 'eslint-plugin-json';
7
+ import eslintPerfectionist from 'eslint-plugin-perfectionist';
8
+ import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
9
+ import eslintReact from 'eslint-plugin-react';
10
+ import eslintReactHooks from 'eslint-plugin-react-hooks';
11
+ import globals from 'globals';
12
+ import eslintTypeScript from 'typescript-eslint';
13
+ import parser from '@typescript-eslint/parser';
14
+ import { ESLintUtils, AST_NODE_TYPES } from '@typescript-eslint/utils';
15
+ import { s as sortUnionTypes, a as sortObjectTypes, b as sortObjects, c as sortExports, d as sortNamedExports, e as sortMaps, f as sortJSXProps, g as sortIntersectionTypes, h as sortInterfaces, i as sortEnums } from './sortUnionTypes_rTLrktP3.js';
16
+
17
+ const createRule = ESLintUtils.RuleCreator(() => {
18
+ return ``;
19
+ });
20
+ const ruleName = 'data-test-id';
21
+ const pluginName = 'eslint-data-test-id-plugin';
22
+ const defaultOptions = [];
23
+
24
+ const MESSAGE_IDS = {
25
+ missingAttribute: 'missingAttribute',
26
+ missingAttributeValue: 'missingAttributeValue',
27
+ };
28
+ const MESSAGES = {
29
+ [MESSAGE_IDS.missingAttribute]: 'JSX element is missing the required "{{propName}}" attribute.',
30
+ [MESSAGE_IDS.missingAttributeValue]: 'JSX element has a "{{propName}}" attribute with a missing value.',
31
+ };
32
+ const ASSERT_DEFAULT_MESSAGE = 'Assert violation';
33
+ /**
34
+ * Property name to check for in JSX elements.
35
+ */
36
+ const PROP_TO_CHECK_BY_COMPONENT_TYPE = {
37
+ CUSTOM: {
38
+ name: 'dataTestId'},
39
+ HTML: {
40
+ name: 'data-test-id'},
41
+ };
42
+ /**
43
+ * Custom element names to which the rule should apply.
44
+ * If the array is empty, the rule applies to all JSX elements.
45
+ */
46
+ const ELEMENT_NAMES_TO_CHECK = [
47
+ 'Group',
48
+ 'Modal',
49
+ 'Drawer',
50
+ 'ModalSheetBottom',
51
+ 'Grid',
52
+ 'Flex',
53
+ ];
54
+ /**
55
+ * Custom element names to ignore by the rule.
56
+ */
57
+ const ELEMENT_NAMES_TO_IGNORE = [
58
+ // Element to ignore for testing purposes
59
+ 'IgnoredElement',
60
+ // Html element from Next.js
61
+ 'Html',
62
+ ];
63
+
64
+ /** Throw an error if the condition is falsy */
65
+ function assert(condition) {
66
+ if (!condition) {
67
+ throw new Error(ASSERT_DEFAULT_MESSAGE);
68
+ }
69
+ }
70
+ /** Extract name from a string or Identifier node */
71
+ function extractNameFromPossibleIdentifier(nodeOrName) {
72
+ if (typeof nodeOrName === 'string') {
73
+ return nodeOrName;
74
+ }
75
+ return nodeOrName.name;
76
+ }
77
+ /** Get name items of functions and variables that wraps the given node */
78
+ const getFunctionOrVariableAncestorNameItems = (context, node) => {
79
+ const ancestorNodes = context.sourceCode.getAncestors(node);
80
+ const functionOrVariableNodes = ancestorNodes.filter((ancestor) => {
81
+ return (ancestor.type === AST_NODE_TYPES.FunctionExpression ||
82
+ ancestor.type === AST_NODE_TYPES.FunctionDeclaration ||
83
+ ancestor.type === AST_NODE_TYPES.VariableDeclaration);
84
+ });
85
+ const nullableNameItems = functionOrVariableNodes.map((node) => {
86
+ if (node.type === AST_NODE_TYPES.FunctionDeclaration ||
87
+ node.type === AST_NODE_TYPES.FunctionExpression) {
88
+ if (node.id !== null) {
89
+ return {
90
+ name: node.id.name,
91
+ kind: 'function',
92
+ };
93
+ }
94
+ }
95
+ if (node.type === AST_NODE_TYPES.VariableDeclaration) {
96
+ const firstDeclaration = node.declarations[0];
97
+ if (firstDeclaration.id.type === AST_NODE_TYPES.Identifier) {
98
+ return {
99
+ name: firstDeclaration.id.name,
100
+ kind: 'variable',
101
+ };
102
+ }
103
+ }
104
+ return null;
105
+ });
106
+ const nameItems = nullableNameItems.filter((item) => item !== null);
107
+ return nameItems;
108
+ };
109
+
110
+ const handleReturnStatement = (context, returnStatementNode) => {
111
+ // We only care about return statements that return JSX elements
112
+ assert(returnStatementNode.argument);
113
+ assert(returnStatementNode.argument.type === AST_NODE_TYPES.JSXElement);
114
+ const openingElement = returnStatementNode.argument.openingElement;
115
+ // Something is wrong if it's not a JSXIdentifier
116
+ assert(openingElement.name.type === AST_NODE_TYPES.JSXIdentifier);
117
+ const elementName = openingElement.name.name;
118
+ const isIgnoredElement = ELEMENT_NAMES_TO_IGNORE.includes(elementName);
119
+ // Ignore elements that are in the ignore list
120
+ assert(!isIgnoredElement);
121
+ const isLowerCasedName = elementName[0] === elementName[0].toLowerCase();
122
+ const isElementToCheck = ELEMENT_NAMES_TO_CHECK.includes(elementName);
123
+ const isAllElementsToCheck = ELEMENT_NAMES_TO_CHECK.length === 0;
124
+ // We only care about lowercase elements or specific Elements
125
+ assert(isLowerCasedName || isElementToCheck || isAllElementsToCheck);
126
+ // Determine which prop name we are looking for
127
+ const propNameWeLookingFor = isLowerCasedName
128
+ ? PROP_TO_CHECK_BY_COMPONENT_TYPE.HTML
129
+ : PROP_TO_CHECK_BY_COMPONENT_TYPE.CUSTOM;
130
+ // Try to find the prop we are looking for
131
+ const propNodeWeLookingFor = openingElement.attributes.find((attr) => {
132
+ // Ignore spread attributes
133
+ if (attr.type === AST_NODE_TYPES.JSXAttribute) {
134
+ const attributeName = extractNameFromPossibleIdentifier(attr.name.name);
135
+ return propNameWeLookingFor.name === attributeName;
136
+ }
137
+ });
138
+ const ancestorNameItems = getFunctionOrVariableAncestorNameItems(context, returnStatementNode);
139
+ // Get the nearest ancestor name as the component name
140
+ const parentComponentNameItem = ancestorNameItems.at(-1);
141
+ // Something is wrong if there is no component name
142
+ assert(parentComponentNameItem);
143
+ if (!propNodeWeLookingFor) {
144
+ // If we reach here - the prop is missing - report it
145
+ context.report({
146
+ messageId: MESSAGE_IDS.missingAttribute,
147
+ fix: (fixer) => {
148
+ const propName = propNameWeLookingFor.name;
149
+ const parentName = parentComponentNameItem.name;
150
+ // Insert the missing prop
151
+ if (parentComponentNameItem.kind === 'function') {
152
+ return fixer.insertTextAfter(openingElement.name, ' ' + `${propName}={${parentName}.name}`);
153
+ }
154
+ if (parentComponentNameItem.kind === 'variable') {
155
+ return fixer.insertTextAfter(openingElement.name, ' ' + `${propName}="${parentName}"`);
156
+ }
157
+ assert(false);
158
+ },
159
+ data: {
160
+ propName: propNameWeLookingFor.name,
161
+ },
162
+ node: openingElement,
163
+ });
164
+ assert(false);
165
+ }
166
+ // At this moment we only care about prop without value
167
+ assert(!propNodeWeLookingFor.value);
168
+ // If we reach here - the prop exists but has no value - report it
169
+ context.report({
170
+ messageId: MESSAGE_IDS.missingAttributeValue,
171
+ fix: (fixer) => {
172
+ const propName = propNameWeLookingFor.name;
173
+ const parentName = parentComponentNameItem.name;
174
+ // Replace incomplete prop with complete one
175
+ if (parentComponentNameItem.kind === 'function') {
176
+ return fixer.replaceText(propNodeWeLookingFor, `${propName}={${parentName}.name}`);
177
+ }
178
+ if (parentComponentNameItem.kind === 'variable') {
179
+ return fixer.replaceText(propNodeWeLookingFor, `${propName}="${parentName}"`);
180
+ }
181
+ assert(false);
182
+ },
183
+ data: {
184
+ propName: propNameWeLookingFor.name,
185
+ },
186
+ node: openingElement,
187
+ });
188
+ };
189
+ const ruleVisitors = (context) => {
190
+ return {
191
+ // Iterate over all return statements
192
+ [AST_NODE_TYPES.ReturnStatement]: (node) => {
193
+ try {
194
+ handleReturnStatement(context, node);
195
+ }
196
+ catch (error) {
197
+ // Only log errors that are not from assert checks.
198
+ // Assert errors are used for early exit.
199
+ if (error instanceof Error &&
200
+ error.message === ASSERT_DEFAULT_MESSAGE) {
201
+ // Ignore assert errors
202
+ return;
203
+ }
204
+ // Log other errors
205
+ console.log(`${pluginName} visitor error:`, error);
206
+ }
207
+ },
208
+ };
209
+ };
210
+
211
+ const ruleMeta = {
212
+ type: 'suggestion',
213
+ messages: MESSAGES,
214
+ docs: {
215
+ description: '',
216
+ },
217
+ fixable: 'code',
218
+ schema: [],
219
+ };
220
+ const rule = createRule({
221
+ name: ruleName,
222
+ create: ruleVisitors,
223
+ defaultOptions: defaultOptions,
224
+ meta: ruleMeta,
225
+ });
226
+
227
+ const plugin = {
228
+ meta: {
229
+ name: pluginName,
230
+ version: '1.0.0',
231
+ },
232
+ processors: {},
233
+ rules: {
234
+ [ruleName]: rule,
235
+ },
236
+ };
237
+ const pluginWithoutConfigs = {
238
+ ...plugin,
239
+ configs: {
240
+ recommended: {
241
+ languageOptions: {
242
+ ecmaVersion: 'latest',
243
+ parser: parser,
244
+ },
245
+ plugins: {
246
+ [pluginName]: plugin,
247
+ },
248
+ rules: {
249
+ // By default this rule is disabled, enable only for required paths
250
+ [`${pluginName}/${ruleName}`]: 'off',
251
+ },
252
+ },
253
+ },
254
+ };
255
+
256
+ /* eslint-disable perfectionist/sort-objects */
257
+ const eslintConfig = [
258
+ eslintJs.configs.recommended,
259
+ ...eslintTypeScript.configs.recommended,
260
+ //...eslintStorybook.configs['flat/recommended'],
261
+ eslintPluginPrettierRecommended,
262
+ pluginWithoutConfigs.configs.recommended,
263
+ {
264
+ languageOptions: {
265
+ globals: {
266
+ ...globals.browser,
267
+ ...globals.node,
268
+ },
269
+ },
270
+ },
271
+ {
272
+ plugins: {
273
+ react: eslintReact,
274
+ // eslint-plugin-react-hooks already supports flat config, but fixupPluginRules
275
+ // is used for compatibility. Type assertion is needed due to type incompatibility.
276
+ 'react-hooks': fixupPluginRules(eslintReactHooks),
277
+ html: eslintHtml,
278
+ import: eslintImport,
279
+ perfectionist: eslintPerfectionist,
280
+ },
281
+ },
282
+ {
283
+ ignores: ['dist', 'node_modules', 'eslint.config.mjs'],
284
+ },
285
+ {
286
+ files: ['**/*.json'],
287
+ ...eslintJson.configs['recommended'],
288
+ },
289
+ {
290
+ files: ['**/*.md', '**/*.mdx'],
291
+ ...eslintMarkdown.configs.recommended,
292
+ },
293
+ {
294
+ files: ['**/*.{js,jsx,mjs,cjs,ts,tsx}'],
295
+ rules: {
296
+ // react-hooks configs recommended rules
297
+ ...eslintReactHooks.configs.recommended.rules,
298
+ 'react/jsx-fragments': ['error', 'element'],
299
+ // @typescript-eslint
300
+ '@typescript-eslint/ban-ts-comment': 'off',
301
+ '@typescript-eslint/no-explicit-any': 'off',
302
+ '@typescript-eslint/no-unused-vars': 'warn',
303
+ // Sometimes you need an empty one, for example when extends
304
+ '@typescript-eslint/no-empty-object-type': 'off',
305
+ '@typescript-eslint/no-unused-expressions': 'off',
306
+ // react
307
+ // TODO: make rule "react/prop-types" as error only for JS(x) files
308
+ 'react/prop-types': 'off',
309
+ 'react/react-in-jsx-scope': 'off',
310
+ // react-hooks
311
+ 'react-hooks/exhaustive-deps': 'warn',
312
+ 'react-hooks/rules-of-hooks': 'error',
313
+ // disables the requirement to format ternary operators in multiline form
314
+ 'multiline-ternary': 'off',
315
+ // shorthand for methods and properties of objects
316
+ 'object-shorthand': ['warn', 'consistent'],
317
+ // import
318
+ 'import/no-default-export': 'warn',
319
+ // Perfectionist
320
+ 'perfectionist/sort-classes': 'off',
321
+ 'perfectionist/sort-enums': sortEnums,
322
+ 'perfectionist/sort-interfaces': sortInterfaces,
323
+ 'perfectionist/sort-intersection-types': sortIntersectionTypes,
324
+ 'perfectionist/sort-jsx-props': sortJSXProps,
325
+ 'perfectionist/sort-maps': sortMaps,
326
+ 'perfectionist/sort-named-exports': sortNamedExports,
327
+ 'perfectionist/sort-exports': sortExports,
328
+ 'perfectionist/sort-objects': sortObjects,
329
+ 'perfectionist/sort-object-types': sortObjectTypes,
330
+ 'perfectionist/sort-union-types': sortUnionTypes,
331
+ },
332
+ },
333
+ // Allow default exports in .page.* files
334
+ {
335
+ files: ['**/*.page.{ts,tsx,js,jsx}'],
336
+ rules: {
337
+ 'import/no-default-export': 'off',
338
+ },
339
+ },
340
+ ];
341
+
342
+ export { eslintConfig as default };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @see https://prettier.io/docs/configuration.html
3
+ * @type {import("prettier").Config}
4
+ */
5
+ declare const _default: {
6
+ arrowParens: string;
7
+ importOrder: string[];
8
+ importOrderSortSpecifiers: boolean;
9
+ plugins: string[];
10
+ printWidth: number;
11
+ semi: boolean;
12
+ singleQuote: boolean;
13
+ tabWidth: number;
14
+ };
15
+ export default _default;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @see https://prettier.io/docs/configuration.html
3
+ * @type {import("prettier").Config}
4
+ */
5
+ declare const _default: {
6
+ importOrder: string[];
7
+ printWidth: number;
8
+ };
9
+ export default _default;
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @see https://prettier.io/docs/configuration.html
3
+ * @type {import("prettier").Config}
4
+ */
5
+ var index = {
6
+ importOrder: [
7
+ '^react$',
8
+ '^react-native$',
9
+ '',
10
+ '^@expo$',
11
+ '^@expo/(.*)$',
12
+ '^expo$',
13
+ '^expo-(.*)$',
14
+ '',
15
+ '^mobx$',
16
+ '^mobx-react-lite$',
17
+ '^mobx-persist-store$',
18
+ '',
19
+ '^@react-navigation/(.*)$',
20
+ '^@react-native-community/(.*)$',
21
+ '^react-native-(.*)$',
22
+ '',
23
+ '^@itcase/(.*)$',
24
+ '',
25
+ '<THIRD_PARTY_MODULES>',
26
+ '',
27
+ '^src/enums$',
28
+ '^src/enums/(.*)$',
29
+ '^src/interfaces$',
30
+ '^src/interfaces/(.*)$',
31
+ '^src/swagger$',
32
+ '^src/swagger/(.*)$',
33
+ '^src/constants$',
34
+ '^src/constants/(.*)$',
35
+ '^src/config$',
36
+ '^src/config/(.*)$',
37
+ '^src/modules$',
38
+ '^src/modules/(.*)$',
39
+ '^src/providers$',
40
+ '^src/providers/(.*)$',
41
+ '^src/navigation$',
42
+ '^src/navigation/(.*)$',
43
+ '^src/dictionaries$',
44
+ '^src/dictionaries/(.*)$',
45
+ '^src/forms$',
46
+ '^src/forms/(.*)$',
47
+ '^src/stores$',
48
+ '^src/stores/(.*)$',
49
+ '^src/screens$',
50
+ '^src/screens/(.*)$',
51
+ '^src/components$',
52
+ '^src/components/(.*)$',
53
+ '^src/screenCompoments$',
54
+ '^src/screenCompoments/(.*)$',
55
+ '^src/hooks$',
56
+ '^src/hooks/(.*)$',
57
+ '^src/utils$',
58
+ '^src/utils/(.*)$',
59
+ '^src/styles$',
60
+ '^src/styles/(.*)$',
61
+ '',
62
+ '^../(.*)$',
63
+ '^./(.*)$',
64
+ ],
65
+ printWidth: 100,
66
+ };
67
+
68
+ export { index as default };
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @see https://prettier.io/docs/configuration.html
3
+ * @type {import("prettier").Config}
4
+ */
5
+ var index = {
6
+ arrowParens: 'always',
7
+ importOrder: [
8
+ '^react$',
9
+ '^react-native$',
10
+ '^prop-types$',
11
+ '',
12
+ '<THIRD_PARTY_MODULES>',
13
+ '',
14
+ '^@itcase/(.*)$',
15
+ '',
16
+ '^(?!.*[.]css)src/(?!icons)(?!stores)(.*)$',
17
+ '^src/stores/(.*)$',
18
+ '^src/stores$',
19
+ '^(?!.*[.]css)[.]',
20
+ '',
21
+ '^src/icons$',
22
+ '^src/icons/(.*)$',
23
+ '(.*).css$',
24
+ '',
25
+ ],
26
+ importOrderSortSpecifiers: true,
27
+ plugins: ['@ianvs/prettier-plugin-sort-imports'],
28
+ printWidth: 80,
29
+ semi: false,
30
+ singleQuote: true,
31
+ tabWidth: 2,
32
+ };
33
+
34
+ export { index as default };