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