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

Function ruleFn

tools/stylelint/no-concrete-rules.ts:15–45  ·  view source on GitHub ↗
(isEnabled, options)

Source from the content-addressed store, hash-verified

13 * Can be used in theme files to ensure that everything is inside a mixin.
14 */
15const ruleFn: Rule<boolean, string> = (isEnabled, options) => {
16 return (root, result) => {
17 if (!isEnabled) {
18 return;
19 }
20
21 const filePattern = options.filePattern ? new RegExp(options.filePattern) : null;
22 const fileName = basename(root.source!.input.file!);
23
24 if ((filePattern !== null && !filePattern.test(fileName)) || !root.nodes) {
25 return;
26 }
27
28 // Go through all the nodes and report a warning for every CSS rule or mixin inclusion.
29 // We use a regular `forEach`, instead of the PostCSS walker utils, because we only care
30 // about the top-level nodes.
31 root.nodes.forEach(node => {
32 if (node.type === 'rule' || (node.type === 'atrule' && node.name === 'include')) {
33 utils.report({
34 result,
35 ruleName,
36 node,
37 message:
38 filePattern !== null
39 ? messages.expectedWithPattern(filePattern)
40 : messages.expectedAllFiles(),
41 });
42 }
43 });
44 };
45};
46
47ruleFn.ruleName = ruleName;
48ruleFn.messages = messages;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected