stylelint-plugin-logical-css 0.4.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -139,3 +139,10 @@ body {
139
139
  max-block-size: 100vb;
140
140
  }
141
141
  ```
142
+
143
+ ## TODO
144
+
145
+ What can be expected in the future.
146
+
147
+ [] Refactor to TypeScript
148
+ [] Support disabling individual property checks
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stylelint-plugin-logical-css",
3
- "version": "0.4.1",
3
+ "version": "0.6.0",
4
4
  "description": "A Stylelint plugin to enforce the use of logical CSS properties, values and units.",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -3,11 +3,12 @@
3
3
  const stylelint = require('stylelint');
4
4
 
5
5
  const { ruleName, ruleMessages, ruleMeta } = require('./base');
6
+ const { vendorPrefixes } = require('../../utils/vendorPrefixes');
7
+ const { physicalProperties } = require('../../utils/physical');
6
8
  const { isPhysicalProperty } = require('../../utils/isPhysicalProperty');
7
9
  const { isPhysicalValue } = require('../../utils/isPhysicalValue');
8
10
  const { physicalPropertiesMap } = require('../../utils/physicalPropertiesMap');
9
11
  const { physicalValuesMap } = require('../../utils/physicalValuesMap');
10
- const { propsToSkip } = require('../../utils/propsToSkip');
11
12
 
12
13
  const ruleFunction = (_, options, context) => {
13
14
  return (root, result) => {
@@ -18,7 +19,13 @@ const ruleFunction = (_, options, context) => {
18
19
  }
19
20
 
20
21
  root.walkDecls((decl) => {
21
- if (propsToSkip.includes(decl.prop)) return;
22
+ let rootProp = decl.prop;
23
+ vendorPrefixes.forEach(
24
+ (prefix) => (rootProp = rootProp.replace(prefix, '')),
25
+ );
26
+
27
+ const isValidProp = Object.values(physicalProperties).includes(rootProp);
28
+ if (!isValidProp) return;
22
29
 
23
30
  const propIsPhysical = isPhysicalProperty(decl.prop);
24
31
  const valueIsPhysical = isPhysicalValue(decl.value);
@@ -28,21 +35,21 @@ const ruleFunction = (_, options, context) => {
28
35
  const message = propIsPhysical
29
36
  ? ruleMessages.unexpectedProp(
30
37
  decl.prop,
31
- physicalPropertiesMap[decl.prop],
38
+ physicalPropertiesMap[rootProp],
32
39
  )
33
40
  : ruleMessages.unexpectedValue(
34
41
  decl.prop,
35
42
  decl.value,
36
- physicalValuesMap[decl.prop][decl.value],
43
+ physicalValuesMap[rootProp][decl.value],
37
44
  );
38
45
 
39
46
  if (context.fix && options?.['enable-auto-fix']) {
40
47
  if (propIsPhysical) {
41
- decl.prop = physicalPropertiesMap[decl.prop];
48
+ decl.prop = physicalPropertiesMap[rootProp];
42
49
  }
43
50
 
44
51
  if (valueIsPhysical) {
45
- decl.value = physicalValuesMap[decl.value];
52
+ decl.value = physicalValuesMap[rootProp][decl.value];
46
53
  }
47
54
 
48
55
  return;
@@ -6,7 +6,6 @@ const physicalAxis = Object.freeze({
6
6
  });
7
7
 
8
8
  const physicalProperties = Object.freeze({
9
- webkitBoxOrient: '-webkit-box-orient',
10
9
  borderBottom: 'border-bottom',
11
10
  borderBottomColor: 'border-bottom-color',
12
11
  borderBottomLeftRadius: 'border-bottom-left-radius',
@@ -27,6 +26,7 @@ const physicalProperties = Object.freeze({
27
26
  borderTopRightRadius: 'border-top-right-radius',
28
27
  borderTopStyle: 'border-top-style',
29
28
  borderTopWidth: 'border-top-width',
29
+ boxOrient: 'box-orient',
30
30
  bottom: 'bottom',
31
31
  captionSide: 'caption-side',
32
32
  clear: 'clear',
@@ -10,7 +10,7 @@ const {
10
10
  } = require('./physical');
11
11
 
12
12
  const physicalValuesMap = Object.freeze({
13
- [physicalProperties.webkitBoxOrient]: {
13
+ [physicalProperties.boxOrient]: {
14
14
  [physicalAxis.horizontal]: `${logicalAxis.inline}-axis`,
15
15
  [physicalAxis.vertical]: `${logicalAxis.block}-axis`,
16
16
  },
@@ -0,0 +1,3 @@
1
+ const vendorPrefixes = ['-webkit-', '-moz-', '-o-', '-ms-'];
2
+
3
+ module.exports = { vendorPrefixes };
@@ -1,21 +0,0 @@
1
- /*
2
- The properties included in this array can contain physical values like left and bottom.
3
- However, logical values for the4se properties are not yet supported. So for the time being,
4
- we skip linting them entirely.
5
- */
6
- const propsToSkip = [
7
- 'background',
8
- 'background-position',
9
- 'background-position-x',
10
- 'background-position-y',
11
- 'grid-area',
12
- 'grid-template-areas',
13
- '-webkit-mask-position',
14
- 'mask-position',
15
- 'transform-origin',
16
- 'vertical-align',
17
- ];
18
-
19
- module.exports = {
20
- propsToSkip,
21
- };