eslint-plugin-crisp 1.0.93 → 1.0.95
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 +1 -0
- package/index.js +2 -0
- package/package.json +1 -1
- package/recommended-vue.js +2 -0
- package/recommended.js +1 -0
- package/rules/no-extra-line-within-function.js +61 -0
- package/rules/vue-props-declaration-line-break.js +50 -0
package/README.md
CHANGED
|
@@ -200,6 +200,7 @@ Each item has emojis denoting:
|
|
|
200
200
|
| [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) | | 🟢 |
|
|
201
201
|
| [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 | | 🟢 |
|
|
202
202
|
| [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 | | 🟢 |
|
|
203
|
+
| [crisp/vue-props-declaration-line-break](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-props-declaration-line-break.js) | Enforces line break between type and default function in prop definition | | 🟢 |
|
|
203
204
|
| [crisp/vue-props-declaration-multiline](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-props-declaration-multiline.js) | Enforces props declarations to be multiline | | 🟢 |
|
|
204
205
|
| [crisp/vue-props-declaration-order](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-props-declaration-order.js) | Ensures props declarations are alphabetically ordered | | 🟢 |
|
|
205
206
|
| [crisp/vue-ref-case](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/vue-ref-case.js) | Enforces `ref` attributes to snake case | | 🟢 |
|
package/index.js
CHANGED
|
@@ -26,6 +26,7 @@ module.exports = {
|
|
|
26
26
|
"multiline-comment-end-backslash": require("./rules/multiline-comment-end-backslash"),
|
|
27
27
|
"newline-after-switch-case": require("./rules/newline-after-switch-case"),
|
|
28
28
|
"no-async": require("./rules/no-async"),
|
|
29
|
+
"no-extra-line-within-function": require("./rules/no-extra-line-within-function"),
|
|
29
30
|
"no-var-in-blocks": require("./rules/no-var-in-blocks"),
|
|
30
31
|
"no-space-in-optional-arguments": require("./rules/no-space-in-optional-arguments"),
|
|
31
32
|
"no-useless-template-literals": require("./rules/no-useless-template-literals"),
|
|
@@ -43,6 +44,7 @@ module.exports = {
|
|
|
43
44
|
"vue-html-indent": require("./rules/vue-html-indent"),
|
|
44
45
|
"vue-html-quotes": require("./rules/vue-html-quotes"),
|
|
45
46
|
"vue-no-regex-data": require("./rules/vue-no-regex-data"),
|
|
47
|
+
"vue-props-declaration-line-break": require("./rules/vue-props-declaration-line-break"),
|
|
46
48
|
"vue-props-declaration-multiline": require("./rules/vue-props-declaration-multiline"),
|
|
47
49
|
"vue-props-declaration-order": require("./rules/vue-props-declaration-order"),
|
|
48
50
|
"vue-ref-case": require("./rules/vue-ref-case")
|
package/package.json
CHANGED
package/recommended-vue.js
CHANGED
|
@@ -152,6 +152,7 @@ module.exports = {
|
|
|
152
152
|
"crisp/multiline-comment-end-backslash": "error",
|
|
153
153
|
"crisp/newline-after-switch-case": "error",
|
|
154
154
|
"crisp/no-async": "error",
|
|
155
|
+
"crisp/no-extra-line-within-function": "error",
|
|
155
156
|
"crisp/no-short-parameters": [
|
|
156
157
|
"error",
|
|
157
158
|
|
|
@@ -352,6 +353,7 @@ module.exports = {
|
|
|
352
353
|
"crisp/vue-html-indent": "error",
|
|
353
354
|
"crisp/vue-html-quotes": "error",
|
|
354
355
|
"crisp/vue-no-regex-data": "error",
|
|
356
|
+
"crisp/vue-props-declaration-line-break": "error",
|
|
355
357
|
"crisp/vue-props-declaration-multiline": "error",
|
|
356
358
|
"crisp/vue-props-declaration-order": "error",
|
|
357
359
|
"crisp/vue-ref-case": "error"
|
package/recommended.js
CHANGED
|
@@ -152,6 +152,7 @@ module.exports = {
|
|
|
152
152
|
"crisp/multiline-comment-end-backslash": "error",
|
|
153
153
|
"crisp/newline-after-switch-case": "error",
|
|
154
154
|
"crisp/no-async": "error",
|
|
155
|
+
"crisp/no-extra-line-within-function": "error",
|
|
155
156
|
"crisp/no-var-in-blocks": "error",
|
|
156
157
|
"crisp/no-short-parameters": [
|
|
157
158
|
"error",
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
meta: {
|
|
3
|
+
type: "layout",
|
|
4
|
+
docs: {
|
|
5
|
+
description: "enforce maximum one line break between declarations within functions",
|
|
6
|
+
category: "Stylistic Issues",
|
|
7
|
+
recommended: false,
|
|
8
|
+
},
|
|
9
|
+
fixable: "whitespace",
|
|
10
|
+
},
|
|
11
|
+
create(context) {
|
|
12
|
+
const sourceCode = context.getSourceCode();
|
|
13
|
+
|
|
14
|
+
function checkFunctionBody(node) {
|
|
15
|
+
const bodyNode = node.body;
|
|
16
|
+
if (bodyNode.type !== 'BlockStatement') return;
|
|
17
|
+
|
|
18
|
+
const lines = sourceCode.lines;
|
|
19
|
+
|
|
20
|
+
for (let i = 1; i < bodyNode.body.length; i++) {
|
|
21
|
+
const currentNode = bodyNode.body[i];
|
|
22
|
+
const previousNode = bodyNode.body[i - 1];
|
|
23
|
+
const lineOfCurrentNode = currentNode.loc.start.line;
|
|
24
|
+
const lineOfPreviousNodeEnd = previousNode.loc.end.line;
|
|
25
|
+
|
|
26
|
+
// Count the empty lines between the end of the previous node and the start of the current one
|
|
27
|
+
let emptyLineCount = 0;
|
|
28
|
+
for (let j = lineOfPreviousNodeEnd; j < lineOfCurrentNode - 1; j++) {
|
|
29
|
+
if (lines[j].trim() === '') {
|
|
30
|
+
emptyLineCount++;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Report an error if there are more than one empty line
|
|
35
|
+
if (emptyLineCount > 1) {
|
|
36
|
+
context.report({
|
|
37
|
+
node: currentNode,
|
|
38
|
+
message: "Expected at most one line break between declarations within a function.",
|
|
39
|
+
fix(fixer) {
|
|
40
|
+
const range = [
|
|
41
|
+
sourceCode.getIndexFromLoc({ line: lineOfPreviousNodeEnd, column: 0 }),
|
|
42
|
+
sourceCode.getIndexFromLoc({ line: lineOfCurrentNode, column: 0 })
|
|
43
|
+
];
|
|
44
|
+
return fixer.replaceTextRange(range, '\n\n');
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
FunctionDeclaration: checkFunctionBody,
|
|
53
|
+
FunctionExpression: checkFunctionBody,
|
|
54
|
+
ArrowFunctionExpression(node) {
|
|
55
|
+
if (node.body.type === 'BlockStatement') {
|
|
56
|
+
checkFunctionBody(node);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
meta: {
|
|
3
|
+
type: "layout",
|
|
4
|
+
docs: {
|
|
5
|
+
description: "Enforce line break between type and default function in Vue props",
|
|
6
|
+
category: "Stylistic Issues",
|
|
7
|
+
recommended: false,
|
|
8
|
+
},
|
|
9
|
+
fixable: "whitespace",
|
|
10
|
+
schema: [], // no options
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
create(context) {
|
|
14
|
+
const sourceCode = context.getSourceCode();
|
|
15
|
+
|
|
16
|
+
function checkPropDefinition(propNode) {
|
|
17
|
+
const typeProperty = propNode.properties.find(p => p.key.name === "type");
|
|
18
|
+
const defaultProperty = propNode.properties.find(p => p.key.name === "default");
|
|
19
|
+
|
|
20
|
+
if (typeProperty && defaultProperty && defaultProperty.value.type === "FunctionExpression") {
|
|
21
|
+
const typeLine = sourceCode.getLastToken(typeProperty).loc.end.line;
|
|
22
|
+
const defaultLine = sourceCode.getFirstToken(defaultProperty).loc.start.line;
|
|
23
|
+
|
|
24
|
+
if (defaultLine - typeLine < 2) {
|
|
25
|
+
context.report({
|
|
26
|
+
node: defaultProperty,
|
|
27
|
+
message: "There should be a line break between 'type' and 'default' function in prop definition.",
|
|
28
|
+
fix(fixer) {
|
|
29
|
+
const typeToken = sourceCode.getLastToken(typeProperty);
|
|
30
|
+
const defaultToken = sourceCode.getFirstToken(defaultProperty);
|
|
31
|
+
const textBetween = sourceCode.text.slice(typeToken.range[1], defaultToken.range[0]);
|
|
32
|
+
const newTextBetween = textBetween.replace(/,?\s*/, ",\n\n");
|
|
33
|
+
return fixer.replaceTextRange([typeToken.range[1], defaultToken.range[0]], newTextBetween);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
'ExportDefaultDeclaration Property[key.name="props"] ObjectExpression'(node) {
|
|
42
|
+
node.properties.forEach(prop => {
|
|
43
|
+
if (prop.value.type === "ObjectExpression") {
|
|
44
|
+
checkPropDefinition(prop.value);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
};
|