UNPKG

1.01 kBJavaScriptView Raw
1'use strict';
2
3const hasInterpolation = require('../utils/hasInterpolation');
4
5/**
6 * Check whether a value is standard
7 *
8 * @param {string} value
9 * @returns {boolean}
10 */
11module.exports = function (value) {
12 let normalizedValue = value;
13
14 // Ignore operators before variables (example -$variable)
15 if (/^[-+*/]/.test(value[0])) {
16 normalizedValue = normalizedValue.slice(1);
17 }
18
19 // SCSS variable (example $variable)
20 if (normalizedValue.startsWith('$')) {
21 return false;
22 }
23
24 // SCSS namespace (example namespace.$variable)
25 if (/^.+\.\$/.test(value)) {
26 return false;
27 }
28
29 // Less variable
30 if (normalizedValue.startsWith('@')) {
31 return false;
32 }
33
34 // SCSS or Less interpolation
35 if (hasInterpolation(normalizedValue)) {
36 return false;
37 }
38
39 // WebExtension replacement keyword used by Chrome/Firefox
40 // more information: https://developer.chrome.com/extensions/i18n
41 // and https://github.com/stylelint/stylelint/issues/4707
42 if (/__MSG_[^\s]+__/.test(value)) {
43 return false;
44 }
45
46 return true;
47};