@blumintinc/eslint-plugin-blumint 0.1.10 → 0.1.11
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 -2
- package/docs/rules/export-if-in-doubt.md +1 -1
- package/docs/rules/extract-global-constants.md +1 -1
- package/docs/rules/no-async-foreach.md +41 -0
- package/docs/rules/no-misused-switch-case.md +3 -3
- package/docs/rules/no-useless-fragment.md +23 -0
- package/lib/index.js +7 -1
- package/lib/rules/no-async-foreach.js +37 -0
- package/lib/rules/no-misused-switch-case.js +2 -2
- package/lib/rules/no-useless-fragment.js +30 -0
- package/lib/rules/prefer-fragment-shorthand.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -58,9 +58,9 @@ Or use the recommended config:
|
|
|
58
58
|
|
|
59
59
|
| Name | Description | 💼 | ⚠️ | 🔧 |
|
|
60
60
|
| :--------------------------------------------------------------------- | :---------------------------------------------------------------------------------------- | :- | :- | :- |
|
|
61
|
-
| [array-methods-this-context](docs/rules/array-methods-this-context.md) |
|
|
61
|
+
| [array-methods-this-context](docs/rules/array-methods-this-context.md) | Prevent misuse of Array methods in OOP | | ✅ | |
|
|
62
62
|
| [export-if-in-doubt](docs/rules/export-if-in-doubt.md) | All top-level const definitions, type definitions, and functions should be exported | | ✅ | |
|
|
63
|
-
| [extract-global-constants](docs/rules/extract-global-constants.md) | Extract constants/functions
|
|
63
|
+
| [extract-global-constants](docs/rules/extract-global-constants.md) | Extract constants/functions to the global scope when possible | | ✅ | |
|
|
64
64
|
| [generic-starts-with-t](docs/rules/generic-starts-with-t.md) | Enforce TypeScript generic types to start with T | | ✅ | |
|
|
65
65
|
| [no-async-array-filter](docs/rules/no-async-array-filter.md) | Disallow async callbacks for Array.filter | ✅ | | |
|
|
66
66
|
| [no-filter-without-return](docs/rules/no-filter-without-return.md) | Disallow Array.filter callbacks without an explicit return (if part of a block statement) | ✅ | | |
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# All top-level const definitions, type definitions, and functions should be exported (`@blumintinc/blumint/export-if-in-doubt`)
|
|
2
2
|
|
|
3
3
|
⚠️ This rule _warns_ in the ✅ `recommended` config.
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Extract
|
|
1
|
+
# Extract constants/functions to the global scope when possible (`@blumintinc/blumint/extract-global-constants`)
|
|
2
2
|
|
|
3
3
|
⚠️ This rule _warns_ in the ✅ `recommended` config.
|
|
4
4
|
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Disallow Array.forEach with an async callback function (`@blumintinc/blumint/no-async-forEach`)
|
|
2
|
+
|
|
3
|
+
💼 This rule is enabled in the ✅ `recommended` config.
|
|
4
|
+
|
|
5
|
+
<!-- end auto-generated rule header -->
|
|
6
|
+
|
|
7
|
+
This rule disallows the use of `Array.forEach` callbacks with the async keyword. These are typically found when sequential promise execution is desired, but in fact these will execute almost concurrently. The use of a standard `for` loop is suggested instead, which will execute sequentially. If concurrent execution is required, `Promise.all` or `Promise.allSettled` should be used.
|
|
8
|
+
|
|
9
|
+
## Rule Details
|
|
10
|
+
|
|
11
|
+
This rule is aimed at ensuring that the async keyword is not used in an `Array.forEach` callback.
|
|
12
|
+
|
|
13
|
+
Examples of **incorrect** code for this rule:
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
['a','b','c'].forEach(async (letter) => {
|
|
17
|
+
await someAsyncFunction(letter)
|
|
18
|
+
console.log(letter)
|
|
19
|
+
})
|
|
20
|
+
['foo','bar'].forEach(async function (letter) {
|
|
21
|
+
await someAsyncFunction(letter)
|
|
22
|
+
console.log(letter)
|
|
23
|
+
})
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Examples of **correct** code for this rule:
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
['a','b','c'].forEach(letter) => {
|
|
30
|
+
someSyncFunction(letter)
|
|
31
|
+
console.log(letter)
|
|
32
|
+
})
|
|
33
|
+
['foo','bar'].forEach(function (letter) {
|
|
34
|
+
someSyncFunction(letter)
|
|
35
|
+
console.log(letter)
|
|
36
|
+
})
|
|
37
|
+
for (const letter of ['a', 'b', 'c']) {
|
|
38
|
+
someSyncFunction(letter);
|
|
39
|
+
console.log(letter);
|
|
40
|
+
}
|
|
41
|
+
```
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
# Prevent
|
|
1
|
+
# Prevent misuse of logical OR in switch case statements (`@blumintinc/blumint/no-misused-switch-case`)
|
|
2
2
|
|
|
3
3
|
💼 This rule is enabled in the ✅ `recommended` config.
|
|
4
4
|
|
|
5
5
|
<!-- end auto-generated rule header -->
|
|
6
6
|
|
|
7
|
-
This rule prevents the misuse of logical OR
|
|
7
|
+
This rule prevents the misuse of logical OR in switch case statements. Instead, cascading cases should be used. This improves code readability and understanding.
|
|
8
8
|
|
|
9
9
|
## Rule Details
|
|
10
10
|
|
|
11
|
-
This rule specifically targets `SwitchStatement` and issues a warning if a case uses a logical OR
|
|
11
|
+
This rule specifically targets `SwitchStatement` and issues a warning if a case uses a logical OR in its test.
|
|
12
12
|
|
|
13
13
|
### Examples of incorrect code for this rule:
|
|
14
14
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Prevent unnecessary use of React fragments (`@blumintinc/blumint/no-useless-fragment`)
|
|
2
|
+
|
|
3
|
+
💼 This rule is enabled in the ✅ `recommended` config.
|
|
4
|
+
|
|
5
|
+
<!-- end auto-generated rule header -->
|
|
6
|
+
|
|
7
|
+
This rule enforces that React fragments (`<>...</>`) are only used when necessary. A fragment is deemed unnecessary if it wraps only a single child.
|
|
8
|
+
|
|
9
|
+
## Rule Details
|
|
10
|
+
|
|
11
|
+
Examples of **incorrect** code for this rule:
|
|
12
|
+
|
|
13
|
+
```jsx
|
|
14
|
+
<><ChildComponent /></>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Examples of **correct** code for this rule:
|
|
18
|
+
|
|
19
|
+
```jsx
|
|
20
|
+
<><ChildComponent /><AnotherChild /></>
|
|
21
|
+
<><ChildComponent />Some Text<AnotherChild /></>
|
|
22
|
+
```
|
|
23
|
+
|
package/lib/index.js
CHANGED
|
@@ -5,15 +5,17 @@ const export_if_in_doubt_1 = require("./rules/export-if-in-doubt");
|
|
|
5
5
|
const extract_global_constants_1 = require("./rules/extract-global-constants");
|
|
6
6
|
const generic_starts_with_t_1 = require("./rules/generic-starts-with-t");
|
|
7
7
|
const no_async_array_filter_1 = require("./rules/no-async-array-filter");
|
|
8
|
+
const no_async_foreach_1 = require("./rules/no-async-foreach");
|
|
8
9
|
const no_filter_without_return_1 = require("./rules/no-filter-without-return");
|
|
9
10
|
const no_misused_switch_case_1 = require("./rules/no-misused-switch-case");
|
|
10
11
|
const no_unpinned_dependencies_1 = require("./rules/no-unpinned-dependencies");
|
|
12
|
+
const no_useless_fragment_1 = require("./rules/no-useless-fragment");
|
|
11
13
|
const prefer_fragment_shorthand_1 = require("./rules/prefer-fragment-shorthand");
|
|
12
14
|
const prefer_type_over_interface_1 = require("./rules/prefer-type-over-interface");
|
|
13
15
|
module.exports = {
|
|
14
16
|
meta: {
|
|
15
17
|
name: '@blumintinc/eslint-plugin-blumint',
|
|
16
|
-
version: '0.1.
|
|
18
|
+
version: '0.1.11',
|
|
17
19
|
},
|
|
18
20
|
parseOptions: {
|
|
19
21
|
ecmaVersion: 2020,
|
|
@@ -27,9 +29,11 @@ module.exports = {
|
|
|
27
29
|
'@blumintinc/blumint/extract-global-constants': 'warn',
|
|
28
30
|
'@blumintinc/blumint/generic-starts-with-t': 'warn',
|
|
29
31
|
'@blumintinc/blumint/no-async-array-filter': 'error',
|
|
32
|
+
'@blumintinc/blumint/no-async-foreach': 'error',
|
|
30
33
|
'@blumintinc/blumint/no-filter-without-return': 'error',
|
|
31
34
|
'@blumintinc/blumint/no-misused-switch-case': 'error',
|
|
32
35
|
'@blumintinc/blumint/no-unpinned-dependencies': 'error',
|
|
36
|
+
'@blumintinc/blumint/no-useless-fragment': 'warn',
|
|
33
37
|
'@blumintinc/blumint/prefer-fragment-shorthand': 'warn',
|
|
34
38
|
'@blumintinc/blumint/prefer-type-over-interface': 'warn',
|
|
35
39
|
},
|
|
@@ -41,9 +45,11 @@ module.exports = {
|
|
|
41
45
|
'extract-global-constants': extract_global_constants_1.extractGlobalConstants,
|
|
42
46
|
'generic-starts-with-t': generic_starts_with_t_1.genericStartsWithT,
|
|
43
47
|
'no-async-array-filter': no_async_array_filter_1.noAsyncArrayFilter,
|
|
48
|
+
'no-async-foreach': no_async_foreach_1.noAsyncForEach,
|
|
44
49
|
'no-filter-without-return': no_filter_without_return_1.noFilterWithoutReturn,
|
|
45
50
|
'no-misused-switch-case': no_misused_switch_case_1.noMisusedSwitchCase,
|
|
46
51
|
'no-unpinned-dependencies': no_unpinned_dependencies_1.noUnpinnedDependencies,
|
|
52
|
+
'no-useless-fragment': no_useless_fragment_1.noUselessFragment,
|
|
47
53
|
'prefer-fragment-shorthand': prefer_fragment_shorthand_1.preferFragmentShorthand,
|
|
48
54
|
'prefer-type-over-interface': prefer_type_over_interface_1.preferTypeOverInterface,
|
|
49
55
|
},
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noAsyncForEach = void 0;
|
|
4
|
+
exports.noAsyncForEach = {
|
|
5
|
+
create(context) {
|
|
6
|
+
return {
|
|
7
|
+
CallExpression(node) {
|
|
8
|
+
const callee = node.callee;
|
|
9
|
+
if (callee.type === 'MemberExpression' &&
|
|
10
|
+
callee.property.type === 'Identifier' &&
|
|
11
|
+
callee.property.name === 'forEach' &&
|
|
12
|
+
node.arguments[0] &&
|
|
13
|
+
(node.arguments[0].type === 'ArrowFunctionExpression' ||
|
|
14
|
+
node.arguments[0].type === 'FunctionExpression') &&
|
|
15
|
+
node.arguments[0].async) {
|
|
16
|
+
context.report({
|
|
17
|
+
node,
|
|
18
|
+
messageId: 'noAsyncForEach',
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
meta: {
|
|
25
|
+
type: 'problem',
|
|
26
|
+
docs: {
|
|
27
|
+
description: 'Disallow Array.forEach with an async callback function',
|
|
28
|
+
recommended: 'error',
|
|
29
|
+
},
|
|
30
|
+
messages: {
|
|
31
|
+
noAsyncForEach: 'Do not use async function as callback in Array.forEach. Use a standard for loop for sequential execution or Promise.all for concurrent execution.',
|
|
32
|
+
},
|
|
33
|
+
schema: [],
|
|
34
|
+
},
|
|
35
|
+
defaultOptions: [],
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=no-async-foreach.js.map
|
|
@@ -7,12 +7,12 @@ exports.noMisusedSwitchCase = (0, createRule_1.createRule)({
|
|
|
7
7
|
meta: {
|
|
8
8
|
type: 'problem',
|
|
9
9
|
docs: {
|
|
10
|
-
description: 'Prevent misuse of logical OR
|
|
10
|
+
description: 'Prevent misuse of logical OR in switch case statements',
|
|
11
11
|
recommended: 'error',
|
|
12
12
|
},
|
|
13
13
|
schema: [],
|
|
14
14
|
messages: {
|
|
15
|
-
noMisusedSwitchCase: 'Avoid using logical OR
|
|
15
|
+
noMisusedSwitchCase: 'Avoid using logical OR in switch case. Use cascading cases instead.',
|
|
16
16
|
},
|
|
17
17
|
},
|
|
18
18
|
defaultOptions: [],
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noUselessFragment = void 0;
|
|
4
|
+
exports.noUselessFragment = {
|
|
5
|
+
create(context) {
|
|
6
|
+
return {
|
|
7
|
+
JSXFragment(node) {
|
|
8
|
+
if (node.children.length === 1) {
|
|
9
|
+
context.report({
|
|
10
|
+
node,
|
|
11
|
+
messageId: 'noUselessFragment',
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
meta: {
|
|
18
|
+
type: 'suggestion',
|
|
19
|
+
docs: {
|
|
20
|
+
description: 'Prevent unnecessary use of React fragments',
|
|
21
|
+
recommended: 'warn',
|
|
22
|
+
},
|
|
23
|
+
messages: {
|
|
24
|
+
noUselessFragment: 'React fragment is unnecessary when wrapping a single child',
|
|
25
|
+
},
|
|
26
|
+
schema: [],
|
|
27
|
+
},
|
|
28
|
+
defaultOptions: [],
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=no-useless-fragment.js.map
|
|
@@ -30,7 +30,7 @@ exports.preferFragmentShorthand = {
|
|
|
30
30
|
recommended: 'warn',
|
|
31
31
|
},
|
|
32
32
|
messages: {
|
|
33
|
-
preferShorthand: 'Use <> shorthand for <React.Fragment
|
|
33
|
+
preferShorthand: 'Use <> shorthand for <React.Fragment>, unless a key is required for an iterator',
|
|
34
34
|
},
|
|
35
35
|
schema: [],
|
|
36
36
|
fixable: 'code',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blumintinc/eslint-plugin-blumint",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "Custom eslint rules for use at BluMint",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"ts-jest": "29.0.5"
|
|
37
37
|
},
|
|
38
38
|
"engines": {
|
|
39
|
-
"node": "16.0.0"
|
|
39
|
+
"node": "^16.0.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"eslint": ">=7"
|