@conarti/eslint-plugin-feature-sliced 1.0.3 → 1.0.5

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 (79) hide show
  1. package/CHANGELOG.md +36 -18
  2. package/README.md +132 -142
  3. package/dist/config.js +27 -27
  4. package/dist/configs/import-order/index.js +20 -20
  5. package/dist/configs/import-order/recommended.js +28 -28
  6. package/dist/configs/import-order/with-newlines-and-type-group.js +28 -28
  7. package/dist/configs/import-order/with-newlines.js +28 -28
  8. package/dist/configs/import-order/with-type-group.js +28 -28
  9. package/dist/configs/recommended.js +11 -11
  10. package/dist/configs/rules.js +11 -11
  11. package/dist/index.js +24 -24
  12. package/dist/lib/{fsd-lib → feature-sliced}/extract-feature-sliced-parts.js +18 -18
  13. package/dist/lib/{fsd-lib → feature-sliced}/extract-layer.js +21 -21
  14. package/dist/lib/{fsd-lib → feature-sliced}/extract-paths-info.js +59 -59
  15. package/dist/lib/{fsd-lib → feature-sliced}/extract-segment.js +18 -18
  16. package/dist/lib/{fsd-lib → feature-sliced}/extract-slice.js +10 -10
  17. package/dist/lib/{fsd-lib → feature-sliced}/index.js +10 -10
  18. package/dist/lib/{fsd-lib → feature-sliced}/layers.js +16 -16
  19. package/dist/lib/{fsd-lib → feature-sliced}/validate-extracted-feature-sliced-parts.js +29 -29
  20. package/dist/lib/{path-lib → path}/convert-to-absolute.js +18 -18
  21. package/dist/lib/{path-lib → path}/index.js +9 -9
  22. package/dist/lib/{path-lib → path}/is-path-relative.js +7 -7
  23. package/dist/lib/{path-lib → path}/join-path.js +12 -12
  24. package/dist/lib/{path-lib → path}/normalize-path.js +19 -19
  25. package/dist/lib/{rule-lib → rule}/create-rule.js +7 -7
  26. package/dist/lib/{rule-lib → rule}/extract-current-file-path.js +11 -11
  27. package/dist/lib/{rule-lib → rule}/extract-cwd.js +13 -13
  28. package/dist/lib/{rule-lib → rule}/extract-node-path.js +13 -13
  29. package/dist/lib/rule/extract-paths.js +21 -0
  30. package/dist/lib/{rule-lib → rule}/extract-rule-options.js +7 -7
  31. package/dist/lib/{rule-lib → rule}/get-source-range-without-quotes.js +7 -7
  32. package/dist/lib/{rule-lib/can-validate.js → rule/has-path.js} +11 -11
  33. package/dist/lib/{rule-lib → rule}/index.js +27 -23
  34. package/dist/lib/{rule-lib → rule}/is-ignored-current-file.js +12 -12
  35. package/dist/lib/rule/is-ignored-target.js +12 -0
  36. package/dist/lib/{rule-lib → rule}/is-ignored.js +12 -12
  37. package/dist/lib/rule/is-node-type.js +16 -0
  38. package/dist/lib/{rule-lib → rule}/models.js +2 -2
  39. package/dist/lib/shared/get-by-reg-exp.js +12 -12
  40. package/dist/lib/shared/index.js +11 -11
  41. package/dist/lib/shared/is-null.js +7 -7
  42. package/dist/lib/shared/is-object.js +7 -7
  43. package/dist/lib/shared/is-undefined.js +7 -7
  44. package/dist/rules/absolute-relative/config.js +2 -2
  45. package/dist/rules/absolute-relative/index.js +51 -52
  46. package/dist/rules/absolute-relative/model/{errors-lib.js → errors.js} +17 -17
  47. package/dist/rules/absolute-relative/model/index.js +5 -5
  48. package/dist/rules/absolute-relative/model/should-be-absolute.js +16 -16
  49. package/dist/rules/absolute-relative/model/should-be-relative.js +21 -21
  50. package/dist/rules/absolute-relative/model/validate-and-report.js +24 -24
  51. package/dist/rules/layers-slices/config.js +2 -2
  52. package/dist/rules/layers-slices/index.js +55 -56
  53. package/dist/rules/layers-slices/model/{errors-lib.js → errors.js} +22 -14
  54. package/dist/rules/layers-slices/model/index.js +5 -5
  55. package/dist/rules/layers-slices/model/is-not-suitable-for-validation.js +17 -0
  56. package/dist/rules/layers-slices/model/specifiers/extract-import-specifiers.js +8 -0
  57. package/dist/rules/layers-slices/model/specifiers/has-errors-at-all-specifiers.js +9 -0
  58. package/dist/rules/layers-slices/model/specifiers/index.js +7 -0
  59. package/dist/rules/layers-slices/model/specifiers/validate-specifiers.js +8 -0
  60. package/dist/rules/layers-slices/model/validate-and-report.js +46 -22
  61. package/dist/rules/layers-slices/model/validate-node/index.js +16 -0
  62. package/dist/rules/layers-slices/model/validate-node/valid-by-layer-order.js +10 -0
  63. package/dist/rules/layers-slices/model/validate-node/valid-by-type-import.js +9 -0
  64. package/dist/rules/public-api/config.js +2 -2
  65. package/dist/rules/public-api/index.js +65 -65
  66. package/dist/rules/public-api/model/convert-to-public-api.js +24 -24
  67. package/dist/rules/public-api/model/{errors-lib.js → errors.js} +34 -34
  68. package/dist/rules/public-api/model/index.js +5 -5
  69. package/dist/rules/public-api/model/is-index-file.js +7 -7
  70. package/dist/rules/public-api/model/is-layer-public-api.js +23 -23
  71. package/dist/rules/public-api/model/is-segments-public-api.js +11 -11
  72. package/dist/rules/public-api/model/is-slice-public-api.js +7 -7
  73. package/dist/rules/public-api/model/should-be-from-public-api.js +21 -21
  74. package/dist/rules/public-api/model/validate-and-report-program.js +15 -15
  75. package/dist/rules/public-api/model/validate-and-report.js +18 -18
  76. package/package.json +15 -14
  77. package/dist/lib/fsd-lib/extract-paths.js +0 -19
  78. package/dist/lib/rule-lib/is-node-type.js +0 -17
  79. package/dist/rules/layers-slices/model/can-import-layer.js +0 -22
@@ -1,16 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.shouldBeAbsolute = void 0;
4
- const path_lib_1 = require("../../../lib/path-lib");
5
- function shouldBeAbsolute(pathsInfo) {
6
- const { normalizedTargetPath, fsdPartsOfTarget, fsdPartsOfCurrentFile, hasUnknownLayers, } = pathsInfo;
7
- const isAbsolute = !(0, path_lib_1.isPathRelative)(normalizedTargetPath);
8
- if (isAbsolute) {
9
- return false;
10
- }
11
- if (hasUnknownLayers) {
12
- return false;
13
- }
14
- return fsdPartsOfCurrentFile.layer !== fsdPartsOfTarget.layer;
15
- }
16
- exports.shouldBeAbsolute = shouldBeAbsolute;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.shouldBeAbsolute = void 0;
4
+ const path_1 = require("../../../lib/path");
5
+ function shouldBeAbsolute(pathsInfo) {
6
+ const { normalizedTargetPath, fsdPartsOfTarget, fsdPartsOfCurrentFile, hasUnknownLayers, } = pathsInfo;
7
+ const isAbsolute = !(0, path_1.isPathRelative)(normalizedTargetPath);
8
+ if (isAbsolute) {
9
+ return false;
10
+ }
11
+ if (hasUnknownLayers) {
12
+ return false;
13
+ }
14
+ return fsdPartsOfCurrentFile.layer !== fsdPartsOfTarget.layer;
15
+ }
16
+ exports.shouldBeAbsolute = shouldBeAbsolute;
@@ -1,21 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.shouldBeRelative = void 0;
4
- const path_lib_1 = require("../../../lib/path-lib");
5
- function shouldBeRelative(pathsInfo) {
6
- const { validatedFeatureSlicedPartsOfCurrentFile, normalizedTargetPath, isSameLayerWithoutSlices, isSameLayer, isSameSlice, } = pathsInfo;
7
- const isRelative = (0, path_lib_1.isPathRelative)(normalizedTargetPath);
8
- if (isRelative) {
9
- return false;
10
- }
11
- const isImportToLayerPublicApi = validatedFeatureSlicedPartsOfCurrentFile.hasNotSlice && isSameLayer;
12
- if (isImportToLayerPublicApi) {
13
- return true;
14
- }
15
- if (isSameLayerWithoutSlices) {
16
- return true;
17
- }
18
- const isSameLayerAndSlice = isSameLayer && isSameSlice;
19
- return isSameLayerAndSlice;
20
- }
21
- exports.shouldBeRelative = shouldBeRelative;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.shouldBeRelative = void 0;
4
+ const path_1 = require("../../../lib/path");
5
+ function shouldBeRelative(pathsInfo) {
6
+ const { validatedFeatureSlicedPartsOfCurrentFile, normalizedTargetPath, isSameLayerWithoutSlices, isSameLayer, isSameSlice, } = pathsInfo;
7
+ const isRelative = (0, path_1.isPathRelative)(normalizedTargetPath);
8
+ if (isRelative) {
9
+ return false;
10
+ }
11
+ const isImportToLayerPublicApi = validatedFeatureSlicedPartsOfCurrentFile.hasNotSlice && isSameLayer;
12
+ if (isImportToLayerPublicApi) {
13
+ return true;
14
+ }
15
+ if (isSameLayerWithoutSlices) {
16
+ return true;
17
+ }
18
+ const isSameLayerAndSlice = isSameLayer && isSameSlice;
19
+ return isSameLayerAndSlice;
20
+ }
21
+ exports.shouldBeRelative = shouldBeRelative;
@@ -1,24 +1,24 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateAndReport = void 0;
4
- const fsd_lib_1 = require("../../../lib/fsd-lib");
5
- const rule_lib_1 = require("../../../lib/rule-lib");
6
- const errors_lib_1 = require("./errors-lib");
7
- const should_be_absolute_1 = require("./should-be-absolute");
8
- const should_be_relative_1 = require("./should-be-relative");
9
- function validateAndReport(node, context, optionsWithDefault, options = { needCheckForAbsolute: true }) {
10
- if (!(0, rule_lib_1.canValidate)(node)) {
11
- return;
12
- }
13
- if ((0, rule_lib_1.isIgnoredCurrentFile)(context, optionsWithDefault)) {
14
- return;
15
- }
16
- const pathsInfo = (0, fsd_lib_1.extractPathsInfo)(node, context);
17
- if ((0, should_be_relative_1.shouldBeRelative)(pathsInfo)) {
18
- (0, errors_lib_1.reportShouldBeRelative)(node, context);
19
- }
20
- if (options.needCheckForAbsolute && (0, should_be_absolute_1.shouldBeAbsolute)(pathsInfo)) {
21
- (0, errors_lib_1.reportShouldBeAbsolute)(node, context);
22
- }
23
- }
24
- exports.validateAndReport = validateAndReport;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateAndReport = void 0;
4
+ const feature_sliced_1 = require("../../../lib/feature-sliced");
5
+ const rule_1 = require("../../../lib/rule");
6
+ const errors_1 = require("./errors");
7
+ const should_be_absolute_1 = require("./should-be-absolute");
8
+ const should_be_relative_1 = require("./should-be-relative");
9
+ function validateAndReport(node, context, optionsWithDefault, options = { needCheckForAbsolute: true }) {
10
+ if (!(0, rule_1.hasPath)(node)) {
11
+ return;
12
+ }
13
+ if ((0, rule_1.isIgnoredCurrentFile)(context, optionsWithDefault)) {
14
+ return;
15
+ }
16
+ const pathsInfo = (0, feature_sliced_1.extractPathsInfo)(node, context);
17
+ if ((0, should_be_relative_1.shouldBeRelative)(pathsInfo)) {
18
+ (0, errors_1.reportShouldBeRelative)(node, context);
19
+ }
20
+ if (options.needCheckForAbsolute && (0, should_be_absolute_1.shouldBeAbsolute)(pathsInfo)) {
21
+ (0, errors_1.reportShouldBeAbsolute)(node, context);
22
+ }
23
+ }
24
+ exports.validateAndReport = validateAndReport;
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,56 +1,55 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const rule_lib_1 = require("../../lib/rule-lib");
4
- const model_1 = require("./model");
5
- exports.default = (0, rule_lib_1.createRule)({
6
- name: 'layers-slices',
7
- meta: {
8
- type: 'problem',
9
- docs: {
10
- description: 'Checks layer imports',
11
- recommended: false,
12
- },
13
- messages: {
14
- ["can-not-import"]: 'You cannot import layer "{{ importLayer }}" into "{{ currentFileLayer }}" (shared -> entities -> features -> widgets -> pages -> processes -> app)',
15
- },
16
- schema: [
17
- {
18
- type: 'object',
19
- properties: {
20
- allowTypeImports: {
21
- type: 'boolean',
22
- },
23
- ignorePatterns: {
24
- type: 'array',
25
- items: {
26
- type: 'string',
27
- },
28
- },
29
- ignoreInFilesPatterns: {
30
- type: 'array',
31
- items: {
32
- type: 'string',
33
- },
34
- },
35
- },
36
- },
37
- ],
38
- },
39
- defaultOptions: [
40
- {
41
- allowTypeImports: true,
42
- ignorePatterns: [],
43
- ignoreInFilesPatterns: [],
44
- },
45
- ],
46
- create(context, optionsWithDefault) {
47
- return {
48
- ImportDeclaration(node) {
49
- (0, model_1.validateAndReport)(node, context, optionsWithDefault);
50
- },
51
- ImportExpression(node) {
52
- (0, model_1.validateAndReport)(node, context, optionsWithDefault);
53
- },
54
- };
55
- },
56
- });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const rule_1 = require("../../lib/rule");
4
+ const model_1 = require("./model");
5
+ exports.default = (0, rule_1.createRule)({
6
+ name: 'layers-slices',
7
+ meta: {
8
+ type: 'problem',
9
+ docs: {
10
+ description: 'Checks layer imports',
11
+ },
12
+ messages: {
13
+ ["can-not-import"]: 'You cannot import layer "{{ importLayer }}" into "{{ currentFileLayer }}" (shared -> entities -> features -> widgets -> pages -> processes -> app)',
14
+ },
15
+ schema: [
16
+ {
17
+ type: 'object',
18
+ properties: {
19
+ allowTypeImports: {
20
+ type: 'boolean',
21
+ },
22
+ ignorePatterns: {
23
+ type: 'array',
24
+ items: {
25
+ type: 'string',
26
+ },
27
+ },
28
+ ignoreInFilesPatterns: {
29
+ type: 'array',
30
+ items: {
31
+ type: 'string',
32
+ },
33
+ },
34
+ },
35
+ },
36
+ ],
37
+ },
38
+ defaultOptions: [
39
+ {
40
+ allowTypeImports: true,
41
+ ignorePatterns: [],
42
+ ignoreInFilesPatterns: [],
43
+ },
44
+ ],
45
+ create(context, optionsWithDefault) {
46
+ return {
47
+ ImportDeclaration(node) {
48
+ (0, model_1.validateAndReport)(node, context, optionsWithDefault);
49
+ },
50
+ ImportExpression(node) {
51
+ (0, model_1.validateAndReport)(node, context, optionsWithDefault);
52
+ },
53
+ };
54
+ },
55
+ });
@@ -1,14 +1,22 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.reportCanNotImportLayer = void 0;
4
- function reportCanNotImportLayer(context, node, pathsInfo) {
5
- context.report({
6
- node: node.source,
7
- messageId: "can-not-import",
8
- data: {
9
- importLayer: pathsInfo.fsdPartsOfTarget.layer,
10
- currentFileLayer: pathsInfo.fsdPartsOfCurrentFile.layer,
11
- },
12
- });
13
- }
14
- exports.reportCanNotImportLayer = reportCanNotImportLayer;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.reportCanNotImportLayer = void 0;
4
+ const utils_1 = require("@typescript-eslint/utils");
5
+ function reportCanNotImportLayer(context, node, pathsInfo) {
6
+ function getReportPosition(validatedNode) {
7
+ const isSpecifier = validatedNode.type === utils_1.AST_NODE_TYPES.ImportSpecifier;
8
+ if (isSpecifier) {
9
+ return validatedNode;
10
+ }
11
+ return validatedNode.source;
12
+ }
13
+ context.report({
14
+ node: getReportPosition(node),
15
+ messageId: "can-not-import",
16
+ data: {
17
+ importLayer: pathsInfo.fsdPartsOfTarget.layer,
18
+ currentFileLayer: pathsInfo.fsdPartsOfCurrentFile.layer,
19
+ },
20
+ });
21
+ }
22
+ exports.reportCanNotImportLayer = reportCanNotImportLayer;
@@ -1,5 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateAndReport = void 0;
4
- var validate_and_report_1 = require("./validate-and-report");
5
- Object.defineProperty(exports, "validateAndReport", { enumerable: true, get: function () { return validate_and_report_1.validateAndReport; } });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateAndReport = void 0;
4
+ var validate_and_report_1 = require("./validate-and-report");
5
+ Object.defineProperty(exports, "validateAndReport", { enumerable: true, get: function () { return validate_and_report_1.validateAndReport; } });
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNotSuitableForValidation = void 0;
4
+ function isNotSuitableForValidation(pathsInfo) {
5
+ const { isSameSlice, isSameLayerWithoutSlices, hasUnknownLayers, } = pathsInfo;
6
+ if (hasUnknownLayers) {
7
+ return true;
8
+ }
9
+ if (isSameSlice) {
10
+ return true;
11
+ }
12
+ if (isSameLayerWithoutSlices) {
13
+ return true;
14
+ }
15
+ return false;
16
+ }
17
+ exports.isNotSuitableForValidation = isNotSuitableForValidation;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractImportSpecifiers = void 0;
4
+ const utils_1 = require("@typescript-eslint/utils");
5
+ function extractImportSpecifiers(node) {
6
+ return node.specifiers.filter((specifier) => specifier.type === utils_1.AST_NODE_TYPES.ImportSpecifier);
7
+ }
8
+ exports.extractImportSpecifiers = extractImportSpecifiers;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasErrorsAtAllSpecifiers = void 0;
4
+ function hasErrorsAtAllSpecifiers(specifiers, invalidSpecifiers) {
5
+ const allSpecifiersCount = specifiers.length;
6
+ const invalidSpecifiersCount = invalidSpecifiers.length;
7
+ return invalidSpecifiersCount === allSpecifiersCount;
8
+ }
9
+ exports.hasErrorsAtAllSpecifiers = hasErrorsAtAllSpecifiers;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasErrorsAtAllSpecifiers = exports.validateSpecifiers = void 0;
4
+ var validate_specifiers_1 = require("./validate-specifiers");
5
+ Object.defineProperty(exports, "validateSpecifiers", { enumerable: true, get: function () { return validate_specifiers_1.validateSpecifiers; } });
6
+ var has_errors_at_all_specifiers_1 = require("./has-errors-at-all-specifiers");
7
+ Object.defineProperty(exports, "hasErrorsAtAllSpecifiers", { enumerable: true, get: function () { return has_errors_at_all_specifiers_1.hasErrorsAtAllSpecifiers; } });
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateSpecifiers = void 0;
4
+ const valid_by_type_import_1 = require("../validate-node/valid-by-type-import");
5
+ function validateSpecifiers(specifiers, allowTypeImports) {
6
+ return specifiers.filter((specifier) => !(0, valid_by_type_import_1.validByTypeImport)(specifier, allowTypeImports));
7
+ }
8
+ exports.validateSpecifiers = validateSpecifiers;
@@ -1,22 +1,46 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateAndReport = void 0;
4
- const fsd_lib_1 = require("../../../lib/fsd-lib");
5
- const rule_lib_1 = require("../../../lib/rule-lib");
6
- const can_import_layer_1 = require("./can-import-layer");
7
- const errors_lib_1 = require("./errors-lib");
8
- function validateAndReport(node, context, optionsWithDefault) {
9
- if (!(0, rule_lib_1.canValidate)(node)) {
10
- return;
11
- }
12
- const pathsInfo = (0, fsd_lib_1.extractPathsInfo)(node, context);
13
- const userDefinedRuleOptions = (0, rule_lib_1.extractRuleOptions)(optionsWithDefault);
14
- const isIgnoredTargetPath = (0, rule_lib_1.isIgnored)(pathsInfo.targetPath, userDefinedRuleOptions.ignorePatterns);
15
- if (isIgnoredTargetPath || (0, rule_lib_1.isIgnoredCurrentFile)(context, optionsWithDefault)) {
16
- return;
17
- }
18
- if (!(0, can_import_layer_1.canImportLayer)(pathsInfo, node, userDefinedRuleOptions)) {
19
- (0, errors_lib_1.reportCanNotImportLayer)(context, node, pathsInfo);
20
- }
21
- }
22
- exports.validateAndReport = validateAndReport;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateAndReport = void 0;
4
+ const utils_1 = require("@typescript-eslint/utils");
5
+ const feature_sliced_1 = require("../../../lib/feature-sliced");
6
+ const rule_1 = require("../../../lib/rule");
7
+ const errors_1 = require("./errors");
8
+ const is_not_suitable_for_validation_1 = require("./is-not-suitable-for-validation");
9
+ const specifiers_1 = require("./specifiers");
10
+ const extract_import_specifiers_1 = require("./specifiers/extract-import-specifiers");
11
+ const validate_node_1 = require("./validate-node");
12
+ function validate(node, pathsInfo, allowTypeImports) {
13
+ if ((0, validate_node_1.validateNode)(node, pathsInfo, allowTypeImports)) {
14
+ return [];
15
+ }
16
+ const isImportExpression = utils_1.ASTUtils.isNodeOfType(utils_1.AST_NODE_TYPES.ImportExpression)(node);
17
+ if (isImportExpression) {
18
+ return [node];
19
+ }
20
+ const specifiers = (0, extract_import_specifiers_1.extractImportSpecifiers)(node);
21
+ const invalidSpecifiers = (0, specifiers_1.validateSpecifiers)(specifiers, allowTypeImports);
22
+ if ((0, specifiers_1.hasErrorsAtAllSpecifiers)(specifiers, invalidSpecifiers)) {
23
+ return [node];
24
+ }
25
+ return invalidSpecifiers;
26
+ }
27
+ function reportValidationErrors(nodes, context, pathsInfo) {
28
+ nodes.forEach((node) => (0, errors_1.reportCanNotImportLayer)(context, node, pathsInfo));
29
+ }
30
+ function validateAndReport(node, context, optionsWithDefault) {
31
+ if (!(0, rule_1.hasPath)(node)) {
32
+ return;
33
+ }
34
+ const isIgnoredForValidation = (0, rule_1.isIgnoredTarget)(node, optionsWithDefault) || (0, rule_1.isIgnoredCurrentFile)(context, optionsWithDefault);
35
+ if (isIgnoredForValidation) {
36
+ return;
37
+ }
38
+ const pathsInfo = (0, feature_sliced_1.extractPathsInfo)(node, context);
39
+ if ((0, is_not_suitable_for_validation_1.isNotSuitableForValidation)(pathsInfo)) {
40
+ return;
41
+ }
42
+ const { allowTypeImports } = (0, rule_1.extractRuleOptions)(optionsWithDefault);
43
+ const nodesToReport = validate(node, pathsInfo, allowTypeImports);
44
+ reportValidationErrors(nodesToReport, context, pathsInfo);
45
+ }
46
+ exports.validateAndReport = validateAndReport;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateNode = void 0;
4
+ const valid_by_layer_order_1 = require("./valid-by-layer-order");
5
+ const valid_by_type_import_1 = require("./valid-by-type-import");
6
+ function validateNode(node, pathsInfo, allowTypeImports) {
7
+ const { fsdPartsOfTarget, fsdPartsOfCurrentFile, } = pathsInfo;
8
+ if ((0, valid_by_type_import_1.validByTypeImport)(node, allowTypeImports)) {
9
+ return true;
10
+ }
11
+ if ((0, valid_by_layer_order_1.validByLayerOrder)(fsdPartsOfTarget, fsdPartsOfCurrentFile)) {
12
+ return true;
13
+ }
14
+ return false;
15
+ }
16
+ exports.validateNode = validateNode;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validByLayerOrder = void 0;
4
+ const feature_sliced_1 = require("../../../../lib/feature-sliced");
5
+ function validByLayerOrder(fsdPartsOfTarget, fsdPartsOfCurrentFile) {
6
+ const importLayerOrder = (0, feature_sliced_1.getLayerWeight)(fsdPartsOfTarget.layer);
7
+ const currentFileLayerOrder = (0, feature_sliced_1.getLayerWeight)(fsdPartsOfCurrentFile.layer);
8
+ return currentFileLayerOrder > importLayerOrder;
9
+ }
10
+ exports.validByLayerOrder = validByLayerOrder;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validByTypeImport = void 0;
4
+ const rule_1 = require("../../../../lib/rule");
5
+ function validByTypeImport(node, allowTypeImports) {
6
+ const isType = (0, rule_1.isNodeType)(node);
7
+ return allowTypeImports && isType;
8
+ }
9
+ exports.validByTypeImport = validByTypeImport;
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,65 +1,65 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const rule_lib_1 = require("../../lib/rule-lib");
4
- const model_1 = require("./model");
5
- const validate_and_report_program_1 = require("./model/validate-and-report-program");
6
- exports.default = (0, rule_lib_1.createRule)({
7
- name: 'public-api',
8
- meta: {
9
- type: 'problem',
10
- docs: {
11
- description: 'Check for module imports from public api',
12
- recommended: false,
13
- },
14
- hasSuggestions: true,
15
- messages: {
16
- ["should-be-from-public-api"]: 'Absolute imports are only allowed from public api ("{{ fixedPath }}")',
17
- ["remove-suggestion"]: 'Remove the "{{ valueToRemove }}"',
18
- ["layers-public-api-not-allowed"]: 'The layer public API is not allowed. It harms both architecturally and practically (code splitting)',
19
- },
20
- schema: [
21
- {
22
- type: 'object',
23
- properties: {
24
- level: {
25
- enum: [
26
- "segments",
27
- "slices",
28
- ],
29
- },
30
- ignoreInFilesPatterns: {
31
- type: 'array',
32
- items: {
33
- type: 'string',
34
- },
35
- },
36
- },
37
- },
38
- ],
39
- },
40
- defaultOptions: [
41
- {
42
- level: "slices",
43
- ignoreInFilesPatterns: [],
44
- },
45
- ],
46
- create(context, optionsWithDefault) {
47
- return {
48
- ImportDeclaration(node) {
49
- (0, model_1.validateAndReport)(node, context, optionsWithDefault);
50
- },
51
- ImportExpression(node) {
52
- (0, model_1.validateAndReport)(node, context, optionsWithDefault);
53
- },
54
- ExportAllDeclaration(node) {
55
- (0, model_1.validateAndReport)(node, context, optionsWithDefault);
56
- },
57
- ExportNamedDeclaration(node) {
58
- (0, model_1.validateAndReport)(node, context, optionsWithDefault);
59
- },
60
- Program(node) {
61
- (0, validate_and_report_program_1.validateAndReportProgram)(node, context, optionsWithDefault);
62
- },
63
- };
64
- },
65
- });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const rule_1 = require("../../lib/rule");
4
+ const model_1 = require("./model");
5
+ const validate_and_report_program_1 = require("./model/validate-and-report-program");
6
+ exports.default = (0, rule_1.createRule)({
7
+ name: 'public-api',
8
+ meta: {
9
+ type: 'problem',
10
+ docs: {
11
+ description: 'Check for module imports from public api',
12
+ },
13
+ hasSuggestions: true,
14
+ messages: {
15
+ ["should-be-from-public-api"]: 'Absolute imports are only allowed from public api ("{{ fixedPath }}")',
16
+ ["remove-suggestion"]: 'Remove the "{{ valueToRemove }}"',
17
+ ["layers-public-api-not-allowed"]: 'The layer public API is not allowed. It harms both architecturally and practically (code splitting)',
18
+ },
19
+ schema: [
20
+ {
21
+ type: 'object',
22
+ properties: {
23
+ level: {
24
+ type: 'string',
25
+ enum: [
26
+ "segments",
27
+ "slices",
28
+ ],
29
+ },
30
+ ignoreInFilesPatterns: {
31
+ type: 'array',
32
+ items: {
33
+ type: 'string',
34
+ },
35
+ },
36
+ },
37
+ },
38
+ ],
39
+ },
40
+ defaultOptions: [
41
+ {
42
+ level: "slices",
43
+ ignoreInFilesPatterns: [],
44
+ },
45
+ ],
46
+ create(context, optionsWithDefault) {
47
+ return {
48
+ ImportDeclaration(node) {
49
+ (0, model_1.validateAndReport)(node, context, optionsWithDefault);
50
+ },
51
+ ImportExpression(node) {
52
+ (0, model_1.validateAndReport)(node, context, optionsWithDefault);
53
+ },
54
+ ExportAllDeclaration(node) {
55
+ (0, model_1.validateAndReport)(node, context, optionsWithDefault);
56
+ },
57
+ ExportNamedDeclaration(node) {
58
+ (0, model_1.validateAndReport)(node, context, optionsWithDefault);
59
+ },
60
+ Program(node) {
61
+ (0, validate_and_report_program_1.validateAndReportProgram)(node, context, optionsWithDefault);
62
+ },
63
+ };
64
+ },
65
+ });