Skip to content

Commit 40b2551

Browse files
Merge pull request #12 from aashutoshrathi/v0.2.4
v0.2.4
2 parents a3d4209 + 43e2322 commit 40b2551

5 files changed

+21
-10
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ But with Mongoose there is a catch, if you attach inject model to non-model vari
1414

1515
One such incident is shown below:
1616

17-
<img alt="GIF of mishap" src="https://s3.ap-south-1.amazonaws.com/shared.aashutosh.dev/eslint-rule-gif.gif">
17+
| Before | After |
18+
| :---: | :---: |
19+
| <img alt="Before" src="https://s3.ap-south-1.amazonaws.com/shared.aashutosh.dev/eslint-rule-gif.gif"> | <img alt="After" src="https://s3.ap-south-1.amazonaws.com/shared.aashutosh.dev/after-eslint.gif"> |
1820

1921
## Installation 🛠️
2022

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-nestjs-orm",
3-
"version": "0.2.3",
3+
"version": "0.2.4",
44
"description": "Guardrails to prevent bad practices or do some serious mistakes when using NestJS Moongose or ORMs.",
55
"keywords": ["eslint", "eslintplugin", "eslint-plugin", "nestjs", "mongoose"],
66
"homepage": "https://github.com/aashutoshrathi/eslint-plugin-nestjs-orm",

src/rules/mongoose-no-bad-model-injection.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ const findNodeWithDecorator = (node: any, decoratorName: string) => {
1616
return null;
1717
}
1818
return node.decorators.find(
19-
(decorator: any) => decorator.expression.callee.name === decoratorName
19+
(decorator: any) => decorator.expression.callee.name === decoratorName,
2020
);
2121
};
2222

2323
const badModelInjectionRule = (
24-
context: TSESLint.RuleContext<MessageIds, []>
24+
context: TSESLint.RuleContext<MessageIds, []>,
2525
) => {
2626
return {
2727
ClassBody(node: any) {
2828
const constructorNode = node.body.find(
2929
(bodyNode: any) =>
3030
bodyNode.type === AST_NODE_TYPES.MethodDefinition &&
31-
bodyNode.kind === "constructor"
31+
bodyNode.kind === "constructor",
3232
);
3333

3434
if (!constructorNode) {
@@ -41,7 +41,7 @@ const badModelInjectionRule = (
4141
}
4242

4343
const paramWithModelDecorator = params.find((param: any) =>
44-
findNodeWithDecorator(param, DECORATOR_NAME)
44+
findNodeWithDecorator(param, DECORATOR_NAME),
4545
);
4646

4747
if (!paramWithModelDecorator) {
@@ -64,7 +64,7 @@ const badModelInjectionRule = (
6464
}
6565

6666
if (parameter.typeAnnotation?.typeAnnotation) {
67-
const { typeName, typeArguments } =
67+
const { typeName, typeParameters } =
6868
parameter.typeAnnotation.typeAnnotation;
6969

7070
if (typeName.name !== "Model") {
@@ -74,7 +74,7 @@ const badModelInjectionRule = (
7474
});
7575
}
7676

77-
if (!typeArguments || typeArguments?.params?.length !== 1) {
77+
if (!typeParameters || typeParameters?.params?.length !== 1) {
7878
return context.report({
7979
node: paramWithModelDecorator,
8080
messageId: MessageIdsEnum.missingModelType,

src/tests/rules/mongoose-no-bad-model-injection.spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ ruleTester.run("mongoose-no-bad-model-injection", noBadModelInjectionRule, {
1616
) {}
1717
}`,
1818
},
19+
{
20+
code: `export class HahaService {
21+
constructor(
22+
@InjectModel(OA.name)
23+
private readonly aModel: Model<OADoc>,
24+
private readonly aFactory: AFactory
25+
) {}
26+
}`,
27+
},
1928
{
2029
code: `class HahaTest {
2130
constructor(

0 commit comments

Comments
 (0)