eslint-plugin-crisp 1.7.0 → 1.7.1
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/index.js +2 -0
- package/package.json +1 -1
- package/recommended-vue.js +1 -0
- package/rules/header-comments-check.js +34 -1
- package/rules/vue-no-mixed-class-shorthand.js +65 -0
- package/tests/rules/header-comments-check.test.js +26 -6
- package/tests/rules/vue-no-mixed-class-shorthand.test.js +57 -0
package/index.js
CHANGED
|
@@ -57,6 +57,7 @@ import ruleVueMethodsSeparator from "./rules/vue-methods-separator.js";
|
|
|
57
57
|
import ruleVueNameProp from "./rules/vue-name-prop.js";
|
|
58
58
|
import ruleVueNoComponentClassShorthand from "./rules/vue-no-component-class-shorthand.js";
|
|
59
59
|
import ruleVueNoMixedClass from "./rules/vue-no-mixed-class.js";
|
|
60
|
+
import ruleVueNoMixedClassShorthand from "./rules/vue-no-mixed-class-shorthand.js";
|
|
60
61
|
import ruleVueNoNameOption from "./rules/vue-no-name-option.js";
|
|
61
62
|
import ruleVueNoRegexData from "./rules/vue-no-regex-data.js";
|
|
62
63
|
import ruleVuePiniaActionSingleParameter from "./rules/vue-pinia-action-single-parameter.js";
|
|
@@ -135,6 +136,7 @@ const plugin = {
|
|
|
135
136
|
"vue-name-prop": ruleVueNameProp,
|
|
136
137
|
"vue-no-component-class-shorthand": ruleVueNoComponentClassShorthand,
|
|
137
138
|
"vue-no-mixed-class": ruleVueNoMixedClass,
|
|
139
|
+
"vue-no-mixed-class-shorthand": ruleVueNoMixedClassShorthand,
|
|
138
140
|
"vue-no-name-option": ruleVueNoNameOption,
|
|
139
141
|
"vue-no-regex-data": ruleVueNoRegexData,
|
|
140
142
|
"vue-pinia-action-single-parameter": ruleVuePiniaActionSingleParameter,
|
package/package.json
CHANGED
package/recommended-vue.js
CHANGED
|
@@ -391,6 +391,7 @@ export default function configRecommendedVue(pluginCrisp) {
|
|
|
391
391
|
"crisp/vue-name-prop": "error",
|
|
392
392
|
"crisp/vue-no-component-class-shorthand": "error",
|
|
393
393
|
"crisp/vue-no-mixed-class": "error",
|
|
394
|
+
"crisp/vue-no-mixed-class-shorthand": "error",
|
|
394
395
|
"crisp/vue-no-name-option": "error",
|
|
395
396
|
"crisp/vue-no-regex-data": "error",
|
|
396
397
|
"crisp/vue-pinia-action-single-parameter": "error",
|
|
@@ -2,6 +2,12 @@ const COMMENT_HEADER_FORMAT = (section) => {
|
|
|
2
2
|
return `/**************************************************************************\n * ${section.toUpperCase()}\n ***************************************************************************/`;
|
|
3
3
|
};
|
|
4
4
|
|
|
5
|
+
const HEADER_COMMENT_REGEX = /^\*+\n \* [A-Z][A-Z0-9 _:-]*\n \*+$/;
|
|
6
|
+
|
|
7
|
+
function isHeaderComment(comment) {
|
|
8
|
+
return comment.type === "Block" && HEADER_COMMENT_REGEX.test(comment.value);
|
|
9
|
+
}
|
|
10
|
+
|
|
5
11
|
function isTypeComment(comment) {
|
|
6
12
|
if (comment.type !== "Block" || !comment.value.startsWith("*")) {
|
|
7
13
|
return false;
|
|
@@ -109,7 +115,7 @@ export default {
|
|
|
109
115
|
category: "Best Practices",
|
|
110
116
|
recommended: false,
|
|
111
117
|
},
|
|
112
|
-
fixable:
|
|
118
|
+
fixable: "whitespace",
|
|
113
119
|
},
|
|
114
120
|
|
|
115
121
|
create(context) {
|
|
@@ -224,6 +230,30 @@ export default {
|
|
|
224
230
|
}
|
|
225
231
|
}
|
|
226
232
|
|
|
233
|
+
// Checks that a header comment block is followed by a blank line
|
|
234
|
+
function checkBlankLineAfterHeaders() {
|
|
235
|
+
for (const comment of allBlockComments) {
|
|
236
|
+
if (!isHeaderComment(comment)) {
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const next = sourceCode.getTokenAfter(comment, { includeComments: true });
|
|
241
|
+
|
|
242
|
+
if (!next || next.loc.start.line - comment.loc.end.line >= 2) {
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const isOnNextLine = next.loc.start.line - comment.loc.end.line === 1;
|
|
247
|
+
|
|
248
|
+
context.report({
|
|
249
|
+
loc: comment.loc,
|
|
250
|
+
message: "Header comment block must be followed by a blank line",
|
|
251
|
+
|
|
252
|
+
fix: isOnNextLine ? (fixer) => fixer.insertTextAfter(comment, "\n") : null,
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
227
257
|
return {
|
|
228
258
|
":statement": (node) => {
|
|
229
259
|
if (node.parent.type !== "Program") {
|
|
@@ -256,6 +286,9 @@ export default {
|
|
|
256
286
|
|
|
257
287
|
// Check type comments group
|
|
258
288
|
checkTypeCommentsGroup();
|
|
289
|
+
|
|
290
|
+
// Check blank line after header comments
|
|
291
|
+
checkBlankLineAfterHeaders();
|
|
259
292
|
}
|
|
260
293
|
};
|
|
261
294
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import utils from "eslint-plugin-vue/dist/utils/index.js";
|
|
2
|
+
|
|
3
|
+
const CLASS_SHORTHAND_PATTERN = /\.[A-Za-z_][\w-]*/;
|
|
4
|
+
|
|
5
|
+
// Checks whether a Pug element name belongs to a Vue component
|
|
6
|
+
function isComponent(node) {
|
|
7
|
+
return node.name.includes("-") || /^[A-Z]/.test(node.rawName);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Checks whether an attribute is a class attribute
|
|
11
|
+
function isClassAttribute(attribute) {
|
|
12
|
+
if (attribute.directive === false) {
|
|
13
|
+
return attribute.key.name === "class";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
attribute.key.name.name === "bind" &&
|
|
18
|
+
attribute.key.argument !== null &&
|
|
19
|
+
attribute.key.argument.type === "VIdentifier" &&
|
|
20
|
+
attribute.key.argument.name === "class"
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default {
|
|
25
|
+
meta: {
|
|
26
|
+
type: "suggestion",
|
|
27
|
+
docs: {
|
|
28
|
+
description: "disallow mixing Pug class shorthand and class attributes",
|
|
29
|
+
category: "Stylistic Issues",
|
|
30
|
+
recommended: false,
|
|
31
|
+
},
|
|
32
|
+
fixable: null,
|
|
33
|
+
schema: [], // no options
|
|
34
|
+
messages: {
|
|
35
|
+
useClassAttribute:
|
|
36
|
+
"Move all Pug class shorthands to the class attribute.",
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
create(context) {
|
|
41
|
+
const sourceCode = context.sourceCode;
|
|
42
|
+
|
|
43
|
+
return utils.default.defineTemplateBodyVisitor(context, {
|
|
44
|
+
VElement(node) {
|
|
45
|
+
if (isComponent(node)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const startTagText = sourceCode.getText(node.startTag);
|
|
50
|
+
const elementHead = startTagText.split(/[\s(]/, 1)[0];
|
|
51
|
+
const classAttribute = node.startTag.attributes.find(isClassAttribute);
|
|
52
|
+
|
|
53
|
+
if (
|
|
54
|
+
classAttribute &&
|
|
55
|
+
CLASS_SHORTHAND_PATTERN.test(elementHead)
|
|
56
|
+
) {
|
|
57
|
+
context.report({
|
|
58
|
+
node: classAttribute,
|
|
59
|
+
messageId: "useClassAttribute",
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
};
|
|
@@ -12,17 +12,17 @@ ruleTester.run("header-comments-check", rule, {
|
|
|
12
12
|
valid: [
|
|
13
13
|
{
|
|
14
14
|
filename: "/project/src/example.js",
|
|
15
|
-
code: `${header("IMPORTS")}\nimport value from "package";`
|
|
15
|
+
code: `${header("IMPORTS")}\n\nimport value from "package";`
|
|
16
16
|
},
|
|
17
17
|
{
|
|
18
18
|
filename: "/project/src/example.ts",
|
|
19
|
-
code: `${header("CONSTANTS")}\nconst MAX_RETRIES = 3;\n\n${header("INSTANCES")}\nconst pattern = /value/;`
|
|
19
|
+
code: `${header("CONSTANTS")}\n\nconst MAX_RETRIES = 3;\n\n${header("INSTANCES")}\n\nconst pattern = /value/;`
|
|
20
20
|
},
|
|
21
21
|
{
|
|
22
22
|
filename: "/project/src/example.js",
|
|
23
23
|
code:
|
|
24
|
-
`${header("TYPES")}\n/** @typedef {string} Identifier */\n\n` +
|
|
25
|
-
`${header("EXPORTS")}\nexport default {};`
|
|
24
|
+
`${header("TYPES")}\n\n/** @typedef {string} Identifier */\n\n` +
|
|
25
|
+
`${header("EXPORTS")}\n\nexport default {};`
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
28
|
filename: "/project/src/example.js",
|
|
@@ -30,12 +30,12 @@ ruleTester.run("header-comments-check", rule, {
|
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
32
|
filename: "/project/src/example.js",
|
|
33
|
-
code: `${header("MIXIN TO MANAGE HANDOFF")}\nexport default {};`
|
|
33
|
+
code: `${header("MIXIN TO MANAGE HANDOFF")}\n\nexport default {};`
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
36
|
filename: "/project/src/example.js",
|
|
37
37
|
code:
|
|
38
|
-
`${header("IMPORTS")}\nimport first from "first";\n` +
|
|
38
|
+
`${header("IMPORTS")}\n\nimport first from "first";\n` +
|
|
39
39
|
"import second from \"second\";"
|
|
40
40
|
},
|
|
41
41
|
{
|
|
@@ -84,6 +84,26 @@ ruleTester.run("header-comments-check", rule, {
|
|
|
84
84
|
message: "Type comments group must be preceded by a 'TYPES' comment block"
|
|
85
85
|
}
|
|
86
86
|
]
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
filename: "/project/src/example.js",
|
|
90
|
+
code: `${header("CONSTANTS")}\nconst MAX_RETRIES = 3;`,
|
|
91
|
+
output: `${header("CONSTANTS")}\n\nconst MAX_RETRIES = 3;`,
|
|
92
|
+
errors: [
|
|
93
|
+
{
|
|
94
|
+
message: "Header comment block must be followed by a blank line"
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
filename: "/project/src/example.js",
|
|
100
|
+
code: `${header("IMPORTS")}\n// NPM\nimport value from "package";`,
|
|
101
|
+
output: `${header("IMPORTS")}\n\n// NPM\nimport value from "package";`,
|
|
102
|
+
errors: [
|
|
103
|
+
{
|
|
104
|
+
message: "Header comment block must be followed by a blank line"
|
|
105
|
+
}
|
|
106
|
+
]
|
|
87
107
|
}
|
|
88
108
|
]
|
|
89
109
|
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import rule from "../../rules/vue-no-mixed-class-shorthand.js";
|
|
2
|
+
import { createPugRuleTester } from "../rule-tester.js";
|
|
3
|
+
|
|
4
|
+
const ruleTester = createPugRuleTester();
|
|
5
|
+
const filename = "TestComponent.vue";
|
|
6
|
+
|
|
7
|
+
ruleTester.run("vue-no-mixed-class-shorthand", rule, {
|
|
8
|
+
valid: [
|
|
9
|
+
{
|
|
10
|
+
filename,
|
|
11
|
+
code: `<template lang="pug">
|
|
12
|
+
.panel
|
|
13
|
+
div(:class="classes")
|
|
14
|
+
div(class="panel")
|
|
15
|
+
</template>`
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
filename,
|
|
19
|
+
code: `<template lang="pug">
|
|
20
|
+
UserCard.panel(:class="classes")
|
|
21
|
+
user-card.panel(class="card")
|
|
22
|
+
</template>`
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
|
|
26
|
+
invalid: [
|
|
27
|
+
{
|
|
28
|
+
filename,
|
|
29
|
+
code: `<template lang="pug">
|
|
30
|
+
.c-conversation-box-content-message-controls__action(
|
|
31
|
+
@click="onActionTranscribeClick"
|
|
32
|
+
:class="\`js-audio-transcription-action-\${fingerprint}\`"
|
|
33
|
+
)
|
|
34
|
+
</template>`,
|
|
35
|
+
errors: [
|
|
36
|
+
{
|
|
37
|
+
messageId: "useClassAttribute"
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
filename,
|
|
43
|
+
code: `<template lang="pug">
|
|
44
|
+
div.panel(class="active")
|
|
45
|
+
section#details.panel(v-bind:class="classes")
|
|
46
|
+
</template>`,
|
|
47
|
+
errors: [
|
|
48
|
+
{
|
|
49
|
+
messageId: "useClassAttribute"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
messageId: "useClassAttribute"
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
});
|