@blumintinc/eslint-plugin-blumint 0.1.2 → 0.1.4-s
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
|
@@ -64,7 +64,7 @@ Or use the recommended config:
|
|
|
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) | ✅ | | |
|
|
67
|
-
| [no-misused-switch-case](docs/rules/no-misused-switch-case.md) | Prevent misuse of logical OR
|
|
67
|
+
| [no-misused-switch-case](docs/rules/no-misused-switch-case.md) | Prevent misuse of logical OR in switch case statements | ✅ | | |
|
|
68
68
|
| [no-unpinned-dependencies](docs/rules/no-unpinned-dependencies.md) | Enforces pinned dependencies | ✅ | | 🔧 |
|
|
69
69
|
| [prefer-fragment-shorthand](docs/rules/prefer-fragment-shorthand.md) | Prefer <> shorthand for <React.Fragment> | | ✅ | 🔧 |
|
|
70
70
|
| [prefer-type-over-interface](docs/rules/prefer-type-over-interface.md) | Prefer using type alias over interface | | ✅ | |
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.testingAFunction = void 0;
|
|
4
3
|
const array_methods_this_context_1 = require("./rules/array-methods-this-context");
|
|
5
4
|
const export_if_in_doubt_1 = require("./rules/export-if-in-doubt");
|
|
6
5
|
const extract_global_constants_1 = require("./rules/extract-global-constants");
|
|
@@ -14,7 +13,7 @@ const prefer_type_over_interface_1 = require("./rules/prefer-type-over-interface
|
|
|
14
13
|
module.exports = {
|
|
15
14
|
meta: {
|
|
16
15
|
name: '@blumintinc/eslint-plugin-blumint',
|
|
17
|
-
version: '0.1.
|
|
16
|
+
version: '0.1.4',
|
|
18
17
|
},
|
|
19
18
|
parseOptions: {
|
|
20
19
|
ecmaVersion: 2020,
|
|
@@ -49,9 +48,4 @@ module.exports = {
|
|
|
49
48
|
'prefer-type-over-interface': prefer_type_over_interface_1.preferTypeOverInterface,
|
|
50
49
|
},
|
|
51
50
|
};
|
|
52
|
-
const testingAFunction = (input) => {
|
|
53
|
-
const a = input?.A;
|
|
54
|
-
return a;
|
|
55
|
-
};
|
|
56
|
-
exports.testingAFunction = testingAFunction;
|
|
57
51
|
//# sourceMappingURL=index.js.map
|
|
@@ -50,7 +50,7 @@ exports.arrayMethodsThisContext = (0, createRule_1.createRule)({
|
|
|
50
50
|
meta: {
|
|
51
51
|
type: 'problem',
|
|
52
52
|
docs: {
|
|
53
|
-
description: '
|
|
53
|
+
description: 'Prevent misuse of Array methods in OOP',
|
|
54
54
|
recommended: 'error',
|
|
55
55
|
},
|
|
56
56
|
schema: [],
|
|
@@ -13,7 +13,8 @@ exports.extractGlobalConstants = (0, createRule_1.createRule)({
|
|
|
13
13
|
const scope = context.getScope();
|
|
14
14
|
const hasDependencies = node.declarations.some((declaration) => declaration.init &&
|
|
15
15
|
ASTHelpers_1.ASTHelpers.declarationIncludesIdentifier(declaration.init));
|
|
16
|
-
if (!hasDependencies &&
|
|
16
|
+
if (!hasDependencies &&
|
|
17
|
+
(scope.type === 'function' || scope.type === 'block')) {
|
|
17
18
|
const constName = node.declarations[0].id.name;
|
|
18
19
|
context.report({
|
|
19
20
|
node,
|
|
@@ -49,7 +50,7 @@ exports.extractGlobalConstants = (0, createRule_1.createRule)({
|
|
|
49
50
|
meta: {
|
|
50
51
|
type: 'suggestion',
|
|
51
52
|
docs: {
|
|
52
|
-
description: 'Extract constants/functions
|
|
53
|
+
description: 'Extract constants/functions to the global scope when possible',
|
|
53
54
|
recommended: 'error',
|
|
54
55
|
},
|
|
55
56
|
schema: [],
|
package/lib/utils/ASTHelpers.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ASTHelpers = void 0;
|
|
4
|
-
// import { RuleContext } from '@typescript-eslint/utils/dist/ts-eslint';
|
|
5
4
|
class ASTHelpers {
|
|
6
5
|
static blockIncludesIdentifier(block) {
|
|
7
6
|
for (const statement of block.body) {
|
|
@@ -15,10 +14,14 @@ class ASTHelpers {
|
|
|
15
14
|
if (!node) {
|
|
16
15
|
return false;
|
|
17
16
|
}
|
|
18
|
-
console.log('visting node of type', node.type);
|
|
19
17
|
switch (node.type) {
|
|
20
18
|
case 'BlockStatement':
|
|
21
|
-
return
|
|
19
|
+
return node.body.some((statement) => statement.type === 'BlockStatement' &&
|
|
20
|
+
ASTHelpers.blockIncludesIdentifier(statement));
|
|
21
|
+
case 'IfStatement':
|
|
22
|
+
return (this.declarationIncludesIdentifier(node.test) ||
|
|
23
|
+
this.declarationIncludesIdentifier(node.consequent) ||
|
|
24
|
+
this.declarationIncludesIdentifier(node.alternate));
|
|
22
25
|
case 'Identifier':
|
|
23
26
|
return true;
|
|
24
27
|
case 'SpreadElement':
|
|
@@ -64,39 +67,6 @@ class ASTHelpers {
|
|
|
64
67
|
return false;
|
|
65
68
|
}
|
|
66
69
|
}
|
|
67
|
-
// public static declarationIncludesIdentifier(
|
|
68
|
-
// node: TSESTree.Expression | null,
|
|
69
|
-
// ): boolean {
|
|
70
|
-
// if (!node) {
|
|
71
|
-
// return false;
|
|
72
|
-
// }
|
|
73
|
-
// switch (node.type) {
|
|
74
|
-
// case 'Identifier':
|
|
75
|
-
// return true;
|
|
76
|
-
// case 'ArrayExpression':
|
|
77
|
-
// return node.elements.some(
|
|
78
|
-
// (element) =>
|
|
79
|
-
// element &&
|
|
80
|
-
// (element.type === 'SpreadElement'
|
|
81
|
-
// ? ASTHelpers.declarationIncludesIdentifier(element.argument)
|
|
82
|
-
// : ASTHelpers.declarationIncludesIdentifier(element)),
|
|
83
|
-
// );
|
|
84
|
-
// case 'ObjectExpression':
|
|
85
|
-
// return node.properties.some((property) => {
|
|
86
|
-
// if (property.type === 'Property') {
|
|
87
|
-
// return ASTHelpers.declarationIncludesIdentifier(property.key);
|
|
88
|
-
// } else if (property.type === 'SpreadElement') {
|
|
89
|
-
// return ASTHelpers.declarationIncludesIdentifier(property.argument);
|
|
90
|
-
// }
|
|
91
|
-
// return false;
|
|
92
|
-
// });
|
|
93
|
-
// default:
|
|
94
|
-
// return (
|
|
95
|
-
// ASTHelpers.declarationIncludesIdentifier((node as any).left) ||
|
|
96
|
-
// ASTHelpers.declarationIncludesIdentifier((node as any).right)
|
|
97
|
-
// );
|
|
98
|
-
// }
|
|
99
|
-
// }
|
|
100
70
|
static isNode(value) {
|
|
101
71
|
return typeof value === 'object' && value !== null && 'type' in value;
|
|
102
72
|
}
|
|
@@ -104,14 +74,12 @@ class ASTHelpers {
|
|
|
104
74
|
if (node.type === 'ReturnStatement') {
|
|
105
75
|
return true;
|
|
106
76
|
}
|
|
107
|
-
|
|
108
|
-
// Check both branches of the if statement
|
|
77
|
+
if (node.type === 'IfStatement') {
|
|
109
78
|
const consequentHasReturn = ASTHelpers.hasReturnStatement(node.consequent);
|
|
110
79
|
const alternateHasReturn = !!node.alternate && ASTHelpers.hasReturnStatement(node.alternate);
|
|
111
80
|
return consequentHasReturn && alternateHasReturn;
|
|
112
81
|
}
|
|
113
|
-
|
|
114
|
-
// Check all statements in the block
|
|
82
|
+
if (node.type === 'BlockStatement') {
|
|
115
83
|
for (const statement of node.body) {
|
|
116
84
|
if (ASTHelpers.hasReturnStatement(statement)) {
|
|
117
85
|
return true;
|