.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / lib / rules / property-no-unknown / index.js
1 "use strict";
2
3 const _ = require("lodash");
4 const isCustomProperty = require("../../utils/isCustomProperty");
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 properties = require("known-css-properties").all;
10 const report = require("../../utils/report");
11 const ruleMessages = require("../../utils/ruleMessages");
12 const validateOptions = require("../../utils/validateOptions");
13
14 const ruleName = "property-no-unknown";
15
16 const messages = ruleMessages(ruleName, {
17   rejected: property => `Unexpected unknown property "${property}"`
18 });
19
20 const rule = function(actual, options) {
21   return (root, result) => {
22     const validOptions = validateOptions(
23       result,
24       ruleName,
25       { actual },
26       {
27         actual: options,
28         possible: {
29           ignoreProperties: [_.isString],
30           checkPrefixed: _.isBoolean
31         },
32         optional: true
33       }
34     );
35
36     if (!validOptions) {
37       return;
38     }
39
40     const shouldCheckPrefixed = _.get(options, "checkPrefixed");
41
42     root.walkDecls(decl => {
43       const prop = decl.prop;
44
45       if (!isStandardSyntaxProperty(prop)) {
46         return;
47       }
48       if (!isStandardSyntaxDeclaration(decl)) {
49         return;
50       }
51       if (isCustomProperty(prop)) {
52         return;
53       }
54
55       if (!shouldCheckPrefixed && postcss.vendor.prefix(prop)) {
56         return;
57       }
58
59       if (optionsMatches(options, "ignoreProperties", prop)) {
60         return;
61       }
62
63       if (properties.indexOf(prop.toLowerCase()) !== -1) {
64         return;
65       }
66
67       report({
68         message: messages.rejected(prop),
69         node: decl,
70         result,
71         ruleName
72       });
73     });
74   };
75 };
76
77 rule.ruleName = ruleName;
78 rule.messages = messages;
79 module.exports = rule;