UNPKG

@conarti/eslint-plugin-feature-sliced

Version:
60 lines (59 loc) 3.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.extractPathsInfo = void 0; const rule_1 = require("../rule"); const extract_feature_sliced_parts_1 = require("./extract-feature-sliced-parts"); const validate_extracted_feature_sliced_parts_1 = require("./validate-extracted-feature-sliced-parts"); function compareFeatureSlicedParts(fsPartsToCompare) { const { target, currentFile, } = fsPartsToCompare; const hasUnknownLayers = target.validatedFeatureSlicedParts.hasNotLayer || currentFile.validatedFeatureSlicedParts.hasNotLayer; const isSameLayer = target.validatedFeatureSlicedParts.hasLayer && currentFile.validatedFeatureSlicedParts.hasLayer && target.fsdParts.layer === currentFile.fsdParts.layer; const isSameSlice = target.validatedFeatureSlicedParts.hasSlice && currentFile.validatedFeatureSlicedParts.hasSlice && target.fsdParts.slice === currentFile.fsdParts.slice; const isSameSegment = target.fsdParts.segment === currentFile.fsdParts.segment; const isSameLayerWithoutSlices = isSameLayer && !target.validatedFeatureSlicedParts.canLayerContainSlices && !currentFile.validatedFeatureSlicedParts.canLayerContainSlices; return { hasUnknownLayers, isSameLayer, isSameSlice, isSameSegment, isSameLayerWithoutSlices, }; } function extractPathsInfo(node, context) { const { targetPath, normalizedTargetPath, normalizedCurrentFilePath, absoluteTargetPath, normalizedCwd, } = (0, rule_1.extractPaths)(node, context); const fsdPartsOfTarget = (0, extract_feature_sliced_parts_1.extractFeatureSlicedParts)(absoluteTargetPath, normalizedCwd); const fsdPartsOfCurrentFile = (0, extract_feature_sliced_parts_1.extractFeatureSlicedParts)(normalizedCurrentFilePath, normalizedCwd); const validatedFeatureSlicedPartsOfTarget = (0, validate_extracted_feature_sliced_parts_1.validateExtractedFeatureSlicedParts)(fsdPartsOfTarget); const validatedFeatureSlicedPartsOfCurrentFile = (0, validate_extracted_feature_sliced_parts_1.validateExtractedFeatureSlicedParts)(fsdPartsOfCurrentFile); const { hasUnknownLayers, isSameLayer, isSameSlice, isSameSegment, isSameLayerWithoutSlices, } = compareFeatureSlicedParts({ target: { validatedFeatureSlicedParts: validatedFeatureSlicedPartsOfTarget, fsdParts: fsdPartsOfTarget, }, currentFile: { validatedFeatureSlicedParts: validatedFeatureSlicedPartsOfCurrentFile, fsdParts: fsdPartsOfCurrentFile, }, }); return { targetPath, normalizedTargetPath, normalizedCurrentFilePath, absoluteTargetPath, fsdPartsOfTarget, fsdPartsOfCurrentFile, isSameLayer, isSameSlice, isSameSegment, isSameLayerWithoutSlices, hasUnknownLayers, validatedFeatureSlicedPartsOfTarget, validatedFeatureSlicedPartsOfCurrentFile, }; } exports.extractPathsInfo = extractPathsInfo;