logicalPropertiesLinter.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _utils = require("./utils");
  7. const 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 '${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. const valueArr = value.split(' ').map(item => item.trim());
  36. if (valueArr.length === 4 && valueArr[1] !== valueArr[3]) {
  37. (0, _utils.lintWarning)(`You seem to be using '${key}' property with different left ${key} and right ${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);
  38. }
  39. }
  40. return;
  41. case 'clear':
  42. case 'textAlign':
  43. if (value === 'left' || value === 'right') {
  44. (0, _utils.lintWarning)(`You seem to be using non-logical value '${value}' of ${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);
  45. }
  46. return;
  47. case 'borderRadius':
  48. if (typeof value === 'string') {
  49. const radiusGroups = value.split('/').map(item => item.trim());
  50. const invalid = radiusGroups.reduce((result, group) => {
  51. if (result) {
  52. return result;
  53. }
  54. const radiusArr = group.split(' ').map(item => item.trim());
  55. // borderRadius: '2px 4px'
  56. if (radiusArr.length >= 2 && radiusArr[0] !== radiusArr[1]) {
  57. return true;
  58. }
  59. // borderRadius: '4px 4px 2px'
  60. if (radiusArr.length === 3 && radiusArr[1] !== radiusArr[2]) {
  61. return true;
  62. }
  63. // borderRadius: '4px 4px 2px 4px'
  64. if (radiusArr.length === 4 && radiusArr[2] !== radiusArr[3]) {
  65. return true;
  66. }
  67. return result;
  68. }, false);
  69. if (invalid) {
  70. (0, _utils.lintWarning)(`You seem to be using non-logical value '${value}' of ${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);
  71. }
  72. }
  73. return;
  74. default:
  75. }
  76. };
  77. var _default = exports.default = linter;