.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / lib / rules / value-no-vendor-prefix / index.js
1 "use strict";
2
3 const _ = require("lodash");
4 const isAutoprefixable = require("../../utils/isAutoprefixable");
5 const isStandardSyntaxDeclaration = require("../../utils/isStandardSyntaxDeclaration");
6 const isStandardSyntaxProperty = require("../../utils/isStandardSyntaxProperty");
7 const optionsMatches = require("../../utils/optionsMatches");
8 const postcss = require("postcss");
9 const report = require("../../utils/report");
10 const ruleMessages = require("../../utils/ruleMessages");
11 const styleSearch = require("style-search");
12 const validateOptions = require("../../utils/validateOptions");
13
14 const ruleName = "value-no-vendor-prefix";
15
16 const messages = ruleMessages(ruleName, {
17   rejected: value => `Unexpected vendor-prefix "${value}"`
18 });
19
20 const valuePrefixes = ["-webkit-", "-moz-", "-ms-", "-o-"];
21
22 const rule = function(actual, options) {
23   return (root, result) => {
24     const validOptions = validateOptions(
25       result,
26       ruleName,
27       { actual },
28       {
29         optional: true,
30         actual: options,
31         possible: {
32           ignoreValues: [_.isString]
33         }
34       }
35     );
36
37     if (!validOptions) {
38       return;
39     }
40
41     root.walkDecls(decl => {
42       if (
43         !isStandardSyntaxDeclaration(decl) ||
44         !isStandardSyntaxProperty(decl.prop) ||
45         decl.value[0] !== "-"
46       ) {
47         return;
48       }
49
50       const prop = decl.prop,
51         value = decl.value,
52         unprefixedValue = postcss.vendor.unprefixed(value);
53
54       //return early if value is to be ignored
55       if (optionsMatches(options, "ignoreValues", unprefixedValue)) {
56         return;
57       }
58
59       // Search the full declaration in order to get an accurate index
60
61       styleSearch(
62         { source: value.toLowerCase(), target: valuePrefixes },
63         match => {
64           const fullIdentifier = /^(-[a-z-]+)\b/i.exec(
65             value.slice(match.startIndex)
66           )[1];
67           if (!isAutoprefixable.propertyValue(prop, fullIdentifier)) {
68             return;
69           }
70
71           report({
72             message: messages.rejected(fullIdentifier),
73             node: decl,
74             index:
75               prop.length + (decl.raws.between || "").length + match.startIndex,
76             result,
77             ruleName
78           });
79         }
80       );
81     });
82   };
83 };
84
85 rule.ruleName = ruleName;
86 rule.messages = messages;
87 module.exports = rule;