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 | function rule(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.startsWith('-')
|
46 | ) {
|
47 | return;
|
48 | }
|
49 |
|
50 | const prop = decl.prop;
|
51 | const value = decl.value;
|
52 | const unprefixedValue = postcss.vendor.unprefixed(value);
|
53 |
|
54 |
|
55 | if (optionsMatches(options, 'ignoreValues', unprefixedValue)) {
|
56 | return;
|
57 | }
|
58 |
|
59 |
|
60 |
|
61 | styleSearch({ source: value.toLowerCase(), target: valuePrefixes }, (match) => {
|
62 | const fullIdentifier = /^(-[a-z-]+)\b/i.exec(value.slice(match.startIndex))[1];
|
63 |
|
64 | if (!isAutoprefixable.propertyValue(prop, fullIdentifier)) {
|
65 | return;
|
66 | }
|
67 |
|
68 | report({
|
69 | message: messages.rejected(fullIdentifier),
|
70 | node: decl,
|
71 | index: prop.length + (decl.raws.between || '').length + match.startIndex,
|
72 | result,
|
73 | ruleName,
|
74 | });
|
75 | });
|
76 | });
|
77 | };
|
78 | }
|
79 |
|
80 | rule.ruleName = ruleName;
|
81 | rule.messages = messages;
|
82 | module.exports = rule;
|