logicalPropertiesLinter.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _utils = require("./utils");
  7. var linter = function linter(key, value, info) {
  8. switch (key) {
  9. case 'marginLeft':
  10. case 'marginRight':
  11. case 'paddingLeft':
  12. case 'paddingRight':
  13. case 'left':
  14. case 'right':
  15. case 'borderLeft':
  16. case 'borderLeftWidth':
  17. case 'borderLeftStyle':
  18. case 'borderLeftColor':
  19. case 'borderRight':
  20. case 'borderRightWidth':
  21. case 'borderRightStyle':
  22. case 'borderRightColor':
  23. case 'borderTopLeftRadius':
  24. case 'borderTopRightRadius':
  25. case 'borderBottomLeftRadius':
  26. case 'borderBottomRightRadius':
  27. (0, _utils.lintWarning)("You seem to be using non-logical property '".concat(key, "' which is not compatible with RTL mode. Please use logical properties and values instead. For more information: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Logical_Properties."), info);
  28. return;
  29. case 'margin':
  30. case 'padding':
  31. case 'borderWidth':
  32. case 'borderStyle':
  33. // case 'borderColor':
  34. if (typeof value === 'string') {
  35. var valueArr = value.split(' ').map(function (item) {
  36. return item.trim();
  37. });
  38. if (valueArr.length === 4 && valueArr[1] !== valueArr[3]) {
  39. (0, _utils.lintWarning)("You seem to be using '".concat(key, "' property with different left ").concat(key, " and right ").concat(key, ", which is not compatible with RTL mode. Please use logical properties and values instead. For more information: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Logical_Properties."), info);
  40. }
  41. }
  42. return;
  43. case 'clear':
  44. case 'textAlign':
  45. if (value === 'left' || value === 'right') {
  46. (0, _utils.lintWarning)("You seem to be using non-logical value '".concat(value, "' of ").concat(key, ", which is not compatible with RTL mode. Please use logical properties and values instead. For more information: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Logical_Properties."), info);
  47. }
  48. return;
  49. case 'borderRadius':
  50. if (typeof value === 'string') {
  51. var radiusGroups = value.split('/').map(function (item) {
  52. return item.trim();
  53. });
  54. var invalid = radiusGroups.reduce(function (result, group) {
  55. if (result) {
  56. return result;
  57. }
  58. var radiusArr = group.split(' ').map(function (item) {
  59. return item.trim();
  60. });
  61. // borderRadius: '2px 4px'
  62. if (radiusArr.length >= 2 && radiusArr[0] !== radiusArr[1]) {
  63. return true;
  64. }
  65. // borderRadius: '4px 4px 2px'
  66. if (radiusArr.length === 3 && radiusArr[1] !== radiusArr[2]) {
  67. return true;
  68. }
  69. // borderRadius: '4px 4px 2px 4px'
  70. if (radiusArr.length === 4 && radiusArr[2] !== radiusArr[3]) {
  71. return true;
  72. }
  73. return result;
  74. }, false);
  75. if (invalid) {
  76. (0, _utils.lintWarning)("You seem to be using non-logical value '".concat(value, "' of ").concat(key, ", which is not compatible with RTL mode. Please use logical properties and values instead. For more information: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Logical_Properties."), info);
  77. }
  78. }
  79. return;
  80. default:
  81. }
  82. };
  83. var _default = exports.default = linter;