.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / stylelint / lib / rules / no-unknown-animations / index.js
1 "use strict";
2
3 const declarationValueIndex = require("../../utils/declarationValueIndex");
4 const findAnimationName = require("../../utils/findAnimationName");
5 const keywordSets = require("../../reference/keywordSets");
6 const report = require("../../utils/report");
7 const ruleMessages = require("../../utils/ruleMessages");
8 const validateOptions = require("../../utils/validateOptions");
9
10 const ruleName = "no-unknown-animations";
11
12 const messages = ruleMessages(ruleName, {
13   rejected: animationName =>
14     `Unexpected unknown animation name "${animationName}"`
15 });
16
17 const rule = function(actual) {
18   return (root, result) => {
19     const validOptions = validateOptions(result, ruleName, { actual });
20     if (!validOptions) {
21       return;
22     }
23
24     const declaredAnimations = new Set();
25     root.walkAtRules(/(-(moz|webkit)-)?keyframes/i, atRule => {
26       declaredAnimations.add(atRule.params);
27     });
28
29     root.walkDecls(decl => {
30       if (
31         decl.prop.toLowerCase() === "animation" ||
32         decl.prop.toLowerCase() === "animation-name"
33       ) {
34         const animationNames = findAnimationName(decl.value);
35
36         if (animationNames.length === 0) {
37           return;
38         }
39
40         animationNames.forEach(animationNameNode => {
41           if (
42             keywordSets.animationNameKeywords.has(
43               animationNameNode.value.toLowerCase()
44             )
45           ) {
46             return;
47           }
48           if (declaredAnimations.has(animationNameNode.value)) {
49             return;
50           }
51
52           report({
53             result,
54             ruleName,
55             message: messages.rejected(animationNameNode.value),
56             node: decl,
57             index: declarationValueIndex(decl) + animationNameNode.sourceIndex
58           });
59         });
60       }
61     });
62   };
63 };
64
65 rule.ruleName = ruleName;
66 rule.messages = messages;
67 module.exports = rule;