MCPcopy Create free account
hub / github.com/angular/components / _generateRules

Method _generateRules

tools/tslint-rules/validateDecoratorsRule.ts:206–264  ·  view source on GitHub ↗

* Cleans out the blank rules that are passed through the tslint.json * and converts the string patterns into regular expressions. * @param config Config object passed in via the tslint.json. * @param filename The filename of the file being checked. * @returns Sanitized rules.

(config: RuleConfig | null, filename: string)

Source from the content-addressed store, hash-verified

204 * @returns Sanitized rules.
205 */
206 private _generateRules(config: RuleConfig | null, filename: string): DecoratorRules {
207 const output: DecoratorRules = {};
208
209 if (config) {
210 Object.keys(config).forEach(decoratorName => {
211 const decoratorConfigs = config[decoratorName];
212 for (const decoratorConfig of decoratorConfigs) {
213 const {argument, properties, required, excludeFiles} = decoratorConfig;
214
215 const skip =
216 excludeFiles &&
217 excludeFiles.length > 0 &&
218 excludeFiles.some(p => minimatch(filename, p));
219 if (skip) {
220 continue;
221 }
222
223 // * is a special token which means to run the pattern across the entire object.
224 const allProperties = properties[ALL_PROPS_TOKEN];
225
226 output[decoratorName] = output[decoratorName] || [];
227 if (allProperties) {
228 output[decoratorName].push({
229 argument,
230 required: !!required,
231 requiredProps: {[ALL_PROPS_TOKEN]: new RegExp(allProperties)},
232 forbiddenProps: {},
233 });
234 } else {
235 output[decoratorName].push(
236 Object.keys(decoratorConfig.properties).reduce(
237 (rules, prop) => {
238 const isForbidden = prop.startsWith('!');
239 const cleanName = isForbidden ? prop.slice(1) : prop;
240 const pattern = new RegExp(properties[prop]);
241
242 if (isForbidden) {
243 rules.forbiddenProps[cleanName] = pattern;
244 } else {
245 rules.requiredProps[cleanName] = pattern;
246 }
247
248 return rules;
249 },
250 {
251 argument,
252 required: !!required,
253 requiredProps: {} as {[key: string]: RegExp},
254 forbiddenProps: {} as {[key: string]: RegExp},
255 },
256 ),
257 );
258 }
259 }
260 });
261 }
262
263 return output;

Callers 1

constructorMethod · 0.95

Calls 1

pushMethod · 0.65

Tested by

no test coverage detected