UNPKG

7.75 kBTypeScriptView Raw
1import { DependencyType, SeverityType } from "./shared-types";
2
3export interface IFromRestriction {
4 /**
5 * A regular expression an end of a dependency should match to be catched by this rule.
6 */
7 path?: string;
8 /**
9 * A regular expression an end of a dependency should NOT match to be catched by this rule.
10 */
11 pathNot?: string;
12 /**
13 * Whether or not to match when the module is an orphan (= has no incoming or outgoing
14 * dependencies). When this property it is part of a rule, dependency-cruiser will
15 * ignore the 'to' part.
16 */
17 orphan?: boolean;
18}
19
20export interface IToRestriction {
21 /**
22 * A regular expression an end of a dependency should match to be catched by this rule.
23 */
24 path?: string;
25 /**
26 * A regular expression an end of a dependency should NOT match to be catched by this rule.
27 */
28 pathNot?: string;
29 /**
30 * Whether or not to match modules dependency-cruiser could not resolve (and probably
31 * aren't on disk). For this one too: leave out if you don't care either way.
32 */
33 couldNotResolve?: boolean;
34 /**
35 * Whether or not to match when following to the to will ultimately end up in the from.
36 */
37 circular?: boolean;
38 /**
39 * If following this dependency will ultimately return to the source
40 * (circular === true), this attribute will contain an (ordered) array of module
41 * names that shows (one of the) circular path(s)
42 */
43 cycle?: string[];
44 /**
45 * Whether or not to match when the dependency is a dynamic one.
46 */
47 dynamic?: boolean;
48 /**
49 * Whether or not to match when the dependency is exotically required
50 */
51 exoticallyRequired?: boolean;
52 /**
53 * A regular expression to match against any 'exotic' require strings
54 */
55 exoticRequire?: string;
56 /**
57 * A regular expression to match against any 'exotic' require strings - when it should NOT be caught by the rule
58 */
59 exoticRequireNot?: string;
60 /**
61 * true if this dependency only exists before compilation (like type only imports),
62 * false in all other cases. Only returned when the tsPreCompilationDeps is set to 'specify'.
63 */
64 preCompilationOnly?: boolean;
65 /**
66 * Whether or not to match modules of any of these types (leaving out matches any of them)
67 */
68 dependencyTypes?: DependencyType[];
69 /**
70 * If true matches dependencies with more than one dependency type (e.g. defined in
71 * _both_ npm and npm-dev)
72 */
73 moreThanOneDependencyType?: boolean;
74 /**
75 * Whether or not to match modules that were released under one of the mentioned
76 * licenses. E.g. to flag GPL-1.0, GPL-2.0 licensed modules (e.g. because your app
77 * is not compatible with the GPL) use "GPL"
78 */
79 license?: string;
80 /**
81 * Whether or not to match modules that were NOT released under one of the mentioned
82 * licenses. E.g. to flag everyting non MIT use "MIT" here
83 */
84 licenseNot?: string;
85}
86
87export interface IReachabilityFromRestrictionType {
88 /**
89 * A regular expression an end of a dependency should match to be catched by this rule.
90 */
91 path?: string;
92 /**
93 * A regular expression an end of a dependency should NOT match to be catched by this rule.
94 */
95 pathNot?: string;
96}
97
98export interface IReachabilityToRestrictionType {
99 /**
100 * A regular expression an end of a dependency should match to be catched by this rule.
101 */
102 path?: string;
103 /**
104 * A regular expression an end of a dependency should NOT match to be catched by this rule.
105 */
106 pathNot?: string;
107 /**
108 * Whether or not to match modules that aren't reachable from the from part of the rule.
109 */
110 reachable: boolean;
111}
112
113export type IAllowedRuleType =
114 | IRegularAllowedRuleType
115 | IReachabilityAllowedRuleType;
116
117export interface IRegularAllowedRuleType {
118 /**
119 * You can use this field to document why the rule is there.
120 */
121 comment?: string;
122 /**
123 * Criteria the 'from' end of a dependency should match to be caught by this rule.
124 * Leave it empty if you want any module to be matched.
125 */
126 from: IFromRestriction;
127 /**
128 * Criteria the 'to' end of a dependency should match to be caught by this rule.
129 * Leave it empty if you want any module to be matched.
130 */
131 to: IToRestriction;
132}
133
134export interface IReachabilityAllowedRuleType {
135 /**
136 * You can use this field to document why the rule is there.
137 */
138 comment?: string;
139 /**
140 * Criteria the 'from' end of a dependency should match to be caught by this rule.
141 * Leave it empty if you want any module to be matched.
142 */
143 from: IReachabilityFromRestrictionType;
144 /**
145 * Criteria the 'to' end of a dependency should match to be caught by this rule.
146 * Leave it empty if you want any module to be matched.
147 */
148 to: IReachabilityToRestrictionType;
149}
150
151export type IForbiddenRuleType =
152 | IRegularForbiddenRuleType
153 | IReachabilityForbiddenRuleType;
154
155export interface IRegularForbiddenRuleType {
156 /**
157 * A short name for the rule - will appear in reporters to enable customers to
158 * quickly identify a violated rule. Try to keep them short, eslint style.
159 * E.g. 'not-to-core' for a rule forbidding dependencies on core modules, or
160 * 'not-to-unresolvable' for one that prevents dependencies on modules that
161 * probably don't exist.
162 */
163 name?: string;
164 /**
165 * How severe a violation of the rule is. The 'error' severity will make some
166 * reporters return a non-zero exit code, so if you want e.g. a build to stop
167 * when there's a rule violated: use that.
168 */
169 severity?: SeverityType;
170 /**
171 * You can use this field to document why the rule is there.
172 */
173 comment?: string;
174 /**
175 * Criteria the 'from' end of a dependency should match to be caught by this
176 * rule. Leave it empty if you want any module to be matched.
177 */
178 from: IFromRestriction;
179 /**
180 * Criteria the 'to' end of a dependency should match to be caught by this
181 * rule. Leave it empty if you want any module to be matched.
182 */
183 to: IToRestriction;
184}
185
186export interface IReachabilityForbiddenRuleType {
187 /**
188 * A short name for the rule - will appear in reporters to enable customers to
189 * quickly identify a violated rule. Try to keep them short, eslint style.
190 * E.g. 'not-to-core' for a rule forbidding dependencies on core modules, or
191 * 'not-to-unresolvable' for one that prevents dependencies on modules that
192 * probably don't exist.
193 */
194 name?: string;
195 /**
196 * How severe a violation of the rule is. The 'error' severity will make some
197 * reporters return a non-zero exit code, so if you want e.g. a build to stop
198 * when there's a rule violated: use that.
199 */
200 severity?: SeverityType;
201 /**
202 * You can use this field to document why the rule is there.
203 */
204 comment?: string;
205 /**
206 * Criteria the 'from' end of a dependency should match to be caught by this
207 * rule. Leave it empty if you want any module to be matched.
208 */
209 from: IReachabilityFromRestrictionType;
210 /**
211 * Criteria the 'to' end of a dependency should match to be caught by this
212 * rule. Leave it empty if you want any module to be matched.
213 */
214 to: IReachabilityToRestrictionType;
215}
216
217export interface IFlattenedRuleSet {
218 /**
219 * A list of rules that describe dependencies that are not allowed.
220 * dependency-cruiser will emit a separate error (warning/ informational)
221 * messages for each violated rule.
222 */
223 forbidden?: IForbiddenRuleType[];
224 /**
225 * A list of rules that describe dependencies that are allowed.
226 * dependency-cruiser will emit the warning message 'not-in-allowed' for
227 * each dependency that does not at least one of them.
228 */
229 allowed?: IAllowedRuleType[];
230 /**
231 * Severity to use when a dependency is not in the 'allowed' set of rules.
232 * Defaults to 'warn'
233 */
234 allowedSeverity?: SeverityType;
235}