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