.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / lib / rules / function-blacklist / index.js
1 "use strict";
2
3 const _ = require("lodash");
4 const declarationValueIndex = require("../../utils/declarationValueIndex");
5 const isStandardSyntaxFunction = require("../../utils/isStandardSyntaxFunction");
6 const matchesStringOrRegExp = require("../../utils/matchesStringOrRegExp");
7 const postcss = require("postcss");
8 const report = require("../../utils/report");
9 const ruleMessages = require("../../utils/ruleMessages");
10 const validateOptions = require("../../utils/validateOptions");
11 const valueParser = require("postcss-value-parser");
12
13 const ruleName = "function-blacklist";
14
15 const messages = ruleMessages(ruleName, {
16   rejected: name => `Unexpected function "${name}"`
17 });
18
19 const rule = function(blacklist) {
20   return (root, result) => {
21     const validOptions = validateOptions(result, ruleName, {
22       actual: blacklist,
23       possible: [_.isString]
24     });
25     if (!validOptions) {
26       return;
27     }
28     root.walkDecls(decl => {
29       const value = decl.value;
30
31       valueParser(value).walk(function(node) {
32         if (node.type !== "function") {
33           return;
34         }
35         if (!isStandardSyntaxFunction(node)) {
36           return;
37         }
38         if (
39           !matchesStringOrRegExp(
40             postcss.vendor.unprefixed(node.value),
41             blacklist
42           )
43         ) {
44           return;
45         }
46
47         report({
48           message: messages.rejected(node.value),
49           node: decl,
50           index: declarationValueIndex(decl) + node.sourceIndex,
51           result,
52           ruleName
53         });
54       });
55     });
56   };
57 };
58
59 rule.primaryOptionArray = true;
60
61 rule.ruleName = ruleName;
62 rule.messages = messages;
63 module.exports = rule;