eslint-plugin-vue-scoped-css 2.0.0 → 2.1.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.
@@ -231,116 +231,121 @@ function* genChildElements(elements) {
231
231
  yield* genChildren(element);
232
232
  }
233
233
  }
234
- function* genParentElements(elements) {
235
- const found = new Set();
236
- for (const element of elements) {
237
- const parent = (0, elements_1.getParentElement)(element);
238
- if (parent) {
239
- if (!found.has(parent)) {
240
- yield parent;
241
- found.add(parent);
242
- }
234
+ function genParentElements(elements) {
235
+ return iterateUnique(function* () {
236
+ for (const element of elements) {
237
+ yield (0, elements_1.getParentElement)(element);
243
238
  }
244
- }
239
+ });
245
240
  }
246
- function* genAdjacentSiblingElements(elements) {
247
- for (const element of elements) {
248
- const parent = (0, elements_1.getParentElement)(element);
249
- if (parent == null) {
250
- continue;
251
- }
252
- const children = [...genChildElements([parent])];
253
- const index = children.indexOf(element);
254
- const e = children[index + 1];
255
- if (e) {
256
- yield e;
241
+ function genAdjacentSiblingElements(elements) {
242
+ return iterateUnique(function* () {
243
+ for (const element of elements) {
244
+ if (hasVFor(element)) {
245
+ yield element;
246
+ }
247
+ const vForTemplate = getVForTemplate(element);
248
+ if (vForTemplate) {
249
+ const children = [...genChildElements([vForTemplate])];
250
+ const index = children.indexOf(element);
251
+ yield children[index + 1] || children[0];
252
+ }
253
+ const parent = (0, elements_1.getParentElement)(element);
254
+ if (parent) {
255
+ const children = [...genChildElements([parent])];
256
+ const index = children.indexOf(element);
257
+ yield children[index + 1];
258
+ }
257
259
  }
258
- }
260
+ });
259
261
  }
260
- function* genPrevAdjacentSiblingElements(elements) {
261
- for (const element of elements) {
262
- const parent = (0, elements_1.getParentElement)(element);
263
- if (parent == null) {
264
- continue;
265
- }
266
- const children = [...genChildElements([parent])];
267
- const index = children.indexOf(element);
268
- const e = children[index - 1];
269
- if (e) {
270
- yield e;
262
+ function genPrevAdjacentSiblingElements(elements) {
263
+ return iterateUnique(function* () {
264
+ for (const element of elements) {
265
+ if (hasVFor(element)) {
266
+ yield element;
267
+ }
268
+ const vForTemplate = getVForTemplate(element);
269
+ if (vForTemplate) {
270
+ const children = [...genChildElements([vForTemplate])];
271
+ const index = children.indexOf(element);
272
+ yield children[index - 1] || children[children.length - 1];
273
+ }
274
+ const parent = (0, elements_1.getParentElement)(element);
275
+ if (parent) {
276
+ const children = [...genChildElements([parent])];
277
+ const index = children.indexOf(element);
278
+ yield children[index - 1];
279
+ }
271
280
  }
272
- }
281
+ });
273
282
  }
274
- function* genGeneralSiblingElements(elements) {
275
- const found = new Set();
276
- for (const element of elements) {
277
- const parent = (0, elements_1.getParentElement)(element);
278
- if (parent == null) {
279
- continue;
280
- }
281
- const children = [...genChildElements([parent])];
282
- const index = children.indexOf(element);
283
- for (const n of children.slice(index + 1)) {
284
- if (!found.has(n)) {
285
- yield n;
286
- found.add(n);
283
+ function genGeneralSiblingElements(elements) {
284
+ return iterateUnique(function* () {
285
+ for (const element of elements) {
286
+ if (hasVFor(element)) {
287
+ yield element;
288
+ }
289
+ const vForTemplate = getVForTemplate(element);
290
+ if (vForTemplate) {
291
+ yield* genChildElements([vForTemplate]);
292
+ }
293
+ const parent = (0, elements_1.getParentElement)(element);
294
+ if (parent) {
295
+ const children = [...genChildElements([parent])];
296
+ const index = children.indexOf(element);
297
+ yield* children.slice(index + 1);
287
298
  }
288
299
  }
289
- }
300
+ });
290
301
  }
291
- function* genPrevGeneralSiblingElements(elements) {
292
- const found = new Set();
293
- for (const element of elements) {
294
- const parent = (0, elements_1.getParentElement)(element);
295
- if (parent == null) {
296
- continue;
297
- }
298
- const children = [...genChildElements([parent])];
299
- const index = children.indexOf(element);
300
- for (const p of children.slice(0, index)) {
301
- if (!found.has(p)) {
302
- yield p;
303
- found.add(p);
302
+ function genPrevGeneralSiblingElements(elements) {
303
+ return iterateUnique(function* () {
304
+ for (const element of elements) {
305
+ if (hasVFor(element)) {
306
+ yield element;
307
+ }
308
+ const vForTemplate = getVForTemplate(element);
309
+ if (vForTemplate) {
310
+ yield* genChildElements([vForTemplate]);
311
+ }
312
+ const parent = (0, elements_1.getParentElement)(element);
313
+ if (parent) {
314
+ const children = [...genChildElements([parent])];
315
+ const index = children.indexOf(element);
316
+ yield* children.slice(0, index);
304
317
  }
305
318
  }
306
- }
319
+ });
307
320
  }
308
321
  function* genVDeepElements(elements, params, query) {
309
322
  if (params.length) {
310
- const found = new Set();
311
- for (const node of params) {
312
- const els = query(elements, node.nodes);
313
- for (const e of els) {
314
- if (!found.has(e)) {
315
- yield e;
316
- found.add(e);
317
- }
323
+ yield* iterateUnique(function* () {
324
+ for (const node of params) {
325
+ yield* query(elements, node.nodes);
318
326
  }
319
- }
327
+ });
320
328
  }
321
329
  else {
322
330
  yield* elements;
323
331
  }
324
332
  }
325
- function* genVSlottedElements(elements, params, query) {
326
- const found = new Set();
327
- for (const element of elements) {
328
- if ((0, elements_1.isSlotElement)(element)) {
329
- if (!found.has(element)) {
333
+ function genVSlottedElements(elements, params, query) {
334
+ return iterateUnique(function* () {
335
+ for (const element of elements) {
336
+ if ((0, elements_1.isSlotElement)(element)) {
330
337
  yield element;
331
- found.add(element);
332
338
  }
333
339
  }
334
- }
335
- for (const node of params) {
336
- const els = query(elements, node.nodes);
337
- for (const e of els) {
338
- if (!found.has(e) && inSlot(e)) {
339
- yield e;
340
- found.add(e);
340
+ for (const node of params) {
341
+ const els = query(elements, node.nodes);
342
+ for (const e of els) {
343
+ if (inSlot(e)) {
344
+ yield e;
345
+ }
341
346
  }
342
347
  }
343
- }
348
+ });
344
349
  function inSlot(e) {
345
350
  if ((0, elements_1.isSlotElement)(e)) {
346
351
  return true;
@@ -348,17 +353,12 @@ function* genVSlottedElements(elements, params, query) {
348
353
  return Boolean(e && e.parent && inSlot(e.parent));
349
354
  }
350
355
  }
351
- function* genVGlobalElements(_elements, params, document, query) {
352
- const found = new Set();
353
- for (const node of params) {
354
- const els = query(document.elements, node.nodes);
355
- for (const e of els) {
356
- if (!found.has(e)) {
357
- yield e;
358
- found.add(e);
359
- }
356
+ function genVGlobalElements(_elements, params, document, query) {
357
+ return iterateUnique(function* () {
358
+ for (const node of params) {
359
+ yield* query(document.elements, node.nodes);
360
360
  }
361
- }
361
+ });
362
362
  }
363
363
  function* genElementsByTagName(elements, tagName) {
364
364
  for (const element of elements) {
@@ -631,3 +631,28 @@ function withinTemplate(expr, document) {
631
631
  const templateRange = (_a = templateBody === null || templateBody === void 0 ? void 0 : templateBody.range) !== null && _a !== void 0 ? _a : [0, 0];
632
632
  return (templateRange[0] <= expr.range[0] && expr.range[1] <= templateRange[1]);
633
633
  }
634
+ function* iterateUnique(gen) {
635
+ const found = new Set();
636
+ for (const e of gen()) {
637
+ if (e != null && !found.has(e)) {
638
+ yield e;
639
+ found.add(e);
640
+ }
641
+ }
642
+ }
643
+ function hasVFor(element) {
644
+ return element.startTag.attributes.some((attr) => attr.directive && attr.key.name.name === "for");
645
+ }
646
+ function getVForTemplate(element) {
647
+ let parent = element.parent;
648
+ while (parent) {
649
+ if (parent.type !== "VElement" || parent.name !== "template") {
650
+ return null;
651
+ }
652
+ if (hasVFor(parent)) {
653
+ return parent;
654
+ }
655
+ parent = parent.parent;
656
+ }
657
+ return null;
658
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-vue-scoped-css",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "ESLint plugin for Scoped CSS in Vue.js",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -28,6 +28,7 @@
28
28
  "url": "git+https://github.com/future-architect/eslint-plugin-vue-scoped-css.git"
29
29
  },
30
30
  "author": "Yosuke Ota",
31
+ "funding": "https://github.com/sponsors/ota-meshi",
31
32
  "license": "MIT",
32
33
  "bugs": {
33
34
  "url": "https://github.com/future-architect/eslint-plugin-vue-scoped-css/issues"
@@ -47,7 +48,7 @@
47
48
  ],
48
49
  "devDependencies": {
49
50
  "@ota-meshi/eslint-plugin": "^0.10.0",
50
- "@types/eslint": "^7.2.0",
51
+ "@types/eslint": "^8.0.0",
51
52
  "@types/eslint-visitor-keys": "^1.0.0",
52
53
  "@types/estree": "^0.0.50",
53
54
  "@types/lodash": "^4.14.158",
@@ -61,15 +62,14 @@
61
62
  "eslint-plugin-eslint-comments": "^3.2.0",
62
63
  "eslint-plugin-eslint-plugin": "^4.0.0",
63
64
  "eslint-plugin-internal-rules": "file:./eslint-internal-rules",
64
- "eslint-plugin-json-schema-validator": "^1.0.0",
65
- "eslint-plugin-jsonc": "^1.7.0",
65
+ "eslint-plugin-json-schema-validator": "^2.0.0",
66
+ "eslint-plugin-jsonc": "^2.0.0",
66
67
  "eslint-plugin-node": "^11.1.0",
67
68
  "eslint-plugin-prettier": "^4.0.0",
68
69
  "eslint-plugin-regexp": "^1.0.0",
69
70
  "eslint-plugin-vue": "^8.0.0",
70
- "eslint-plugin-vue-scoped-css": "^1.0.0",
71
- "eslint-plugin-yml": "^0.10.0",
72
- "eslint4b": "^7.19.0",
71
+ "eslint-plugin-vue-scoped-css": "^2.0.0",
72
+ "eslint-plugin-yml": "^0.12.0",
73
73
  "mocha": "^9.1.2",
74
74
  "nyc": "^15.1.0",
75
75
  "pack": "^2.2.0",
@@ -78,7 +78,8 @@
78
78
  "rimraf": "^3.0.2",
79
79
  "semver": "^7.3.2",
80
80
  "stylelint": "^14.0.0",
81
- "stylelint-config-standard": "^23.0.0",
81
+ "stylelint-config-recommended-vue": "^1.1.0",
82
+ "stylelint-config-standard": "^24.0.0",
82
83
  "stylelint-plugin-stylus": "^0.13.0",
83
84
  "ts-node": "^10.0.0",
84
85
  "typescript": "^4.1.3",