Skip to content

Commit f692b04

Browse files
authored
feat: support for description in directive comments (#256)
* feat: support for description in directive comments * Create wise-cougars-jump.md
1 parent 1c95b83 commit f692b04

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

.changeset/wise-cougars-jump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-vue-scoped-css": minor
3+
---
4+
5+
feat: support for description in directive comments

lib/styles/context/comment-directive/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,23 @@ const COMMENT_DIRECTIVE_L =
1616
type ParsingResult = { type: string; rules: string[] };
1717
type BlockData = { loc: LineAndColumnData; disable: boolean };
1818

19+
/**
20+
* Remove the ignored part from a given directive comment and trim it.
21+
* @param {string} value The comment text to strip.
22+
* @returns {string} The stripped text.
23+
*/
24+
function stripDirectiveComment(value: string) {
25+
return value.split(/\s-{2,}\s/u)[0];
26+
}
27+
1928
/**
2029
* Parse a given comment.
2130
* @param {RegExp} pattern The RegExp pattern to parse.
2231
* @param {string} comment The comment value to parse.
2332
* @returns {({type:string,rules:string[]})|null} The parsing result.
2433
*/
2534
function parse(pattern: RegExp, comment: string): ParsingResult | null {
26-
const match = pattern.exec(comment);
35+
const match = pattern.exec(stripDirectiveComment(comment));
2736
if (match == null) {
2837
return null;
2938
}

tests/lib/comment-directives.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,25 @@ tester.run("no-unused-selector-comment-directives", rule as any, {
3232
`,
3333
errors: [{ messageId: "unused", data: { selector: ".foo" } }],
3434
},
35+
{
36+
code: `
37+
<template>
38+
<div><ul>
39+
<li class="bar"/>
40+
</ul></div>
41+
</template>
42+
<style scoped>
43+
/* eslint-disable-next-line -- description */
44+
div {
45+
& > .foo,
46+
& > li.foo {/* eslint-disable-line -- description */
47+
}
48+
& > li.bar {}
49+
}
50+
</style>
51+
`,
52+
errors: [{ messageId: "unused", data: { selector: ".foo" } }],
53+
},
3554
{
3655
code: `
3756
<template>

0 commit comments

Comments
 (0)