isStandardSyntaxValue.js 1.0 KB

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