Skip to content

Commit 151305b

Browse files
authored
Merge pull request #101 from Boehringer-Ingelheim/feature/perfectionist-v5
feat(deps): update eslint-plugin-perfectionist to v5
2 parents 474ef1c + ee211c0 commit 151305b

File tree

5 files changed

+272
-108
lines changed

5 files changed

+272
-108
lines changed

configs/base.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const { defineConfig } = require('eslint/config');
66
const tseslint = require('typescript-eslint');
77

88
const {
9+
PERFECTIONIST_SETTINGS,
910
SORT_CLASSES_GROUPS,
1011
SORT_IMPORTS_GROUPS,
1112
SORT_INTERSECTION_TYPES_GROUPS,
@@ -93,36 +94,31 @@ module.exports = defineConfig(
9394
'perfectionist/sort-classes': [
9495
'error',
9596
{
96-
...perfectionist.configs['recommended-natural'].rules['perfectionist/sort-classes'][1],
9797
groups: SORT_CLASSES_GROUPS,
9898
},
9999
],
100100
'perfectionist/sort-imports': [
101101
'error',
102102
{
103-
...perfectionist.configs['recommended-natural'].rules['perfectionist/sort-imports'][1],
104103
groups: SORT_IMPORTS_GROUPS,
105-
newlinesBetween: 'ignore',
104+
newlinesBetween: 0, // No newlines are allowed between groups
106105
},
107106
],
108107
'perfectionist/sort-intersection-types': [
109108
'error',
110109
{
111-
...perfectionist.configs['recommended-natural'].rules['perfectionist/sort-intersection-types'][1],
112110
groups: SORT_INTERSECTION_TYPES_GROUPS,
113111
},
114112
],
115113
'perfectionist/sort-named-imports': [
116114
'error',
117115
{
118-
...perfectionist.configs['recommended-natural'].rules['perfectionist/sort-named-imports'][1],
119116
ignoreAlias: true,
120117
},
121118
],
122119
'perfectionist/sort-objects': [
123120
'error',
124121
{
125-
...perfectionist.configs['recommended-natural'].rules['perfectionist/sort-objects'][1],
126122
partitionByComment: true,
127123
},
128124
],
@@ -131,6 +127,9 @@ module.exports = defineConfig(
131127
'import/resolver': {
132128
typescript: true,
133129
},
130+
perfectionist: {
131+
...PERFECTIONIST_SETTINGS,
132+
},
134133
},
135134
},
136135
{

configs/react.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ const reactHooks = require('eslint-plugin-react-hooks');
44
const reactRefresh = require('eslint-plugin-react-refresh');
55
const { defineConfig } = require('eslint/config');
66
const globals = require('globals');
7-
8-
const { SORT_IMPORTS_GROUPS } = require('../lib/eslint-plugin-perfectionist.js');
7+
const { PERFECTIONIST_SETTINGS, SORT_IMPORTS_GROUPS } = require('../lib/eslint-plugin-perfectionist.js');
98
const base = require('./base.js');
109

1110
module.exports = defineConfig(
@@ -60,30 +59,30 @@ module.exports = defineConfig(
6059
'perfectionist/sort-imports': [
6160
'error',
6261
{
63-
customGroups: {
64-
type: {
65-
react: ['react'],
66-
},
67-
value: {
68-
react: ['react'],
62+
customGroups: [
63+
{
64+
elementNamePattern: ['^react$'],
65+
groupName: 'react',
6966
},
70-
},
67+
],
7168
groups: ['react', ...SORT_IMPORTS_GROUPS],
72-
ignoreCase: true,
73-
newlinesBetween: 'ignore',
74-
type: 'natural',
69+
newlinesBetween: 0, // No newlines are allowed between groups
7570
},
7671
],
7772
'perfectionist/sort-jsx-props': [
7873
'error',
7974
{
80-
customGroups: {
81-
callback: '^on.+',
82-
reservedProps: ['children', 'dangerouslySetInnerHTML', 'key', 'ref'], // Reserved props from: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/rules/jsx-sort-props.js#L41-L46
83-
},
75+
customGroups: [
76+
{
77+
elementNamePattern: '^on.+',
78+
groupName: 'callback',
79+
},
80+
{
81+
elementNamePattern: ['children', 'dangerouslySetInnerHTML', 'key', 'ref'], // Reserved props from: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/rules/jsx-sort-props.js#L41-L46
82+
groupName: 'reservedProps',
83+
},
84+
],
8485
groups: ['reservedProps', 'unknown', 'callback'],
85-
ignoreCase: true,
86-
type: 'natural',
8786
},
8887
],
8988

@@ -100,6 +99,9 @@ module.exports = defineConfig(
10099
],
101100
},
102101
settings: {
102+
perfectionist: {
103+
...PERFECTIONIST_SETTINGS,
104+
},
103105
react: {
104106
version: 'detect',
105107
},

lib/eslint-plugin-perfectionist.js

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
1+
/**
2+
* Opinionated 'default' settings for eslint-plugin-perfectionist.
3+
* @see https://perfectionist.dev/guide/getting-started#settings
4+
*/
5+
const PERFECTIONIST_SETTINGS = {
6+
ignoreCase: true, // Ignore case when sorting
7+
type: 'natural',
8+
};
9+
110
/**
211
* While the sorting of imports is done by `eslint-plugin-perfectionist/sort-imports`,
312
* the order and grouping of imports is still taken from the previous configuration of `eslint-plugin-import/order`,
413
* as it feels more natural.
514
* The following group names are available for configuration: https://eslint-plugin-perfectionist.azat.io/rules/sort-imports#groups
615
*/
716
const SORT_IMPORTS_GROUPS = [
8-
['builtin', 'builtin-type'],
9-
['external', 'external-type'],
10-
['internal', 'internal-type'],
11-
['parent', 'parent-type', 'sibling', 'sibling-type', 'index', 'index-type'],
12-
'style',
13-
['side-effect-style', 'side-effect'],
14-
'object',
17+
['value-builtin', 'named-type-builtin'],
18+
['value-external', 'named-type-external'],
19+
['value-internal', 'named-type-internal'],
20+
['value-parent', 'named-type-parent'],
21+
['value-sibling', 'named-type-sibling'],
22+
['value-index', 'named-type-index'],
23+
'value-style',
24+
['value-side-effect-style', 'value-side-effect'],
25+
'value-ts-equals-import',
1526
'unknown',
1627
];
1728

1829
/**
19-
* This is the the groups configuration of all the recommended configs by eslint-plugin-perfectionist.
30+
* This is the the default groups configuration of all the recommended configs by eslint-plugin-perfectionist.
2031
* This array can be used to reconfigure some options of the perfectionist/sort-classes rule without
2132
* overwriting the groups configuration of this rule.
2233
* This config can be found here:
@@ -25,19 +36,31 @@ const SORT_IMPORTS_GROUPS = [
2536
*/
2637
const SORT_CLASSES_GROUPS = [
2738
'index-signature',
28-
'static-property',
29-
'private-property',
30-
'property',
31-
'constructor',
32-
'static-method',
33-
'private-method',
34-
'method',
39+
['static-property', 'static-accessor-property'],
40+
['static-get-method', 'static-set-method'],
41+
['protected-static-property', 'protected-static-accessor-property'],
42+
['protected-static-get-method', 'protected-static-set-method'],
43+
['private-static-property', 'private-static-accessor-property'],
44+
['private-static-get-method', 'private-static-set-method'],
45+
'static-block',
46+
['property', 'accessor-property'],
3547
['get-method', 'set-method'],
48+
['protected-property', 'protected-accessor-property'],
49+
['protected-get-method', 'protected-set-method'],
50+
['private-property', 'private-accessor-property'],
51+
['private-get-method', 'private-set-method'],
52+
'constructor',
53+
['static-method', 'static-function-property'],
54+
['protected-static-method', 'protected-static-function-property'],
55+
['private-static-method', 'private-static-function-property'],
56+
['method', 'function-property'],
57+
['protected-method', 'protected-function-property'],
58+
['private-method', 'private-function-property'],
3659
'unknown',
3760
];
3861

3962
/**
40-
* This array can be used to configure the perfectionist/sort-intersection-types rule.
63+
* Customized configuration to configure the perfectionist/sort-intersection-types rule.
4164
* The following group names are available for configuration: https://perfectionist.dev/rules/sort-intersection-types#groups
4265
*/
4366
const SORT_INTERSECTION_TYPES_GROUPS = [
@@ -57,6 +80,7 @@ const SORT_INTERSECTION_TYPES_GROUPS = [
5780
];
5881

5982
module.exports = {
83+
PERFECTIONIST_SETTINGS,
6084
SORT_CLASSES_GROUPS,
6185
SORT_IMPORTS_GROUPS,
6286
SORT_INTERSECTION_TYPES_GROUPS,

0 commit comments

Comments
 (0)