eslint-plugin-crisp 1.7.21 → 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 -2
- package/package.json +1 -1
- package/recommended-ts.js +2 -0
- package/recommended-vue.js +9 -1
- package/recommended.js +1 -0
- package/tests/recommended.test.js +71 -0
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,6 +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
109
|
| [padded-blocks](https://eslint.org/docs/latest/rules/padded-blocks) | Disallows empty lines at the beginning and ending of blocks | 🟠 | 🟢 | 🟣 |
|
|
109
110
|
| [padding-line-between-statements](https://eslint.org/docs/latest/rules/padding-line-between-statements) | Requires padding lines between various statements | 🟠 | 🟢 | 🟣 |
|
|
110
111
|
| [prefer-arrow-callback](https://eslint.org/docs/latest/rules/prefer-arrow-callback) | Requires using arrow functions for callbacks | | 🟢 | 🟣 |
|
|
@@ -137,7 +138,7 @@ Each item has emojis denoting:
|
|
|
137
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` | 🟠 | 🟢 | 🟣 |
|
|
138
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 | 🟠 | 🟢 | 🟣 |
|
|
139
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 | 🟠 | 🟢 | 🟣 |
|
|
140
|
-
| [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` | 🟠 | | |
|
|
141
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 | 🟠 | 🟢 | 🟣 |
|
|
142
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 | 🟠 | 🟢 | 🟣 |
|
|
143
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."
|
|
@@ -119,6 +120,7 @@ export default function configRecommendedTS(pluginCrisp) {
|
|
|
119
120
|
}
|
|
120
121
|
],
|
|
121
122
|
"object-curly-spacing": ["error", "always"],
|
|
123
|
+
"object-shorthand": ["error", "never"],
|
|
122
124
|
"padded-blocks": ["error", "never"],
|
|
123
125
|
"padding-line-between-statements": [
|
|
124
126
|
"error",
|
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",
|
|
@@ -174,7 +182,7 @@ export default function configRecommendedVue(pluginCrisp) {
|
|
|
174
182
|
"crisp/methods-ordering": "error",
|
|
175
183
|
"crisp/multiline-comment-end-backslash": "error",
|
|
176
184
|
"crisp/newline-after-switch-case": "error",
|
|
177
|
-
"crisp/no-async": "
|
|
185
|
+
"crisp/no-async": "off",
|
|
178
186
|
"crisp/no-extra-line-within-function": "error",
|
|
179
187
|
"crisp/no-inline-function-in-ternary": "error",
|
|
180
188
|
"crisp/no-short-parameters": [
|
package/recommended.js
CHANGED
|
@@ -123,6 +123,7 @@ export default function configRecommended(pluginCrisp) {
|
|
|
123
123
|
}
|
|
124
124
|
],
|
|
125
125
|
"object-curly-spacing": ["error", "always"],
|
|
126
|
+
"object-shorthand": ["error", "never"],
|
|
126
127
|
"padded-blocks": ["error", "never"],
|
|
127
128
|
"padding-line-between-statements": [
|
|
128
129
|
"error",
|
|
@@ -20,6 +20,77 @@ test("all recommended configs reject multiple spaces", () => {
|
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
+
test("JS and TS recommended configs reject and expand property and method shorthand", () => {
|
|
24
|
+
for (const configName of ["recommended", "recommended-ts"]) {
|
|
25
|
+
const rules = plugin.configs[configName].find(
|
|
26
|
+
config => config.rules?.["object-shorthand"]
|
|
27
|
+
).rules;
|
|
28
|
+
|
|
29
|
+
assert.deepEqual(rules["object-shorthand"], ["error", "never"]);
|
|
30
|
+
assert.ok(!JSON.stringify(rules["no-restricted-syntax"] ?? []).includes("shorthand"));
|
|
31
|
+
|
|
32
|
+
const linter = new Linter();
|
|
33
|
+
const config = [{ rules: { "object-shorthand": rules["object-shorthand"] } }];
|
|
34
|
+
const input = "const object = { value, method() {} };";
|
|
35
|
+
const messages = linter.verify(input, config);
|
|
36
|
+
|
|
37
|
+
assert.equal(messages.length, 2);
|
|
38
|
+
assert.ok(messages.every(message => message.ruleId === "object-shorthand"));
|
|
39
|
+
|
|
40
|
+
const result = linter.verifyAndFix(input, config);
|
|
41
|
+
|
|
42
|
+
assert.equal(result.output, "const object = { value: value, method: function() {} };");
|
|
43
|
+
assert.deepEqual(result.messages, []);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
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
|
+
|
|
23
94
|
test("recommended config uses standard default parameter spacing", () => {
|
|
24
95
|
const result = new Linter().verifyAndFix(
|
|
25
96
|
"function greet(name=\"World\") {}",
|