@dineroregnskab/eslint-plugin-custom-rules 2.1.3 → 2.1.4
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/package.json
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
const eslintUtils = require("eslint-utils");
|
|
2
|
-
|
|
3
1
|
module.exports = {
|
|
4
2
|
meta: {
|
|
5
3
|
type: "suggestion",
|
|
@@ -25,9 +23,6 @@ module.exports = {
|
|
|
25
23
|
node,
|
|
26
24
|
message:
|
|
27
25
|
"Replace `first()` with `take(1)` to avoid errors if no value is ever emitted.",
|
|
28
|
-
fix(fixer) {
|
|
29
|
-
return fixer.replaceText(node, "take(1)");
|
|
30
|
-
},
|
|
31
26
|
});
|
|
32
27
|
}
|
|
33
28
|
|
|
@@ -54,61 +49,12 @@ module.exports = {
|
|
|
54
49
|
arg.callee.name === "filter"
|
|
55
50
|
);
|
|
56
51
|
|
|
57
|
-
//
|
|
52
|
+
// Report an error if `take(1)` is used without `filter()`
|
|
58
53
|
if (hasTakeOne && !hasFilter) {
|
|
59
54
|
context.report({
|
|
60
55
|
node,
|
|
61
56
|
message:
|
|
62
|
-
"Using `take(1)` requires `filter()` to be used in the same pipe to avoid `null` or `undefined` values which will trigger an error.",
|
|
63
|
-
fix(fixer) {
|
|
64
|
-
const sourceCode = context.getSourceCode();
|
|
65
|
-
const firstArg = pipeArguments[0];
|
|
66
|
-
|
|
67
|
-
const fixes = [
|
|
68
|
-
// Add the `filter()` inside the pipe
|
|
69
|
-
fixer.insertTextBefore(
|
|
70
|
-
firstArg,
|
|
71
|
-
"filter((value) => Boolean(value ?? false)), "
|
|
72
|
-
),
|
|
73
|
-
];
|
|
74
|
-
|
|
75
|
-
// Check if `filter` is imported, if not, add the import
|
|
76
|
-
const importDeclaration =
|
|
77
|
-
sourceCode.ast.body.find(
|
|
78
|
-
(node) =>
|
|
79
|
-
node.type === "ImportDeclaration" &&
|
|
80
|
-
node.source.value ===
|
|
81
|
-
"rxjs/operators"
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
if (importDeclaration) {
|
|
85
|
-
const filterImported =
|
|
86
|
-
importDeclaration.specifiers.some(
|
|
87
|
-
(specifier) =>
|
|
88
|
-
specifier.imported.name ===
|
|
89
|
-
"filter"
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
if (!filterImported) {
|
|
93
|
-
fixes.push(
|
|
94
|
-
fixer.insertTextBefore(
|
|
95
|
-
importDeclaration.specifiers[0],
|
|
96
|
-
"filter, "
|
|
97
|
-
)
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
} else {
|
|
101
|
-
// Add a new import if none exist
|
|
102
|
-
fixes.push(
|
|
103
|
-
fixer.insertTextBefore(
|
|
104
|
-
sourceCode.ast.body[0],
|
|
105
|
-
'import { filter } from "rxjs/operators";\n'
|
|
106
|
-
)
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return fixes;
|
|
111
|
-
},
|
|
57
|
+
"Using `take(1)` requires `filter()` to be used in the same pipe to avoid `null` or `undefined` values which will trigger an error. Example `filter((value) => Boolean(value ?? false)),`",
|
|
112
58
|
});
|
|
113
59
|
}
|
|
114
60
|
}
|