@blumintinc/eslint-plugin-blumint 0.1.11 → 0.1.13
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 +15 -12
- package/docs/rules/export-if-in-doubt.md +0 -2
- package/docs/rules/extract-global-constants.md +0 -2
- package/docs/rules/no-async-foreach.md +1 -1
- package/docs/rules/no-conditional-literals-in-jsx.md +25 -0
- package/docs/rules/no-useless-fragment.md +3 -1
- package/docs/rules/prefer-type-over-interface.md +2 -0
- package/lib/index.js +6 -3
- package/lib/rules/no-conditional-literals-in-jsx.js +61 -0
- package/lib/rules/no-useless-fragment.js +16 -0
- package/lib/rules/prefer-type-over-interface.js +15 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -56,18 +56,21 @@ Or use the recommended config:
|
|
|
56
56
|
✅ Set in the `recommended` configuration.\
|
|
57
57
|
🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).
|
|
58
58
|
|
|
59
|
-
| Name
|
|
60
|
-
|
|
|
61
|
-
| [array-methods-this-context](docs/rules/array-methods-this-context.md)
|
|
62
|
-
| [export-if-in-doubt](docs/rules/export-if-in-doubt.md)
|
|
63
|
-
| [extract-global-constants](docs/rules/extract-global-constants.md)
|
|
64
|
-
| [generic-starts-with-t](docs/rules/generic-starts-with-t.md)
|
|
65
|
-
| [no-async-array-filter](docs/rules/no-async-array-filter.md)
|
|
66
|
-
| [no-
|
|
67
|
-
| [no-
|
|
68
|
-
| [no-
|
|
69
|
-
| [
|
|
70
|
-
| [
|
|
59
|
+
| Name | Description | 💼 | ⚠️ | 🔧 |
|
|
60
|
+
| :----------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------- | :- | :- | :- |
|
|
61
|
+
| [array-methods-this-context](docs/rules/array-methods-this-context.md) | Prevent misuse of Array methods in OOP | | ✅ | |
|
|
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 to the global scope when possible | | | |
|
|
64
|
+
| [generic-starts-with-t](docs/rules/generic-starts-with-t.md) | Enforce TypeScript generic types to start with T | | ✅ | |
|
|
65
|
+
| [no-async-array-filter](docs/rules/no-async-array-filter.md) | Disallow async callbacks for Array.filter | ✅ | | |
|
|
66
|
+
| [no-async-foreach](docs/rules/no-async-foreach.md) | Disallow Array.forEach with an async callback function | ✅ | | |
|
|
67
|
+
| [no-conditional-literals-in-jsx](docs/rules/no-conditional-literals-in-jsx.md) | Disallow use of conditional literals in JSX code | | | |
|
|
68
|
+
| [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) | ✅ | | |
|
|
69
|
+
| [no-misused-switch-case](docs/rules/no-misused-switch-case.md) | Prevent misuse of logical OR in switch case statements | ✅ | | |
|
|
70
|
+
| [no-unpinned-dependencies](docs/rules/no-unpinned-dependencies.md) | Enforces pinned dependencies | ✅ | | 🔧 |
|
|
71
|
+
| [no-useless-fragment](docs/rules/no-useless-fragment.md) | Prevent unnecessary use of React fragments | | ✅ | 🔧 |
|
|
72
|
+
| [prefer-fragment-shorthand](docs/rules/prefer-fragment-shorthand.md) | Prefer <> shorthand for <React.Fragment> | | ✅ | 🔧 |
|
|
73
|
+
| [prefer-type-over-interface](docs/rules/prefer-type-over-interface.md) | Prefer using type alias over interface | | ✅ | 🔧 |
|
|
71
74
|
|
|
72
75
|
<!-- end auto-generated rules list -->
|
|
73
76
|
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# All top-level const definitions, type definitions, and functions should be exported (`@blumintinc/blumint/export-if-in-doubt`)
|
|
2
2
|
|
|
3
|
-
⚠️ This rule _warns_ in the ✅ `recommended` config.
|
|
4
|
-
|
|
5
3
|
<!-- end auto-generated rule header -->
|
|
6
4
|
|
|
7
5
|
This rule enforces that all top-level const definitions, type definitions, and functions should always be exported. If not done, this rule will trigger a warning message suggesting to export the declaration.
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# Extract constants/functions to the global scope when possible (`@blumintinc/blumint/extract-global-constants`)
|
|
2
2
|
|
|
3
|
-
⚠️ This rule _warns_ in the ✅ `recommended` config.
|
|
4
|
-
|
|
5
3
|
<!-- end auto-generated rule header -->
|
|
6
4
|
|
|
7
5
|
This rule suggests that if a constant or a function within a function or block scope doesn't depend on any other identifiers in that scope, it should be moved to the global scope. This aims to improve the readability of the code and the possibility of reuse.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Disallow use of conditional literals in JSX code (`@blumintinc/blumint/no-conditional-literals-in-jsx`)
|
|
2
|
+
|
|
3
|
+
<!-- end auto-generated rule header -->
|
|
4
|
+
|
|
5
|
+
This rule disallows the use of conditional literals in JSX.
|
|
6
|
+
|
|
7
|
+
## Rule Details
|
|
8
|
+
|
|
9
|
+
Browser auto-translation will break if pieces of text nodes are be rendered conditionally.
|
|
10
|
+
|
|
11
|
+
Examples of **incorrect** code for this rule:
|
|
12
|
+
|
|
13
|
+
```jsx
|
|
14
|
+
<div>This will cause {conditional && 'errors'}</div>
|
|
15
|
+
<div><span>This will {conditional && 'also'} cause errors </span></div>
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Examples of **correct** code for this rule:
|
|
19
|
+
|
|
20
|
+
```jsx
|
|
21
|
+
<div>Foo</div>
|
|
22
|
+
<div>
|
|
23
|
+
Bar {conditional && <span>Baz</span>}
|
|
24
|
+
</div>
|
|
25
|
+
```
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# Prevent unnecessary use of React fragments (`@blumintinc/blumint/no-useless-fragment`)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
⚠️ This rule _warns_ in the ✅ `recommended` config.
|
|
4
|
+
|
|
5
|
+
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
|
|
4
6
|
|
|
5
7
|
<!-- end auto-generated rule header -->
|
|
6
8
|
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
⚠️ This rule _warns_ in the ✅ `recommended` config.
|
|
4
4
|
|
|
5
|
+
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
|
|
6
|
+
|
|
5
7
|
<!-- end auto-generated rule header -->
|
|
6
8
|
|
|
7
9
|
This rule prefers the use of `Type` over `Interface` in Typescript.
|
package/lib/index.js
CHANGED
|
@@ -6,6 +6,7 @@ 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
8
|
const no_async_foreach_1 = require("./rules/no-async-foreach");
|
|
9
|
+
const no_conditional_literals_in_jsx_1 = require("./rules/no-conditional-literals-in-jsx");
|
|
9
10
|
const no_filter_without_return_1 = require("./rules/no-filter-without-return");
|
|
10
11
|
const no_misused_switch_case_1 = require("./rules/no-misused-switch-case");
|
|
11
12
|
const no_unpinned_dependencies_1 = require("./rules/no-unpinned-dependencies");
|
|
@@ -15,7 +16,7 @@ const prefer_type_over_interface_1 = require("./rules/prefer-type-over-interface
|
|
|
15
16
|
module.exports = {
|
|
16
17
|
meta: {
|
|
17
18
|
name: '@blumintinc/eslint-plugin-blumint',
|
|
18
|
-
version: '0.1.
|
|
19
|
+
version: '0.1.13',
|
|
19
20
|
},
|
|
20
21
|
parseOptions: {
|
|
21
22
|
ecmaVersion: 2020,
|
|
@@ -25,11 +26,12 @@ module.exports = {
|
|
|
25
26
|
plugins: ['@blumintinc/blumint'],
|
|
26
27
|
rules: {
|
|
27
28
|
'@blumintinc/blumint/array-methods-this-context': 'warn',
|
|
28
|
-
'@blumintinc/blumint/export-if-in-doubt': 'warn',
|
|
29
|
-
'@blumintinc/blumint/extract-global-constants': 'warn',
|
|
29
|
+
// '@blumintinc/blumint/export-if-in-doubt': 'warn',
|
|
30
|
+
// '@blumintinc/blumint/extract-global-constants': 'warn',
|
|
30
31
|
'@blumintinc/blumint/generic-starts-with-t': 'warn',
|
|
31
32
|
'@blumintinc/blumint/no-async-array-filter': 'error',
|
|
32
33
|
'@blumintinc/blumint/no-async-foreach': 'error',
|
|
34
|
+
'@blumincinc/blumint/no-conditional-literals-in-jsx': 'error',
|
|
33
35
|
'@blumintinc/blumint/no-filter-without-return': 'error',
|
|
34
36
|
'@blumintinc/blumint/no-misused-switch-case': 'error',
|
|
35
37
|
'@blumintinc/blumint/no-unpinned-dependencies': 'error',
|
|
@@ -46,6 +48,7 @@ module.exports = {
|
|
|
46
48
|
'generic-starts-with-t': generic_starts_with_t_1.genericStartsWithT,
|
|
47
49
|
'no-async-array-filter': no_async_array_filter_1.noAsyncArrayFilter,
|
|
48
50
|
'no-async-foreach': no_async_foreach_1.noAsyncForEach,
|
|
51
|
+
'no-conditional-literals-in-jsx': no_conditional_literals_in_jsx_1.noConditionalLiteralsInJsx,
|
|
49
52
|
'no-filter-without-return': no_filter_without_return_1.noFilterWithoutReturn,
|
|
50
53
|
'no-misused-switch-case': no_misused_switch_case_1.noMisusedSwitchCase,
|
|
51
54
|
'no-unpinned-dependencies': no_unpinned_dependencies_1.noUnpinnedDependencies,
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noConditionalLiteralsInJsx = void 0;
|
|
4
|
+
/* eslint-disable @blumintinc/blumint/extract-global-constants */
|
|
5
|
+
// import { ASTHelpers } from '../utils/ASTHelpers';
|
|
6
|
+
const createRule_1 = require("../utils/createRule");
|
|
7
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
8
|
+
exports.noConditionalLiteralsInJsx = (0, createRule_1.createRule)({
|
|
9
|
+
name: 'no-conditional-literals-in-jsx',
|
|
10
|
+
meta: {
|
|
11
|
+
type: 'problem',
|
|
12
|
+
docs: {
|
|
13
|
+
description: 'Disallow use of conditional literals in JSX code',
|
|
14
|
+
recommended: 'error',
|
|
15
|
+
},
|
|
16
|
+
schema: [],
|
|
17
|
+
messages: {
|
|
18
|
+
unexpected: 'Conditional expression is a sibling of raw text and must be wrapped in <div> or <span>',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
defaultOptions: [],
|
|
22
|
+
create(context) {
|
|
23
|
+
return {
|
|
24
|
+
// Imagine evaluating <div>text {conditional && 'string'}</div>
|
|
25
|
+
JSXExpressionContainer(node) {
|
|
26
|
+
// We start at the expression {conditional && 'string'}
|
|
27
|
+
if (node.expression.type !== 'LogicalExpression') {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const parentChildren = node.parent && 'children' in node.parent ? node.parent.children : [];
|
|
31
|
+
// "text" is one of the siblingTextNodes.
|
|
32
|
+
const siblingTextNodes = parentChildren.filter((n) => {
|
|
33
|
+
if (n.type === utils_1.TSESTree.AST_NODE_TYPES.Literal ||
|
|
34
|
+
n.type === utils_1.TSESTree.AST_NODE_TYPES.JSXText) {
|
|
35
|
+
return !!('value' in n && !!n.value ? `${n.value}`.trim() : false);
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
});
|
|
39
|
+
// If we were evaluating
|
|
40
|
+
// <div>{property} {conditional && 'string'}</div>
|
|
41
|
+
// Then {property} would be one of the siblingExpressionNodes
|
|
42
|
+
const siblingExpressionNodes = parentChildren.filter((n) => n.type === 'JSXExpressionContainer' &&
|
|
43
|
+
'expression' in n &&
|
|
44
|
+
(n.expression.type === 'Identifier' ||
|
|
45
|
+
n.expression.type === 'MemberExpression'));
|
|
46
|
+
// Operands of {conditional && 'string'} -- the conditional and the
|
|
47
|
+
// literal. We want to make sure we have a text literal, otherwise we'd
|
|
48
|
+
// trigger this rule on the (safe) {conditional && <div>string</div>}.
|
|
49
|
+
const expressionOperandTypes = [
|
|
50
|
+
node.expression.left.type,
|
|
51
|
+
node.expression.right.type,
|
|
52
|
+
];
|
|
53
|
+
if (siblingTextNodes.concat(siblingExpressionNodes).length > 0 &&
|
|
54
|
+
expressionOperandTypes.includes(utils_1.TSESTree.AST_NODE_TYPES.Literal)) {
|
|
55
|
+
context.report({ node, messageId: 'unexpected' });
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=no-conditional-literals-in-jsx.js.map
|
|
@@ -9,6 +9,21 @@ exports.noUselessFragment = {
|
|
|
9
9
|
context.report({
|
|
10
10
|
node,
|
|
11
11
|
messageId: 'noUselessFragment',
|
|
12
|
+
fix(fixer) {
|
|
13
|
+
const sourceCode = context.getSourceCode();
|
|
14
|
+
const openingFragment = sourceCode.getFirstToken(node);
|
|
15
|
+
const closingFragment = sourceCode.getLastToken(node);
|
|
16
|
+
return [
|
|
17
|
+
fixer.removeRange([
|
|
18
|
+
openingFragment.range[0],
|
|
19
|
+
openingFragment.range[0] + 2,
|
|
20
|
+
]),
|
|
21
|
+
fixer.removeRange([
|
|
22
|
+
closingFragment.range[0] - 3,
|
|
23
|
+
closingFragment.range[0],
|
|
24
|
+
]),
|
|
25
|
+
];
|
|
26
|
+
},
|
|
12
27
|
});
|
|
13
28
|
}
|
|
14
29
|
},
|
|
@@ -24,6 +39,7 @@ exports.noUselessFragment = {
|
|
|
24
39
|
noUselessFragment: 'React fragment is unnecessary when wrapping a single child',
|
|
25
40
|
},
|
|
26
41
|
schema: [],
|
|
42
|
+
fixable: 'code',
|
|
27
43
|
},
|
|
28
44
|
defaultOptions: [],
|
|
29
45
|
};
|
|
@@ -14,6 +14,7 @@ exports.preferTypeOverInterface = (0, createRule_1.createRule)({
|
|
|
14
14
|
messages: {
|
|
15
15
|
preferType: 'Prefer using type alias over interface.',
|
|
16
16
|
},
|
|
17
|
+
fixable: 'code',
|
|
17
18
|
},
|
|
18
19
|
defaultOptions: [],
|
|
19
20
|
create(context) {
|
|
@@ -22,6 +23,20 @@ exports.preferTypeOverInterface = (0, createRule_1.createRule)({
|
|
|
22
23
|
context.report({
|
|
23
24
|
node,
|
|
24
25
|
messageId: 'preferType',
|
|
26
|
+
fix(fixer) {
|
|
27
|
+
const sourceCode = context.getSourceCode();
|
|
28
|
+
const openingBrace = sourceCode.getTokenAfter(node.id, {
|
|
29
|
+
filter: (token) => token.value === '{',
|
|
30
|
+
});
|
|
31
|
+
const fixes = [
|
|
32
|
+
fixer.replaceTextRange([node.range[0], node.id.range[1]], `type ${node.id.name} =`),
|
|
33
|
+
];
|
|
34
|
+
if (node.extends && node.extends.length > 0 && openingBrace) {
|
|
35
|
+
const extendsKeyword = sourceCode.getFirstTokenBetween(node.id, openingBrace, { filter: (token) => token.value === 'extends' });
|
|
36
|
+
fixes.push(fixer.remove(extendsKeyword), fixer.insertTextBefore(openingBrace, '& '));
|
|
37
|
+
}
|
|
38
|
+
return fixes;
|
|
39
|
+
},
|
|
25
40
|
});
|
|
26
41
|
},
|
|
27
42
|
};
|