@mrhenry/stylelint-mrhenry-nesting 2.2.0 → 2.2.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrhenry/stylelint-mrhenry-nesting",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "Mr. Henry's preferred way of writing nested CSS",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -140,7 +140,7 @@ const ruleFunction = (primaryOption, secondaryOptionObject, context) => {
140
140
  selectorAST.nodes[selectorAST.nodes.length - 2]?.type === 'combinator'
141
141
  ) {
142
142
  fixSelector_AncestorPattern(rule, selectorsAST, selectorAST);
143
- return;
143
+ continue;
144
144
  }
145
145
 
146
146
  // .foo { :focus& {} }
@@ -161,14 +161,14 @@ const ruleFunction = (primaryOption, secondaryOptionObject, context) => {
161
161
  ]
162
162
  }))
163
163
  rule.selector = selectorsAST.toString();
164
- return;
164
+ continue;
165
165
  }
166
166
 
167
167
  // .foo { .bar {} }
168
168
  if (selectorAST.nodes[0]?.type !== 'nesting') {
169
169
  if (context.fix) {
170
170
  fixSelector(rule, selectorsAST, selectorAST);
171
- return;
171
+ continue;
172
172
  }
173
173
 
174
174
  stylelint.utils.report({
@@ -180,15 +180,25 @@ const ruleFunction = (primaryOption, secondaryOptionObject, context) => {
180
180
  ruleName,
181
181
  });
182
182
 
183
- return;
183
+ continue;
184
184
  }
185
185
 
186
186
  // .foo { & + .bar {} }
187
187
  if (selectorAST.nodes.length !== 2) {
188
188
  if (context.fix) {
189
- selectorAST.nodes[0]?.remove();
190
- fixSelector(rule, selectorsAST, selectorAST);
191
- return;
189
+
190
+ const firstPart = selectorAST.nodes[0];
191
+ const afterFirstPart = selectorAST.nodes[0]?.next();
192
+
193
+ if (firstPart && afterFirstPart?.type === 'combinator') {
194
+ selectorAST.nodes[0]?.replaceWith(selectorParser.nesting())
195
+ fixSelector(rule, selectorsAST, selectorAST);
196
+ } else {
197
+ selectorAST.nodes[0]?.remove();
198
+ fixSelector(rule, selectorsAST, selectorAST);
199
+ }
200
+
201
+ continue;
192
202
  }
193
203
 
194
204
  stylelint.utils.report({
@@ -200,7 +210,7 @@ const ruleFunction = (primaryOption, secondaryOptionObject, context) => {
200
210
  ruleName,
201
211
  });
202
212
 
203
- return;
213
+ continue;
204
214
  }
205
215
 
206
216
  // .foo { &.bar {} }
@@ -208,7 +218,7 @@ const ruleFunction = (primaryOption, secondaryOptionObject, context) => {
208
218
  if (context.fix) {
209
219
  selectorAST.nodes[0]?.remove();
210
220
  fixSelector(rule, selectorsAST, selectorAST);
211
- return;
221
+ continue;
212
222
  }
213
223
 
214
224
  stylelint.utils.report({
@@ -220,7 +230,7 @@ const ruleFunction = (primaryOption, secondaryOptionObject, context) => {
220
230
  ruleName,
221
231
  });
222
232
 
223
- return;
233
+ continue;
224
234
  }
225
235
  }
226
236
  });