@tarsilla/eslint-config 1.0.6 → 1.2.0

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 (42) hide show
  1. package/lib/index.cjs +1 -1
  2. package/lib/index.cjs.map +1 -1
  3. package/lib/index.d.ts +7 -5
  4. package/lib/index.mjs +1 -1
  5. package/lib/index.mjs.map +1 -1
  6. package/lib/library/index.cjs +1 -1
  7. package/lib/library/index.cjs.map +1 -1
  8. package/lib/library/index.d.ts +2 -2
  9. package/lib/library/index.mjs +1 -1
  10. package/lib/library/index.mjs.map +1 -1
  11. package/lib/next/index.cjs +1 -1
  12. package/lib/next/index.cjs.map +1 -1
  13. package/lib/next/index.d.ts +2 -2
  14. package/lib/next/index.mjs +1 -1
  15. package/lib/next/index.mjs.map +1 -1
  16. package/lib/react/index.cjs +1 -1
  17. package/lib/react/index.cjs.map +1 -1
  18. package/lib/react/index.d.ts +2 -2
  19. package/lib/react/index.mjs +1 -1
  20. package/lib/react/index.mjs.map +1 -1
  21. package/lib/storybook/index.cjs +2 -0
  22. package/lib/storybook/index.cjs.map +1 -0
  23. package/lib/storybook/index.d.ts +9 -0
  24. package/lib/storybook/index.mjs +2 -0
  25. package/lib/storybook/index.mjs.map +1 -0
  26. package/package.json +43 -24
  27. package/src/commons/all.ts +14 -11
  28. package/src/commons/index.ts +1 -2
  29. package/src/commons/javascript.ts +4 -4
  30. package/src/commons/jest.ts +2 -3
  31. package/src/commons/perfectionist.ts +140 -0
  32. package/src/commons/prettier.ts +6 -7
  33. package/src/commons/react-hooks.ts +3 -4
  34. package/src/commons/unusedImports.ts +10 -7
  35. package/src/index.ts +1 -0
  36. package/src/library/eslintLibraryConfig.ts +6 -19
  37. package/src/next/eslintNextConfig.ts +10 -52
  38. package/src/react/eslintReactConfig.ts +12 -18
  39. package/src/storybook/eslintStorybookConfig.ts +47 -0
  40. package/src/storybook/index.ts +1 -0
  41. package/src/commons/imports.ts +0 -44
  42. package/src/commons/sortImports.ts +0 -17
@@ -0,0 +1,140 @@
1
+ import perfectionistPlugin from 'eslint-plugin-perfectionist';
2
+ import { defineConfig } from 'eslint/config';
3
+ import { RuleConfig } from '@eslint/core';
4
+
5
+ const perfectionistOverrides = new Map<string, RuleConfig>([
6
+ [
7
+ 'sort-arrays',
8
+ [
9
+ 'error',
10
+ {
11
+ ignoreCase: false,
12
+ order: 'asc',
13
+ specialCharacters: 'trim',
14
+ useConfigurationIf: {
15
+ matchesAstSelector: 'TSAsExpression > ArrayExpression',
16
+ },
17
+ },
18
+ ],
19
+ ],
20
+ [
21
+ 'sort-exports',
22
+ [
23
+ 'error',
24
+ {
25
+ ignoreCase: false,
26
+ order: 'asc',
27
+ specialCharacters: 'trim',
28
+ type: 'alphabetical',
29
+ },
30
+ ],
31
+ ],
32
+ [
33
+ 'sort-imports',
34
+ [
35
+ 'error',
36
+ {
37
+ customGroups: [
38
+ {
39
+ elementNamePattern: '@tarsilla(/.*)?$',
40
+ groupName: '@tarsilla',
41
+ },
42
+ ],
43
+ groups: [
44
+ 'type-import',
45
+ 'value-builtin',
46
+ 'value-external',
47
+ '@tarsilla',
48
+ 'value-internal',
49
+ ['type-parent', 'type-sibling', 'type-index'],
50
+ ['value-parent', 'value-sibling', 'value-index'],
51
+ 'ts-equals-import',
52
+ 'unknown',
53
+ ],
54
+ ignoreCase: false,
55
+ newlinesBetween: 1,
56
+ order: 'asc',
57
+ specialCharacters: 'trim',
58
+ tsconfig: {
59
+ rootDir: '.',
60
+ },
61
+ type: 'alphabetical',
62
+ },
63
+ ],
64
+ ],
65
+ [
66
+ 'sort-named-exports',
67
+ [
68
+ 'error',
69
+ {
70
+ ignoreCase: false,
71
+ order: 'asc',
72
+ specialCharacters: 'trim',
73
+ type: 'alphabetical',
74
+ },
75
+ ],
76
+ ],
77
+ [
78
+ 'sort-named-imports',
79
+ [
80
+ 'error',
81
+ {
82
+ ignoreCase: false,
83
+ order: 'asc',
84
+ specialCharacters: 'trim',
85
+ type: 'alphabetical',
86
+ },
87
+ ],
88
+ ],
89
+ [
90
+ 'sort-union-types',
91
+ [
92
+ 'error',
93
+ {
94
+ groups: [
95
+ 'conditional',
96
+ 'function',
97
+ 'import',
98
+ 'intersection',
99
+ 'keyword',
100
+ 'literal',
101
+ 'named',
102
+ 'object',
103
+ 'operator',
104
+ 'tuple',
105
+ 'union',
106
+ 'nullish',
107
+ ],
108
+ ignoreCase: false,
109
+ order: 'asc',
110
+ specialCharacters: 'trim',
111
+ type: 'alphabetical',
112
+ },
113
+ ],
114
+ ],
115
+ ]);
116
+
117
+ const perfectionist = defineConfig({
118
+ plugins: {
119
+ perfectionistPlugin,
120
+ },
121
+ rules: Object.fromEntries(
122
+ Object.keys(perfectionistPlugin.rules ?? {}).map((rule) => {
123
+ const override = perfectionistOverrides.get(rule);
124
+ return [
125
+ `perfectionist/${rule}`,
126
+ override ?? [
127
+ 'error',
128
+ {
129
+ ignoreCase: true,
130
+ order: 'asc',
131
+ specialCharacters: 'trim',
132
+ type: 'alphabetical',
133
+ },
134
+ ],
135
+ ];
136
+ }),
137
+ ),
138
+ });
139
+
140
+ export { perfectionist };
@@ -1,8 +1,7 @@
1
- import type { TSESLint } from '@typescript-eslint/utils';
2
1
  import prettierRecommended from 'eslint-plugin-prettier/recommended';
3
- import { config } from 'typescript-eslint';
2
+ import { defineConfig } from 'eslint/config';
4
3
 
5
- const prettierConfig: TSESLint.FlatConfig.ConfigArray = config([
4
+ const prettierConfig = defineConfig([
6
5
  prettierRecommended,
7
6
  {
8
7
  rules: {
@@ -10,18 +9,18 @@ const prettierConfig: TSESLint.FlatConfig.ConfigArray = config([
10
9
  'prettier/prettier': [
11
10
  'error',
12
11
  {
13
- semi: true,
14
- trailingComma: 'all',
15
- singleQuote: true,
16
12
  jsxSingleQuote: true,
17
13
  printWidth: 120,
14
+ semi: true,
15
+ singleQuote: true,
18
16
  tabWidth: 2,
17
+ trailingComma: 'all',
19
18
  },
20
19
  {
21
- usePrettierrc: false,
22
20
  fileInfoOptions: {
23
21
  withNodeModules: true,
24
22
  },
23
+ usePrettierrc: false,
25
24
  },
26
25
  ],
27
26
  },
@@ -1,16 +1,15 @@
1
- import type { TSESLint } from '@typescript-eslint/utils';
2
1
  import reactHooks from 'eslint-plugin-react-hooks';
3
- import { config } from 'typescript-eslint';
2
+ import { defineConfig } from 'eslint/config';
4
3
 
5
- const reactHooksConfig: TSESLint.FlatConfig.ConfigArray = config({
4
+ const reactHooksConfig = defineConfig({
6
5
  files: ['**/*.{jsx,tsx}'],
7
6
  plugins: {
8
7
  'react-hooks': reactHooks,
9
8
  },
10
9
  rules: {
11
10
  ...reactHooks.configs.recommended.rules,
12
- 'react/react-in-jsx-scope': 'off',
13
11
  'react/jsx-uses-react': 'off',
12
+ 'react/react-in-jsx-scope': 'off',
14
13
  },
15
14
  });
16
15
 
@@ -1,25 +1,28 @@
1
- import type { TSESLint } from '@typescript-eslint/utils';
2
1
  import unusedImports from 'eslint-plugin-unused-imports';
3
- import { config } from 'typescript-eslint';
2
+ import { defineConfig } from 'eslint/config';
4
3
 
5
- const unusedImportsConfig: TSESLint.FlatConfig.ConfigArray = config({
4
+ const unusedImportsConfig = defineConfig({
6
5
  plugins: {
7
6
  'unused-imports': unusedImports,
8
7
  },
9
8
  rules: {
10
- '@typescript-eslint/no-unused-vars': 'off',
11
- 'no-unused-vars': 'off',
12
9
  'unused-imports/no-unused-imports': 'error',
13
10
  'unused-imports/no-unused-vars': [
14
11
  'error',
15
12
  {
16
- vars: 'all',
17
- varsIgnorePattern: '^_',
18
13
  args: 'after-used',
19
14
  argsIgnorePattern: '^_',
15
+ vars: 'all',
16
+ varsIgnorePattern: '^_',
20
17
  },
21
18
  ],
22
19
  },
20
+ settings: {
21
+ 'import/resolver': {
22
+ node: true,
23
+ typescript: true,
24
+ },
25
+ },
23
26
  });
24
27
 
25
28
  export { unusedImportsConfig };
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './library/index.js';
2
2
  export * from './next/index.js';
3
3
  export * from './react/index.js';
4
+ export * from './storybook/index.js';
4
5
  export * from './types/index.js';
@@ -1,34 +1,21 @@
1
- import type { TSESLint } from '@typescript-eslint/utils';
2
- import globals from 'globals';
3
- import { config } from 'typescript-eslint';
1
+ import { defineConfig, globalIgnores } from 'eslint/config';
4
2
 
5
3
  import {
6
4
  allConfig,
7
- importsConfig,
8
5
  javascriptConfig,
9
6
  jestConfig,
7
+ perfectionist,
10
8
  prettierConfig,
11
- sortImportsConfig,
12
9
  unusedImportsConfig,
13
10
  } from '../commons/index.js';
14
11
  import { EslintOptions } from '../types/index.js';
15
12
 
16
- function eslintLibraryConfig({ ignores }: EslintOptions): TSESLint.FlatConfig.ConfigArray {
17
- return config(
18
- ...config({
19
- ignores,
20
- }),
21
- ...config({
22
- languageOptions: {
23
- globals: {
24
- ...globals.node,
25
- },
26
- },
27
- }),
13
+ function eslintLibraryConfig({ ignores }: EslintOptions) {
14
+ return defineConfig(
15
+ globalIgnores(ignores),
28
16
  ...allConfig,
29
17
  ...unusedImportsConfig,
30
- ...sortImportsConfig,
31
- ...importsConfig,
18
+ ...perfectionist,
32
19
  ...javascriptConfig,
33
20
  ...jestConfig,
34
21
  ...prettierConfig,
@@ -1,75 +1,33 @@
1
- import { dirname } from 'path';
2
- import { fileURLToPath } from 'url';
3
-
4
- import { FlatCompat } from '@eslint/eslintrc';
5
- import type { TSESLint } from '@typescript-eslint/utils';
1
+ import { defineConfig, globalIgnores } from 'eslint/config';
6
2
  import globals from 'globals';
7
- import { config } from 'typescript-eslint';
3
+ import nextPlugin from '@next/eslint-plugin-next';
8
4
 
9
5
  import {
10
6
  allConfig,
11
7
  javascriptConfig,
12
8
  jestConfig,
9
+ perfectionist,
13
10
  prettierConfig,
14
11
  reactHooksConfig,
15
- sortImportsConfig,
16
12
  unusedImportsConfig,
17
13
  } from '../commons/index.js';
18
14
  import { EslintOptions } from '../types/index.js';
19
15
 
20
- const __filename = fileURLToPath(import.meta.url);
21
- const __dirname = dirname(__filename);
22
-
23
- const compat = new FlatCompat({
24
- baseDirectory: __dirname,
25
- });
26
-
27
- function eslintNextConfig({ ignores }: EslintOptions): TSESLint.FlatConfig.ConfigArray {
28
- return config(
29
- ...config({
30
- ignores,
31
- }),
32
- ...config({
16
+ function eslintNextConfig({ ignores }: EslintOptions) {
17
+ return defineConfig(
18
+ globalIgnores(ignores),
19
+ {
33
20
  languageOptions: {
34
21
  globals: {
35
- ...globals.node,
36
22
  ...globals.browser,
37
23
  },
38
24
  },
39
- }),
25
+ },
40
26
  ...allConfig,
41
- ...compat.config({
42
- extends: ['next/core-web-vitals', 'next/typescript'],
43
- rules: {
44
- 'import/order': [
45
- 'error',
46
- {
47
- groups: ['builtin', 'external', 'internal', ['parent', 'sibling']],
48
- pathGroups: [
49
- {
50
- pattern: 'react',
51
- group: 'external',
52
- position: 'before',
53
- },
54
- {
55
- pattern: '@tarsilla/**',
56
- group: 'internal',
57
- position: 'before',
58
- },
59
- ],
60
- pathGroupsExcludedImportTypes: ['react', '@tarsilla'],
61
- 'newlines-between': 'always',
62
- alphabetize: {
63
- order: 'asc',
64
- caseInsensitive: true,
65
- },
66
- },
67
- ],
68
- },
69
- }),
27
+ nextPlugin.configs['core-web-vitals'],
70
28
  ...reactHooksConfig,
71
29
  ...unusedImportsConfig,
72
- ...sortImportsConfig,
30
+ ...perfectionist,
73
31
  ...javascriptConfig,
74
32
  ...jestConfig,
75
33
  ...prettierConfig,
@@ -1,47 +1,41 @@
1
- import type { TSESLint } from '@typescript-eslint/utils';
2
- import reactPlugin from 'eslint-plugin-react';
1
+ import reactPlugin from 'eslint-plugin-react-x';
2
+ import { defineConfig, globalIgnores } from 'eslint/config';
3
3
  import globals from 'globals';
4
- import { config } from 'typescript-eslint';
5
4
 
6
5
  import {
7
6
  allConfig,
8
- importsConfig,
9
7
  javascriptConfig,
10
8
  jestConfig,
9
+ perfectionist,
11
10
  prettierConfig,
12
11
  reactHooksConfig,
13
- sortImportsConfig,
14
12
  unusedImportsConfig,
15
13
  } from '../commons/index.js';
16
14
  import { EslintOptions } from '../types/index.js';
17
15
 
18
- function eslintReactConfig({ ignores }: EslintOptions): TSESLint.FlatConfig.ConfigArray {
19
- return config(
20
- ...config({
21
- ignores,
22
- }),
23
- ...config({
16
+ function eslintReactConfig({ ignores }: EslintOptions) {
17
+ return defineConfig(
18
+ globalIgnores(ignores),
19
+ {
24
20
  languageOptions: {
25
21
  globals: {
26
22
  ...globals.browser,
27
23
  },
28
24
  },
29
- }),
25
+ },
30
26
  ...allConfig,
31
- ...config({
27
+ {
32
28
  files: ['**/*.{jsx,tsx}'],
33
- ...reactPlugin.configs.flat.recommended,
34
- ...reactPlugin.configs.flat['jsx-runtime'],
29
+ ...reactPlugin.configs['strict-type-checked'],
35
30
  settings: {
36
31
  react: {
37
32
  version: 'detect',
38
33
  },
39
34
  },
40
- }),
35
+ },
41
36
  ...reactHooksConfig,
42
37
  ...unusedImportsConfig,
43
- ...sortImportsConfig,
44
- ...importsConfig,
38
+ ...perfectionist,
45
39
  ...javascriptConfig,
46
40
  ...jestConfig,
47
41
  ...prettierConfig,
@@ -0,0 +1,47 @@
1
+ import reactPlugin from 'eslint-plugin-react-x';
2
+ import storybookPlugin from 'eslint-plugin-storybook';
3
+ import { defineConfig, globalIgnores } from 'eslint/config';
4
+ import globals from 'globals';
5
+
6
+ import {
7
+ allConfig,
8
+ javascriptConfig,
9
+ jestConfig,
10
+ perfectionist,
11
+ prettierConfig,
12
+ reactHooksConfig,
13
+ unusedImportsConfig,
14
+ } from '../commons/index.js';
15
+ import { EslintOptions } from '../types/index.js';
16
+
17
+ function eslintStorybookConfig({ ignores }: EslintOptions) {
18
+ return defineConfig(
19
+ globalIgnores(ignores),
20
+ {
21
+ languageOptions: {
22
+ globals: {
23
+ ...globals.browser,
24
+ },
25
+ },
26
+ },
27
+ ...allConfig,
28
+ {
29
+ files: ['**/*.{jsx,tsx}'],
30
+ ...reactPlugin.configs['strict-type-checked'],
31
+ settings: {
32
+ react: {
33
+ version: 'detect',
34
+ },
35
+ },
36
+ },
37
+ ...reactHooksConfig,
38
+ ...unusedImportsConfig,
39
+ ...perfectionist,
40
+ ...javascriptConfig,
41
+ ...jestConfig,
42
+ ...prettierConfig,
43
+ ...storybookPlugin.configs['flat/recommended'],
44
+ );
45
+ }
46
+
47
+ export { eslintStorybookConfig };
@@ -0,0 +1 @@
1
+ export * from './eslintStorybookConfig.js';
@@ -1,44 +0,0 @@
1
- import type { TSESLint } from '@typescript-eslint/utils';
2
- import imports from 'eslint-plugin-import';
3
- import { config } from 'typescript-eslint';
4
-
5
- const importsConfig: TSESLint.FlatConfig.ConfigArray = config([
6
- imports.flatConfigs.recommended,
7
- imports.flatConfigs.typescript,
8
- {
9
- rules: {
10
- 'import/order': [
11
- 'error',
12
- {
13
- groups: ['builtin', 'external', 'internal', ['parent', 'sibling']],
14
- pathGroups: [
15
- {
16
- pattern: 'react',
17
- group: 'external',
18
- position: 'before',
19
- },
20
- {
21
- pattern: '@tarsilla/**',
22
- group: 'internal',
23
- position: 'before',
24
- },
25
- ],
26
- pathGroupsExcludedImportTypes: ['react', '@tarsilla'],
27
- 'newlines-between': 'always',
28
- alphabetize: {
29
- order: 'asc',
30
- caseInsensitive: true,
31
- },
32
- },
33
- ],
34
- },
35
- settings: {
36
- 'import/resolver': {
37
- typescript: true,
38
- node: true,
39
- },
40
- },
41
- },
42
- ]);
43
-
44
- export { importsConfig };
@@ -1,17 +0,0 @@
1
- import type { TSESLint } from '@typescript-eslint/utils';
2
- import { config } from 'typescript-eslint';
3
-
4
- const sortImportsConfig: TSESLint.FlatConfig.ConfigArray = config({
5
- rules: {
6
- 'sort-imports': [
7
- 'error',
8
- {
9
- ignoreCase: true,
10
- ignoreDeclarationSort: true,
11
- ignoreMemberSort: false,
12
- },
13
- ],
14
- },
15
- });
16
-
17
- export { sortImportsConfig };