eslint-plugin-crisp 1.7.22 → 1.7.23
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 +3 -3
- package/package.json +1 -1
- package/recommended-ts.js +1 -0
- package/recommended-vue.js +9 -2
- package/tests/recommended.test.js +55 -18
package/README.md
CHANGED
|
@@ -97,7 +97,7 @@ Each item has emojis denoting:
|
|
|
97
97
|
| [no-multi-spaces](https://eslint.org/docs/latest/rules/no-multi-spaces) | Disallows multiple consecutive spaces except for indentation | 🟠 | 🟢 | 🟣 |
|
|
98
98
|
| [no-multiple-empty-lines](https://eslint.org/docs/latest/rules/no-multiple-empty-lines) | Allows a maximum of 1 consecutive empty lines | | 🟢 | 🟣 |
|
|
99
99
|
| [no-mixed-spaces-and-tabs](https://eslint.org/docs/latest/rules/no-mixed-spaces-and-tabs) | Disallows mixed spaces and tabs for indentation | 🟠 | 🟢 | 🟣 |
|
|
100
|
-
| [no-restricted-syntax](https://eslint.org/docs/latest/rules/no-restricted-syntax) |
|
|
100
|
+
| [no-restricted-syntax](https://eslint.org/docs/latest/rules/no-restricted-syntax) | Disallows specific syntax patterns according to each configuration's coding conventions | | 🟢 | 🟣 |
|
|
101
101
|
| [no-tabs](https://eslint.org/docs/latest/rules/no-tabs) | Disallows tabs | 🟠 | 🟢 | 🟣 |
|
|
102
102
|
| [no-trailing-spaces](https://eslint.org/docs/latest/rules/no-trailing-spaces) | Disallows trailing whitespace at the end of lines | 🟠 | 🟢 | 🟣 |
|
|
103
103
|
| [no-undef](https://eslint.org/docs/latest/rules/no-undef) | Disallows use of undeclared variables | 🟠 | 🟢 | 🟣 |
|
|
@@ -105,7 +105,7 @@ Each item has emojis denoting:
|
|
|
105
105
|
| [no-unsafe-optional-chaining](https://eslint.org/docs/latest/rules/no-unsafe-optional-chaining) | Disallows use of optional chaining in contexts where the `undefined` value is not allowed | 🟠 | 🟢 | 🟣 |
|
|
106
106
|
| [object-curly-newline](https://eslint.org/docs/latest/rules/object-curly-newline) | Requires line breaks after opening and before closing braces | 🟠 | 🟢 | 🟣 |
|
|
107
107
|
| [object-curly-spacing](https://eslint.org/docs/latest/rules/object-curly-spacing) | Requires spacing inside of braces | 🟠 | 🟢 | 🟣 |
|
|
108
|
-
| [object-shorthand](https://eslint.org/docs/latest/rules/object-shorthand) | Disallows shorthand properties and methods in object literals, requiring explicit keys and values even when their names match | 🟠 |
|
|
108
|
+
| [object-shorthand](https://eslint.org/docs/latest/rules/object-shorthand) | Disallows shorthand properties and methods in object literals, requiring explicit keys and values even when their names match | 🟠 | | 🟣 |
|
|
109
109
|
| [padded-blocks](https://eslint.org/docs/latest/rules/padded-blocks) | Disallows empty lines at the beginning and ending of blocks | 🟠 | 🟢 | 🟣 |
|
|
110
110
|
| [padding-line-between-statements](https://eslint.org/docs/latest/rules/padding-line-between-statements) | Requires padding lines between various statements | 🟠 | 🟢 | 🟣 |
|
|
111
111
|
| [prefer-arrow-callback](https://eslint.org/docs/latest/rules/prefer-arrow-callback) | Requires using arrow functions for callbacks | | 🟢 | 🟣 |
|
|
@@ -138,7 +138,7 @@ Each item has emojis denoting:
|
|
|
138
138
|
| [crisp/methods-ordering](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/methods-ordering.js) | Ensures methods order according to their access: `public` then `protected` then `private` | 🟠 | 🟢 | 🟣 |
|
|
139
139
|
| [crisp/multiline-comment-end-backslash](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/multiline-comment-end-backslash.js) | Enforces multiline comments to end with a backslash | 🟠 | 🟢 | 🟣 |
|
|
140
140
|
| [crisp/newline-after-switch-case](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/newline-after-switch-case.js) | Requires newline between switch cases | 🟠 | 🟢 | 🟣 |
|
|
141
|
-
| [crisp/no-async](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/no-async.js) | Disallows
|
|
141
|
+
| [crisp/no-async](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/no-async.js) | Disallows `async`/`await` in favor of `Promise` | 🟠 | | |
|
|
142
142
|
| [crisp/no-extra-line-within-function](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/no-extra-line-within-function.js) | Allows at most one empty line between declarations within functions | 🟠 | 🟢 | 🟣 |
|
|
143
143
|
| [crisp/no-inline-function-in-ternary](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/no-inline-function-in-ternary.js) | Disallows inline functions in ternary branches | 🟠 | 🟢 | 🟣 |
|
|
144
144
|
| [crisp/no-short-parameters](https://github.com/crisp-oss/eslint-plugin-crisp/blob/master/rules/no-short-parameters.js) | Disallows one-character parameter names | 🟠 | 🟢 | 🟣 |
|
package/package.json
CHANGED
package/recommended-ts.js
CHANGED
|
@@ -102,6 +102,7 @@ export default function configRecommendedTS(pluginCrisp) {
|
|
|
102
102
|
"no-restricted-syntax": [
|
|
103
103
|
"error",
|
|
104
104
|
|
|
105
|
+
// Require switch case contents to be enclosed in braces
|
|
105
106
|
{
|
|
106
107
|
"selector": "SwitchCase > *.consequent[type!='BlockStatement']",
|
|
107
108
|
"message": "Switch cases without braces are disallowed."
|
package/recommended-vue.js
CHANGED
|
@@ -108,9 +108,17 @@ export default function configRecommendedVue(pluginCrisp) {
|
|
|
108
108
|
"no-restricted-syntax": [
|
|
109
109
|
"error",
|
|
110
110
|
|
|
111
|
+
// Require switch case contents to be enclosed in braces
|
|
111
112
|
{
|
|
112
113
|
"selector": "SwitchCase > *.consequent[type!='BlockStatement']",
|
|
113
114
|
"message": "Switch cases without braces are disallowed."
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
// Require explicit object property keys and values, but allow shorthand methods
|
|
118
|
+
// Exempt direct entries in components objects and direct export default objects
|
|
119
|
+
{
|
|
120
|
+
"selector": "ObjectExpression > Property[shorthand=true]:not(Property[key.name='components'] > ObjectExpression > Property):not(Property[key.value='components'] > ObjectExpression > Property):not(ExportDefaultDeclaration > ObjectExpression > Property)",
|
|
121
|
+
"message": "Use explicit keys and values instead of shorthand properties."
|
|
114
122
|
}
|
|
115
123
|
],
|
|
116
124
|
"no-tabs": "error",
|
|
@@ -126,7 +134,6 @@ export default function configRecommendedVue(pluginCrisp) {
|
|
|
126
134
|
}
|
|
127
135
|
],
|
|
128
136
|
"object-curly-spacing": ["error", "always"],
|
|
129
|
-
"object-shorthand": ["error", "never"],
|
|
130
137
|
"padded-blocks": ["error", "never"],
|
|
131
138
|
"padding-line-between-statements": [
|
|
132
139
|
"error",
|
|
@@ -175,7 +182,7 @@ export default function configRecommendedVue(pluginCrisp) {
|
|
|
175
182
|
"crisp/methods-ordering": "error",
|
|
176
183
|
"crisp/multiline-comment-end-backslash": "error",
|
|
177
184
|
"crisp/newline-after-switch-case": "error",
|
|
178
|
-
"crisp/no-async": "
|
|
185
|
+
"crisp/no-async": "off",
|
|
179
186
|
"crisp/no-extra-line-within-function": "error",
|
|
180
187
|
"crisp/no-inline-function-in-ternary": "error",
|
|
181
188
|
"crisp/no-short-parameters": [
|
|
@@ -20,25 +20,18 @@ test("all recommended configs reject multiple spaces", () => {
|
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
test("
|
|
24
|
-
for (const configName of [
|
|
25
|
-
"recommended",
|
|
26
|
-
"recommended-vue",
|
|
27
|
-
"recommended-ts"
|
|
28
|
-
]) {
|
|
23
|
+
test("JS and TS recommended configs reject and expand property and method shorthand", () => {
|
|
24
|
+
for (const configName of ["recommended", "recommended-ts"]) {
|
|
29
25
|
const rules = plugin.configs[configName].find(
|
|
30
26
|
config => config.rules?.["object-shorthand"]
|
|
31
|
-
)
|
|
27
|
+
).rules;
|
|
32
28
|
|
|
33
|
-
assert.deepEqual(rules
|
|
29
|
+
assert.deepEqual(rules["object-shorthand"], ["error", "never"]);
|
|
30
|
+
assert.ok(!JSON.stringify(rules["no-restricted-syntax"] ?? []).includes("shorthand"));
|
|
34
31
|
|
|
35
32
|
const linter = new Linter();
|
|
36
|
-
const config = [{
|
|
37
|
-
|
|
38
|
-
"object-shorthand": rules["object-shorthand"]
|
|
39
|
-
}
|
|
40
|
-
}];
|
|
41
|
-
const input = "const value = 1; const object = { value, method() {} };";
|
|
33
|
+
const config = [{ rules: { "object-shorthand": rules["object-shorthand"] } }];
|
|
34
|
+
const input = "const object = { value, method() {} };";
|
|
42
35
|
const messages = linter.verify(input, config);
|
|
43
36
|
|
|
44
37
|
assert.equal(messages.length, 2);
|
|
@@ -46,14 +39,58 @@ test("all recommended configs reject and expand object shorthand", () => {
|
|
|
46
39
|
|
|
47
40
|
const result = linter.verifyAndFix(input, config);
|
|
48
41
|
|
|
49
|
-
assert.equal(
|
|
50
|
-
result.output,
|
|
51
|
-
"const value = 1; const object = { value: value, method: function() {} };"
|
|
52
|
-
);
|
|
42
|
+
assert.equal(result.output, "const object = { value: value, method: function() {} };");
|
|
53
43
|
assert.deepEqual(result.messages, []);
|
|
54
44
|
}
|
|
55
45
|
});
|
|
56
46
|
|
|
47
|
+
test("Vue recommended config rejects property shorthand but allows methods and components", () => {
|
|
48
|
+
for (const configName of ["recommended-vue"]) {
|
|
49
|
+
const rules = plugin.configs[configName].find(
|
|
50
|
+
config => config.rules?.["no-restricted-syntax"]
|
|
51
|
+
).rules;
|
|
52
|
+
|
|
53
|
+
assert.ok(plugin.configs[configName].every(
|
|
54
|
+
config => !Object.hasOwn(config.rules ?? {}, "object-shorthand")
|
|
55
|
+
));
|
|
56
|
+
|
|
57
|
+
const linter = new Linter();
|
|
58
|
+
const config = [{
|
|
59
|
+
rules: {
|
|
60
|
+
"no-restricted-syntax": rules["no-restricted-syntax"]
|
|
61
|
+
}
|
|
62
|
+
}];
|
|
63
|
+
|
|
64
|
+
for (const input of [
|
|
65
|
+
"const object = { value };",
|
|
66
|
+
"this.setTreeContent({ section, locale, path, value: contentData });",
|
|
67
|
+
"const object = { components: { nested: { value } } };",
|
|
68
|
+
"export default { nested: { value } };",
|
|
69
|
+
"const object = { value }; export default object;",
|
|
70
|
+
"defineComponent({ data() { return { value }; } });"
|
|
71
|
+
]) {
|
|
72
|
+
const messages = linter.verify(input, config);
|
|
73
|
+
|
|
74
|
+
assert.ok(messages.length > 0, `${configName}: ${input}`);
|
|
75
|
+
assert.ok(messages.every(message =>
|
|
76
|
+
message.ruleId === "no-restricted-syntax" &&
|
|
77
|
+
message.message === "Use explicit keys and values instead of shorthand properties."
|
|
78
|
+
));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
for (const input of [
|
|
82
|
+
"const object = { value: value, method() {} };",
|
|
83
|
+
"export default { base, form, initiate, layouts, common, hugo, editor, settings };",
|
|
84
|
+
"export default { components: { ContentNavigate }, mounted() {} };",
|
|
85
|
+
"export default defineComponent({ components: { ContentNavigate }, data() { return {}; } });",
|
|
86
|
+
"defineComponent({ 'components': { ContentNavigate } });",
|
|
87
|
+
"const { value } = object;"
|
|
88
|
+
]) {
|
|
89
|
+
assert.deepEqual(linter.verify(input, config), [], `${configName}: ${input}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
57
94
|
test("recommended config uses standard default parameter spacing", () => {
|
|
58
95
|
const result = new Linter().verifyAndFix(
|
|
59
96
|
"function greet(name=\"World\") {}",
|