@boundaries/eslint-plugin 5.2.0-beta.1
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/LICENSE +21 -0
- package/README.md +798 -0
- package/dist/Config/Config.d.ts +40 -0
- package/dist/Config/Config.js +119 -0
- package/dist/Config/Recommended.d.ts +10 -0
- package/dist/Config/Recommended.js +36 -0
- package/dist/Config/Strict.d.ts +8 -0
- package/dist/Config/Strict.js +26 -0
- package/dist/Elements/Elements.d.ts +43 -0
- package/dist/Elements/Elements.js +107 -0
- package/dist/Elements/Elements.types.d.ts +5 -0
- package/dist/Elements/Elements.types.js +2 -0
- package/dist/Elements/index.d.ts +2 -0
- package/dist/Elements/index.js +18 -0
- package/dist/Messages/Messages.d.ts +14 -0
- package/dist/Messages/Messages.js +204 -0
- package/dist/Messages/index.d.ts +1 -0
- package/dist/Messages/index.js +17 -0
- package/dist/Public/Config.types.d.ts +2 -0
- package/dist/Public/Config.types.js +5 -0
- package/dist/Public/Rules.types.d.ts +10 -0
- package/dist/Public/Rules.types.js +15 -0
- package/dist/Public/Settings.types.d.ts +13 -0
- package/dist/Public/Settings.types.js +21 -0
- package/dist/Public/index.d.ts +3 -0
- package/dist/Public/index.js +19 -0
- package/dist/Rules/ElementTypes.d.ts +25 -0
- package/dist/Rules/ElementTypes.js +269 -0
- package/dist/Rules/EntryPoint.d.ts +2 -0
- package/dist/Rules/EntryPoint.js +122 -0
- package/dist/Rules/External.d.ts +2 -0
- package/dist/Rules/External.js +119 -0
- package/dist/Rules/NoIgnored.d.ts +2 -0
- package/dist/Rules/NoIgnored.js +19 -0
- package/dist/Rules/NoPrivate.d.ts +2 -0
- package/dist/Rules/NoPrivate.js +53 -0
- package/dist/Rules/NoUnknown.d.ts +2 -0
- package/dist/Rules/NoUnknown.js +22 -0
- package/dist/Rules/NoUnknownFiles.d.ts +3 -0
- package/dist/Rules/NoUnknownFiles.js +29 -0
- package/dist/Rules/Support/DependencyRule.d.ts +4 -0
- package/dist/Rules/Support/DependencyRule.js +49 -0
- package/dist/Rules/Support/DependencyRule.types.d.ts +17 -0
- package/dist/Rules/Support/DependencyRule.types.js +2 -0
- package/dist/Rules/Support/Helpers.d.ts +8 -0
- package/dist/Rules/Support/Helpers.js +39 -0
- package/dist/Rules/Support/index.d.ts +3 -0
- package/dist/Rules/Support/index.js +19 -0
- package/dist/Settings/Helpers.d.ts +41 -0
- package/dist/Settings/Helpers.js +72 -0
- package/dist/Settings/Settings.d.ts +6 -0
- package/dist/Settings/Settings.js +49 -0
- package/dist/Settings/Settings.types.d.ts +448 -0
- package/dist/Settings/Settings.types.js +190 -0
- package/dist/Settings/Validations.d.ts +137 -0
- package/dist/Settings/Validations.js +359 -0
- package/dist/Settings/index.d.ts +4 -0
- package/dist/Settings/index.js +20 -0
- package/dist/Support/Common.d.ts +30 -0
- package/dist/Support/Common.js +47 -0
- package/dist/Support/Debug.d.ts +5 -0
- package/dist/Support/Debug.js +54 -0
- package/dist/Support/index.d.ts +2 -0
- package/dist/Support/index.js +18 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +76 -0
- package/package.json +81 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const Settings_1 = require("../Settings");
|
|
4
|
+
const Support_1 = require("./Support");
|
|
5
|
+
const { RULE_NO_IGNORED } = Settings_1.SETTINGS;
|
|
6
|
+
exports.default = (0, Support_1.dependencyRule)({
|
|
7
|
+
schema: [],
|
|
8
|
+
ruleName: RULE_NO_IGNORED,
|
|
9
|
+
description: `Prevent importing ignored files from recognized elements`,
|
|
10
|
+
}, function ({ dependency, node, context }) {
|
|
11
|
+
if (dependency.to.isIgnored) {
|
|
12
|
+
context.report({
|
|
13
|
+
message: `Importing ignored files is not allowed`,
|
|
14
|
+
node: node,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}, {
|
|
18
|
+
validate: false,
|
|
19
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const elements_1 = require("@boundaries/elements");
|
|
4
|
+
const Messages_1 = require("../Messages");
|
|
5
|
+
const Settings_1 = require("../Settings");
|
|
6
|
+
const Support_1 = require("./Support");
|
|
7
|
+
const { RULE_NO_PRIVATE } = Settings_1.SETTINGS;
|
|
8
|
+
function errorMessage(dependency, options) {
|
|
9
|
+
if (options?.message) {
|
|
10
|
+
return (0, Messages_1.customErrorMessage)(options.message, dependency);
|
|
11
|
+
}
|
|
12
|
+
// @ts-expect-error could not be defined. TODO: I have to decide whether to unify properties in all elements, or to use type guards
|
|
13
|
+
return `Dependency is private of element ${(0, Messages_1.elementMessage)(dependency.to.parents?.[0])}`;
|
|
14
|
+
}
|
|
15
|
+
exports.default = (0, Support_1.dependencyRule)({
|
|
16
|
+
ruleName: RULE_NO_PRIVATE,
|
|
17
|
+
description: `Prevent importing private elements of another element`,
|
|
18
|
+
schema: [
|
|
19
|
+
{
|
|
20
|
+
type: "object",
|
|
21
|
+
properties: {
|
|
22
|
+
allowUncles: {
|
|
23
|
+
type: "boolean",
|
|
24
|
+
},
|
|
25
|
+
message: {
|
|
26
|
+
type: "string",
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
additionalProperties: false,
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
}, function ({ dependency, node, context, options }) {
|
|
33
|
+
if (!dependency.to.isIgnored &&
|
|
34
|
+
(0, elements_1.isLocalDependencyElement)(dependency.to) &&
|
|
35
|
+
dependency.to.type &&
|
|
36
|
+
dependency.to.parents.length &&
|
|
37
|
+
dependency.dependency.relationship.to !==
|
|
38
|
+
elements_1.DEPENDENCY_RELATIONSHIPS_MAP.INTERNAL &&
|
|
39
|
+
dependency.dependency.relationship.to !==
|
|
40
|
+
elements_1.DEPENDENCY_RELATIONSHIPS_MAP.CHILD &&
|
|
41
|
+
dependency.dependency.relationship.to !==
|
|
42
|
+
elements_1.DEPENDENCY_RELATIONSHIPS_MAP.SIBLING &&
|
|
43
|
+
(!options?.allowUncles ||
|
|
44
|
+
dependency.dependency.relationship.to !==
|
|
45
|
+
elements_1.DEPENDENCY_RELATIONSHIPS_MAP.UNCLE)) {
|
|
46
|
+
context.report({
|
|
47
|
+
message: errorMessage(dependency, options),
|
|
48
|
+
node: node,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}, {
|
|
52
|
+
validate: false,
|
|
53
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const elements_1 = require("@boundaries/elements");
|
|
4
|
+
const Settings_1 = require("../Settings");
|
|
5
|
+
const Support_1 = require("./Support");
|
|
6
|
+
const { RULE_NO_UNKNOWN } = Settings_1.SETTINGS;
|
|
7
|
+
exports.default = (0, Support_1.dependencyRule)({
|
|
8
|
+
schema: [],
|
|
9
|
+
ruleName: RULE_NO_UNKNOWN,
|
|
10
|
+
description: `Prevent importing unknown elements from the known ones`,
|
|
11
|
+
}, function ({ dependency, node, context }) {
|
|
12
|
+
if (!dependency.to.isIgnored &&
|
|
13
|
+
(0, elements_1.isLocalDependencyElement)(dependency.to) &&
|
|
14
|
+
dependency.to.isUnknown) {
|
|
15
|
+
context.report({
|
|
16
|
+
message: `Importing unknown elements is not allowed`,
|
|
17
|
+
node: node,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}, {
|
|
21
|
+
validate: false,
|
|
22
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const Elements_1 = require("../Elements");
|
|
4
|
+
const Settings_1 = require("../Settings");
|
|
5
|
+
const Support_1 = require("./Support");
|
|
6
|
+
const { RULE_NO_UNKNOWN_FILES } = Settings_1.SETTINGS;
|
|
7
|
+
const noUnknownFilesRule = {
|
|
8
|
+
...(0, Support_1.meta)({
|
|
9
|
+
ruleName: RULE_NO_UNKNOWN_FILES,
|
|
10
|
+
schema: [],
|
|
11
|
+
description: `Prevent creating files not recognized as any of the element types`,
|
|
12
|
+
}),
|
|
13
|
+
create: function (context) {
|
|
14
|
+
const settings = (0, Settings_1.getSettings)(context);
|
|
15
|
+
const file = (0, Elements_1.elementDescription)(context.filename, settings);
|
|
16
|
+
if (file.isIgnored || !file.isUnknown) {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
Program: (node) => {
|
|
21
|
+
context.report({
|
|
22
|
+
message: `File is not of any known element type`,
|
|
23
|
+
node: node,
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
exports.default = noUnknownFilesRule;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Rule } from "eslint";
|
|
2
|
+
import type { RuleOptionsWithRules, RuleMetaDefinition } from "../../Settings";
|
|
3
|
+
import type { DependencyRuleRunner, DependencyRuleOptions } from "./DependencyRule.types";
|
|
4
|
+
export declare function dependencyRule<Options extends RuleOptionsWithRules>(ruleMeta: RuleMetaDefinition, rule: DependencyRuleRunner<Options>, ruleOptions?: DependencyRuleOptions): Rule.RuleModule;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dependencyRule = dependencyRule;
|
|
4
|
+
const Elements_1 = require("../../Elements");
|
|
5
|
+
const Settings_1 = require("../../Settings");
|
|
6
|
+
const Support_1 = require("../../Support");
|
|
7
|
+
const Helpers_1 = require("./Helpers");
|
|
8
|
+
const { ADDITIONAL_DEPENDENCY_NODES } = Settings_1.SETTINGS;
|
|
9
|
+
function optionsHaveRules(options) {
|
|
10
|
+
if (!options) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
return Boolean(options.rules);
|
|
14
|
+
}
|
|
15
|
+
function dependencyRule(ruleMeta, rule, ruleOptions = {}) {
|
|
16
|
+
return {
|
|
17
|
+
...(0, Helpers_1.meta)(ruleMeta),
|
|
18
|
+
create: function (context) {
|
|
19
|
+
const options = context.options[0];
|
|
20
|
+
const settings = (0, Settings_1.getSettings)(context);
|
|
21
|
+
const file = (0, Elements_1.elementDescription)(context.filename, settings);
|
|
22
|
+
if (ruleOptions.validate !== false && !options) {
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
if (ruleOptions.validate !== false && optionsHaveRules(options)) {
|
|
26
|
+
(0, Settings_1.validateRules)(settings, options.rules, ruleOptions.validateRules);
|
|
27
|
+
}
|
|
28
|
+
// TODO: Remove this check when allowing to select by any other property
|
|
29
|
+
if (file.isIgnored || !file.type) {
|
|
30
|
+
return {};
|
|
31
|
+
}
|
|
32
|
+
return settings.dependencyNodes.reduce((visitors, { selector, kind, name }) => {
|
|
33
|
+
visitors[selector] = (node) => {
|
|
34
|
+
if (!(0, Support_1.isString)(node.value)) {
|
|
35
|
+
(0, Support_1.warnOnce)(`Dependency node is not a Literal, skipping node. Please check your ${ADDITIONAL_DEPENDENCY_NODES} setting.`);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const dependency = (0, Elements_1.dependencyDescription)({
|
|
39
|
+
node,
|
|
40
|
+
kind,
|
|
41
|
+
nodeKind: name,
|
|
42
|
+
}, context.filename, settings, context);
|
|
43
|
+
rule({ dependency, options, node, context, settings });
|
|
44
|
+
};
|
|
45
|
+
return visitors;
|
|
46
|
+
}, {});
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { DependencyDescription } from "@boundaries/elements";
|
|
2
|
+
import type { Rule } from "eslint";
|
|
3
|
+
import type { EslintLiteralNode } from "../../Elements";
|
|
4
|
+
import type { ValidateRulesOptions, SettingsNormalized } from "../../Settings";
|
|
5
|
+
export type DependencyRuleRunner<Options> = (options: {
|
|
6
|
+
dependency: DependencyDescription;
|
|
7
|
+
options?: Options;
|
|
8
|
+
node: EslintLiteralNode;
|
|
9
|
+
context: Rule.RuleContext;
|
|
10
|
+
settings: SettingsNormalized;
|
|
11
|
+
}) => void;
|
|
12
|
+
export type DependencyRuleOptions = {
|
|
13
|
+
/** Whether to validate the presence of options */
|
|
14
|
+
validate?: boolean;
|
|
15
|
+
/** Whether to validate the rules */
|
|
16
|
+
validateRules?: ValidateRulesOptions;
|
|
17
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Rule } from "eslint";
|
|
2
|
+
import type { RuleMetaDefinition } from "../../Settings";
|
|
3
|
+
/**
|
|
4
|
+
* Returns the meta object for an ESLint rule.
|
|
5
|
+
* @param param0 The rule metadata definition.
|
|
6
|
+
* @returns The meta object for the ESLint rule.
|
|
7
|
+
*/
|
|
8
|
+
export declare function meta({ description, schema, ruleName, type, }: RuleMetaDefinition): Pick<Rule.RuleModule, "meta">;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.meta = meta;
|
|
4
|
+
const Settings_1 = require("../../Settings");
|
|
5
|
+
/**
|
|
6
|
+
* Removes the plugin namespace from a rule name.
|
|
7
|
+
* @param ruleName The name of the rule.
|
|
8
|
+
* @returns The rule name without the plugin namespace.
|
|
9
|
+
*/
|
|
10
|
+
function removePluginNamespace(ruleName) {
|
|
11
|
+
return ruleName.replace(`${Settings_1.PLUGIN_NAME}/`, "");
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Returns the documentation URL for an ESLint rule.
|
|
15
|
+
* @param ruleName The name of the rule.
|
|
16
|
+
* @returns The documentation URL for the ESLint rule.
|
|
17
|
+
*/
|
|
18
|
+
function docsUrl(ruleName) {
|
|
19
|
+
return `${Settings_1.REPO_URL}/blob/master/docs/rules/${removePluginNamespace(ruleName)}.md`;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Returns the meta object for an ESLint rule.
|
|
23
|
+
* @param param0 The rule metadata definition.
|
|
24
|
+
* @returns The meta object for the ESLint rule.
|
|
25
|
+
*/
|
|
26
|
+
function meta({ description, schema = [], ruleName, type, }) {
|
|
27
|
+
return {
|
|
28
|
+
meta: {
|
|
29
|
+
// TODO: Consider changing default to "suggestion" in a future major release, because most rules are not fixing code issues, but only suggesting best practices.
|
|
30
|
+
type: type || "problem",
|
|
31
|
+
docs: {
|
|
32
|
+
url: docsUrl(ruleName),
|
|
33
|
+
description,
|
|
34
|
+
category: "dependencies",
|
|
35
|
+
},
|
|
36
|
+
schema,
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./DependencyRule.types"), exports);
|
|
18
|
+
__exportStar(require("./DependencyRule"), exports);
|
|
19
|
+
__exportStar(require("./Helpers"), exports);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { DependencyKind } from "@boundaries/elements";
|
|
2
|
+
import type { DependencyNodeKey, SettingsKey, RulePolicy, RuleShortName, RuleName, RuleMainKey } from "./Settings.types";
|
|
3
|
+
/**
|
|
4
|
+
* Type guard to check if a value is a valid DependencyKind.
|
|
5
|
+
* @param value The value to check.
|
|
6
|
+
* @returns True if the value is a valid DependencyKind, false otherwise.
|
|
7
|
+
* @deprecated Use isDependencyKind instead.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isImportKind(value: unknown): value is DependencyKind;
|
|
10
|
+
/**
|
|
11
|
+
* Type guard to check if a value is a valid DependencyNodeKey.
|
|
12
|
+
* @param value The value to check.
|
|
13
|
+
* @returns True if the value is a valid DependencyNodeKey, false otherwise.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isDependencyNodeKey(value: unknown): value is DependencyNodeKey;
|
|
16
|
+
/**
|
|
17
|
+
* Type guard to check if a value is a valid key for the plugin settings.
|
|
18
|
+
* @param value - The value to check.
|
|
19
|
+
* @returns True if the value is a valid settings key, false otherwise.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isSettingsKey(value: unknown): value is SettingsKey;
|
|
22
|
+
/**
|
|
23
|
+
* Type guard to check if a value is a valid RulePolicy.
|
|
24
|
+
* @param value - The value to check.
|
|
25
|
+
* @returns True if the value is a valid RulePolicy, false otherwise.
|
|
26
|
+
*/
|
|
27
|
+
export declare function isRulePolicy(value: unknown): value is RulePolicy;
|
|
28
|
+
/**
|
|
29
|
+
* Type guard to check if a value is a valid rule name including the default plugin prefix.
|
|
30
|
+
* @param value - The value to check.
|
|
31
|
+
* @returns True if the value is a valid rule name with the default plugin prefix, false otherwise.
|
|
32
|
+
*/
|
|
33
|
+
export declare function isRuleName(value: unknown): value is RuleName;
|
|
34
|
+
/**
|
|
35
|
+
* Type guard to check if a value is a valid rule short name.
|
|
36
|
+
* @param value - The value to check.
|
|
37
|
+
* @returns True if the value is a valid rule short name, false otherwise.
|
|
38
|
+
*/
|
|
39
|
+
export declare function isRuleShortName(value: unknown): value is RuleShortName;
|
|
40
|
+
export declare function isLegacyType(type: unknown): type is string;
|
|
41
|
+
export declare function rulesMainKey(key?: RuleMainKey): RuleMainKey;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isImportKind = isImportKind;
|
|
4
|
+
exports.isDependencyNodeKey = isDependencyNodeKey;
|
|
5
|
+
exports.isSettingsKey = isSettingsKey;
|
|
6
|
+
exports.isRulePolicy = isRulePolicy;
|
|
7
|
+
exports.isRuleName = isRuleName;
|
|
8
|
+
exports.isRuleShortName = isRuleShortName;
|
|
9
|
+
exports.isLegacyType = isLegacyType;
|
|
10
|
+
exports.rulesMainKey = rulesMainKey;
|
|
11
|
+
const elements_1 = require("@boundaries/elements");
|
|
12
|
+
const Support_1 = require("../Support");
|
|
13
|
+
const Settings_types_1 = require("./Settings.types");
|
|
14
|
+
/**
|
|
15
|
+
* Type guard to check if a value is a valid DependencyKind.
|
|
16
|
+
* @param value The value to check.
|
|
17
|
+
* @returns True if the value is a valid DependencyKind, false otherwise.
|
|
18
|
+
* @deprecated Use isDependencyKind instead.
|
|
19
|
+
*/
|
|
20
|
+
function isImportKind(value) {
|
|
21
|
+
return ((0, Support_1.isString)(value) &&
|
|
22
|
+
Object.values(elements_1.DEPENDENCY_KINDS_MAP).includes(value));
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Type guard to check if a value is a valid DependencyNodeKey.
|
|
26
|
+
* @param value The value to check.
|
|
27
|
+
* @returns True if the value is a valid DependencyNodeKey, false otherwise.
|
|
28
|
+
*/
|
|
29
|
+
function isDependencyNodeKey(value) {
|
|
30
|
+
return ((0, Support_1.isString)(value) &&
|
|
31
|
+
Object.values(Settings_types_1.DEPENDENCY_NODE_KEYS_MAP).includes(value));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Type guard to check if a value is a valid key for the plugin settings.
|
|
35
|
+
* @param value - The value to check.
|
|
36
|
+
* @returns True if the value is a valid settings key, false otherwise.
|
|
37
|
+
*/
|
|
38
|
+
function isSettingsKey(value) {
|
|
39
|
+
return ((0, Support_1.isString)(value) &&
|
|
40
|
+
Object.values(Settings_types_1.SETTINGS_KEYS_MAP).includes(value));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Type guard to check if a value is a valid RulePolicy.
|
|
44
|
+
* @param value - The value to check.
|
|
45
|
+
* @returns True if the value is a valid RulePolicy, false otherwise.
|
|
46
|
+
*/
|
|
47
|
+
function isRulePolicy(value) {
|
|
48
|
+
return ((0, Support_1.isString)(value) &&
|
|
49
|
+
(value === Settings_types_1.RULE_POLICY_ALLOW || value === Settings_types_1.RULE_POLICY_DISALLOW));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Type guard to check if a value is a valid rule name including the default plugin prefix.
|
|
53
|
+
* @param value - The value to check.
|
|
54
|
+
* @returns True if the value is a valid rule name with the default plugin prefix, false otherwise.
|
|
55
|
+
*/
|
|
56
|
+
function isRuleName(value) {
|
|
57
|
+
return Settings_types_1.RULE_NAMES.includes(value);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Type guard to check if a value is a valid rule short name.
|
|
61
|
+
* @param value - The value to check.
|
|
62
|
+
* @returns True if the value is a valid rule short name, false otherwise.
|
|
63
|
+
*/
|
|
64
|
+
function isRuleShortName(value) {
|
|
65
|
+
return Settings_types_1.RULE_SHORT_NAMES.includes(value);
|
|
66
|
+
}
|
|
67
|
+
function isLegacyType(type) {
|
|
68
|
+
return (0, Support_1.isString)(type);
|
|
69
|
+
}
|
|
70
|
+
function rulesMainKey(key = Settings_types_1.FROM) {
|
|
71
|
+
return key;
|
|
72
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ElementDescriptors } from "@boundaries/elements";
|
|
2
|
+
import type { Settings } from "./Settings.types";
|
|
3
|
+
export declare function transformLegacyTypes(typesFromSettings?: string[] | ElementDescriptors): ElementDescriptors;
|
|
4
|
+
export declare function getElementsTypeNames(descriptors: ElementDescriptors): string[];
|
|
5
|
+
export declare function getRootPath(settings: Settings): string;
|
|
6
|
+
export declare function isDebugModeEnabled(): string | undefined;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformLegacyTypes = transformLegacyTypes;
|
|
4
|
+
exports.getElementsTypeNames = getElementsTypeNames;
|
|
5
|
+
exports.getRootPath = getRootPath;
|
|
6
|
+
exports.isDebugModeEnabled = isDebugModeEnabled;
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
8
|
+
const Support_1 = require("../Support");
|
|
9
|
+
const Helpers_1 = require("./Helpers");
|
|
10
|
+
const Settings_types_1 = require("./Settings.types");
|
|
11
|
+
const { VALID_MODES, ROOT_PATH, ENV_ROOT_PATH, DEBUG } = Settings_types_1.SETTINGS;
|
|
12
|
+
// TODO, remove in next major version
|
|
13
|
+
function transformLegacyTypes(typesFromSettings) {
|
|
14
|
+
const types = typesFromSettings || [];
|
|
15
|
+
if (!(0, Support_1.isArray)(types)) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
return types.map((type) => {
|
|
19
|
+
// backward compatibility with v1
|
|
20
|
+
if ((0, Helpers_1.isLegacyType)(type)) {
|
|
21
|
+
return {
|
|
22
|
+
type: type,
|
|
23
|
+
match: VALID_MODES[0],
|
|
24
|
+
pattern: `${type}/*`,
|
|
25
|
+
capture: ["elementName"],
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
// default options
|
|
29
|
+
return {
|
|
30
|
+
match: VALID_MODES[0],
|
|
31
|
+
...type,
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function getElementsTypeNames(descriptors) {
|
|
36
|
+
return descriptors.map((element) => element.type).filter(Boolean);
|
|
37
|
+
}
|
|
38
|
+
function getRootPath(settings) {
|
|
39
|
+
const rootPathUserSetting = process.env[ENV_ROOT_PATH] || settings[ROOT_PATH];
|
|
40
|
+
if (rootPathUserSetting) {
|
|
41
|
+
return (0, node_path_1.isAbsolute)(rootPathUserSetting)
|
|
42
|
+
? rootPathUserSetting
|
|
43
|
+
: (0, node_path_1.resolve)(process.cwd(), rootPathUserSetting);
|
|
44
|
+
}
|
|
45
|
+
return process.cwd();
|
|
46
|
+
}
|
|
47
|
+
function isDebugModeEnabled() {
|
|
48
|
+
return process.env[DEBUG];
|
|
49
|
+
}
|