eslint-plugin-crisp 1.5.5 → 1.5.7
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/README.md +2 -0
- package/index.js +4 -0
- package/package.json +1 -1
- package/recommended-vue.js +2 -0
- package/recommended.js +1 -1
- package/rules/vue-class-shorthand-max-len.js +71 -0
- package/rules/vue-no-component-class-shorthand.js +50 -0
package/README.md
CHANGED
|
@@ -221,12 +221,14 @@ Each item has emojis denoting:
|
|
|
221
221
|
| [crisp/vue-attribute-comma](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-attribute-comma.js) | Disallows trailing comma after attribute | | 🟢 |
|
|
222
222
|
| [crisp/vue-attribute-linebreak](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-attribute-linebreak.js) | Enforces linebreak before first attribute and after last attribute | | 🟢 |
|
|
223
223
|
| [crisp/vue-class-attribute-last](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-class-attribute-last.js) | Enforces `class` to be the last attribute holding a value, and `:class` to be the last bound attribute | | 🟢 |
|
|
224
|
+
| [crisp/vue-class-shorthand-max-len](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-class-shorthand-max-len.js) | Requires a multiline `:class` array when Pug class shorthand exceeds 100 characters | | 🟢 |
|
|
224
225
|
| [crisp/vue-computed-order](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-computed-order.js) | Ensures computed properties are alphabetically ordered | | 🟢 |
|
|
225
226
|
| [crisp/vue-define-component](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-define-component.js) | Enforces mixins and components to use the `defineComponent` wrapper | | 🟢 |
|
|
226
227
|
| [crisp/vue-emits-order](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-emits-order.js) | Ensures emits properties are alphabetically ordered | | 🟢 |
|
|
227
228
|
| [crisp/vue-header-check](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-header-check.js) | Ensures `script`, `template` and `style` tags start with corresponding comment block | | 🟢 |
|
|
228
229
|
| [crisp/vue-html-indent](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-html-indent.js) | Enforces consistent indentation in `template` (supports for Pug) | | 🟢 |
|
|
229
230
|
| [crisp/vue-html-quotes](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-html-quotes.js) | Enforces HTML attributes to be enclosed with double quotes | | 🟢 |
|
|
231
|
+
| [crisp/vue-no-component-class-shorthand](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-no-component-class-shorthand.js) | Disallows Pug class shorthand on Vue components | | 🟢 |
|
|
230
232
|
| [crisp/vue-no-mixed-class](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-no-mixed-class.js) | Disallows using both `class` and `:class` on the same element | | 🟢 |
|
|
231
233
|
| [crisp/vue-no-name-option](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-no-name-option.js) | Disallows explicit component names in Vue single-file components | | 🟢 |
|
|
232
234
|
| [crisp/vue-no-regex-data](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-no-regex-data.js) | Disallows regular expressions to be declared in Vue data object | | 🟢 |
|
package/index.js
CHANGED
|
@@ -44,6 +44,7 @@ import ruleVariableNames from "./rules/variable-names.js";
|
|
|
44
44
|
import ruleVueAttributeComma from "./rules/vue-attribute-comma.js";
|
|
45
45
|
import ruleVueAttributeLinebreak from "./rules/vue-attribute-linebreak.js";
|
|
46
46
|
import ruleVueClassAttributeLast from "./rules/vue-class-attribute-last.js";
|
|
47
|
+
import ruleVueClassShorthandMaxLen from "./rules/vue-class-shorthand-max-len.js";
|
|
47
48
|
import ruleVueComputedOrder from "./rules/vue-computed-order.js";
|
|
48
49
|
import ruleVueDataComment from "./rules/vue-data-comment.js";
|
|
49
50
|
import ruleVueDefineComponent from "./rules/vue-define-component.js";
|
|
@@ -53,6 +54,7 @@ import ruleVueHtmlIndent from "./rules/vue-html-indent.js";
|
|
|
53
54
|
import ruleVueHtmlQuotes from "./rules/vue-html-quotes.js";
|
|
54
55
|
import ruleVueMethodsSeparator from "./rules/vue-methods-separator.js";
|
|
55
56
|
import ruleVueNameProp from "./rules/vue-name-prop.js";
|
|
57
|
+
import ruleVueNoComponentClassShorthand from "./rules/vue-no-component-class-shorthand.js";
|
|
56
58
|
import ruleVueNoMixedClass from "./rules/vue-no-mixed-class.js";
|
|
57
59
|
import ruleVueNoNameOption from "./rules/vue-no-name-option.js";
|
|
58
60
|
import ruleVueNoRegexData from "./rules/vue-no-regex-data.js";
|
|
@@ -118,6 +120,7 @@ const plugin = {
|
|
|
118
120
|
"vue-attribute-comma": ruleVueAttributeComma,
|
|
119
121
|
"vue-attribute-linebreak": ruleVueAttributeLinebreak,
|
|
120
122
|
"vue-class-attribute-last": ruleVueClassAttributeLast,
|
|
123
|
+
"vue-class-shorthand-max-len": ruleVueClassShorthandMaxLen,
|
|
121
124
|
"vue-computed-order": ruleVueComputedOrder,
|
|
122
125
|
"vue-data-comment": ruleVueDataComment,
|
|
123
126
|
"vue-define-component": ruleVueDefineComponent,
|
|
@@ -127,6 +130,7 @@ const plugin = {
|
|
|
127
130
|
"vue-html-quotes": ruleVueHtmlQuotes,
|
|
128
131
|
"vue-methods-separator": ruleVueMethodsSeparator,
|
|
129
132
|
"vue-name-prop": ruleVueNameProp,
|
|
133
|
+
"vue-no-component-class-shorthand": ruleVueNoComponentClassShorthand,
|
|
130
134
|
"vue-no-mixed-class": ruleVueNoMixedClass,
|
|
131
135
|
"vue-no-name-option": ruleVueNoNameOption,
|
|
132
136
|
"vue-no-regex-data": ruleVueNoRegexData,
|
package/package.json
CHANGED
package/recommended-vue.js
CHANGED
|
@@ -379,6 +379,7 @@ export default function configRecommendedVue(pluginCrisp) {
|
|
|
379
379
|
"crisp/vue-attribute-comma": "error",
|
|
380
380
|
"crisp/vue-attribute-linebreak": "error",
|
|
381
381
|
"crisp/vue-class-attribute-last": "error",
|
|
382
|
+
"crisp/vue-class-shorthand-max-len": "error",
|
|
382
383
|
"crisp/vue-computed-order": "error",
|
|
383
384
|
"crisp/vue-data-comment": "error",
|
|
384
385
|
"crisp/vue-define-component": "error",
|
|
@@ -388,6 +389,7 @@ export default function configRecommendedVue(pluginCrisp) {
|
|
|
388
389
|
"crisp/vue-html-quotes": "error",
|
|
389
390
|
"crisp/vue-methods-separator": "error",
|
|
390
391
|
"crisp/vue-name-prop": "error",
|
|
392
|
+
"crisp/vue-no-component-class-shorthand": "error",
|
|
391
393
|
"crisp/vue-no-mixed-class": "error",
|
|
392
394
|
"crisp/vue-no-name-option": "error",
|
|
393
395
|
"crisp/vue-no-regex-data": "error",
|
package/recommended.js
CHANGED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import utils from "eslint-plugin-vue/dist/utils/index.js";
|
|
2
|
+
|
|
3
|
+
const DEFAULT_MAX_LENGTH = 100;
|
|
4
|
+
const PUG_ELEMENT_HEAD_PATTERN =
|
|
5
|
+
/^(?:[A-Za-z][\w-]*)?(?:[.#][A-Za-z_][\w-]*)+$/;
|
|
6
|
+
const CLASS_SHORTHAND_PATTERN = /\.[A-Za-z_][\w-]*/;
|
|
7
|
+
|
|
8
|
+
// Checks whether a Pug element name belongs to a Vue component
|
|
9
|
+
function isComponent(node) {
|
|
10
|
+
return node.name.includes("-") || /^[A-Z]/.test(node.rawName);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default {
|
|
14
|
+
meta: {
|
|
15
|
+
type: "layout",
|
|
16
|
+
docs: {
|
|
17
|
+
description: "enforce a maximum length for Pug class shorthand",
|
|
18
|
+
category: "Stylistic Issues",
|
|
19
|
+
recommended: false,
|
|
20
|
+
},
|
|
21
|
+
fixable: null,
|
|
22
|
+
schema: [
|
|
23
|
+
{
|
|
24
|
+
type: "object",
|
|
25
|
+
properties: {
|
|
26
|
+
max: {
|
|
27
|
+
type: "integer",
|
|
28
|
+
minimum: 1,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
additionalProperties: false,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
messages: {
|
|
35
|
+
tooLong:
|
|
36
|
+
"Pug class shorthand is {{length}} characters long. Move classes to a multiline :class array (maximum: {{max}}).",
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
create(context) {
|
|
41
|
+
const sourceCode = context.getSourceCode();
|
|
42
|
+
const maxLength = context.options[0]?.max ?? DEFAULT_MAX_LENGTH;
|
|
43
|
+
|
|
44
|
+
return utils.default.defineTemplateBodyVisitor(context, {
|
|
45
|
+
VElement(node) {
|
|
46
|
+
// Component shorthand is handled by vue-no-component-class-shorthand
|
|
47
|
+
if (isComponent(node)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const startTagText = sourceCode.getText(node.startTag);
|
|
52
|
+
const elementHead = startTagText.split(/[\s(]/, 1)[0];
|
|
53
|
+
|
|
54
|
+
if (
|
|
55
|
+
PUG_ELEMENT_HEAD_PATTERN.test(elementHead) &&
|
|
56
|
+
CLASS_SHORTHAND_PATTERN.test(elementHead) &&
|
|
57
|
+
elementHead.length > maxLength
|
|
58
|
+
) {
|
|
59
|
+
context.report({
|
|
60
|
+
node: node.startTag,
|
|
61
|
+
messageId: "tooLong",
|
|
62
|
+
data: {
|
|
63
|
+
length: elementHead.length,
|
|
64
|
+
max: maxLength,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
export default {
|
|
11
|
+
meta: {
|
|
12
|
+
type: "suggestion",
|
|
13
|
+
docs: {
|
|
14
|
+
description: "disallow Pug class shorthand on Vue components",
|
|
15
|
+
category: "Stylistic Issues",
|
|
16
|
+
recommended: false,
|
|
17
|
+
},
|
|
18
|
+
fixable: null,
|
|
19
|
+
schema: [], // no options
|
|
20
|
+
messages: {
|
|
21
|
+
useClassAttribute:
|
|
22
|
+
"Use a class attribute instead of Pug class shorthand on component \"{{name}}\".",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
create(context) {
|
|
27
|
+
const sourceCode = context.getSourceCode();
|
|
28
|
+
|
|
29
|
+
return utils.default.defineTemplateBodyVisitor(context, {
|
|
30
|
+
VElement(node) {
|
|
31
|
+
if (!isComponent(node)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const startTagText = sourceCode.getText(node.startTag);
|
|
36
|
+
const elementHead = startTagText.split(/[\s(]/, 1)[0];
|
|
37
|
+
|
|
38
|
+
if (CLASS_SHORTHAND_PATTERN.test(elementHead)) {
|
|
39
|
+
context.report({
|
|
40
|
+
node: node.startTag,
|
|
41
|
+
messageId: "useClassAttribute",
|
|
42
|
+
data: {
|
|
43
|
+
name: node.rawName,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
};
|