@conarti/eslint-plugin-feature-sliced 1.0.5 → 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.
Files changed (78) hide show
  1. package/README.md +43 -38
  2. package/dist/index.cjs +1004 -0
  3. package/dist/index.d.cts +61 -0
  4. package/dist/index.d.ts +61 -0
  5. package/dist/index.js +978 -21
  6. package/package.json +39 -40
  7. package/dist/config.js +0 -27
  8. package/dist/configs/import-order/index.js +0 -20
  9. package/dist/configs/import-order/recommended.js +0 -28
  10. package/dist/configs/import-order/with-newlines-and-type-group.js +0 -28
  11. package/dist/configs/import-order/with-newlines.js +0 -28
  12. package/dist/configs/import-order/with-type-group.js +0 -28
  13. package/dist/configs/recommended.js +0 -11
  14. package/dist/configs/rules.js +0 -11
  15. package/dist/lib/feature-sliced/extract-feature-sliced-parts.js +0 -18
  16. package/dist/lib/feature-sliced/extract-layer.js +0 -21
  17. package/dist/lib/feature-sliced/extract-paths-info.js +0 -59
  18. package/dist/lib/feature-sliced/extract-segment.js +0 -18
  19. package/dist/lib/feature-sliced/extract-slice.js +0 -10
  20. package/dist/lib/feature-sliced/index.js +0 -10
  21. package/dist/lib/feature-sliced/layers.js +0 -16
  22. package/dist/lib/feature-sliced/validate-extracted-feature-sliced-parts.js +0 -29
  23. package/dist/lib/path/convert-to-absolute.js +0 -18
  24. package/dist/lib/path/index.js +0 -9
  25. package/dist/lib/path/is-path-relative.js +0 -7
  26. package/dist/lib/path/join-path.js +0 -12
  27. package/dist/lib/path/normalize-path.js +0 -19
  28. package/dist/lib/rule/create-rule.js +0 -7
  29. package/dist/lib/rule/extract-current-file-path.js +0 -11
  30. package/dist/lib/rule/extract-cwd.js +0 -13
  31. package/dist/lib/rule/extract-node-path.js +0 -13
  32. package/dist/lib/rule/extract-paths.js +0 -21
  33. package/dist/lib/rule/extract-rule-options.js +0 -7
  34. package/dist/lib/rule/get-source-range-without-quotes.js +0 -7
  35. package/dist/lib/rule/has-path.js +0 -11
  36. package/dist/lib/rule/index.js +0 -27
  37. package/dist/lib/rule/is-ignored-current-file.js +0 -12
  38. package/dist/lib/rule/is-ignored-target.js +0 -12
  39. package/dist/lib/rule/is-ignored.js +0 -12
  40. package/dist/lib/rule/is-node-type.js +0 -16
  41. package/dist/lib/rule/models.js +0 -2
  42. package/dist/lib/shared/get-by-reg-exp.js +0 -12
  43. package/dist/lib/shared/index.js +0 -11
  44. package/dist/lib/shared/is-null.js +0 -7
  45. package/dist/lib/shared/is-object.js +0 -7
  46. package/dist/lib/shared/is-undefined.js +0 -7
  47. package/dist/rules/absolute-relative/config.js +0 -2
  48. package/dist/rules/absolute-relative/index.js +0 -51
  49. package/dist/rules/absolute-relative/model/errors.js +0 -17
  50. package/dist/rules/absolute-relative/model/index.js +0 -5
  51. package/dist/rules/absolute-relative/model/should-be-absolute.js +0 -16
  52. package/dist/rules/absolute-relative/model/should-be-relative.js +0 -21
  53. package/dist/rules/absolute-relative/model/validate-and-report.js +0 -24
  54. package/dist/rules/layers-slices/config.js +0 -2
  55. package/dist/rules/layers-slices/index.js +0 -55
  56. package/dist/rules/layers-slices/model/errors.js +0 -22
  57. package/dist/rules/layers-slices/model/index.js +0 -5
  58. package/dist/rules/layers-slices/model/is-not-suitable-for-validation.js +0 -17
  59. package/dist/rules/layers-slices/model/specifiers/extract-import-specifiers.js +0 -8
  60. package/dist/rules/layers-slices/model/specifiers/has-errors-at-all-specifiers.js +0 -9
  61. package/dist/rules/layers-slices/model/specifiers/index.js +0 -7
  62. package/dist/rules/layers-slices/model/specifiers/validate-specifiers.js +0 -8
  63. package/dist/rules/layers-slices/model/validate-and-report.js +0 -46
  64. package/dist/rules/layers-slices/model/validate-node/index.js +0 -16
  65. package/dist/rules/layers-slices/model/validate-node/valid-by-layer-order.js +0 -10
  66. package/dist/rules/layers-slices/model/validate-node/valid-by-type-import.js +0 -9
  67. package/dist/rules/public-api/config.js +0 -2
  68. package/dist/rules/public-api/index.js +0 -65
  69. package/dist/rules/public-api/model/convert-to-public-api.js +0 -24
  70. package/dist/rules/public-api/model/errors.js +0 -34
  71. package/dist/rules/public-api/model/index.js +0 -5
  72. package/dist/rules/public-api/model/is-index-file.js +0 -7
  73. package/dist/rules/public-api/model/is-layer-public-api.js +0 -23
  74. package/dist/rules/public-api/model/is-segments-public-api.js +0 -11
  75. package/dist/rules/public-api/model/is-slice-public-api.js +0 -7
  76. package/dist/rules/public-api/model/should-be-from-public-api.js +0 -21
  77. package/dist/rules/public-api/model/validate-and-report-program.js +0 -15
  78. package/dist/rules/public-api/model/validate-and-report.js +0 -18
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractRuleOptions = void 0;
4
- function extractRuleOptions(optionsWithDefault) {
5
- return optionsWithDefault[0];
6
- }
7
- exports.extractRuleOptions = extractRuleOptions;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSourceRangeWithoutQuotes = void 0;
4
- function getSourceRangeWithoutQuotes([rangeStart, rangeEnd]) {
5
- return [rangeStart + 1, rangeEnd - 1];
6
- }
7
- exports.getSourceRangeWithoutQuotes = getSourceRangeWithoutQuotes;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasPath = void 0;
4
- const shared_1 = require("../shared");
5
- function hasPath(node) {
6
- if ((0, shared_1.isObject)(node) && 'source' in node) {
7
- return node.source !== null;
8
- }
9
- return false;
10
- }
11
- exports.hasPath = hasPath;
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractPaths = exports.isIgnoredTarget = exports.isIgnoredCurrentFile = exports.extractCwd = exports.extractCurrentFilePath = exports.extractNodePath = exports.isNodeType = exports.createRule = exports.isIgnored = exports.getSourceRangeWithoutQuotes = exports.hasPath = exports.extractRuleOptions = void 0;
4
- var extract_rule_options_1 = require("./extract-rule-options");
5
- Object.defineProperty(exports, "extractRuleOptions", { enumerable: true, get: function () { return extract_rule_options_1.extractRuleOptions; } });
6
- var has_path_1 = require("./has-path");
7
- Object.defineProperty(exports, "hasPath", { enumerable: true, get: function () { return has_path_1.hasPath; } });
8
- var get_source_range_without_quotes_1 = require("./get-source-range-without-quotes");
9
- Object.defineProperty(exports, "getSourceRangeWithoutQuotes", { enumerable: true, get: function () { return get_source_range_without_quotes_1.getSourceRangeWithoutQuotes; } });
10
- var is_ignored_1 = require("./is-ignored");
11
- Object.defineProperty(exports, "isIgnored", { enumerable: true, get: function () { return is_ignored_1.isIgnored; } });
12
- var create_rule_1 = require("./create-rule");
13
- Object.defineProperty(exports, "createRule", { enumerable: true, get: function () { return create_rule_1.createRule; } });
14
- var is_node_type_1 = require("./is-node-type");
15
- Object.defineProperty(exports, "isNodeType", { enumerable: true, get: function () { return is_node_type_1.isNodeType; } });
16
- var extract_node_path_1 = require("./extract-node-path");
17
- Object.defineProperty(exports, "extractNodePath", { enumerable: true, get: function () { return extract_node_path_1.extractNodePath; } });
18
- var extract_current_file_path_1 = require("./extract-current-file-path");
19
- Object.defineProperty(exports, "extractCurrentFilePath", { enumerable: true, get: function () { return extract_current_file_path_1.extractCurrentFilePath; } });
20
- var extract_cwd_1 = require("./extract-cwd");
21
- Object.defineProperty(exports, "extractCwd", { enumerable: true, get: function () { return extract_cwd_1.extractCwd; } });
22
- var is_ignored_current_file_1 = require("./is-ignored-current-file");
23
- Object.defineProperty(exports, "isIgnoredCurrentFile", { enumerable: true, get: function () { return is_ignored_current_file_1.isIgnoredCurrentFile; } });
24
- var is_ignored_target_1 = require("./is-ignored-target");
25
- Object.defineProperty(exports, "isIgnoredTarget", { enumerable: true, get: function () { return is_ignored_target_1.isIgnoredTarget; } });
26
- var extract_paths_1 = require("./extract-paths");
27
- Object.defineProperty(exports, "extractPaths", { enumerable: true, get: function () { return extract_paths_1.extractPaths; } });
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isIgnoredCurrentFile = void 0;
4
- const extract_current_file_path_1 = require("./extract-current-file-path");
5
- const extract_rule_options_1 = require("./extract-rule-options");
6
- const is_ignored_1 = require("./is-ignored");
7
- function isIgnoredCurrentFile(context, optionsWithDefault) {
8
- const ruleOptions = (0, extract_rule_options_1.extractRuleOptions)(optionsWithDefault);
9
- const normalizedCurrentFilePath = (0, extract_current_file_path_1.extractCurrentFilePath)(context);
10
- return (0, is_ignored_1.isIgnored)(normalizedCurrentFilePath, ruleOptions.ignoreInFilesPatterns);
11
- }
12
- exports.isIgnoredCurrentFile = isIgnoredCurrentFile;
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isIgnoredTarget = void 0;
4
- const extract_node_path_1 = require("./extract-node-path");
5
- const extract_rule_options_1 = require("./extract-rule-options");
6
- const is_ignored_1 = require("./is-ignored");
7
- function isIgnoredTarget(node, optionsWithDefault) {
8
- const { targetPath } = (0, extract_node_path_1.extractNodePath)(node);
9
- const userDefinedRuleOptions = (0, extract_rule_options_1.extractRuleOptions)(optionsWithDefault);
10
- return (0, is_ignored_1.isIgnored)(targetPath, userDefinedRuleOptions.ignorePatterns);
11
- }
12
- exports.isIgnoredTarget = isIgnoredTarget;
@@ -1,12 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isIgnored = void 0;
7
- const picomatch_1 = __importDefault(require("picomatch"));
8
- function isIgnored(path, patterns) {
9
- const match = (0, picomatch_1.default)(patterns);
10
- return match(path);
11
- }
12
- exports.isIgnored = isIgnored;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNodeType = void 0;
4
- const utils_1 = require("@typescript-eslint/utils");
5
- function isNodeType(node) {
6
- const isImport = utils_1.ASTUtils.isNodeOfTypes([utils_1.AST_NODE_TYPES.ImportSpecifier, utils_1.AST_NODE_TYPES.ImportDeclaration])(node);
7
- const isExport = utils_1.ASTUtils.isNodeOfTypes([utils_1.AST_NODE_TYPES.ExportAllDeclaration, utils_1.AST_NODE_TYPES.ExportNamedDeclaration])(node);
8
- if (isImport) {
9
- return node.importKind === 'type';
10
- }
11
- if (isExport) {
12
- return node.exportKind === 'type';
13
- }
14
- return false;
15
- }
16
- exports.isNodeType = isNodeType;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getByRegExp = void 0;
4
- function getByRegExp(target, regExp, fromEnd = false) {
5
- const results = target.match(regExp) || [];
6
- if (fromEnd) {
7
- const lastResult = results[results.length - 1];
8
- return lastResult || null;
9
- }
10
- return results[0] || null;
11
- }
12
- exports.getByRegExp = getByRegExp;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isUndefined = exports.isNull = exports.isObject = exports.getByRegExp = void 0;
4
- var get_by_reg_exp_1 = require("./get-by-reg-exp");
5
- Object.defineProperty(exports, "getByRegExp", { enumerable: true, get: function () { return get_by_reg_exp_1.getByRegExp; } });
6
- var is_object_1 = require("./is-object");
7
- Object.defineProperty(exports, "isObject", { enumerable: true, get: function () { return is_object_1.isObject; } });
8
- var is_null_1 = require("./is-null");
9
- Object.defineProperty(exports, "isNull", { enumerable: true, get: function () { return is_null_1.isNull; } });
10
- var is_undefined_1 = require("./is-undefined");
11
- Object.defineProperty(exports, "isUndefined", { enumerable: true, get: function () { return is_undefined_1.isUndefined; } });
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNull = void 0;
4
- function isNull(target) {
5
- return target === null;
6
- }
7
- exports.isNull = isNull;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isObject = void 0;
4
- function isObject(target) {
5
- return (typeof target === 'object' || typeof target === 'function') && (target !== null);
6
- }
7
- exports.isObject = isObject;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isUndefined = void 0;
4
- function isUndefined(target) {
5
- return target === undefined;
6
- }
7
- exports.isUndefined = isUndefined;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,51 +0,0 @@
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: 'absolute-relative',
7
- meta: {
8
- type: 'problem',
9
- docs: {
10
- description: 'Checks for absolute and relative paths',
11
- },
12
- messages: {
13
- ["must-be-relative-path"]: 'There must be relative paths',
14
- ["must-be-absolute-path"]: 'There must be absolute paths',
15
- },
16
- schema: [
17
- {
18
- type: 'object',
19
- properties: {
20
- ignoreInFilesPatterns: {
21
- type: 'array',
22
- items: {
23
- type: 'string',
24
- },
25
- },
26
- },
27
- },
28
- ],
29
- },
30
- defaultOptions: [
31
- {
32
- ignoreInFilesPatterns: [],
33
- },
34
- ],
35
- create(context, optionsWithDefault) {
36
- return {
37
- ImportDeclaration(node) {
38
- (0, model_1.validateAndReport)(node, context, optionsWithDefault);
39
- },
40
- ImportExpression(node) {
41
- (0, model_1.validateAndReport)(node, context, optionsWithDefault);
42
- },
43
- ExportAllDeclaration(node) {
44
- (0, model_1.validateAndReport)(node, context, optionsWithDefault, { needCheckForAbsolute: false });
45
- },
46
- ExportNamedDeclaration(node) {
47
- (0, model_1.validateAndReport)(node, context, optionsWithDefault, { needCheckForAbsolute: false });
48
- },
49
- };
50
- },
51
- });
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.reportShouldBeAbsolute = exports.reportShouldBeRelative = void 0;
4
- function reportShouldBeRelative(node, context) {
5
- context.report({
6
- node: node.source,
7
- messageId: "must-be-relative-path",
8
- });
9
- }
10
- exports.reportShouldBeRelative = reportShouldBeRelative;
11
- function reportShouldBeAbsolute(node, context) {
12
- context.report({
13
- node: node.source,
14
- messageId: "must-be-absolute-path",
15
- });
16
- }
17
- exports.reportShouldBeAbsolute = reportShouldBeAbsolute;
@@ -1,5 +0,0 @@
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,16 +0,0 @@
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 +0,0 @@
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 +0,0 @@
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 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,55 +0,0 @@
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,22 +0,0 @@
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 +0,0 @@
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,17 +0,0 @@
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;
@@ -1,8 +0,0 @@
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;
@@ -1,9 +0,0 @@
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;
@@ -1,7 +0,0 @@
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; } });
@@ -1,8 +0,0 @@
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,46 +0,0 @@
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;
@@ -1,16 +0,0 @@
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;
@@ -1,10 +0,0 @@
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;
@@ -1,9 +0,0 @@
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 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,65 +0,0 @@
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
- });