@blumintinc/eslint-plugin-blumint 0.1.18 → 0.1.20
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.
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Dynamic elements of errors should be in the 'details' field (`@blumintinc/blumint/dynamic-https-errors`)
|
|
2
|
+
|
|
3
|
+
⚠️ This rule _warns_ in the ✅ `recommended` config.
|
|
4
|
+
|
|
5
|
+
<!-- end auto-generated rule header -->
|
|
6
|
+
|
|
7
|
+
This rule warns against the use of template literals in the `message` field of the `HttpsError` constructor, and suggests their use in the `details` field instead.
|
|
8
|
+
|
|
9
|
+
## Rule Details
|
|
10
|
+
|
|
11
|
+
Examples of **incorrect** code for this rule:
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
throw new https.HttpsError('foo', `Error: ${bar}`, 'baz');
|
|
15
|
+
throw new HttpsError('foo', `Error: ${bar}`, 'baz');
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Examples of **correct** code for this rule:
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
throw new https.HttpsError('foo', 'bar', 'baz');
|
|
22
|
+
throw new https.HttpsError('foo', 'bar', `Details: ${baz}`);
|
|
23
|
+
```
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const array_methods_this_context_1 = require("./rules/array-methods-this-context");
|
|
4
|
+
const dynamic_https_errors_1 = require("./rules/dynamic-https-errors");
|
|
4
5
|
const export_if_in_doubt_1 = require("./rules/export-if-in-doubt");
|
|
5
6
|
const extract_global_constants_1 = require("./rules/extract-global-constants");
|
|
6
7
|
const generic_starts_with_t_1 = require("./rules/generic-starts-with-t");
|
|
@@ -17,7 +18,7 @@ const require_memo_1 = require("./rules/require-memo");
|
|
|
17
18
|
module.exports = {
|
|
18
19
|
meta: {
|
|
19
20
|
name: '@blumintinc/eslint-plugin-blumint',
|
|
20
|
-
version: '0.1.
|
|
21
|
+
version: '0.1.20',
|
|
21
22
|
},
|
|
22
23
|
parseOptions: {
|
|
23
24
|
ecmaVersion: 2020,
|
|
@@ -27,6 +28,7 @@ module.exports = {
|
|
|
27
28
|
plugins: ['@blumintinc/blumint'],
|
|
28
29
|
rules: {
|
|
29
30
|
'@blumintinc/blumint/array-methods-this-context': 'warn',
|
|
31
|
+
'@blumintinc/blumint/dynamic-https-errors': 'warn',
|
|
30
32
|
// '@blumintinc/blumint/export-if-in-doubt': 'warn',
|
|
31
33
|
// '@blumintinc/blumint/extract-global-constants': 'warn',
|
|
32
34
|
'@blumintinc/blumint/generic-starts-with-t': 'warn',
|
|
@@ -45,6 +47,7 @@ module.exports = {
|
|
|
45
47
|
},
|
|
46
48
|
rules: {
|
|
47
49
|
'array-methods-this-context': array_methods_this_context_1.arrayMethodsThisContext,
|
|
50
|
+
'dynamic-https-errors': dynamic_https_errors_1.dynamicHttpsErrors,
|
|
48
51
|
'export-if-in-doubt': export_if_in_doubt_1.exportIfInDoubt,
|
|
49
52
|
'extract-global-constants': extract_global_constants_1.extractGlobalConstants,
|
|
50
53
|
'generic-starts-with-t': generic_starts_with_t_1.genericStartsWithT,
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dynamicHttpsErrors = void 0;
|
|
4
|
+
/* eslint-disable @blumintinc/blumint/extract-global-constants */
|
|
5
|
+
const createRule_1 = require("../utils/createRule");
|
|
6
|
+
const isHttpsErrorCall = (callee) => {
|
|
7
|
+
if (callee.type === 'MemberExpression') {
|
|
8
|
+
return (callee.object.type === 'Identifier' &&
|
|
9
|
+
callee.object.name === 'https' &&
|
|
10
|
+
callee.property.type === 'Identifier' &&
|
|
11
|
+
callee.property.name === 'HttpsError');
|
|
12
|
+
}
|
|
13
|
+
else if (callee.type === 'Identifier') {
|
|
14
|
+
return callee.name === 'HttpsError';
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
};
|
|
18
|
+
exports.dynamicHttpsErrors = (0, createRule_1.createRule)({
|
|
19
|
+
name: 'dynamic-https-errors',
|
|
20
|
+
meta: {
|
|
21
|
+
type: 'suggestion',
|
|
22
|
+
docs: {
|
|
23
|
+
description: 'Dynamic error details should only be in the third argument of the HttpsError constructor. The second argument is hashed to produce a unique id.',
|
|
24
|
+
recommended: 'warn',
|
|
25
|
+
},
|
|
26
|
+
schema: [],
|
|
27
|
+
messages: {
|
|
28
|
+
dynamicHttpsErrors: 'Found dynamic error details in the second argument of the HttpsError constructor - the "message" field. This field is hashed to produce a unique id for error monitoring. Move any dynamic details to the third argument - the "details" field - to preserve the unique id and to monitor the error correctly.',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
defaultOptions: [],
|
|
32
|
+
create(context) {
|
|
33
|
+
const checkForHttpsError = (node) => {
|
|
34
|
+
const callee = node.callee;
|
|
35
|
+
if (isHttpsErrorCall(callee)) {
|
|
36
|
+
const secondArg = node.arguments[1];
|
|
37
|
+
if (secondArg && secondArg.type === 'TemplateLiteral') {
|
|
38
|
+
if (secondArg.expressions.length > 0) {
|
|
39
|
+
context.report({
|
|
40
|
+
node: secondArg,
|
|
41
|
+
messageId: 'dynamicHttpsErrors',
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
NewExpression(node) {
|
|
49
|
+
return checkForHttpsError(node);
|
|
50
|
+
},
|
|
51
|
+
CallExpression(node) {
|
|
52
|
+
return checkForHttpsError(node);
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
//# sourceMappingURL=dynamic-https-errors.js.map
|