stylelint-plugin-logical-css 0.1.1 → 0.2.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
@@ -52,7 +52,28 @@ Let's explore each rule to better understand what it does, and does not, allow.
52
52
  This rule is responsible for checking both CSS properties and values. When a
53
53
  physical property or value is found, it will be flagged.
54
54
 
55
- #### Not Allowed
55
+ #### Options
56
+
57
+ The `use-logical-properties-and-values` rule accepts the following options:
58
+
59
+ | Option | Type | Default | Description |
60
+ | ----------------- | ------- | ------- | --------------------------------------------------------------------------------------------- |
61
+ | `enable-auto-fix` | boolean | false | Use this flag in addition to the native Stylelint `--fix` flag to enable auto fixing on save. |
62
+
63
+ ```json
64
+ {
65
+ "rules": {
66
+ "plugin/use-logical-properties-and-values": [
67
+ true,
68
+ { "severity": "warning", "enable-auto-fix": true }
69
+ ]
70
+ }
71
+ }
72
+ ```
73
+
74
+ #### Usage
75
+
76
+ ##### Not Allowed
56
77
 
57
78
  ```css
58
79
  .heading {
@@ -61,7 +82,7 @@ physical property or value is found, it will be flagged.
61
82
  }
62
83
  ```
63
84
 
64
- #### Allowed
85
+ ##### Allowed
65
86
 
66
87
  ```css
67
88
  .heading {
@@ -84,7 +105,28 @@ and viewport height respectively will not reflect different writing modes and
84
105
  directions. Instead, this rule will enforce the logical equivalents, `vi` and
85
106
  `vb`.
86
107
 
87
- #### Not Allowed
108
+ #### Options
109
+
110
+ The `use-logical-units` rule accepts the following options:
111
+
112
+ | Option | Type | Default | Description |
113
+ | ----------------- | ------- | ------- | --------------------------------------------------------------------------------------------- |
114
+ | `enable-auto-fix` | boolean | false | Use this flag in addition to the native Stylelint `--fix` flag to enable auto fixing on save. |
115
+
116
+ ```json
117
+ {
118
+ "rules": {
119
+ "plugin/use-logical-units": [
120
+ true,
121
+ { "severity": "warning", "enable-auto-fix": true }
122
+ ]
123
+ }
124
+ }
125
+ ```
126
+
127
+ #### Usage
128
+
129
+ ##### Not Allowed
88
130
 
89
131
  ```css
90
132
  body {
@@ -92,7 +134,7 @@ body {
92
134
  }
93
135
  ```
94
136
 
95
- #### Allowed
137
+ ##### Allowed
96
138
 
97
139
  ```css
98
140
  body {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stylelint-plugin-logical-css",
3
- "version": "0.1.1",
3
+ "version": "0.2.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": [
@@ -10,13 +10,7 @@ const { physicalValuesMap } = require('../../utils/physicalValuesMap');
10
10
 
11
11
  const ruleFunction = (_, options, context) => {
12
12
  return (root, result) => {
13
- const validOptions = stylelint.utils.validateOptions(result, ruleName, [
14
- {
15
- action: 'enableAutoFix',
16
- possible: [true, false],
17
- optional: true,
18
- },
19
- ]);
13
+ const validOptions = stylelint.utils.validateOptions(result, ruleName);
20
14
 
21
15
  if (!validOptions) {
22
16
  return;
@@ -39,7 +33,7 @@ const ruleFunction = (_, options, context) => {
39
33
  physicalValuesMap[decl.prop][decl.value],
40
34
  );
41
35
 
42
- if (context.fix && options.enableAutoFix) {
36
+ if (context.fix && options?.['enable-auto-fix']) {
43
37
  if (propIsPhysical) {
44
38
  decl.prop = physicalPropertiesMap[decl.prop];
45
39
  }
@@ -6,7 +6,7 @@ const { ruleName, ruleMessages, ruleMeta } = require('./base');
6
6
  const { getValueUnit, isPhysicalUnit } = require('../../utils/isPhysicalUnit');
7
7
  const { physicalUnitsMap } = require('../../utils/physicalUnitsMap');
8
8
 
9
- const ruleFunction = () => {
9
+ const ruleFunction = (_, options, context) => {
10
10
  return (root, result) => {
11
11
  const validOptions = stylelint.utils.validateOptions(result, ruleName);
12
12
 
@@ -25,6 +25,15 @@ const ruleFunction = () => {
25
25
  physicalUnitsMap[physicalUnit],
26
26
  );
27
27
 
28
+ if (context.fix && options?.['enable-auto-fix']) {
29
+ decl.value = decl.value.replace(
30
+ physicalUnit,
31
+ physicalUnitsMap[physicalUnit],
32
+ );
33
+
34
+ return;
35
+ }
36
+
28
37
  stylelint.utils.report({
29
38
  message,
30
39
  node: decl,