@blumintinc/eslint-plugin-blumint 0.1.11 → 0.1.12
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
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
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Disallow use of conditional literals in JSX code (`@blumintinc/blumint/no-conditional-literals-in-jsx`)
|
|
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 conditional literals in JSX.
|
|
8
|
+
|
|
9
|
+
## Rule Details
|
|
10
|
+
|
|
11
|
+
Browser auto-translation will break if pieces of text nodes are be rendered conditionally.
|
|
12
|
+
|
|
13
|
+
Examples of **incorrect** code for this rule:
|
|
14
|
+
|
|
15
|
+
```jsx
|
|
16
|
+
<div>This will cause {conditional && 'errors'}</div>
|
|
17
|
+
<div><span>This will {conditional && 'also'} cause errors </span></div>
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Examples of **correct** code for this rule:
|
|
21
|
+
|
|
22
|
+
```jsx
|
|
23
|
+
<div>Foo</div>
|
|
24
|
+
<div>
|
|
25
|
+
Bar {conditional && <span>Baz</span>}
|
|
26
|
+
</div>
|
|
27
|
+
```
|
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.12',
|
|
19
20
|
},
|
|
20
21
|
parseOptions: {
|
|
21
22
|
ecmaVersion: 2020,
|
|
@@ -30,6 +31,7 @@ module.exports = {
|
|
|
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
|