@conarti/eslint-plugin-feature-sliced 2.0.0-rc.1 → 2.0.0-rc.2
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.
- package/README.md +38 -36
- package/dist/index.cjs +71 -149
- package/dist/index.d.cts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +71 -149
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -71,9 +71,7 @@ npm i eslint --save-dev
|
|
|
71
71
|
Next, install `@conarti/eslint-plugin-feature-sliced`:
|
|
72
72
|
|
|
73
73
|
```sh
|
|
74
|
-
npm
|
|
75
|
-
# or by yarn
|
|
76
|
-
yarn add -D @conarti/eslint-plugin-feature-sliced
|
|
74
|
+
npm i -D @conarti/eslint-plugin-feature-sliced
|
|
77
75
|
```
|
|
78
76
|
|
|
79
77
|
Note: the plugin may conflict with other import sorting plugins installed in your project.
|
|
@@ -81,45 +79,49 @@ If you do not want to use this plugin's sorting, disable it. More about this bel
|
|
|
81
79
|
|
|
82
80
|
## Usage
|
|
83
81
|
|
|
84
|
-
|
|
82
|
+
For simple use with loose settings, just call the function:
|
|
85
83
|
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
```js
|
|
85
|
+
// eslint.config.js
|
|
86
|
+
import featureSliced from '@conarti/eslint-plugin-feature-sliced';
|
|
88
87
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
"plugin:@conarti/feature-sliced/recommended"
|
|
93
|
-
]
|
|
94
|
-
}
|
|
88
|
+
export default [
|
|
89
|
+
featureSliced(),
|
|
90
|
+
]
|
|
95
91
|
```
|
|
96
92
|
|
|
97
93
|
## Customisation
|
|
98
94
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
95
|
+
You can also manage any rule and disable them:
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
import featureSliced from '@conarti/eslint-plugin-feature-sliced';
|
|
99
|
+
|
|
100
|
+
export default [
|
|
101
|
+
featureSliced({
|
|
102
|
+
/* Enables public api check in segments */
|
|
103
|
+
publicApi: { level: 'segments' },
|
|
104
|
+
/* Uses a different import sorter. You can disable it and use your own plugins and configurations */
|
|
105
|
+
sortImports: 'with-newlines',
|
|
106
|
+
/* This is how you can completely disable the rule */
|
|
107
|
+
absoluteRelative: false,
|
|
108
|
+
layersSlices: {
|
|
109
|
+
/* This is how you can disable the rule for imports in any files (ignore paths in code) */
|
|
110
|
+
ignorePatterns: [
|
|
111
|
+
/**
|
|
112
|
+
* Please note that the plugin reads the entire file path from the root of your system, not the project.
|
|
113
|
+
* That's why we added "**" to the beginning.
|
|
114
|
+
*/
|
|
115
|
+
"**/src/components/**/*"
|
|
116
|
+
],
|
|
117
|
+
/* This is how you can disable the rule for files or folders (ignore all paths in files or folders) */
|
|
118
|
+
ignoreInFilesPatterns: [
|
|
119
|
+
/* Do not check imports like "import foo from '@/app/some-module/foo'" */
|
|
120
|
+
"@/app/some-module/*",
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
}),
|
|
124
|
+
]
|
|
123
125
|
```
|
|
124
126
|
|
|
125
127
|
## Rules
|
package/dist/index.cjs
CHANGED
|
@@ -34,11 +34,14 @@ __export(src_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(src_exports);
|
|
36
36
|
|
|
37
|
-
// src/create-plugin.ts
|
|
38
|
-
var import_eslint_flat_config_utils = require("eslint-flat-config-utils");
|
|
39
|
-
|
|
40
37
|
// src/config.ts
|
|
41
38
|
var PLUGIN_NAME = "@conarti/feature-sliced";
|
|
39
|
+
var RULE_NAMES = {
|
|
40
|
+
LAYERS_SLICES: `${PLUGIN_NAME}/layers-slices`,
|
|
41
|
+
ABSOLUTE_RELATIVE: `${PLUGIN_NAME}/absolute-relative`,
|
|
42
|
+
PUBLIC_API: `${PLUGIN_NAME}/public-api`,
|
|
43
|
+
IMPORT_ORDER: `${PLUGIN_NAME}/import-order`
|
|
44
|
+
};
|
|
42
45
|
var layers = [
|
|
43
46
|
"shared",
|
|
44
47
|
"entities",
|
|
@@ -63,136 +66,12 @@ var segments = [
|
|
|
63
66
|
];
|
|
64
67
|
var pathSeparator = "/";
|
|
65
68
|
|
|
66
|
-
// src/configs/import-order/shared.ts
|
|
67
|
-
var import_eslint_plugin_import_x = __toESM(require("eslint-plugin-import-x"), 1);
|
|
68
|
-
var plugins = {
|
|
69
|
-
import: import_eslint_plugin_import_x.default
|
|
70
|
-
};
|
|
71
|
-
var LAYERS_REVERSED = [...layers].reverse();
|
|
72
|
-
|
|
73
|
-
// src/configs/import-order/recommended.ts
|
|
74
|
-
var recommended = {
|
|
75
|
-
name: "@conarti/sort-imports/recommended",
|
|
76
|
-
plugins,
|
|
77
|
-
rules: {
|
|
78
|
-
"import/order": [
|
|
79
|
-
2,
|
|
80
|
-
{
|
|
81
|
-
"alphabetize": {
|
|
82
|
-
order: "asc",
|
|
83
|
-
caseInsensitive: true
|
|
84
|
-
},
|
|
85
|
-
"newlines-between": "never",
|
|
86
|
-
"pathGroups": LAYERS_REVERSED.map(
|
|
87
|
-
(layer) => ({
|
|
88
|
-
pattern: `**/?(*)${layer}{,/**}`,
|
|
89
|
-
group: "internal",
|
|
90
|
-
position: "after"
|
|
91
|
-
})
|
|
92
|
-
),
|
|
93
|
-
"distinctGroup": false,
|
|
94
|
-
"pathGroupsExcludedImportTypes": ["builtin"],
|
|
95
|
-
"groups": ["builtin", "external", "internal", "parent", "sibling", "index"]
|
|
96
|
-
}
|
|
97
|
-
]
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
// src/configs/import-order/with-newlines.ts
|
|
102
|
-
var withNewlines = {
|
|
103
|
-
name: "@conarti/sort-imports/with-newlines",
|
|
104
|
-
plugins,
|
|
105
|
-
rules: {
|
|
106
|
-
"import/order": [
|
|
107
|
-
2,
|
|
108
|
-
{
|
|
109
|
-
"alphabetize": {
|
|
110
|
-
order: "asc",
|
|
111
|
-
caseInsensitive: true
|
|
112
|
-
},
|
|
113
|
-
"newlines-between": "always",
|
|
114
|
-
"pathGroups": LAYERS_REVERSED.map(
|
|
115
|
-
(layer) => ({
|
|
116
|
-
pattern: `**/?(*)${layer}{,/**}`,
|
|
117
|
-
group: "internal",
|
|
118
|
-
position: "after"
|
|
119
|
-
})
|
|
120
|
-
),
|
|
121
|
-
"distinctGroup": false,
|
|
122
|
-
"pathGroupsExcludedImportTypes": ["builtin"],
|
|
123
|
-
"groups": ["builtin", "external", "internal", "parent", "sibling", "index"]
|
|
124
|
-
}
|
|
125
|
-
]
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
// src/configs/import-order/with-newlines-and-type-group.ts
|
|
130
|
-
var withNewlinesAndTypeGroup = {
|
|
131
|
-
name: "@conarti/sort-imports/with-newlines-and-type-group",
|
|
132
|
-
plugins,
|
|
133
|
-
rules: {
|
|
134
|
-
"import/order": [
|
|
135
|
-
2,
|
|
136
|
-
{
|
|
137
|
-
"alphabetize": {
|
|
138
|
-
order: "asc",
|
|
139
|
-
caseInsensitive: true
|
|
140
|
-
},
|
|
141
|
-
"newlines-between": "always",
|
|
142
|
-
"pathGroups": LAYERS_REVERSED.map(
|
|
143
|
-
(layer) => ({
|
|
144
|
-
pattern: `**/?(*)${layer}{,/**}`,
|
|
145
|
-
group: "internal",
|
|
146
|
-
position: "after"
|
|
147
|
-
})
|
|
148
|
-
),
|
|
149
|
-
"distinctGroup": false,
|
|
150
|
-
"pathGroupsExcludedImportTypes": ["builtin", "type"],
|
|
151
|
-
"groups": ["builtin", "external", "internal", "type", "parent", "sibling", "index"]
|
|
152
|
-
}
|
|
153
|
-
]
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
// src/configs/import-order/with-type-group.ts
|
|
158
|
-
var withTypeGroup = {
|
|
159
|
-
name: "@conarti/sort-imports/with-type-group",
|
|
160
|
-
plugins,
|
|
161
|
-
rules: {
|
|
162
|
-
"import/order": [
|
|
163
|
-
2,
|
|
164
|
-
{
|
|
165
|
-
"alphabetize": {
|
|
166
|
-
order: "asc",
|
|
167
|
-
caseInsensitive: true
|
|
168
|
-
},
|
|
169
|
-
"newlines-between": "never",
|
|
170
|
-
"pathGroups": LAYERS_REVERSED.map(
|
|
171
|
-
(layer) => ({
|
|
172
|
-
pattern: `**/?(*)${layer}{,/**}`,
|
|
173
|
-
group: "internal",
|
|
174
|
-
position: "after"
|
|
175
|
-
})
|
|
176
|
-
),
|
|
177
|
-
"distinctGroup": false,
|
|
178
|
-
"pathGroupsExcludedImportTypes": ["builtin", "type"],
|
|
179
|
-
"groups": ["builtin", "external", "internal", "type", "parent", "sibling", "index"]
|
|
180
|
-
}
|
|
181
|
-
]
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
// src/configs/import-order/index.ts
|
|
186
|
-
var importOrder = {
|
|
187
|
-
recommended,
|
|
188
|
-
"with-newlines": withNewlines,
|
|
189
|
-
"with-type-group": withTypeGroup,
|
|
190
|
-
"with-newlines-and-type-group": withNewlinesAndTypeGroup
|
|
191
|
-
};
|
|
192
|
-
|
|
193
69
|
// package.json
|
|
194
70
|
var version = "2.0.0-rc.1";
|
|
195
71
|
|
|
72
|
+
// src/rules/index.ts
|
|
73
|
+
var import_eslint_plugin_import_x = __toESM(require("eslint-plugin-import-x"), 1);
|
|
74
|
+
|
|
196
75
|
// src/lib/rule/create-rule.ts
|
|
197
76
|
var import_eslint_utils = require("@typescript-eslint/utils/eslint-utils");
|
|
198
77
|
var blobUrl = "https://github.com/conarti/eslint-plugin-feature-sliced/blob/master/src/rules";
|
|
@@ -1019,6 +898,7 @@ var public_api_default = createEslintRule({
|
|
|
1019
898
|
// src/rules/index.ts
|
|
1020
899
|
var rules = {
|
|
1021
900
|
"absolute-relative": absolute_relative_default,
|
|
901
|
+
"import-order": import_eslint_plugin_import_x.default.rules.order,
|
|
1022
902
|
"layers-slices": layers_slices_default,
|
|
1023
903
|
"public-api": public_api_default
|
|
1024
904
|
};
|
|
@@ -1033,6 +913,57 @@ var plugin = {
|
|
|
1033
913
|
rules: rules_default
|
|
1034
914
|
};
|
|
1035
915
|
|
|
916
|
+
// src/rules/import-order/configs.ts
|
|
917
|
+
var LAYERS_REVERSED = [...layers].reverse();
|
|
918
|
+
var baseConfig = {
|
|
919
|
+
alphabetize: {
|
|
920
|
+
order: "asc",
|
|
921
|
+
caseInsensitive: true
|
|
922
|
+
},
|
|
923
|
+
pathGroups: LAYERS_REVERSED.map((layer) => ({
|
|
924
|
+
pattern: `**/?(*)${layer}{,/**}`,
|
|
925
|
+
group: "internal",
|
|
926
|
+
position: "after"
|
|
927
|
+
})),
|
|
928
|
+
distinctGroup: false,
|
|
929
|
+
pathGroupsExcludedImportTypes: ["builtin"],
|
|
930
|
+
groups: ["builtin", "external", "internal", "parent", "sibling", "index"]
|
|
931
|
+
};
|
|
932
|
+
var importOrderRuleConfigs = {
|
|
933
|
+
"recommended": [
|
|
934
|
+
"error",
|
|
935
|
+
{
|
|
936
|
+
...baseConfig,
|
|
937
|
+
"newlines-between": "never"
|
|
938
|
+
}
|
|
939
|
+
],
|
|
940
|
+
"with-newlines": [
|
|
941
|
+
"error",
|
|
942
|
+
{
|
|
943
|
+
...baseConfig,
|
|
944
|
+
"newlines-between": "always"
|
|
945
|
+
}
|
|
946
|
+
],
|
|
947
|
+
"with-type-group": [
|
|
948
|
+
"error",
|
|
949
|
+
{
|
|
950
|
+
...baseConfig,
|
|
951
|
+
"newlines-between": "never",
|
|
952
|
+
"pathGroupsExcludedImportTypes": ["builtin", "type"],
|
|
953
|
+
"groups": ["builtin", "external", "internal", "type", "parent", "sibling", "index"]
|
|
954
|
+
}
|
|
955
|
+
],
|
|
956
|
+
"with-newlines-and-type-group": [
|
|
957
|
+
"error",
|
|
958
|
+
{
|
|
959
|
+
...baseConfig,
|
|
960
|
+
"newlines-between": "always",
|
|
961
|
+
"pathGroupsExcludedImportTypes": ["builtin", "type"],
|
|
962
|
+
"groups": ["builtin", "external", "internal", "type", "parent", "sibling", "index"]
|
|
963
|
+
}
|
|
964
|
+
]
|
|
965
|
+
};
|
|
966
|
+
|
|
1036
967
|
// src/create-plugin.ts
|
|
1037
968
|
function createPlugin(options = {}) {
|
|
1038
969
|
const {
|
|
@@ -1041,41 +972,32 @@ function createPlugin(options = {}) {
|
|
|
1041
972
|
layersSlices,
|
|
1042
973
|
publicApi
|
|
1043
974
|
} = options;
|
|
1044
|
-
const rules2 = defineRules({ absoluteRelative, layersSlices, publicApi });
|
|
1045
|
-
|
|
975
|
+
const rules2 = defineRules({ absoluteRelative, layersSlices, publicApi, sortImports });
|
|
976
|
+
return {
|
|
1046
977
|
name: PLUGIN_NAME,
|
|
1047
978
|
plugins: {
|
|
1048
979
|
[PLUGIN_NAME]: plugin
|
|
1049
980
|
},
|
|
1050
981
|
rules: rules2
|
|
1051
982
|
};
|
|
1052
|
-
return enhanceWithImportOrder(config, sortImports);
|
|
1053
983
|
}
|
|
1054
984
|
function defineRules(options) {
|
|
1055
985
|
const {
|
|
1056
986
|
absoluteRelative = {},
|
|
1057
987
|
layersSlices = {},
|
|
1058
|
-
publicApi = {}
|
|
988
|
+
publicApi = {},
|
|
989
|
+
sortImports = "recommended"
|
|
1059
990
|
} = options;
|
|
1060
|
-
const createRuleName = (rule) => `${PLUGIN_NAME}/${rule}`;
|
|
1061
991
|
const createRuleEntry = (ruleOptions) => ruleOptions ? ["error", ruleOptions] : ["off"];
|
|
1062
992
|
const rules2 = {
|
|
1063
|
-
[
|
|
1064
|
-
[
|
|
1065
|
-
[
|
|
993
|
+
[RULE_NAMES.LAYERS_SLICES]: createRuleEntry(layersSlices),
|
|
994
|
+
[RULE_NAMES.ABSOLUTE_RELATIVE]: createRuleEntry(absoluteRelative),
|
|
995
|
+
[RULE_NAMES.PUBLIC_API]: createRuleEntry(publicApi)
|
|
1066
996
|
};
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
function enhanceWithImportOrder(config, importOrderConfigName) {
|
|
1070
|
-
if (!importOrderConfigName) {
|
|
1071
|
-
return config;
|
|
997
|
+
if (sortImports) {
|
|
998
|
+
rules2[RULE_NAMES.IMPORT_ORDER] = importOrderRuleConfigs[sortImports];
|
|
1072
999
|
}
|
|
1073
|
-
|
|
1074
|
-
return (0, import_eslint_flat_config_utils.mergeConfigs)(
|
|
1075
|
-
importOrderConfig,
|
|
1076
|
-
config
|
|
1077
|
-
// the last one is to set the configuration name as 'PLUGIN_NAME'
|
|
1078
|
-
);
|
|
1000
|
+
return rules2;
|
|
1079
1001
|
}
|
|
1080
1002
|
|
|
1081
1003
|
// src/index.ts
|
package/dist/index.d.cts
CHANGED
|
@@ -50,12 +50,10 @@ interface PublicApiOptions {
|
|
|
50
50
|
*/
|
|
51
51
|
ignoreInFilesPatterns: string[];
|
|
52
52
|
}
|
|
53
|
-
interface
|
|
53
|
+
interface ESLintPluginFeatureSlicedOptions {
|
|
54
54
|
absoluteRelative?: false | AbsoluteRelativeOptions;
|
|
55
55
|
layersSlices?: false | LayersSlicesOptions;
|
|
56
56
|
publicApi?: false | PublicApiOptions;
|
|
57
|
-
}
|
|
58
|
-
interface ESLintPluginFeatureSlicedOptions extends ESLintPluginFeatureSlicedRuleOptions {
|
|
59
57
|
sortImports?: false | ImportOrderConfigName;
|
|
60
58
|
}
|
|
61
59
|
declare function createPlugin(options?: ESLintPluginFeatureSlicedOptions): TypedFlatConfigItem;
|
package/dist/index.d.ts
CHANGED
|
@@ -50,12 +50,10 @@ interface PublicApiOptions {
|
|
|
50
50
|
*/
|
|
51
51
|
ignoreInFilesPatterns: string[];
|
|
52
52
|
}
|
|
53
|
-
interface
|
|
53
|
+
interface ESLintPluginFeatureSlicedOptions {
|
|
54
54
|
absoluteRelative?: false | AbsoluteRelativeOptions;
|
|
55
55
|
layersSlices?: false | LayersSlicesOptions;
|
|
56
56
|
publicApi?: false | PublicApiOptions;
|
|
57
|
-
}
|
|
58
|
-
interface ESLintPluginFeatureSlicedOptions extends ESLintPluginFeatureSlicedRuleOptions {
|
|
59
57
|
sortImports?: false | ImportOrderConfigName;
|
|
60
58
|
}
|
|
61
59
|
declare function createPlugin(options?: ESLintPluginFeatureSlicedOptions): TypedFlatConfigItem;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
// src/create-plugin.ts
|
|
2
|
-
import { mergeConfigs } from "eslint-flat-config-utils";
|
|
3
|
-
|
|
4
1
|
// src/config.ts
|
|
5
2
|
var PLUGIN_NAME = "@conarti/feature-sliced";
|
|
3
|
+
var RULE_NAMES = {
|
|
4
|
+
LAYERS_SLICES: `${PLUGIN_NAME}/layers-slices`,
|
|
5
|
+
ABSOLUTE_RELATIVE: `${PLUGIN_NAME}/absolute-relative`,
|
|
6
|
+
PUBLIC_API: `${PLUGIN_NAME}/public-api`,
|
|
7
|
+
IMPORT_ORDER: `${PLUGIN_NAME}/import-order`
|
|
8
|
+
};
|
|
6
9
|
var layers = [
|
|
7
10
|
"shared",
|
|
8
11
|
"entities",
|
|
@@ -27,136 +30,12 @@ var segments = [
|
|
|
27
30
|
];
|
|
28
31
|
var pathSeparator = "/";
|
|
29
32
|
|
|
30
|
-
// src/configs/import-order/shared.ts
|
|
31
|
-
import pluginImport from "eslint-plugin-import-x";
|
|
32
|
-
var plugins = {
|
|
33
|
-
import: pluginImport
|
|
34
|
-
};
|
|
35
|
-
var LAYERS_REVERSED = [...layers].reverse();
|
|
36
|
-
|
|
37
|
-
// src/configs/import-order/recommended.ts
|
|
38
|
-
var recommended = {
|
|
39
|
-
name: "@conarti/sort-imports/recommended",
|
|
40
|
-
plugins,
|
|
41
|
-
rules: {
|
|
42
|
-
"import/order": [
|
|
43
|
-
2,
|
|
44
|
-
{
|
|
45
|
-
"alphabetize": {
|
|
46
|
-
order: "asc",
|
|
47
|
-
caseInsensitive: true
|
|
48
|
-
},
|
|
49
|
-
"newlines-between": "never",
|
|
50
|
-
"pathGroups": LAYERS_REVERSED.map(
|
|
51
|
-
(layer) => ({
|
|
52
|
-
pattern: `**/?(*)${layer}{,/**}`,
|
|
53
|
-
group: "internal",
|
|
54
|
-
position: "after"
|
|
55
|
-
})
|
|
56
|
-
),
|
|
57
|
-
"distinctGroup": false,
|
|
58
|
-
"pathGroupsExcludedImportTypes": ["builtin"],
|
|
59
|
-
"groups": ["builtin", "external", "internal", "parent", "sibling", "index"]
|
|
60
|
-
}
|
|
61
|
-
]
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
// src/configs/import-order/with-newlines.ts
|
|
66
|
-
var withNewlines = {
|
|
67
|
-
name: "@conarti/sort-imports/with-newlines",
|
|
68
|
-
plugins,
|
|
69
|
-
rules: {
|
|
70
|
-
"import/order": [
|
|
71
|
-
2,
|
|
72
|
-
{
|
|
73
|
-
"alphabetize": {
|
|
74
|
-
order: "asc",
|
|
75
|
-
caseInsensitive: true
|
|
76
|
-
},
|
|
77
|
-
"newlines-between": "always",
|
|
78
|
-
"pathGroups": LAYERS_REVERSED.map(
|
|
79
|
-
(layer) => ({
|
|
80
|
-
pattern: `**/?(*)${layer}{,/**}`,
|
|
81
|
-
group: "internal",
|
|
82
|
-
position: "after"
|
|
83
|
-
})
|
|
84
|
-
),
|
|
85
|
-
"distinctGroup": false,
|
|
86
|
-
"pathGroupsExcludedImportTypes": ["builtin"],
|
|
87
|
-
"groups": ["builtin", "external", "internal", "parent", "sibling", "index"]
|
|
88
|
-
}
|
|
89
|
-
]
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
// src/configs/import-order/with-newlines-and-type-group.ts
|
|
94
|
-
var withNewlinesAndTypeGroup = {
|
|
95
|
-
name: "@conarti/sort-imports/with-newlines-and-type-group",
|
|
96
|
-
plugins,
|
|
97
|
-
rules: {
|
|
98
|
-
"import/order": [
|
|
99
|
-
2,
|
|
100
|
-
{
|
|
101
|
-
"alphabetize": {
|
|
102
|
-
order: "asc",
|
|
103
|
-
caseInsensitive: true
|
|
104
|
-
},
|
|
105
|
-
"newlines-between": "always",
|
|
106
|
-
"pathGroups": LAYERS_REVERSED.map(
|
|
107
|
-
(layer) => ({
|
|
108
|
-
pattern: `**/?(*)${layer}{,/**}`,
|
|
109
|
-
group: "internal",
|
|
110
|
-
position: "after"
|
|
111
|
-
})
|
|
112
|
-
),
|
|
113
|
-
"distinctGroup": false,
|
|
114
|
-
"pathGroupsExcludedImportTypes": ["builtin", "type"],
|
|
115
|
-
"groups": ["builtin", "external", "internal", "type", "parent", "sibling", "index"]
|
|
116
|
-
}
|
|
117
|
-
]
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
// src/configs/import-order/with-type-group.ts
|
|
122
|
-
var withTypeGroup = {
|
|
123
|
-
name: "@conarti/sort-imports/with-type-group",
|
|
124
|
-
plugins,
|
|
125
|
-
rules: {
|
|
126
|
-
"import/order": [
|
|
127
|
-
2,
|
|
128
|
-
{
|
|
129
|
-
"alphabetize": {
|
|
130
|
-
order: "asc",
|
|
131
|
-
caseInsensitive: true
|
|
132
|
-
},
|
|
133
|
-
"newlines-between": "never",
|
|
134
|
-
"pathGroups": LAYERS_REVERSED.map(
|
|
135
|
-
(layer) => ({
|
|
136
|
-
pattern: `**/?(*)${layer}{,/**}`,
|
|
137
|
-
group: "internal",
|
|
138
|
-
position: "after"
|
|
139
|
-
})
|
|
140
|
-
),
|
|
141
|
-
"distinctGroup": false,
|
|
142
|
-
"pathGroupsExcludedImportTypes": ["builtin", "type"],
|
|
143
|
-
"groups": ["builtin", "external", "internal", "type", "parent", "sibling", "index"]
|
|
144
|
-
}
|
|
145
|
-
]
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
// src/configs/import-order/index.ts
|
|
150
|
-
var importOrder = {
|
|
151
|
-
recommended,
|
|
152
|
-
"with-newlines": withNewlines,
|
|
153
|
-
"with-type-group": withTypeGroup,
|
|
154
|
-
"with-newlines-and-type-group": withNewlinesAndTypeGroup
|
|
155
|
-
};
|
|
156
|
-
|
|
157
33
|
// package.json
|
|
158
34
|
var version = "2.0.0-rc.1";
|
|
159
35
|
|
|
36
|
+
// src/rules/index.ts
|
|
37
|
+
import pluginImport from "eslint-plugin-import-x";
|
|
38
|
+
|
|
160
39
|
// src/lib/rule/create-rule.ts
|
|
161
40
|
import { RuleCreator } from "@typescript-eslint/utils/eslint-utils";
|
|
162
41
|
var blobUrl = "https://github.com/conarti/eslint-plugin-feature-sliced/blob/master/src/rules";
|
|
@@ -993,6 +872,7 @@ var public_api_default = createEslintRule({
|
|
|
993
872
|
// src/rules/index.ts
|
|
994
873
|
var rules = {
|
|
995
874
|
"absolute-relative": absolute_relative_default,
|
|
875
|
+
"import-order": pluginImport.rules.order,
|
|
996
876
|
"layers-slices": layers_slices_default,
|
|
997
877
|
"public-api": public_api_default
|
|
998
878
|
};
|
|
@@ -1007,6 +887,57 @@ var plugin = {
|
|
|
1007
887
|
rules: rules_default
|
|
1008
888
|
};
|
|
1009
889
|
|
|
890
|
+
// src/rules/import-order/configs.ts
|
|
891
|
+
var LAYERS_REVERSED = [...layers].reverse();
|
|
892
|
+
var baseConfig = {
|
|
893
|
+
alphabetize: {
|
|
894
|
+
order: "asc",
|
|
895
|
+
caseInsensitive: true
|
|
896
|
+
},
|
|
897
|
+
pathGroups: LAYERS_REVERSED.map((layer) => ({
|
|
898
|
+
pattern: `**/?(*)${layer}{,/**}`,
|
|
899
|
+
group: "internal",
|
|
900
|
+
position: "after"
|
|
901
|
+
})),
|
|
902
|
+
distinctGroup: false,
|
|
903
|
+
pathGroupsExcludedImportTypes: ["builtin"],
|
|
904
|
+
groups: ["builtin", "external", "internal", "parent", "sibling", "index"]
|
|
905
|
+
};
|
|
906
|
+
var importOrderRuleConfigs = {
|
|
907
|
+
"recommended": [
|
|
908
|
+
"error",
|
|
909
|
+
{
|
|
910
|
+
...baseConfig,
|
|
911
|
+
"newlines-between": "never"
|
|
912
|
+
}
|
|
913
|
+
],
|
|
914
|
+
"with-newlines": [
|
|
915
|
+
"error",
|
|
916
|
+
{
|
|
917
|
+
...baseConfig,
|
|
918
|
+
"newlines-between": "always"
|
|
919
|
+
}
|
|
920
|
+
],
|
|
921
|
+
"with-type-group": [
|
|
922
|
+
"error",
|
|
923
|
+
{
|
|
924
|
+
...baseConfig,
|
|
925
|
+
"newlines-between": "never",
|
|
926
|
+
"pathGroupsExcludedImportTypes": ["builtin", "type"],
|
|
927
|
+
"groups": ["builtin", "external", "internal", "type", "parent", "sibling", "index"]
|
|
928
|
+
}
|
|
929
|
+
],
|
|
930
|
+
"with-newlines-and-type-group": [
|
|
931
|
+
"error",
|
|
932
|
+
{
|
|
933
|
+
...baseConfig,
|
|
934
|
+
"newlines-between": "always",
|
|
935
|
+
"pathGroupsExcludedImportTypes": ["builtin", "type"],
|
|
936
|
+
"groups": ["builtin", "external", "internal", "type", "parent", "sibling", "index"]
|
|
937
|
+
}
|
|
938
|
+
]
|
|
939
|
+
};
|
|
940
|
+
|
|
1010
941
|
// src/create-plugin.ts
|
|
1011
942
|
function createPlugin(options = {}) {
|
|
1012
943
|
const {
|
|
@@ -1015,41 +946,32 @@ function createPlugin(options = {}) {
|
|
|
1015
946
|
layersSlices,
|
|
1016
947
|
publicApi
|
|
1017
948
|
} = options;
|
|
1018
|
-
const rules2 = defineRules({ absoluteRelative, layersSlices, publicApi });
|
|
1019
|
-
|
|
949
|
+
const rules2 = defineRules({ absoluteRelative, layersSlices, publicApi, sortImports });
|
|
950
|
+
return {
|
|
1020
951
|
name: PLUGIN_NAME,
|
|
1021
952
|
plugins: {
|
|
1022
953
|
[PLUGIN_NAME]: plugin
|
|
1023
954
|
},
|
|
1024
955
|
rules: rules2
|
|
1025
956
|
};
|
|
1026
|
-
return enhanceWithImportOrder(config, sortImports);
|
|
1027
957
|
}
|
|
1028
958
|
function defineRules(options) {
|
|
1029
959
|
const {
|
|
1030
960
|
absoluteRelative = {},
|
|
1031
961
|
layersSlices = {},
|
|
1032
|
-
publicApi = {}
|
|
962
|
+
publicApi = {},
|
|
963
|
+
sortImports = "recommended"
|
|
1033
964
|
} = options;
|
|
1034
|
-
const createRuleName = (rule) => `${PLUGIN_NAME}/${rule}`;
|
|
1035
965
|
const createRuleEntry = (ruleOptions) => ruleOptions ? ["error", ruleOptions] : ["off"];
|
|
1036
966
|
const rules2 = {
|
|
1037
|
-
[
|
|
1038
|
-
[
|
|
1039
|
-
[
|
|
967
|
+
[RULE_NAMES.LAYERS_SLICES]: createRuleEntry(layersSlices),
|
|
968
|
+
[RULE_NAMES.ABSOLUTE_RELATIVE]: createRuleEntry(absoluteRelative),
|
|
969
|
+
[RULE_NAMES.PUBLIC_API]: createRuleEntry(publicApi)
|
|
1040
970
|
};
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
function enhanceWithImportOrder(config, importOrderConfigName) {
|
|
1044
|
-
if (!importOrderConfigName) {
|
|
1045
|
-
return config;
|
|
971
|
+
if (sortImports) {
|
|
972
|
+
rules2[RULE_NAMES.IMPORT_ORDER] = importOrderRuleConfigs[sortImports];
|
|
1046
973
|
}
|
|
1047
|
-
|
|
1048
|
-
return mergeConfigs(
|
|
1049
|
-
importOrderConfig,
|
|
1050
|
-
config
|
|
1051
|
-
// the last one is to set the configuration name as 'PLUGIN_NAME'
|
|
1052
|
-
);
|
|
974
|
+
return rules2;
|
|
1053
975
|
}
|
|
1054
976
|
|
|
1055
977
|
// src/index.ts
|
package/package.json
CHANGED