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