Skip to content

Commit a48b8c6

Browse files
committed
v2.1.2
1 parent 3f0a30c commit a48b8c6

File tree

4 files changed

+87
-22
lines changed

4 files changed

+87
-22
lines changed

.tape.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,30 @@ module.exports = {
77
source: 'body { left: 0 }',
88
args: [ 'always', { except: 'left' }],
99
warnings: 0,
10+
}, {
11+
source: 'body { top: -4px; left: 0; }',
12+
args: 'always',
13+
warnings: 2,
14+
}, {
15+
source: 'body { top: -4px; left: 0; }',
16+
args: ['always', { except: 'top' }],
17+
warnings: 1,
18+
}, {
19+
source: 'body { top: -4px; left: 0; }',
20+
args: ['always', { except: 'left' }],
21+
warnings: 1,
22+
}, {
23+
source: 'body { top: -4px; left: 0; }',
24+
args: ['always', { except: ['top', 'left'] }],
25+
warnings: 0,
26+
}, {
27+
source: 'body { margin-top: 0.5rem; margin-bottom: 0.5rem; }',
28+
args: ['always', { except: ['margin-top'] }],
29+
warnings: 1,
30+
}, {
31+
source: 'body { margin-top: 0.5rem; margin-bottom: 0.5rem; }',
32+
args: ['always', { except: ['margin-top', 'margin-bottom'] }],
33+
warnings: 0,
1034
}, {
1135
source: 'body { top: 0; left: 0 }',
1236
args: 'always',

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changes to Property Use Logical
22

3+
### 2.1.2 (March 3, 2024)
4+
5+
- Fix `exports` in `package.json` [#25](https://github.com/csstools/stylelint-use-logical/issues/25)
6+
- Fix `except` plugin option [#3](https://github.com/csstools/stylelint-use-logical/issues/3)
7+
38
### 2.1.1 (February 19, 2024)
49

510
- Updated: peer `stylelint` to `>= 11 < 17` (patch) [#22](https://github.com/csstools/stylelint-use-logical/pull/22)

index.js

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ function ruleFunc(method, opts, context) {
4141
// validate or autofix 4 physical properties as logical shorthands
4242
physical4Prop.forEach(([ props, prop ]) => {
4343
validateRuleWithProps(node, props, (blockStartDecl, blockStartIndex, inlineStartDecl, inlineStartIndex, blockEndDecl, blockEndIndex, inlineEndDecl, inlineEndIndex) => { // eslint-disable-line
44+
if (
45+
isDeclAnException(blockStartDecl, propExceptions) ||
46+
isDeclAnException(inlineStartDecl, propExceptions) ||
47+
isDeclAnException(blockEndDecl, propExceptions) ||
48+
isDeclAnException(inlineEndDecl, propExceptions)
49+
) {
50+
return;
51+
}
52+
4453
const firstInlineDecl = blockStartDecl;
4554

4655
if (isAutofix) {
@@ -81,6 +90,13 @@ function ruleFunc(method, opts, context) {
8190
// validate or autofix 2 physical properties as logical shorthands
8291
physical2Prop().forEach(([ props, prop ]) => {
8392
validateRuleWithProps(node, props, (blockStartDecl, blockStartIndex, inlineStartDecl, inlineStartIndex) => { // eslint-disable-line
93+
if (
94+
isDeclAnException(blockStartDecl, propExceptions) ||
95+
isDeclAnException(inlineStartDecl, propExceptions)
96+
) {
97+
return;
98+
}
99+
84100
const firstInlineDecl = blockStartIndex < inlineStartIndex
85101
? blockStartDecl
86102
: inlineStartDecl;
@@ -107,33 +123,41 @@ function ruleFunc(method, opts, context) {
107123
// validate or autofix physical properties as logical
108124
physicalProp(dir).forEach(([ props, prop ]) => {
109125
validateRuleWithProps(node, props, physicalDecl => {
110-
if (!isDeclAnException(physicalDecl, propExceptions)) {
111-
if (isAutofix) {
112-
physicalDecl.prop = prop;
113-
} else if (!isDeclReported(physicalDecl)) {
114-
reportUnexpectedProperty(physicalDecl, prop);
126+
if (isDeclAnException(physicalDecl, propExceptions)) {
127+
return;
128+
}
115129

116-
reportedDecls.set(physicalDecl);
117-
}
130+
if (isAutofix) {
131+
physicalDecl.prop = prop;
132+
} else if (!isDeclReported(physicalDecl)) {
133+
reportUnexpectedProperty(physicalDecl, prop);
134+
135+
reportedDecls.set(physicalDecl);
118136
}
119137
});
120138
});
121139

122140
// validate or autofix physical values as logical
123141
physicalValue(dir).forEach(([ regexp, props ]) => {
124-
if (isNodeMatchingDecl(node, regexp) && !isDeclAnException(node, propExceptions)) {
125-
const valuekey = node.value.toLowerCase();
142+
if (!isNodeMatchingDecl(node, regexp)) {
143+
return;
144+
}
126145

127-
if (valuekey in props) {
128-
const value = props[valuekey];
146+
if (isDeclAnException(node, propExceptions)) {
147+
return;
148+
}
129149

130-
if (isAutofix) {
131-
node.value = value;
132-
} else {
133-
reportUnexpectedValue(node, value);
150+
const valuekey = node.value.toLowerCase();
134151

135-
reportedDecls.set(node);
136-
}
152+
if (valuekey in props) {
153+
const value = props[valuekey];
154+
155+
if (isAutofix) {
156+
node.value = value;
157+
} else {
158+
reportUnexpectedValue(node, value);
159+
160+
reportedDecls.set(node);
137161
}
138162
}
139163
});
@@ -149,7 +173,19 @@ const isMethodIndifferent = method => method === 'ignore' || method === false ||
149173
const isMethodAlways = method => method === 'always' || method === true;
150174
const isContextAutofixing = context => Boolean(Object(context).fix);
151175
const isNodeMatchingDecl = (decl, regexp) => decl.type === 'decl' && regexp.test(decl.prop);
152-
const isDeclAnException = (decl, propExceptions) => propExceptions.some(match => match instanceof RegExp
153-
? match.test(decl.prop)
154-
: String(match || '').toLowerCase() === String(decl.prop || '').toLowerCase());
176+
177+
const isDeclAnException = (decl, propExceptions) => {
178+
if (!decl || decl.type !== 'decl') {
179+
return false;
180+
}
181+
182+
return propExceptions.some((match) => {
183+
if (match instanceof RegExp) {
184+
return match.test(decl.prop);
185+
}
186+
187+
return String(match || '').toLowerCase() === String(decl.prop || '').toLowerCase();
188+
});
189+
}
190+
155191
const isDeclReported = decl => reportedDecls.has(decl);

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "stylelint-use-logical",
3-
"version": "2.1.1",
3+
"version": "2.1.2",
44
"description": "Enforce usage of logical properties and values in CSS",
55
"license": "CC0-1.0",
66
"author": "Jonathan Neal <[email protected]>",
@@ -12,7 +12,7 @@
1212
"exports": {
1313
".": {
1414
"import": "./index.mjs",
15-
"node": "./index.cjs"
15+
"require": "./index.cjs"
1616
}
1717
},
1818
"files": [

0 commit comments

Comments
 (0)