@featurevisor/core 3.11.0 → 4.0.0
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 +20 -2
- package/lib/assess-distribution/index.js +6 -2
- package/lib/assess-distribution/index.js.map +1 -1
- package/lib/benchmark/index.d.ts +1 -1
- package/lib/benchmark/index.js +15 -10
- package/lib/benchmark/index.js.map +1 -1
- package/lib/builder/applyContextToConditions.d.ts +5 -4
- package/lib/builder/applyContextToConditions.js +84 -89
- package/lib/builder/applyContextToConditions.js.map +1 -1
- package/lib/builder/applyContextToDatafile.d.ts +2 -2
- package/lib/builder/applyContextToDatafile.js +45 -149
- package/lib/builder/applyContextToDatafile.js.map +1 -1
- package/lib/builder/applyContextToSegments.d.ts +6 -4
- package/lib/builder/applyContextToSegments.js +9 -98
- package/lib/builder/applyContextToSegments.js.map +1 -1
- package/lib/builder/buildDatafile.d.ts +15 -6
- package/lib/builder/buildDatafile.js +320 -220
- package/lib/builder/buildDatafile.js.map +1 -1
- package/lib/builder/buildProject.d.ts +2 -1
- package/lib/builder/buildProject.js +36 -37
- package/lib/builder/buildProject.js.map +1 -1
- package/lib/builder/buildRuntimeDatafiles.js +2 -0
- package/lib/builder/buildRuntimeDatafiles.js.map +1 -1
- package/lib/builder/environments.d.ts +3 -0
- package/lib/builder/environments.js +26 -0
- package/lib/builder/environments.js.map +1 -0
- package/lib/builder/hashes.d.ts +5 -5
- package/lib/builder/hashes.js +82 -100
- package/lib/builder/hashes.js.map +1 -1
- package/lib/builder/inflate.d.ts +7 -0
- package/lib/builder/inflate.js +26 -0
- package/lib/builder/inflate.js.map +1 -0
- package/lib/builder/mutateVariables.d.ts +6 -2
- package/lib/builder/mutateVariables.js +26 -18
- package/lib/builder/mutateVariables.js.map +1 -1
- package/lib/builder/mutationEntries.d.ts +5 -0
- package/lib/builder/mutationEntries.js +23 -0
- package/lib/builder/mutationEntries.js.map +1 -0
- package/lib/builder/mutator.d.ts +4 -2
- package/lib/builder/mutator.js +20 -209
- package/lib/builder/mutator.js.map +1 -1
- package/lib/builder/traffic.d.ts +2 -4
- package/lib/builder/traffic.js +48 -19
- package/lib/builder/traffic.js.map +1 -1
- package/lib/builder/variableOverrideProgram.d.ts +9 -0
- package/lib/builder/variableOverrideProgram.js +147 -0
- package/lib/builder/variableOverrideProgram.js.map +1 -0
- package/lib/catalog.d.ts +23 -0
- package/lib/catalog.js +117 -0
- package/lib/catalog.js.map +1 -0
- package/lib/cli/cli.d.ts +2 -0
- package/lib/cli/cli.js +38 -13
- package/lib/cli/cli.js.map +1 -1
- package/lib/cli/options.js +72 -17
- package/lib/cli/options.js.map +1 -1
- package/lib/cli/plugins.js +11 -3
- package/lib/cli/plugins.js.map +1 -1
- package/lib/cli/suggestions.d.ts +4 -0
- package/lib/cli/suggestions.js +61 -0
- package/lib/cli/suggestions.js.map +1 -0
- package/lib/config/allowedConditions.d.ts +9 -0
- package/lib/config/allowedConditions.js +44 -0
- package/lib/config/allowedConditions.js.map +1 -0
- package/lib/config/index.d.ts +1 -0
- package/lib/config/index.js +1 -0
- package/lib/config/index.js.map +1 -1
- package/lib/config/projectConfig.d.ts +9 -3
- package/lib/config/projectConfig.js +68 -11
- package/lib/config/projectConfig.js.map +1 -1
- package/lib/config/removedGroups.d.ts +5 -0
- package/lib/config/removedGroups.js +62 -0
- package/lib/config/removedGroups.js.map +1 -0
- package/lib/datasource/adapter.d.ts +10 -1
- package/lib/datasource/adapter.js.map +1 -1
- package/lib/datasource/attributeNamespaces.d.ts +14 -0
- package/lib/datasource/attributeNamespaces.js +70 -0
- package/lib/datasource/attributeNamespaces.js.map +1 -0
- package/lib/datasource/composition.d.ts +5 -0
- package/lib/datasource/composition.js +19 -0
- package/lib/datasource/composition.js.map +1 -0
- package/lib/datasource/conditions.d.ts +20 -0
- package/lib/datasource/conditions.js +113 -0
- package/lib/datasource/conditions.js.map +1 -0
- package/lib/datasource/datasource.d.ts +18 -12
- package/lib/datasource/datasource.js +137 -76
- package/lib/datasource/datasource.js.map +1 -1
- package/lib/datasource/dependencies.d.ts +52 -0
- package/lib/datasource/dependencies.js +347 -0
- package/lib/datasource/dependencies.js.map +1 -0
- package/lib/datasource/filesystemAdapter.d.ts +31 -1
- package/lib/datasource/filesystemAdapter.js +581 -99
- package/lib/datasource/filesystemAdapter.js.map +1 -1
- package/lib/datasource/index.d.ts +3 -0
- package/lib/datasource/index.js +3 -0
- package/lib/datasource/index.js.map +1 -1
- package/lib/datasource/parseError.d.ts +5 -0
- package/lib/datasource/parseError.js +68 -0
- package/lib/datasource/parseError.js.map +1 -0
- package/lib/datasource/testSpecs.d.ts +4 -0
- package/lib/datasource/testSpecs.js +40 -0
- package/lib/datasource/testSpecs.js.map +1 -0
- package/lib/diff/details.js +31 -0
- package/lib/diff/details.js.map +1 -1
- package/lib/diff/index.d.ts +1 -1
- package/lib/diff/index.js +11 -4
- package/lib/diff/index.js.map +1 -1
- package/lib/error.d.ts +1 -0
- package/lib/error.js +6 -0
- package/lib/error.js.map +1 -1
- package/lib/evaluate/explain.d.ts +15 -2
- package/lib/evaluate/explain.js +273 -79
- package/lib/evaluate/explain.js.map +1 -1
- package/lib/evaluate/index.js +128 -17
- package/lib/evaluate/index.js.map +1 -1
- package/lib/evaluate/probeConditions.d.ts +30 -0
- package/lib/evaluate/probeConditions.js +165 -0
- package/lib/evaluate/probeConditions.js.map +1 -0
- package/lib/evaluate/validateExplanation.js +175 -16
- package/lib/evaluate/validateExplanation.js.map +1 -1
- package/lib/find-duplicate-segments/findDuplicateSegments.js +20 -1
- package/lib/find-duplicate-segments/findDuplicateSegments.js.map +1 -1
- package/lib/find-usage/index.d.ts +14 -1
- package/lib/find-usage/index.js +359 -155
- package/lib/find-usage/index.js.map +1 -1
- package/lib/generate-code/typescript.js +156 -60
- package/lib/generate-code/typescript.js.map +1 -1
- package/lib/info/index.js +11 -5
- package/lib/info/index.js.map +1 -1
- package/lib/init/index.js +234 -28
- package/lib/init/index.js.map +1 -1
- package/lib/linter/attributeSchema.d.ts +6 -11
- package/lib/linter/attributeSchema.js +59 -53
- package/lib/linter/attributeSchema.js.map +1 -1
- package/lib/linter/comparisonOperators.d.ts +18 -0
- package/lib/linter/comparisonOperators.js +82 -0
- package/lib/linter/comparisonOperators.js.map +1 -0
- package/lib/linter/composedOverrideSchema.d.ts +5 -0
- package/lib/linter/composedOverrideSchema.js +243 -0
- package/lib/linter/composedOverrideSchema.js.map +1 -0
- package/lib/linter/compositionWarnings.d.ts +8 -0
- package/lib/linter/compositionWarnings.js +212 -0
- package/lib/linter/compositionWarnings.js.map +1 -0
- package/lib/linter/conditionKinds.d.ts +12 -0
- package/lib/linter/conditionKinds.js +129 -0
- package/lib/linter/conditionKinds.js.map +1 -0
- package/lib/linter/conditionSchema.d.ts +8 -2
- package/lib/linter/conditionSchema.js +253 -52
- package/lib/linter/conditionSchema.js.map +1 -1
- package/lib/linter/contextWarnings.d.ts +13 -0
- package/lib/linter/contextWarnings.js +241 -0
- package/lib/linter/contextWarnings.js.map +1 -0
- package/lib/linter/definitionReferences.d.ts +39 -0
- package/lib/linter/definitionReferences.js +234 -0
- package/lib/linter/definitionReferences.js.map +1 -0
- package/lib/linter/dependencyDepth.d.ts +14 -0
- package/lib/linter/dependencyDepth.js +106 -0
- package/lib/linter/dependencyDepth.js.map +1 -0
- package/lib/linter/diagnostics.d.ts +129 -0
- package/lib/linter/diagnostics.js +84 -0
- package/lib/linter/diagnostics.js.map +1 -0
- package/lib/linter/featureSchema.d.ts +189 -72
- package/lib/linter/featureSchema.js +385 -210
- package/lib/linter/featureSchema.js.map +1 -1
- package/lib/linter/lintProject.d.ts +4 -1
- package/lib/linter/lintProject.js +449 -143
- package/lib/linter/lintProject.js.map +1 -1
- package/lib/linter/mutationNotation.d.ts +7 -1
- package/lib/linter/mutationNotation.js +40 -20
- package/lib/linter/mutationNotation.js.map +1 -1
- package/lib/linter/mutationOrder.d.ts +6 -0
- package/lib/linter/mutationOrder.js +105 -0
- package/lib/linter/mutationOrder.js.map +1 -0
- package/lib/linter/mutationResultPaths.d.ts +4 -0
- package/lib/linter/mutationResultPaths.js +131 -0
- package/lib/linter/mutationResultPaths.js.map +1 -0
- package/lib/linter/mutationSchema.d.ts +3 -0
- package/lib/linter/mutationSchema.js +32 -0
- package/lib/linter/mutationSchema.js.map +1 -0
- package/lib/linter/printError.d.ts +3 -0
- package/lib/linter/printError.js +38 -25
- package/lib/linter/printError.js.map +1 -1
- package/lib/linter/regexSafety.d.ts +19 -0
- package/lib/linter/regexSafety.js +307 -0
- package/lib/linter/regexSafety.js.map +1 -0
- package/lib/linter/removedConditionFields.d.ts +10 -0
- package/lib/linter/removedConditionFields.js +47 -0
- package/lib/linter/removedConditionFields.js.map +1 -0
- package/lib/linter/requiredFeaturesSchema.d.ts +2 -2
- package/lib/linter/requiredFeaturesSchema.js +32 -28
- package/lib/linter/requiredFeaturesSchema.js.map +1 -1
- package/lib/linter/requiredVariableCost.d.ts +5 -0
- package/lib/linter/requiredVariableCost.js +60 -0
- package/lib/linter/requiredVariableCost.js.map +1 -0
- package/lib/linter/requiredVariablesSchema.d.ts +13 -0
- package/lib/linter/requiredVariablesSchema.js +498 -0
- package/lib/linter/requiredVariablesSchema.js.map +1 -0
- package/lib/linter/reservedNames.d.ts +12 -0
- package/lib/linter/reservedNames.js +52 -0
- package/lib/linter/reservedNames.js.map +1 -0
- package/lib/linter/schema.d.ts +12 -15
- package/lib/linter/schema.js +108 -26
- package/lib/linter/schema.js.map +1 -1
- package/lib/linter/schemaFormats.d.ts +35 -0
- package/lib/linter/schemaFormats.js +66 -0
- package/lib/linter/schemaFormats.js.map +1 -0
- package/lib/linter/segmentSchema.d.ts +11 -1
- package/lib/linter/segmentSchema.js +12 -2
- package/lib/linter/segmentSchema.js.map +1 -1
- package/lib/linter/testSchema.d.ts +394 -2
- package/lib/linter/testSchema.js +565 -34
- package/lib/linter/testSchema.js.map +1 -1
- package/lib/linter/variableSchema.d.ts +60 -43
- package/lib/linter/variableSchema.js +459 -60
- package/lib/linter/variableSchema.js.map +1 -1
- package/lib/linter/zodHelpers.d.ts +8 -1
- package/lib/linter/zodHelpers.js +9 -1
- package/lib/linter/zodHelpers.js.map +1 -1
- package/lib/list/index.js +384 -66
- package/lib/list/index.js.map +1 -1
- package/lib/list/matrix.d.ts +2 -2
- package/lib/list/matrix.js +60 -39
- package/lib/list/matrix.js.map +1 -1
- package/lib/list/scenarios.d.ts +8 -0
- package/lib/list/scenarios.js +84 -0
- package/lib/list/scenarios.js.map +1 -0
- package/lib/promoter/index.d.ts +1 -1
- package/lib/promoter/index.js +469 -210
- package/lib/promoter/index.js.map +1 -1
- package/lib/sets.js +14 -5
- package/lib/sets.js.map +1 -1
- package/lib/tester/checks.d.ts +12 -0
- package/lib/tester/checks.js +418 -0
- package/lib/tester/checks.js.map +1 -0
- package/lib/tester/coverage.d.ts +16 -0
- package/lib/tester/coverage.js +64 -0
- package/lib/tester/coverage.js.map +1 -0
- package/lib/tester/datafileKey.d.ts +4 -0
- package/lib/tester/datafileKey.js +18 -0
- package/lib/tester/datafileKey.js.map +1 -0
- package/lib/tester/diagnostics.d.ts +5 -0
- package/lib/tester/diagnostics.js +32 -0
- package/lib/tester/diagnostics.js.map +1 -0
- package/lib/tester/index.d.ts +2 -0
- package/lib/tester/printTestResult.d.ts +3 -2
- package/lib/tester/printTestResult.js +53 -8
- package/lib/tester/printTestResult.js.map +1 -1
- package/lib/tester/provenance.d.ts +21 -0
- package/lib/tester/provenance.js +98 -0
- package/lib/tester/provenance.js.map +1 -0
- package/lib/tester/report.d.ts +78 -0
- package/lib/tester/report.js +246 -0
- package/lib/tester/report.js.map +1 -0
- package/lib/tester/segments.d.ts +23 -0
- package/lib/tester/segments.js +103 -0
- package/lib/tester/segments.js.map +1 -0
- package/lib/tester/testFeature.d.ts +2 -0
- package/lib/tester/testFeature.js +17 -8
- package/lib/tester/testFeature.js.map +1 -1
- package/lib/tester/testProject.d.ts +15 -3
- package/lib/tester/testProject.js +198 -83
- package/lib/tester/testProject.js.map +1 -1
- package/lib/tester/testSegment.d.ts +2 -4
- package/lib/tester/testSegment.js +89 -7
- package/lib/tester/testSegment.js.map +1 -1
- package/lib/tester/testVariable.d.ts +2 -2
- package/lib/tester/testVariable.js +195 -24
- package/lib/tester/testVariable.js.map +1 -1
- package/lib/utils/conditionReferences.d.ts +5 -0
- package/lib/utils/conditionReferences.js +30 -0
- package/lib/utils/conditionReferences.js.map +1 -0
- package/lib/utils/extractKeys.d.ts +7 -3
- package/lib/utils/extractKeys.js +32 -113
- package/lib/utils/extractKeys.js.map +1 -1
- package/lib/utils/git.d.ts +7 -2
- package/lib/utils/git.js +87 -72
- package/lib/utils/git.js.map +1 -1
- package/package.json +11 -8
- package/lib/builder/getFeatureRanges.d.ts +0 -11
- package/lib/builder/getFeatureRanges.js +0 -70
- package/lib/builder/getFeatureRanges.js.map +0 -1
- package/lib/datasource/requiredFeatures.d.ts +0 -14
- package/lib/datasource/requiredFeatures.js +0 -75
- package/lib/datasource/requiredFeatures.js.map +0 -1
- package/lib/linter/checkCircularDependency.d.ts +0 -3
- package/lib/linter/checkCircularDependency.js +0 -8
- package/lib/linter/checkCircularDependency.js.map +0 -1
- package/lib/linter/checkPercentageExceedingSlot.d.ts +0 -3
- package/lib/linter/checkPercentageExceedingSlot.js +0 -45
- package/lib/linter/checkPercentageExceedingSlot.js.map +0 -1
- package/lib/linter/groupSchema.d.ts +0 -11
- package/lib/linter/groupSchema.js +0 -31
- package/lib/linter/groupSchema.js.map +0 -1
|
@@ -40,24 +40,34 @@ const fs = __importStar(require("fs"));
|
|
|
40
40
|
const path = __importStar(require("path"));
|
|
41
41
|
const attributeSchema_1 = require("./attributeSchema");
|
|
42
42
|
const conditionSchema_1 = require("./conditionSchema");
|
|
43
|
+
const definitionReferences_1 = require("./definitionReferences");
|
|
44
|
+
const conditionKinds_1 = require("./conditionKinds");
|
|
43
45
|
const segmentSchema_1 = require("./segmentSchema");
|
|
44
|
-
const groupSchema_1 = require("./groupSchema");
|
|
45
46
|
const featureSchema_1 = require("./featureSchema");
|
|
47
|
+
const removedGroups_1 = require("../config/removedGroups");
|
|
46
48
|
const schema_1 = require("./schema");
|
|
47
49
|
const testSchema_1 = require("./testSchema");
|
|
48
50
|
const targetSchema_1 = require("./targetSchema");
|
|
49
51
|
const variableSchema_1 = require("./variableSchema");
|
|
50
|
-
const checkCircularDependency_1 = require("./checkCircularDependency");
|
|
51
|
-
const checkPercentageExceedingSlot_1 = require("./checkPercentageExceedingSlot");
|
|
52
52
|
const printError_1 = require("./printError");
|
|
53
53
|
const cliFormat_1 = require("../tester/cliFormat");
|
|
54
54
|
const validation_1 = require("../cli/validation");
|
|
55
55
|
const sets_1 = require("../sets");
|
|
56
|
-
const
|
|
56
|
+
const dependencies_1 = require("../datasource/dependencies");
|
|
57
57
|
const config_1 = require("../config");
|
|
58
|
+
const requiredVariableCost_1 = require("./requiredVariableCost");
|
|
59
|
+
const reservedNames_1 = require("./reservedNames");
|
|
60
|
+
const dependencyDepth_1 = require("./dependencyDepth");
|
|
61
|
+
const mutationOrder_1 = require("./mutationOrder");
|
|
62
|
+
const contextWarnings_1 = require("./contextWarnings");
|
|
63
|
+
const compositionWarnings_1 = require("./compositionWarnings");
|
|
64
|
+
const diagnostics_1 = require("./diagnostics");
|
|
65
|
+
const parseError_1 = require("../datasource/parseError");
|
|
66
|
+
const attributeNamespaces_1 = require("../datasource/attributeNamespaces");
|
|
58
67
|
const ENTITY_NAME_REGEX = /^[a-zA-Z0-9_\-./]+$/;
|
|
59
68
|
const ENTITY_NAME_REGEX_ERROR = "Names must be alphanumeric and can contain _, -, /, ., and the configured namespace character";
|
|
60
|
-
const
|
|
69
|
+
const ATTRIBUTE_NAME_REGEX = /^[a-zA-Z0-9_\-]+$/;
|
|
70
|
+
const ATTRIBUTE_NAME_REGEX_ERROR = "Attribute names must be alphanumeric and can contain _ and -. Dots, directory separators and the configured namespace character are not allowed.";
|
|
61
71
|
function escapeRegExp(value) {
|
|
62
72
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
63
73
|
}
|
|
@@ -70,7 +80,7 @@ function isReservedKey(key, reservedKeys) {
|
|
|
70
80
|
}
|
|
71
81
|
function getPathSegmentsFromKey(key, namespaceCharacter, entityType) {
|
|
72
82
|
const pathSegments = key.split(namespaceCharacter);
|
|
73
|
-
if (entityType === "test" &&
|
|
83
|
+
if ((entityType === "test" || entityType === "scenario") &&
|
|
74
84
|
pathSegments.length > 1 &&
|
|
75
85
|
["spec", "feature", "segment"].includes(pathSegments[pathSegments.length - 1])) {
|
|
76
86
|
const suffix = pathSegments[pathSegments.length - 1];
|
|
@@ -81,7 +91,7 @@ function getPathSegmentsFromKey(key, namespaceCharacter, entityType) {
|
|
|
81
91
|
}
|
|
82
92
|
function getReservedNameCheckValue(entityType, name, isFile, extension) {
|
|
83
93
|
let value = isFile && name.endsWith(`.${extension}`) ? name.slice(0, -extension.length - 1) : name;
|
|
84
|
-
if (entityType === "test" && isFile) {
|
|
94
|
+
if ((entityType === "test" || entityType === "scenario") && isFile) {
|
|
85
95
|
for (const suffix of [".spec", ".feature", ".segment"]) {
|
|
86
96
|
if (value.endsWith(suffix)) {
|
|
87
97
|
value = value.slice(0, -suffix.length);
|
|
@@ -112,18 +122,24 @@ function collectExplicitAttributePaths(attributeKey, attribute, result) {
|
|
|
112
122
|
}
|
|
113
123
|
async function lintProject(deps, options = {}) {
|
|
114
124
|
const { projectConfig, datasource } = deps;
|
|
125
|
+
await (0, removedGroups_1.assertNoLegacyDatasourceGroups)(datasource);
|
|
115
126
|
const isJsonMode = options.json === true;
|
|
116
127
|
const errors = [];
|
|
128
|
+
const warnings = [];
|
|
129
|
+
const reportedParseErrors = new Set();
|
|
117
130
|
function log(...args) {
|
|
118
131
|
if (!isJsonMode) {
|
|
119
132
|
console.log(...args);
|
|
120
133
|
}
|
|
121
134
|
}
|
|
135
|
+
function logProgress(count, entityType) {
|
|
136
|
+
log(`Linting ${count} ${entityType}${count === 1 ? "" : "s"}...\n`);
|
|
137
|
+
}
|
|
122
138
|
function getFullPathFromKey(type, key, relative = false) {
|
|
123
139
|
const fileName = `${getPathSegmentsFromKey(key, projectConfig.namespaceCharacter, type).join(path.sep)}.${datasource.getExtension()}`;
|
|
124
140
|
let fullPath = "";
|
|
125
141
|
if (type === "attribute") {
|
|
126
|
-
fullPath = path.join(projectConfig.attributesDirectoryPath,
|
|
142
|
+
fullPath = path.join(projectConfig.attributesDirectoryPath, `${key}.${datasource.getExtension()}`);
|
|
127
143
|
}
|
|
128
144
|
else if (type === "segment") {
|
|
129
145
|
fullPath = path.join(projectConfig.segmentsDirectoryPath, fileName);
|
|
@@ -131,9 +147,6 @@ async function lintProject(deps, options = {}) {
|
|
|
131
147
|
else if (type === "feature") {
|
|
132
148
|
fullPath = path.join(projectConfig.featuresDirectoryPath, fileName);
|
|
133
149
|
}
|
|
134
|
-
else if (type === "group") {
|
|
135
|
-
fullPath = path.join(projectConfig.groupsDirectoryPath, fileName);
|
|
136
|
-
}
|
|
137
150
|
else if (type === "schema") {
|
|
138
151
|
fullPath = path.join(projectConfig.schemasDirectoryPath, fileName);
|
|
139
152
|
}
|
|
@@ -161,9 +174,6 @@ async function lintProject(deps, options = {}) {
|
|
|
161
174
|
if (type === "feature") {
|
|
162
175
|
return projectConfig.featuresDirectoryPath;
|
|
163
176
|
}
|
|
164
|
-
if (type === "group") {
|
|
165
|
-
return projectConfig.groupsDirectoryPath;
|
|
166
|
-
}
|
|
167
177
|
if (type === "schema") {
|
|
168
178
|
return projectConfig.schemasDirectoryPath;
|
|
169
179
|
}
|
|
@@ -221,6 +231,11 @@ async function lintProject(deps, options = {}) {
|
|
|
221
231
|
function recordError(error) {
|
|
222
232
|
errors.push(error);
|
|
223
233
|
}
|
|
234
|
+
function reportWarning(warning) {
|
|
235
|
+
warnings.push(warning);
|
|
236
|
+
if (!isJsonMode)
|
|
237
|
+
console.log(` => Warning: ${warning.message} (${warning.entityType} ${warning.key}: ${warning.path.join(".")})`);
|
|
238
|
+
}
|
|
224
239
|
async function reportSimpleError({ entityType, key, fullPath, message, detail, pathParts = [], code, value, }) {
|
|
225
240
|
recordError({
|
|
226
241
|
filePath: path.relative(process.cwd(), fullPath),
|
|
@@ -249,6 +264,33 @@ async function lintProject(deps, options = {}) {
|
|
|
249
264
|
: undefined;
|
|
250
265
|
const targetPath = pathFromError || fullPath;
|
|
251
266
|
const message = error instanceof Error ? error.message : String(error);
|
|
267
|
+
if (error instanceof parseError_1.EntityParseError) {
|
|
268
|
+
if (reportedParseErrors.has(targetPath))
|
|
269
|
+
return;
|
|
270
|
+
reportedParseErrors.add(targetPath);
|
|
271
|
+
for (const type of [
|
|
272
|
+
"attribute",
|
|
273
|
+
"segment",
|
|
274
|
+
"feature",
|
|
275
|
+
"variable",
|
|
276
|
+
"schema",
|
|
277
|
+
"target",
|
|
278
|
+
"test",
|
|
279
|
+
"scenario",
|
|
280
|
+
]) {
|
|
281
|
+
if (targetPath === fullPath)
|
|
282
|
+
break;
|
|
283
|
+
const relativePath = path.relative(getEntityDirectoryPath(type), targetPath);
|
|
284
|
+
if (relativePath.startsWith(`..${path.sep}`) || path.isAbsolute(relativePath))
|
|
285
|
+
continue;
|
|
286
|
+
entityType = type;
|
|
287
|
+
key = relativePath
|
|
288
|
+
.slice(0, -(datasource.getExtension().length + 1))
|
|
289
|
+
.split(path.sep)
|
|
290
|
+
.join(projectConfig.namespaceCharacter);
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
252
294
|
recordError({
|
|
253
295
|
filePath: path.relative(process.cwd(), targetPath),
|
|
254
296
|
entityType,
|
|
@@ -259,12 +301,17 @@ async function lintProject(deps, options = {}) {
|
|
|
259
301
|
});
|
|
260
302
|
if (!isJsonMode) {
|
|
261
303
|
await printEntityHeader(entityType, key, targetPath);
|
|
304
|
+
console.log(cliFormat_1.CLI_FORMAT_RED, ` => Error: ${message}`);
|
|
305
|
+
if (options.verbose || deps.options.verbose) {
|
|
306
|
+
console.log(error instanceof parseError_1.EntityParseError ? error.cause : error);
|
|
307
|
+
}
|
|
262
308
|
console.log("");
|
|
263
|
-
console.log(error);
|
|
264
309
|
}
|
|
265
310
|
}
|
|
266
|
-
async function reportZodValidationError(entityType, key, fullPath, error) {
|
|
267
|
-
const issues = (0, printError_1.getLintIssuesFromZodError)(error);
|
|
311
|
+
async function reportZodValidationError(entityType, key, fullPath, error, { ignoreUnknownReferences = false } = {}) {
|
|
312
|
+
const issues = (0, printError_1.getLintIssuesFromZodError)(error).filter((issue) => !(ignoreUnknownReferences && issue.unknownReference));
|
|
313
|
+
if (issues.length === 0)
|
|
314
|
+
return;
|
|
268
315
|
const issuesWithTargetPath = [];
|
|
269
316
|
for (const issue of issues) {
|
|
270
317
|
const targetPath = fullPath;
|
|
@@ -293,7 +340,7 @@ async function lintProject(deps, options = {}) {
|
|
|
293
340
|
await printEntityHeader(entityType, key, targetPathKey);
|
|
294
341
|
for (const { issue, pathRelativeToFile } of groupItems) {
|
|
295
342
|
console.log(cliFormat_1.CLI_FORMAT_RED, ` => Error: ${issue.message}`);
|
|
296
|
-
console.log(" Path:", pathRelativeToFile.join("."));
|
|
343
|
+
console.log(" Path:", pathRelativeToFile.join(".") || "(root)");
|
|
297
344
|
if (typeof issue.value !== "undefined" && issue.value !== "undefined") {
|
|
298
345
|
console.log(" Value:", issue.value);
|
|
299
346
|
}
|
|
@@ -303,7 +350,7 @@ async function lintProject(deps, options = {}) {
|
|
|
303
350
|
}
|
|
304
351
|
else {
|
|
305
352
|
await printEntityHeader(entityType, key, fullPath);
|
|
306
|
-
(0, printError_1.
|
|
353
|
+
(0, printError_1.printLintIssues)(issues);
|
|
307
354
|
}
|
|
308
355
|
}
|
|
309
356
|
}
|
|
@@ -327,7 +374,24 @@ async function lintProject(deps, options = {}) {
|
|
|
327
374
|
}
|
|
328
375
|
}
|
|
329
376
|
// lint attributes
|
|
330
|
-
|
|
377
|
+
let attributes;
|
|
378
|
+
try {
|
|
379
|
+
attributes = await datasource.listAttributes();
|
|
380
|
+
}
|
|
381
|
+
catch (error) {
|
|
382
|
+
if (!(error instanceof attributeNamespaces_1.AttributeNamespaceError))
|
|
383
|
+
throw error;
|
|
384
|
+
attributes = error.validKeys;
|
|
385
|
+
for (const { key, filePath } of error.invalidAttributes) {
|
|
386
|
+
await reportSimpleError({
|
|
387
|
+
entityType: "attribute",
|
|
388
|
+
key,
|
|
389
|
+
fullPath: filePath,
|
|
390
|
+
message: attributeNamespaces_1.ATTRIBUTE_NAMESPACE_MESSAGE,
|
|
391
|
+
code: "invalid_attribute_namespace",
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
}
|
|
331
395
|
const attributeZodSchema = (0, attributeSchema_1.getAttributeZodSchema)();
|
|
332
396
|
const attributesByKey = {};
|
|
333
397
|
for (const key of attributes) {
|
|
@@ -339,16 +403,15 @@ async function lintProject(deps, options = {}) {
|
|
|
339
403
|
}
|
|
340
404
|
}
|
|
341
405
|
if (!options.entityType || options.entityType === "attribute") {
|
|
342
|
-
await lintReservedNamespaceCharacterInEntityPaths("attribute");
|
|
343
406
|
const filteredKeys = !keyPattern
|
|
344
407
|
? attributes
|
|
345
408
|
: attributes.filter((key) => keyPattern.test(key));
|
|
346
409
|
if (filteredKeys.length > 0) {
|
|
347
|
-
|
|
410
|
+
logProgress(filteredKeys.length, "attribute");
|
|
348
411
|
}
|
|
349
412
|
for (const key of filteredKeys) {
|
|
350
413
|
const fullPath = getFullPathFromKey("attribute", key);
|
|
351
|
-
if (!
|
|
414
|
+
if (!ATTRIBUTE_NAME_REGEX.test(key)) {
|
|
352
415
|
await reportSimpleError({
|
|
353
416
|
entityType: "attribute",
|
|
354
417
|
key,
|
|
@@ -358,9 +421,29 @@ async function lintProject(deps, options = {}) {
|
|
|
358
421
|
code: "invalid_name",
|
|
359
422
|
});
|
|
360
423
|
}
|
|
424
|
+
const reservedName = (0, reservedNames_1.getInheritedPropertyNameError)(key, "Attribute name");
|
|
425
|
+
if (reservedName) {
|
|
426
|
+
await reportSimpleError({
|
|
427
|
+
entityType: "attribute",
|
|
428
|
+
key,
|
|
429
|
+
fullPath,
|
|
430
|
+
message: reservedName,
|
|
431
|
+
code: "reserved_name",
|
|
432
|
+
});
|
|
433
|
+
}
|
|
361
434
|
try {
|
|
362
435
|
const parsed = attributesByKey[key] ?? (await datasource.readAttribute(key));
|
|
363
|
-
const
|
|
436
|
+
for (const property of (0, reservedNames_1.findInheritedPropertyNames)(parsed)) {
|
|
437
|
+
await reportSimpleError({
|
|
438
|
+
entityType: "attribute",
|
|
439
|
+
key,
|
|
440
|
+
fullPath,
|
|
441
|
+
message: (0, reservedNames_1.getInheritedPropertyNameError)(property.name, "Property name"),
|
|
442
|
+
pathParts: property.path,
|
|
443
|
+
code: "reserved_name",
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
const result = attributeZodSchema.safeParse(parsed, diagnostics_1.diagnosticParseOptions);
|
|
364
447
|
if (!result.success && "error" in result) {
|
|
365
448
|
await reportZodValidationError("attribute", key, fullPath, result.error);
|
|
366
449
|
}
|
|
@@ -379,15 +462,96 @@ async function lintProject(deps, options = {}) {
|
|
|
379
462
|
collectExplicitAttributePaths(key, parsed, explicitAttributePaths);
|
|
380
463
|
}
|
|
381
464
|
const flattenedAttributes = Array.from(explicitAttributePaths);
|
|
465
|
+
// Load both key spaces before linting either one so a focused feature or
|
|
466
|
+
// variable lint can report collisions independently.
|
|
467
|
+
const variables = await datasource.listVariables();
|
|
468
|
+
const variablesByKey = {};
|
|
469
|
+
for (const key of variables) {
|
|
470
|
+
try {
|
|
471
|
+
variablesByKey[key] = await datasource.readVariable(key);
|
|
472
|
+
}
|
|
473
|
+
catch {
|
|
474
|
+
// Variable read failures are reported during variable linting below.
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
// lint features
|
|
478
|
+
const features = await datasource.listFeatures();
|
|
479
|
+
const featuresByKey = {};
|
|
480
|
+
for (const key of features) {
|
|
481
|
+
try {
|
|
482
|
+
featuresByKey[key] = await datasource.readFeature(key);
|
|
483
|
+
}
|
|
484
|
+
catch {
|
|
485
|
+
// Feature read failures are reported during feature linting below.
|
|
486
|
+
}
|
|
487
|
+
}
|
|
382
488
|
// lint segments
|
|
383
489
|
const segments = await datasource.listSegments();
|
|
384
|
-
const
|
|
490
|
+
const segmentsByKey = {};
|
|
491
|
+
for (const key of segments) {
|
|
492
|
+
try {
|
|
493
|
+
segmentsByKey[key] = await datasource.readSegment(key);
|
|
494
|
+
}
|
|
495
|
+
catch {
|
|
496
|
+
// Read errors are reported alongside the segment's schema diagnostics.
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
const referenceIndex = {
|
|
500
|
+
attributes: attributesByKey,
|
|
501
|
+
segments: segmentsByKey,
|
|
502
|
+
features: featuresByKey,
|
|
503
|
+
variables: variablesByKey,
|
|
504
|
+
};
|
|
505
|
+
async function reportArchivedReferences(entityType, key, fullPath, definition) {
|
|
506
|
+
for (const issue of (0, definitionReferences_1.getArchivedReferenceIssues)(entityType, definition, referenceIndex)) {
|
|
507
|
+
await reportSimpleError({
|
|
508
|
+
entityType,
|
|
509
|
+
key,
|
|
510
|
+
fullPath,
|
|
511
|
+
message: issue.message,
|
|
512
|
+
pathParts: issue.path,
|
|
513
|
+
code: "archived_reference",
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
function reportDeprecatedReferences(entityType, key, fullPath, definition) {
|
|
518
|
+
for (const warning of (0, definitionReferences_1.getDeprecatedReferenceWarnings)(entityType, definition, referenceIndex)) {
|
|
519
|
+
reportWarning({
|
|
520
|
+
filePath: path.relative(process.cwd(), fullPath),
|
|
521
|
+
entityType,
|
|
522
|
+
key,
|
|
523
|
+
path: warning.path,
|
|
524
|
+
code: "deprecated_reference",
|
|
525
|
+
message: warning.message,
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
async function reportConditionKinds(entityType, key, fullPath, definition) {
|
|
530
|
+
for (const issue of (0, conditionKinds_1.getConditionKindIssues)(entityType, definition, projectConfig.allowedConditions)) {
|
|
531
|
+
await reportSimpleError({
|
|
532
|
+
entityType,
|
|
533
|
+
key,
|
|
534
|
+
fullPath,
|
|
535
|
+
message: issue.message,
|
|
536
|
+
pathParts: issue.path,
|
|
537
|
+
code: "disallowed_condition",
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
const isArchived = (definition) => !!definition &&
|
|
542
|
+
typeof definition === "object" &&
|
|
543
|
+
definition.archived === true;
|
|
544
|
+
const conditionsZodSchema = (0, conditionSchema_1.getConditionsZodSchema)(projectConfig, attributesByKey, schemasByKey, featuresByKey, variablesByKey, segments);
|
|
385
545
|
const segmentZodSchema = (0, segmentSchema_1.getSegmentZodSchema)(projectConfig, conditionsZodSchema);
|
|
546
|
+
// Archived definitions never reach a datafile. Lint checks their shape alone, resolving
|
|
547
|
+
// no attribute, segment, feature or global variable, so what they used can change or go.
|
|
548
|
+
const isolatedConditionsZodSchema = (0, conditionSchema_1.getConditionsZodSchema)(projectConfig, {}, schemasByKey, {}, {}, []);
|
|
549
|
+
const isolatedSegmentZodSchema = (0, segmentSchema_1.getSegmentZodSchema)(projectConfig, isolatedConditionsZodSchema);
|
|
386
550
|
if (!options.entityType || options.entityType === "segment") {
|
|
387
551
|
await lintReservedNamespaceCharacterInEntityPaths("segment");
|
|
388
552
|
const filteredKeys = !keyPattern ? segments : segments.filter((key) => keyPattern.test(key));
|
|
389
553
|
if (filteredKeys.length > 0) {
|
|
390
|
-
|
|
554
|
+
logProgress(filteredKeys.length, "segment");
|
|
391
555
|
}
|
|
392
556
|
for (const key of filteredKeys) {
|
|
393
557
|
const fullPath = getFullPathFromKey("segment", key);
|
|
@@ -403,36 +567,29 @@ async function lintProject(deps, options = {}) {
|
|
|
403
567
|
}
|
|
404
568
|
try {
|
|
405
569
|
const parsed = await datasource.readSegment(key);
|
|
406
|
-
const
|
|
570
|
+
const archived = isArchived(parsed);
|
|
571
|
+
const result = (archived ? isolatedSegmentZodSchema : segmentZodSchema).safeParse(parsed, diagnostics_1.diagnosticParseOptions);
|
|
407
572
|
if (!result.success && "error" in result) {
|
|
408
|
-
await reportZodValidationError("segment", key, fullPath, result.error
|
|
573
|
+
await reportZodValidationError("segment", key, fullPath, result.error, {
|
|
574
|
+
ignoreUnknownReferences: archived,
|
|
575
|
+
});
|
|
409
576
|
}
|
|
577
|
+
await reportArchivedReferences("segment", key, fullPath, parsed);
|
|
578
|
+
await reportConditionKinds("segment", key, fullPath, parsed);
|
|
579
|
+
reportDeprecatedReferences("segment", key, fullPath, parsed);
|
|
410
580
|
}
|
|
411
581
|
catch (error) {
|
|
412
582
|
await reportThrownError("segment", key, fullPath, error);
|
|
413
583
|
}
|
|
414
584
|
}
|
|
415
585
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
const variables = await datasource.listVariables();
|
|
419
|
-
// lint features
|
|
420
|
-
const features = await datasource.listFeatures();
|
|
421
|
-
const featuresByKey = {};
|
|
422
|
-
for (const key of features) {
|
|
423
|
-
try {
|
|
424
|
-
featuresByKey[key] = await datasource.readFeature(key);
|
|
425
|
-
}
|
|
426
|
-
catch {
|
|
427
|
-
// Feature read failures are reported during feature linting below.
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
const featureZodSchema = (0, featureSchema_1.getFeatureZodSchema)(projectConfig, conditionsZodSchema, flattenedAttributes, segments, features, schemas, schemasByKey, featuresByKey);
|
|
586
|
+
const featureZodSchema = (0, featureSchema_1.getFeatureZodSchema)(projectConfig, conditionsZodSchema, flattenedAttributes, segments, features, schemas, schemasByKey, featuresByKey, variablesByKey);
|
|
587
|
+
const isolatedFeatureZodSchema = (0, featureSchema_1.getFeatureZodSchema)(projectConfig, isolatedConditionsZodSchema, [], [], [], schemas, schemasByKey, {}, {});
|
|
431
588
|
if (!options.entityType || options.entityType === "feature") {
|
|
432
589
|
await lintReservedNamespaceCharacterInEntityPaths("feature");
|
|
433
590
|
const filteredKeys = !keyPattern ? features : features.filter((key) => keyPattern.test(key));
|
|
434
591
|
if (filteredKeys.length > 0) {
|
|
435
|
-
|
|
592
|
+
logProgress(filteredKeys.length, "feature");
|
|
436
593
|
}
|
|
437
594
|
for (const key of filteredKeys) {
|
|
438
595
|
const fullPath = getFullPathFromKey("feature", key);
|
|
@@ -447,14 +604,14 @@ async function lintProject(deps, options = {}) {
|
|
|
447
604
|
});
|
|
448
605
|
}
|
|
449
606
|
if (options.entityType === "feature" &&
|
|
450
|
-
!projectConfig.
|
|
607
|
+
!projectConfig.allowFeatureAndVariableKeyCollisions &&
|
|
451
608
|
variables.includes(key)) {
|
|
452
609
|
await reportSimpleError({
|
|
453
610
|
entityType: "feature",
|
|
454
611
|
key,
|
|
455
612
|
fullPath,
|
|
456
613
|
message: `Feature "${key}" conflicts with a global variable using the same key`,
|
|
457
|
-
detail: "Rename either entity, or set
|
|
614
|
+
detail: "Rename either entity, or set allowFeatureAndVariableKeyCollisions to true in featurevisor.config.js.",
|
|
458
615
|
code: "feature_variable_key_collision",
|
|
459
616
|
});
|
|
460
617
|
}
|
|
@@ -471,37 +628,44 @@ async function lintProject(deps, options = {}) {
|
|
|
471
628
|
let parsed;
|
|
472
629
|
try {
|
|
473
630
|
parsed = featuresByKey[key] ?? (await datasource.readFeature(key));
|
|
474
|
-
const
|
|
631
|
+
const archived = isArchived(parsed);
|
|
632
|
+
const result = (archived ? isolatedFeatureZodSchema : featureZodSchema).safeParse(parsed, diagnostics_1.diagnosticParseOptions);
|
|
475
633
|
if (!result.success && "error" in result) {
|
|
476
|
-
await reportZodValidationError("feature", key, fullPath, result.error
|
|
634
|
+
await reportZodValidationError("feature", key, fullPath, result.error, {
|
|
635
|
+
ignoreUnknownReferences: archived,
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
await reportArchivedReferences("feature", key, fullPath, parsed);
|
|
639
|
+
await reportConditionKinds("feature", key, fullPath, parsed);
|
|
640
|
+
reportDeprecatedReferences("feature", key, fullPath, parsed);
|
|
641
|
+
if (options.v3MutationOrder) {
|
|
642
|
+
for (const change of (0, mutationOrder_1.getMutationOrderChanges)(parsed)) {
|
|
643
|
+
reportWarning({
|
|
644
|
+
filePath: path.relative(process.cwd(), fullPath),
|
|
645
|
+
entityType: "feature",
|
|
646
|
+
key,
|
|
647
|
+
path: change.path,
|
|
648
|
+
code: "mutation_order_changed",
|
|
649
|
+
message: change.message,
|
|
650
|
+
});
|
|
651
|
+
}
|
|
477
652
|
}
|
|
478
653
|
}
|
|
479
654
|
catch (error) {
|
|
480
655
|
await reportThrownError("feature", key, fullPath, error);
|
|
481
656
|
}
|
|
482
|
-
if (parsed && (parsed.required || parsed.requiredFeatures)) {
|
|
483
|
-
try {
|
|
484
|
-
await (0, checkCircularDependency_1.checkForCircularDependencyInRequired)(datasource, key, (0, requiredFeatures_1.normalizeFeatureRequirements)(parsed));
|
|
485
|
-
}
|
|
486
|
-
catch (error) {
|
|
487
|
-
await reportSimpleError({
|
|
488
|
-
entityType: "feature",
|
|
489
|
-
key,
|
|
490
|
-
fullPath,
|
|
491
|
-
message: error instanceof Error ? error.message : String(error),
|
|
492
|
-
code: error instanceof Error ? error.name : "error",
|
|
493
|
-
});
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
657
|
}
|
|
497
658
|
}
|
|
498
659
|
// lint global variables
|
|
499
|
-
const
|
|
660
|
+
const getCompositionWarnings = (0, compositionWarnings_1.createCompositionWarningInspector)(featuresByKey, variablesByKey, schemasByKey);
|
|
661
|
+
let currentVariableKey = "value";
|
|
662
|
+
const variableZodSchema = (0, variableSchema_1.getVariableZodSchema)(projectConfig, attributesByKey, segments, featuresByKey, schemasByKey, variablesByKey, () => currentVariableKey);
|
|
663
|
+
const isolatedVariableZodSchema = (0, variableSchema_1.getVariableZodSchema)(projectConfig, {}, [], {}, schemasByKey, {}, () => currentVariableKey);
|
|
500
664
|
if (!options.entityType || options.entityType === "variable") {
|
|
501
665
|
await lintReservedNamespaceCharacterInEntityPaths("variable");
|
|
502
666
|
const filteredKeys = !keyPattern ? variables : variables.filter((key) => keyPattern.test(key));
|
|
503
667
|
if (filteredKeys.length > 0) {
|
|
504
|
-
|
|
668
|
+
logProgress(filteredKeys.length, "variable");
|
|
505
669
|
}
|
|
506
670
|
for (const key of filteredKeys) {
|
|
507
671
|
const fullPath = getFullPathFromKey("variable", key);
|
|
@@ -515,13 +679,13 @@ async function lintProject(deps, options = {}) {
|
|
|
515
679
|
code: "reserved_key",
|
|
516
680
|
});
|
|
517
681
|
}
|
|
518
|
-
if (!projectConfig.
|
|
682
|
+
if (!projectConfig.allowFeatureAndVariableKeyCollisions && features.includes(key)) {
|
|
519
683
|
await reportSimpleError({
|
|
520
684
|
entityType: "variable",
|
|
521
685
|
key,
|
|
522
686
|
fullPath,
|
|
523
687
|
message: `Variable "${key}" conflicts with a feature using the same key`,
|
|
524
|
-
detail: "Rename either entity, or set
|
|
688
|
+
detail: "Rename either entity, or set allowFeatureAndVariableKeyCollisions to true in featurevisor.config.js.",
|
|
525
689
|
code: "feature_variable_key_collision",
|
|
526
690
|
});
|
|
527
691
|
}
|
|
@@ -536,73 +700,41 @@ async function lintProject(deps, options = {}) {
|
|
|
536
700
|
});
|
|
537
701
|
}
|
|
538
702
|
try {
|
|
539
|
-
const parsed = await datasource.readVariable(key);
|
|
540
|
-
|
|
703
|
+
const parsed = variablesByKey[key] ?? (await datasource.readVariable(key));
|
|
704
|
+
currentVariableKey = key;
|
|
705
|
+
const archived = isArchived(parsed);
|
|
706
|
+
const result = (archived ? isolatedVariableZodSchema : variableZodSchema).safeParse(parsed, diagnostics_1.diagnosticParseOptions);
|
|
707
|
+
await reportArchivedReferences("variable", key, fullPath, parsed);
|
|
708
|
+
await reportConditionKinds("variable", key, fullPath, parsed);
|
|
709
|
+
reportDeprecatedReferences("variable", key, fullPath, parsed);
|
|
541
710
|
if (!result.success && "error" in result) {
|
|
542
|
-
await reportZodValidationError("variable", key, fullPath, result.error
|
|
711
|
+
await reportZodValidationError("variable", key, fullPath, result.error, {
|
|
712
|
+
ignoreUnknownReferences: archived,
|
|
713
|
+
});
|
|
543
714
|
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
if (!options.entityType || options.entityType === "group") {
|
|
554
|
-
await lintReservedNamespaceCharacterInEntityPaths("group");
|
|
555
|
-
const filteredKeys = !keyPattern ? groups : groups.filter((key) => keyPattern.test(key));
|
|
556
|
-
if (filteredKeys.length > 0) {
|
|
557
|
-
log(`Linting ${filteredKeys.length} groups...\n`);
|
|
558
|
-
}
|
|
559
|
-
for (const key of filteredKeys) {
|
|
560
|
-
const fullPath = getFullPathFromKey("group", key);
|
|
561
|
-
if (!isValidEntityKey(key, projectConfig.namespaceCharacter)) {
|
|
562
|
-
await reportSimpleError({
|
|
563
|
-
entityType: "group",
|
|
564
|
-
key,
|
|
565
|
-
fullPath,
|
|
566
|
-
message: `Invalid name: "${key}"`,
|
|
567
|
-
detail: ENTITY_NAME_REGEX_ERROR,
|
|
568
|
-
code: "invalid_name",
|
|
569
|
-
});
|
|
570
|
-
}
|
|
571
|
-
let parsed;
|
|
572
|
-
try {
|
|
573
|
-
parsed = await datasource.readGroup(key);
|
|
574
|
-
const result = groupZodSchema.safeParse(parsed);
|
|
575
|
-
if (!result.success && "error" in result) {
|
|
576
|
-
await reportZodValidationError("group", key, fullPath, result.error);
|
|
715
|
+
else if (result.success && !archived) {
|
|
716
|
+
for (const warning of getCompositionWarnings(result.data)) {
|
|
717
|
+
reportWarning({
|
|
718
|
+
...warning,
|
|
719
|
+
filePath: path.relative(process.cwd(), fullPath),
|
|
720
|
+
entityType: "variable",
|
|
721
|
+
key,
|
|
722
|
+
});
|
|
723
|
+
}
|
|
577
724
|
}
|
|
578
725
|
}
|
|
579
726
|
catch (error) {
|
|
580
|
-
await reportThrownError("
|
|
581
|
-
}
|
|
582
|
-
if (parsed) {
|
|
583
|
-
try {
|
|
584
|
-
await (0, checkPercentageExceedingSlot_1.checkForFeatureExceedingGroupSlotPercentage)(datasource, parsed, features);
|
|
585
|
-
}
|
|
586
|
-
catch (error) {
|
|
587
|
-
await reportSimpleError({
|
|
588
|
-
entityType: "group",
|
|
589
|
-
key,
|
|
590
|
-
fullPath,
|
|
591
|
-
message: error instanceof Error ? error.message : String(error),
|
|
592
|
-
code: error instanceof Error ? error.name : "error",
|
|
593
|
-
});
|
|
594
|
-
}
|
|
727
|
+
await reportThrownError("variable", key, fullPath, error);
|
|
595
728
|
}
|
|
596
729
|
}
|
|
597
730
|
}
|
|
598
|
-
// @TODO: feature cannot exist in multiple groups
|
|
599
731
|
// lint schemas (schemas and schemasByKey already loaded above for feature linting)
|
|
600
|
-
const schemaZodSchema = (0, schema_1.getSchemaZodSchema)(schemas);
|
|
732
|
+
const schemaZodSchema = (0, schema_1.getSchemaZodSchema)(schemas, schemasByKey);
|
|
601
733
|
if (!options.entityType || options.entityType === "schema") {
|
|
602
734
|
await lintReservedNamespaceCharacterInEntityPaths("schema");
|
|
603
735
|
const filteredKeys = !keyPattern ? schemas : schemas.filter((key) => keyPattern.test(key));
|
|
604
736
|
if (filteredKeys.length > 0) {
|
|
605
|
-
|
|
737
|
+
logProgress(filteredKeys.length, "schema");
|
|
606
738
|
}
|
|
607
739
|
for (const key of filteredKeys) {
|
|
608
740
|
const fullPath = getFullPathFromKey("schema", key);
|
|
@@ -618,7 +750,7 @@ async function lintProject(deps, options = {}) {
|
|
|
618
750
|
}
|
|
619
751
|
try {
|
|
620
752
|
const parsed = await datasource.readSchema(key);
|
|
621
|
-
const result = schemaZodSchema.safeParse(parsed);
|
|
753
|
+
const result = schemaZodSchema.safeParse(parsed, diagnostics_1.diagnosticParseOptions);
|
|
622
754
|
if (!result.success && "error" in result) {
|
|
623
755
|
await reportZodValidationError("schema", key, fullPath, result.error);
|
|
624
756
|
}
|
|
@@ -635,7 +767,7 @@ async function lintProject(deps, options = {}) {
|
|
|
635
767
|
await lintReservedNamespaceCharacterInEntityPaths("target");
|
|
636
768
|
const filteredKeys = !keyPattern ? targets : targets.filter((key) => keyPattern.test(key));
|
|
637
769
|
if (filteredKeys.length > 0) {
|
|
638
|
-
|
|
770
|
+
logProgress(filteredKeys.length, "target");
|
|
639
771
|
}
|
|
640
772
|
for (const key of filteredKeys) {
|
|
641
773
|
const fullPath = getFullPathFromKey("target", key);
|
|
@@ -651,10 +783,11 @@ async function lintProject(deps, options = {}) {
|
|
|
651
783
|
}
|
|
652
784
|
try {
|
|
653
785
|
const parsed = await datasource.readTarget(key);
|
|
654
|
-
const result = targetZodSchema.safeParse(parsed);
|
|
786
|
+
const result = targetZodSchema.safeParse(parsed, diagnostics_1.diagnosticParseOptions);
|
|
655
787
|
if (!result.success && "error" in result) {
|
|
656
788
|
await reportZodValidationError("target", key, fullPath, result.error);
|
|
657
789
|
}
|
|
790
|
+
await reportArchivedReferences("target", key, fullPath, parsed);
|
|
658
791
|
}
|
|
659
792
|
catch (error) {
|
|
660
793
|
await reportThrownError("target", key, fullPath, error);
|
|
@@ -663,15 +796,17 @@ async function lintProject(deps, options = {}) {
|
|
|
663
796
|
}
|
|
664
797
|
// lint tests
|
|
665
798
|
const tests = await datasource.listTests();
|
|
666
|
-
const testsZodSchema = (0, testSchema_1.getTestsZodSchema)(projectConfig, features, segments, targets, variables, featuresByKey);
|
|
799
|
+
const testsZodSchema = (0, testSchema_1.getTestsZodSchema)(projectConfig, features, segments, targets, variables, featuresByKey, segmentsByKey);
|
|
667
800
|
if (!options.entityType || options.entityType === "test") {
|
|
668
801
|
await lintReservedNamespaceCharacterInEntityPaths("test");
|
|
669
802
|
const filteredKeys = !keyPattern ? tests : tests.filter((key) => keyPattern.test(key));
|
|
670
803
|
if (filteredKeys.length > 0) {
|
|
671
|
-
|
|
804
|
+
logProgress(filteredKeys.length, "test");
|
|
672
805
|
}
|
|
673
806
|
for (const key of filteredKeys) {
|
|
674
|
-
const fullPath =
|
|
807
|
+
const fullPath = datasource.getTestSourcePath
|
|
808
|
+
? datasource.getTestSourcePath(key)
|
|
809
|
+
: getFullPathFromKey("test", key);
|
|
675
810
|
if (!isValidEntityKey(key, projectConfig.namespaceCharacter)) {
|
|
676
811
|
await reportSimpleError({
|
|
677
812
|
entityType: "test",
|
|
@@ -684,19 +819,184 @@ async function lintProject(deps, options = {}) {
|
|
|
684
819
|
}
|
|
685
820
|
try {
|
|
686
821
|
const parsed = await datasource.readTest(key);
|
|
687
|
-
const
|
|
822
|
+
for (const warning of (0, contextWarnings_1.getTestContextWarnings)(parsed, attributesByKey, schemasByKey)) {
|
|
823
|
+
reportWarning({
|
|
824
|
+
filePath: path.relative(process.cwd(), fullPath),
|
|
825
|
+
entityType: "test",
|
|
826
|
+
key,
|
|
827
|
+
path: warning.path,
|
|
828
|
+
code: "context_value_mismatch",
|
|
829
|
+
message: warning.message,
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
const result = testsZodSchema.safeParse(parsed, diagnostics_1.diagnosticParseOptions);
|
|
688
833
|
if (!result.success && "error" in result) {
|
|
689
834
|
await reportZodValidationError("test", key, fullPath, result.error);
|
|
690
835
|
}
|
|
836
|
+
await reportArchivedReferences("test", key, fullPath, parsed);
|
|
691
837
|
}
|
|
692
838
|
catch (error) {
|
|
693
839
|
await reportThrownError("test", key, fullPath, error);
|
|
694
840
|
}
|
|
695
841
|
}
|
|
696
842
|
}
|
|
843
|
+
// lint scenarios
|
|
844
|
+
const scenarios = await datasource.listScenarios();
|
|
845
|
+
const scenariosZodSchema = (0, testSchema_1.getScenariosZodSchema)(projectConfig, features, segments, targets, variables, featuresByKey);
|
|
846
|
+
if (!options.entityType || options.entityType === "scenario") {
|
|
847
|
+
if (options.entityType === "scenario") {
|
|
848
|
+
await lintReservedNamespaceCharacterInEntityPaths("scenario");
|
|
849
|
+
}
|
|
850
|
+
const filteredKeys = !keyPattern ? scenarios : scenarios.filter((key) => keyPattern.test(key));
|
|
851
|
+
if (filteredKeys.length > 0) {
|
|
852
|
+
logProgress(filteredKeys.length, "scenario");
|
|
853
|
+
}
|
|
854
|
+
for (const key of filteredKeys) {
|
|
855
|
+
let fullPath = getFullPathFromKey("scenario", key);
|
|
856
|
+
try {
|
|
857
|
+
fullPath = datasource.getScenarioSourcePath(key);
|
|
858
|
+
}
|
|
859
|
+
catch {
|
|
860
|
+
// Custom adapters may not expose a source path.
|
|
861
|
+
}
|
|
862
|
+
if (!isValidEntityKey(key, projectConfig.namespaceCharacter)) {
|
|
863
|
+
await reportSimpleError({
|
|
864
|
+
entityType: "scenario",
|
|
865
|
+
key,
|
|
866
|
+
fullPath,
|
|
867
|
+
message: `Invalid name: "${key}"`,
|
|
868
|
+
detail: ENTITY_NAME_REGEX_ERROR,
|
|
869
|
+
code: "invalid_name",
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
try {
|
|
873
|
+
const parsed = await datasource.readScenario(key);
|
|
874
|
+
for (const warning of (0, contextWarnings_1.getTestContextWarnings)(parsed, attributesByKey, schemasByKey, true)) {
|
|
875
|
+
reportWarning({
|
|
876
|
+
filePath: path.relative(process.cwd(), fullPath),
|
|
877
|
+
entityType: "scenario",
|
|
878
|
+
key,
|
|
879
|
+
path: warning.path,
|
|
880
|
+
code: "context_value_mismatch",
|
|
881
|
+
message: warning.message,
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
const result = scenariosZodSchema.safeParse(parsed, diagnostics_1.diagnosticParseOptions);
|
|
885
|
+
if (!result.success && "error" in result) {
|
|
886
|
+
await reportZodValidationError("scenario", key, fullPath, result.error);
|
|
887
|
+
}
|
|
888
|
+
await reportArchivedReferences("scenario", key, fullPath, parsed);
|
|
889
|
+
}
|
|
890
|
+
catch (error) {
|
|
891
|
+
await reportThrownError("scenario", key, fullPath, error);
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
if (!options.entityType ||
|
|
896
|
+
options.entityType === "feature" ||
|
|
897
|
+
options.entityType === "variable" ||
|
|
898
|
+
options.entityType === "segment") {
|
|
899
|
+
const reportDependencyError = async (error) => {
|
|
900
|
+
const cycleError = (0, dependencies_1.isDependencyCycleError)(error) ? error : null;
|
|
901
|
+
const cycleOrigin = cycleError?.origin;
|
|
902
|
+
const entityType = cycleOrigin
|
|
903
|
+
? cycleOrigin[0] === "variable"
|
|
904
|
+
? "variable"
|
|
905
|
+
: cycleOrigin[0] === "segment"
|
|
906
|
+
? "segment"
|
|
907
|
+
: "feature"
|
|
908
|
+
: variables.length > 0
|
|
909
|
+
? "variable"
|
|
910
|
+
: "feature";
|
|
911
|
+
const key = cycleOrigin
|
|
912
|
+
? cycleOrigin[1]
|
|
913
|
+
: entityType === "variable"
|
|
914
|
+
? variables[0] || ""
|
|
915
|
+
: features[0] || "";
|
|
916
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
917
|
+
if (error instanceof parseError_1.EntityParseError) {
|
|
918
|
+
await reportThrownError(entityType, key, getFullPathFromKey(entityType, key), error);
|
|
919
|
+
}
|
|
920
|
+
else if (!message.startsWith("Legacy feature `required` was removed") ||
|
|
921
|
+
!errors.some((item) => item.path.join(".") === "required")) {
|
|
922
|
+
await reportSimpleError({
|
|
923
|
+
entityType,
|
|
924
|
+
key,
|
|
925
|
+
fullPath: key ? getFullPathFromKey(entityType, key) : process.cwd(),
|
|
926
|
+
message,
|
|
927
|
+
pathParts: cycleError ? cycleError.path : [],
|
|
928
|
+
code: cycleError ? cycleError.code : "dependency_validation_failed",
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
};
|
|
932
|
+
try {
|
|
933
|
+
const graph = await (0, dependencies_1.buildDependencyGraph)(datasource);
|
|
934
|
+
const cycles = await (0, dependencies_1.findDependencyCycles)(datasource, graph);
|
|
935
|
+
for (const cycle of cycles)
|
|
936
|
+
await reportDependencyError(cycle);
|
|
937
|
+
// Depth and cost estimation are useful only for an acyclic evaluation graph.
|
|
938
|
+
const deepChains = cycles.length
|
|
939
|
+
? []
|
|
940
|
+
: (0, dependencyDepth_1.findDeepDependencyChains)(graph, dependencyDepth_1.PORTABLE_DEPENDENCY_HANDOFFS);
|
|
941
|
+
for (const chain of deepChains) {
|
|
942
|
+
const node = JSON.parse(chain.root);
|
|
943
|
+
const entityType = node[0] === "variable" ? "variable" : "feature";
|
|
944
|
+
const key = node[1];
|
|
945
|
+
if (options.entityType && options.entityType !== entityType)
|
|
946
|
+
continue;
|
|
947
|
+
const location = node[0] === "feature-variable"
|
|
948
|
+
? ["variablesSchema", node[2]]
|
|
949
|
+
: entityType === "variable" && variablesByKey[key]?.compose
|
|
950
|
+
? ["compose"]
|
|
951
|
+
: ["conditions"];
|
|
952
|
+
const description = (0, dependencyDepth_1.describeDependencyChain)(chain.nodes);
|
|
953
|
+
if (chain.handoffs > dependencyDepth_1.DEPENDENCY_HANDOFF_LIMIT) {
|
|
954
|
+
await reportSimpleError({
|
|
955
|
+
entityType,
|
|
956
|
+
key,
|
|
957
|
+
fullPath: getFullPathFromKey(entityType, key),
|
|
958
|
+
message: `Evaluation needs ${chain.handoffs} dependency handoffs, more than the runtime limit of ${dependencyDepth_1.DEPENDENCY_HANDOFF_LIMIT}, so SDKs fail it: ${description}. Shorten the chain.`,
|
|
959
|
+
pathParts: location,
|
|
960
|
+
code: "dependency_depth_exceeded",
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
else {
|
|
964
|
+
reportWarning({
|
|
965
|
+
filePath: path.relative(process.cwd(), getFullPathFromKey(entityType, key)),
|
|
966
|
+
entityType,
|
|
967
|
+
key,
|
|
968
|
+
path: location,
|
|
969
|
+
code: "dependency_depth",
|
|
970
|
+
message: `Evaluation needs ${chain.handoffs} dependency handoffs: ${description}. Small native thread stacks, such as 512 KB mobile threads, can fail deep chains. Keep chains at ${dependencyDepth_1.PORTABLE_DEPENDENCY_HANDOFFS} or fewer where you can.`,
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
for (const estimate of cycles.length ? [] : (0, requiredVariableCost_1.estimateDependencyExpansion)(graph)) {
|
|
975
|
+
const node = JSON.parse(estimate.root);
|
|
976
|
+
const entityType = node[0] === "variable" ? "variable" : node[0] === "segment" ? "segment" : "feature";
|
|
977
|
+
const key = node[1];
|
|
978
|
+
if (options.entityType && options.entityType !== entityType)
|
|
979
|
+
continue;
|
|
980
|
+
reportWarning({
|
|
981
|
+
filePath: path.relative(process.cwd(), getFullPathFromKey(entityType, key)),
|
|
982
|
+
entityType,
|
|
983
|
+
key,
|
|
984
|
+
path: entityType === "variable" && variablesByKey[key]?.compose
|
|
985
|
+
? ["compose"]
|
|
986
|
+
: ["conditions"],
|
|
987
|
+
code: "dependency_expansion_cost",
|
|
988
|
+
message: `More than 1000 distinct dependency edges are reachable from this request (estimate capped at 1001). Memoization avoids counting shared paths repeatedly.`,
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
catch (error) {
|
|
993
|
+
await reportDependencyError(error);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
697
996
|
return {
|
|
698
997
|
hasError: errors.length > 0,
|
|
699
998
|
errors,
|
|
999
|
+
...(warnings.length > 0 ? { warnings } : {}),
|
|
700
1000
|
};
|
|
701
1001
|
}
|
|
702
1002
|
exports.lintPlugin = {
|
|
@@ -719,9 +1019,11 @@ exports.lintPlugin = {
|
|
|
719
1019
|
authors: parsed.authors,
|
|
720
1020
|
json: parsed.json,
|
|
721
1021
|
pretty: parsed.pretty,
|
|
1022
|
+
v3MutationOrder: parsed.v3MutationOrder,
|
|
1023
|
+
verbose: parsed.verbose,
|
|
722
1024
|
});
|
|
723
1025
|
if (parsed.json) {
|
|
724
|
-
const payload = { errors: result.errors };
|
|
1026
|
+
const payload = { errors: result.errors, warnings: result.warnings || [] };
|
|
725
1027
|
console.log(parsed.pretty ? JSON.stringify(payload, null, 2) : JSON.stringify(payload));
|
|
726
1028
|
}
|
|
727
1029
|
if (result.hasError) {
|
|
@@ -739,39 +1041,43 @@ exports.lintPlugin = {
|
|
|
739
1041
|
examples: [
|
|
740
1042
|
{
|
|
741
1043
|
command: "lint",
|
|
742
|
-
description: "
|
|
1044
|
+
description: "Lint all entities",
|
|
1045
|
+
},
|
|
1046
|
+
{
|
|
1047
|
+
command: "lint --v3-mutation-order",
|
|
1048
|
+
description: "Show values that change because v4 applies mutations in authored order",
|
|
743
1049
|
},
|
|
744
1050
|
{
|
|
745
|
-
command: "lint --
|
|
746
|
-
description: "
|
|
1051
|
+
command: "lint --entity-type=feature",
|
|
1052
|
+
description: "Lint only features",
|
|
747
1053
|
},
|
|
748
1054
|
{
|
|
749
|
-
command: "lint --
|
|
750
|
-
description: "
|
|
1055
|
+
command: "lint --entity-type=segment",
|
|
1056
|
+
description: "Lint only segments",
|
|
751
1057
|
},
|
|
752
1058
|
{
|
|
753
|
-
command: "lint --
|
|
754
|
-
description: "
|
|
1059
|
+
command: "lint --entity-type=schema",
|
|
1060
|
+
description: "Lint only schemas",
|
|
755
1061
|
},
|
|
756
1062
|
{
|
|
757
|
-
command: "lint --
|
|
758
|
-
description: "
|
|
1063
|
+
command: "lint --entity-type=test",
|
|
1064
|
+
description: "Lint only tests",
|
|
759
1065
|
},
|
|
760
1066
|
{
|
|
761
|
-
command: "lint --
|
|
762
|
-
description: "
|
|
1067
|
+
command: "lint --entity-type=scenario",
|
|
1068
|
+
description: "Lint only scenarios",
|
|
763
1069
|
},
|
|
764
1070
|
{
|
|
765
|
-
command: 'lint --
|
|
766
|
-
description: `
|
|
1071
|
+
command: 'lint --key-pattern="abc"',
|
|
1072
|
+
description: `Lint only entities with keys containing "abc"`,
|
|
767
1073
|
},
|
|
768
1074
|
{
|
|
769
1075
|
command: "lint --json",
|
|
770
|
-
description: "
|
|
1076
|
+
description: "Print lint errors as JSON",
|
|
771
1077
|
},
|
|
772
1078
|
{
|
|
773
1079
|
command: "lint --json --pretty",
|
|
774
|
-
description: "
|
|
1080
|
+
description: "Print lint errors as pretty JSON",
|
|
775
1081
|
},
|
|
776
1082
|
],
|
|
777
1083
|
};
|