react-obsidian 2.3.0 → 2.4.0

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.
Files changed (39) hide show
  1. package/dist/src/injectors/components/InjectComponent.d.ts +3 -3
  2. package/dist/src/injectors/components/InjectComponent.d.ts.map +1 -1
  3. package/dist/src/injectors/components/InjectComponent.js +12 -1
  4. package/dist/src/injectors/components/InjectComponent.js.map +1 -1
  5. package/package.json +19 -23
  6. package/src/injectors/components/InjectComponent.ts +22 -8
  7. package/wallaby.js +1 -1
  8. package/.yarnrc +0 -1
  9. package/README.md +0 -84
  10. package/dist/eslint/undefinedDependencies/ASTFunctions.d.ts +0 -16
  11. package/dist/eslint/undefinedDependencies/ASTFunctions.d.ts.map +0 -1
  12. package/dist/eslint/undefinedDependencies/ASTFunctions.js +0 -136
  13. package/dist/eslint/undefinedDependencies/ASTFunctions.js.map +0 -1
  14. package/dist/eslint/undefinedDependencies/createFunction.d.ts +0 -6
  15. package/dist/eslint/undefinedDependencies/createFunction.d.ts.map +0 -1
  16. package/dist/eslint/undefinedDependencies/createFunction.js +0 -39
  17. package/dist/eslint/undefinedDependencies/createFunction.js.map +0 -1
  18. package/dist/eslint/undefinedDependencies/invalidGraphs.d.ts +0 -3
  19. package/dist/eslint/undefinedDependencies/invalidGraphs.d.ts.map +0 -1
  20. package/dist/eslint/undefinedDependencies/invalidGraphs.js +0 -27
  21. package/dist/eslint/undefinedDependencies/invalidGraphs.js.map +0 -1
  22. package/dist/eslint/undefinedDependencies/ruleConfiguration.d.ts +0 -3
  23. package/dist/eslint/undefinedDependencies/ruleConfiguration.d.ts.map +0 -1
  24. package/dist/eslint/undefinedDependencies/ruleConfiguration.js +0 -23
  25. package/dist/eslint/undefinedDependencies/ruleConfiguration.js.map +0 -1
  26. package/dist/eslint/undefinedDependencies/testUtils/subgraph.d.ts +0 -6
  27. package/dist/eslint/undefinedDependencies/testUtils/subgraph.d.ts.map +0 -1
  28. package/dist/eslint/undefinedDependencies/testUtils/subgraph.js +0 -38
  29. package/dist/eslint/undefinedDependencies/testUtils/subgraph.js.map +0 -1
  30. package/dist/eslint/undefinedDependencies/testUtils/validGraphs.d.ts +0 -3
  31. package/dist/eslint/undefinedDependencies/testUtils/validGraphs.d.ts.map +0 -1
  32. package/dist/eslint/undefinedDependencies/testUtils/validGraphs.js +0 -29
  33. package/dist/eslint/undefinedDependencies/testUtils/validGraphs.js.map +0 -1
  34. package/eslint/undefinedDependencies/ASTFunctions.ts +0 -115
  35. package/eslint/undefinedDependencies/createFunction.ts +0 -45
  36. package/eslint/undefinedDependencies/invalidGraphs.ts +0 -24
  37. package/eslint/undefinedDependencies/ruleConfiguration.ts +0 -24
  38. package/eslint/undefinedDependencies/testUtils/subgraph.ts +0 -15
  39. package/eslint/undefinedDependencies/testUtils/validGraphs.ts +0 -26
@@ -1,8 +1,8 @@
1
1
  import { ObjectGraph } from '../../graph/ObjectGraph';
2
2
  import { Constructable } from '../../types';
3
- interface Descriminator {
4
- obsidianDescriminator: never;
3
+ interface Discriminator {
4
+ obsidianDiscriminator: never;
5
5
  }
6
- export declare const injectComponent: <OwnProps = Descriminator, InjectedProps = Descriminator>(Target: import("react").FunctionComponent<(OwnProps extends infer P ? OwnProps extends Descriminator ? P : OwnProps : never) & (InjectedProps extends Descriminator ? any : InjectedProps)>, Graph: Constructable<ObjectGraph>) => import("react").FunctionComponent<InjectedProps extends Descriminator ? OwnProps extends Descriminator ? Partial<OwnProps> : OwnProps : OwnProps extends InjectedProps ? Partial<OwnProps> : OwnProps & Partial<InjectedProps>>;
6
+ export declare const injectComponent: <OwnProps = Discriminator, InjectedProps = Discriminator>(Target: import("react").FunctionComponent<(OwnProps extends infer P ? OwnProps extends Discriminator ? P : OwnProps : never) & (InjectedProps extends Discriminator ? any : InjectedProps)>, Graph: Constructable<ObjectGraph>) => import("react").FunctionComponent<InjectedProps extends Discriminator ? OwnProps extends Discriminator ? Partial<OwnProps> : OwnProps : OwnProps extends InjectedProps ? Partial<OwnProps> : OwnProps & Partial<InjectedProps>>;
7
7
  export {};
8
8
  //# sourceMappingURL=InjectComponent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"InjectComponent.d.ts","sourceRoot":"","sources":["../../../../src/injectors/components/InjectComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,UAAU,aAAa;IACrB,qBAAqB,EAAE,KAAK,CAAC;CAC9B;AAID,eAAO,MAAM,eAAe,gQAKnB,cAAc,WAAW,CAAC,oOAKhC,CAAC"}
1
+ {"version":3,"file":"InjectComponent.d.ts","sourceRoot":"","sources":["../../../../src/injectors/components/InjectComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,UAAU,aAAa;IACrB,qBAAqB,EAAE,KAAK,CAAC;CAC9B;AAID,eAAO,MAAM,eAAe,gQAKnB,cAAc,WAAW,CAAC,oOASlC,CAAC"}
@@ -6,6 +6,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.injectComponent = void 0;
7
7
  const ComponentInjector_1 = __importDefault(require("./ComponentInjector"));
8
8
  const componentInjector = new ComponentInjector_1.default();
9
- const injectComponent = (Target, Graph) => componentInjector.inject(Target, Graph);
9
+ const injectComponent = (Target, Graph) => {
10
+ assertGraph(Graph, Target);
11
+ return componentInjector.inject(Target, Graph);
12
+ };
10
13
  exports.injectComponent = injectComponent;
14
+ function assertGraph(Graph, Target) {
15
+ if (!Graph) {
16
+ throw new Error(`injectComponent was called with an undefined Graph.`
17
+ + `This is probably not an issue with Obsidian.`
18
+ + `It's typically caused by circular dependencies.`
19
+ + ` Check the implementation of ${Target.name}.`);
20
+ }
21
+ }
11
22
  //# sourceMappingURL=InjectComponent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"InjectComponent.js","sourceRoot":"","sources":["../../../../src/injectors/components/InjectComponent.ts"],"names":[],"mappings":";;;;;;AAEA,4EAAoD;AAMpD,MAAM,iBAAiB,GAAG,IAAI,2BAAiB,EAAE,CAAC;AAE3C,MAAM,eAAe,GAAG,CAC7B,MAGC,EACD,KAAiC,EACjC,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAIxC,CAAC;AAVS,QAAA,eAAe,mBAUxB"}
1
+ {"version":3,"file":"InjectComponent.js","sourceRoot":"","sources":["../../../../src/injectors/components/InjectComponent.ts"],"names":[],"mappings":";;;;;;AAEA,4EAAoD;AAMpD,MAAM,iBAAiB,GAAG,IAAI,2BAAiB,EAAE,CAAC;AAE3C,MAAM,eAAe,GAAG,CAC7B,MAGC,EACD,KAAiC,EACjC,EAAE;IACF,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAE3B,OAAO,iBAAiB,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAI5C,CAAC;AACJ,CAAC,CAAC;AAdW,QAAA,eAAe,mBAc1B;AACF,SAAS,WAAW,CAAC,KAA0C,EAAE,MAAW;IAC1E,IAAI,CAAC,KAAK,EAAE;QACV,MAAM,IAAI,KAAK,CACb,qDAAqD;cACnD,8CAA8C;cAC9C,iDAAiD;cACjD,gCAAgC,MAAM,CAAC,IAAI,GAAG,CACjD,CAAC;KACH;AACH,CAAC"}
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "react-obsidian",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "description": "Dependency injection framework for React and React Native applications",
5
5
  "scripts": {
6
6
  "prepack": "npm run lint && tsc --project tsconfig.prod.json",
7
7
  "lint": "npx eslint src transformers test --ignore-pattern '*.d.ts' --ext .ts,.tsx,.js",
8
- "build-local": "tsc --project tsconfig.json",
8
+ "build": "tsc --project tsconfig.json",
9
9
  "pretest": "tsc --project tsconfig.json",
10
- "test": "npx jest"
10
+ "test": "npx jest",
11
+ "test-coverage": "npx jest --coverage"
11
12
  },
12
13
  "main": "dist/src/index.js",
13
14
  "directories": {
@@ -15,7 +16,6 @@
15
16
  },
16
17
  "dependencies": {
17
18
  "hoist-non-react-statics": "3.x.x",
18
- "jest-cli": "^29.5.0",
19
19
  "reflect-metadata": "~0.1.13"
20
20
  },
21
21
  "peerDependencies": {
@@ -29,42 +29,38 @@
29
29
  "@babel/preset-env": "7.22.x",
30
30
  "@babel/preset-react": "7.22.x",
31
31
  "@babel/preset-typescript": "7.22.x",
32
- "@babel/types": "7.22.x",
33
- "@johanblumenberg/ts-mockito": "1.x.x",
32
+ "@babel/types": "7.24.x",
33
+ "@stylistic/eslint-plugin": "^1.7.0",
34
34
  "@testing-library/react": "14.x.x",
35
- "@types/eslint": "8.4.9",
36
35
  "@types/hoist-non-react-statics": "^3.3.1",
37
36
  "@types/jest": "29.5.x",
37
+ "@types/jest-when": "^3.5.5",
38
38
  "@types/lodash": "^4.14.176",
39
- "@types/react": "18.2.x",
40
- "@types/react-dom": "18.2.x",
41
- "@typescript-eslint/eslint-plugin": "6.6.x",
42
- "@typescript-eslint/parser": "6.6.x",
43
- "@typescript-eslint/types": "6.6.x",
44
- "@typescript-eslint/rule-tester": "6.6.x",
45
- "@typescript-eslint/typescript-estree": "6.6.x",
46
- "@typescript-eslint/utils": "6.6.x",
47
- "babel-eslint": "^10.1.0",
39
+ "@types/react": "18.3.x",
40
+ "@types/react-dom": "18.3.x",
41
+ "@typescript-eslint/eslint-plugin": "6.x.x",
42
+ "@typescript-eslint/parser": "6.x.x",
48
43
  "babel-plugin-parameter-decorator": "1.x.x",
49
- "class-validator": "^0.14.0",
50
- "eslint": "^8.36.0",
44
+ "cross-env": "^7.0.3",
45
+ "eslint": "8.x.x",
46
+ "eslint-config-airbnb-typescript": "17.x.x",
51
47
  "eslint-plugin-import": "^2.25.2",
52
48
  "eslint-plugin-import-newlines": "^1.1.5",
53
- "eslint-plugin-local-rules": "^1.3.2",
49
+ "eslint-plugin-jest-formatting": "^3.1.0",
50
+ "eslint-plugin-obsidian": "2.4.0",
54
51
  "eslint-plugin-react": "^7.26.1",
55
52
  "eslint-plugin-react-hooks": "^4.2.0",
56
53
  "eslint-plugin-unused-imports": "3.1.x",
57
- "husky": "8.0.1",
58
54
  "jest": "29.5.x",
59
- "jest-create-mock-instance": "2.0.0",
60
55
  "jest-environment-jsdom": "^29.5.0",
61
56
  "jest-extended": "^4.0.0",
57
+ "jest-mock-extended": "3.x.x",
58
+ "jest-when": "3.x.x",
62
59
  "lodash": "^4.17.21",
63
60
  "react": "18.2.x",
64
61
  "react-dom": "18.2.x",
65
62
  "setimmediate": "^1.0.5",
66
- "typescript": "^4.5.4",
67
- "eslint-config-airbnb-typescript": "17.x.x"
63
+ "typescript": "^4.5.4"
68
64
  },
69
65
  "repository": {
70
66
  "type": "git",
@@ -2,20 +2,34 @@ import { ObjectGraph } from '../../graph/ObjectGraph';
2
2
  import { Constructable } from '../../types';
3
3
  import ComponentInjector from './ComponentInjector';
4
4
 
5
- interface Descriminator {
6
- obsidianDescriminator: never;
5
+ interface Discriminator {
6
+ obsidianDiscriminator: never;
7
7
  }
8
8
 
9
9
  const componentInjector = new ComponentInjector();
10
10
 
11
- export const injectComponent = <OwnProps = Descriminator, InjectedProps = Descriminator> (
11
+ export const injectComponent = <OwnProps = Discriminator, InjectedProps = Discriminator> (
12
12
  Target: React.FunctionComponent<
13
- (OwnProps extends infer P ? OwnProps extends Descriminator ? P : OwnProps : never) &
14
- (InjectedProps extends Descriminator ? any : InjectedProps)
13
+ (OwnProps extends infer P ? OwnProps extends Discriminator ? P : OwnProps : never) &
14
+ (InjectedProps extends Discriminator ? any : InjectedProps)
15
15
  >,
16
16
  Graph: Constructable<ObjectGraph>,
17
- ) => componentInjector.inject(Target, Graph) as React.FunctionComponent<
18
- InjectedProps extends Descriminator ?
19
- OwnProps extends Descriminator ? Partial<OwnProps> : OwnProps :
17
+ ) => {
18
+ assertGraph(Graph, Target);
19
+
20
+ return componentInjector.inject(Target, Graph) as React.FunctionComponent<
21
+ InjectedProps extends Discriminator ?
22
+ OwnProps extends Discriminator ? Partial<OwnProps> : OwnProps :
20
23
  OwnProps extends InjectedProps ? Partial<OwnProps> : OwnProps & Partial<InjectedProps>
21
24
  >;
25
+ };
26
+ function assertGraph(Graph: Constructable<ObjectGraph<unknown>>, Target: any) {
27
+ if (!Graph) {
28
+ throw new Error(
29
+ `injectComponent was called with an undefined Graph.`
30
+ + `This is probably not an issue with Obsidian.`
31
+ + `It's typically caused by circular dependencies.`
32
+ + ` Check the implementation of ${Target.name}.`,
33
+ );
34
+ }
35
+ }
package/wallaby.js CHANGED
@@ -2,7 +2,7 @@ module.exports = () => {
2
2
  return {
3
3
  autoDetect: true,
4
4
  testFramework: {
5
- configFile: './node_modules/@wix/shono-testjs/dist/src/jestConfig.js',
5
+ configFile: 'jest.config.js',
6
6
  },
7
7
  env: {params: {env: 'NODE_OPTIONS="--max_old_space_size=4096"'}},
8
8
  };
package/.yarnrc DELETED
@@ -1 +0,0 @@
1
- --registry "https://registry.npmjs.org/"
package/README.md DELETED
@@ -1,84 +0,0 @@
1
- [![SWUbanner](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://vshymanskyy.github.io/StandWithUkraine)
2
-
3
- <p align="center">
4
- </br><img width="300px" src=".github/logo.svg"></br></br>
5
- <a href="https://npmjs.com/package/react-obsidian"><img src="https://img.shields.io/npm/v/react-obsidian.svg" alt="npm package"></a>
6
- <a href="https://www.npmjs.com/package/react-obsidian"><img src="https://img.shields.io/npm/dm/react-obsidian.svg" alt="NPM downloads"></a>
7
- <a href="https://github.com/wix-incubator/react-obsidian/actions/workflows/ci.yml"><img src="https://github.com/wix-incubator/react-obsidian/actions/workflows/ci.yml/badge.svg?branch=master" alt="build status"></a>
8
- <a href="https://discord.gg/MDH2axwaPy"><img src="https://img.shields.io/badge/chat-discord-blue?style=flat&logo=discord" alt="discord chat"></a>
9
- <h1 align="center">Obsidian</h1>
10
- </p>
11
-
12
- React Obsidian is a dependency injection framework for React and React Native applications. It allows you to inject dependencies into hooks, components, and classes. Separating the construction and consumption of dependencies is crucial to maintaining a readable and testable codebase.
13
-
14
- > 📖 Read more about Dependency Injection and Obsidian in [Breaking complexity with Dependency Injection: Introducing Obsidian](https://guyca.medium.com/breaking-complexity-with-dependency-injection-introducing-obsidian-cd452802f076) on Medium.
15
-
16
- * [Documentation](https://wix-incubator.github.io/obsidian/docs/documentation)
17
- * [Getting Started](https://wix-incubator.github.io/obsidian/docs/documentation/#the-2-steps-tutorial-for-injecting-dependencies-with-obsidian)
18
- * [Installation](https://wix-incubator.github.io/obsidian/docs/documentation/installation)
19
- * [Guides](https://wix-incubator.github.io/obsidian/docs/guides/mockDependencies)
20
- * [Chat on Discord](https://discord.gg/MDH2axwaPy)
21
-
22
- ## Example - Injecting a hook
23
- Obsidian supports injecting hooks, components and classes. The example below shows how to inject a hook.
24
-
25
- ### Step 1: Declare an object graph
26
- Before we can inject dependencies into hooks, components and classes, we first need to declare our dependencies. Dependencies are declared in classes called "Graphs" where the relationships between the dependencies are outlined.
27
-
28
- In the `ApplicationGraph` below, we declare two dependencies:
29
- 1. `httpClient`
30
- 2. `biLogger`
31
-
32
- Both functions are annotated by the `@Provides()` annotation. This signals Obsidian that the results of these functions are provided by the graph and can be injected.
33
-
34
- Notice how the `biLogger` function receives an `httpClient` as an argument. This means that `biLogger` is dependent on `httpClient`. Obsidian will create an `httpClient` when `biLogger` is injected.
35
-
36
- ``` typescript
37
- @Singleton() @Graph()
38
- class ApplicationGraph extends ObjectGraph {
39
- @Provides()
40
- httpClient(): HttpClient {
41
- return new HttpClient();
42
- }
43
-
44
- @Provides()
45
- biLogger(httpClient: HttpClient): BiLogger {
46
- return new BiLogger(httpClient);
47
- }
48
- }
49
- ```
50
-
51
- ### Step 2: Inject a dependency
52
-
53
- ```typescript
54
- type Injected = DependenciesOf<ApplicationGraph, 'biLogger'>; // { biLogger: BiLogger }
55
-
56
- interface UseButtonPress {
57
- usePress: () => void;
58
- }
59
-
60
- // We must use destructuring for Obsidian to be able to inject the dependencies
61
- const useButtonClick = ({ biLogger }: Injected): UseButtonPress => {
62
- const onClick = useCallback(() => {
63
- biLogger.logButtonClick();
64
- }, [biLogger]);
65
-
66
- return { onClick };
67
- };
68
-
69
- // Export the injected hook
70
- export default injectHook(useButtonClick, ApplicationGraph);
71
- ```
72
-
73
- ### Step 3: Use the injected hook
74
- Now that we exported the injected hook, we can use it in a component without needing to provide its dependencies manually.
75
-
76
- ```tsx
77
- const Component = () => (
78
- // No need to specify dependencies as they are injected automatically
79
- const { onClick } = useButtonClick();
80
- <>
81
- <button onclick={onClick}>Click Me</button>
82
- </>
83
- );
84
- ```
@@ -1,16 +0,0 @@
1
- import { TSESTree } from '@typescript-eslint/typescript-estree';
2
- import { TSESLint } from '@typescript-eslint/utils';
3
- export type MessageIds = 'undefinedDependency';
4
- export declare function getSubGraphs(decorators: TSESTree.Decorator[]): string[];
5
- export declare function getDependenciesFromSubgraphs(imports: TSESTree.ImportDeclaration[], subGraphs: string[], context: Readonly<TSESLint.RuleContext<MessageIds, []>>): string[];
6
- export declare function mapFunctions(node: TSESTree.ClassDeclaration): string[];
7
- export declare function checkDependencies(node: TSESTree.ClassDeclaration, existingDependencies: string[]): {
8
- value: boolean;
9
- param: string;
10
- } | {
11
- value: boolean;
12
- param?: undefined;
13
- };
14
- export declare function getDecoratorName(decorator: TSESTree.Decorator): string;
15
- export declare function getPropertyDeclarations(node: TSESTree.ClassDeclaration): string[];
16
- //# sourceMappingURL=ASTFunctions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ASTFunctions.d.ts","sourceRoot":"","sources":["../../../eslint/undefinedDependencies/ASTFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAC;AAIhE,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,MAAM,MAAM,UAAU,GAAG,qBAAqB,CAAC;AAE/C,wBAAgB,YAAY,CAAC,UAAU,EAAE,QAAQ,CAAC,SAAS,EAAE,YAkB5D;AAED,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,QAAQ,CAAC,iBAAiB,EAAE,EACrC,SAAS,EAAC,MAAM,EAAE,EAClB,OAAO,EAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,YAqCvD;AACD,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,CAAC,gBAAgB,YAc3D;AACD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,QAAQ,CAAC,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,EAAE;;;;;;EAmBhG;AACD,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,QAAQ,CAAC,SAAS,UAE7D;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAC,QAAQ,CAAC,gBAAgB,YAMrE"}
@@ -1,136 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getPropertyDeclarations = exports.getDecoratorName = exports.checkDependencies = exports.mapFunctions = exports.getDependenciesFromSubgraphs = exports.getSubGraphs = void 0;
27
- const typescript_estree_1 = require("@typescript-eslint/typescript-estree");
28
- const fs = __importStar(require("fs"));
29
- const parser_1 = require("@typescript-eslint/parser");
30
- const path = require("path");
31
- function getSubGraphs(decorators) {
32
- const args = decorators[0].expression.arguments;
33
- if (args) {
34
- for (let i = 0; i < args.length; i++) {
35
- if (args[i].type === typescript_estree_1.TSESTree.AST_NODE_TYPES.ObjectExpression) {
36
- const { properties } = args[i];
37
- if (properties) {
38
- for (let j = 0; j < properties.length; j++) {
39
- if (properties[j].key.name === 'subgraphs') {
40
- return properties[j].value
41
- .elements.map((subGraph) => subGraph.name);
42
- }
43
- }
44
- }
45
- }
46
- }
47
- }
48
- return [];
49
- }
50
- exports.getSubGraphs = getSubGraphs;
51
- function getDependenciesFromSubgraphs(imports, subGraphs, context) {
52
- const paths = [];
53
- const dependencies = [];
54
- imports.forEach((el) => {
55
- el.specifiers.forEach((specifier) => {
56
- if (subGraphs.includes(specifier.local.name)) {
57
- paths.push({ path: el.source.value, import: specifier.local.name });
58
- }
59
- });
60
- });
61
- paths.forEach((el) => {
62
- const filePath = path.join(path.dirname(context.getFilename()), `${el['path']}.ts`);
63
- const fileContent = fs.readFileSync(filePath, 'utf8');
64
- const fileAST = (0, parser_1.parse)(fileContent, {
65
- ecmaVersion: 9,
66
- ecmaFeatures: {
67
- globalReturn: false,
68
- jsx: true,
69
- },
70
- sourceType: 'module',
71
- comment: true,
72
- attachComment: true,
73
- tokens: true,
74
- loc: true,
75
- range: true,
76
- filePath,
77
- });
78
- dependencies.push(...mapFunctions(fileAST.body[fileAST.body.length - 1]
79
- .declaration));
80
- });
81
- return dependencies;
82
- }
83
- exports.getDependenciesFromSubgraphs = getDependenciesFromSubgraphs;
84
- function mapFunctions(node) {
85
- const { body } = node.body;
86
- const existingDependencies = [];
87
- body.forEach((el) => {
88
- var _a;
89
- if (el.type === typescript_estree_1.TSESTree.AST_NODE_TYPES.MethodDefinition) {
90
- const decorators = (_a = (el)) === null || _a === void 0 ? void 0 : _a.decorators;
91
- if (decorators) {
92
- if (decorators.map((decorator) => getDecoratorName(decorator)).includes('Provides')) {
93
- existingDependencies.push(el.key.name);
94
- }
95
- }
96
- }
97
- });
98
- return existingDependencies;
99
- }
100
- exports.mapFunctions = mapFunctions;
101
- function checkDependencies(node, existingDependencies) {
102
- var _a, _b;
103
- const body = (_a = node === null || node === void 0 ? void 0 : node.body) === null || _a === void 0 ? void 0 : _a.body;
104
- for (let j = 0; j < body.length; j++) {
105
- if (body[j].type === typescript_estree_1.TSESTree.AST_NODE_TYPES.MethodDefinition
106
- && body[j].key.name !== 'constructor') {
107
- const params = (_b = body[j].value) === null || _b === void 0 ? void 0 : _b.params;
108
- if (params) {
109
- for (let i = 0; i < params.length; i++) {
110
- if (!existingDependencies.includes(params[i].name)) {
111
- return {
112
- value: false,
113
- param: params[i].name,
114
- };
115
- }
116
- }
117
- }
118
- }
119
- }
120
- return { value: true };
121
- }
122
- exports.checkDependencies = checkDependencies;
123
- function getDecoratorName(decorator) {
124
- var _a, _b;
125
- return (_b = (_a = decorator === null || decorator === void 0 ? void 0 : decorator.expression) === null || _a === void 0 ? void 0 : _a.callee) === null || _b === void 0 ? void 0 : _b.name;
126
- }
127
- exports.getDecoratorName = getDecoratorName;
128
- function getPropertyDeclarations(node) {
129
- const classBody = node.body.body;
130
- const properties = classBody.map((method) => {
131
- return method.key.name;
132
- });
133
- return properties;
134
- }
135
- exports.getPropertyDeclarations = getPropertyDeclarations;
136
- //# sourceMappingURL=ASTFunctions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ASTFunctions.js","sourceRoot":"","sources":["../../../eslint/undefinedDependencies/ASTFunctions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;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Z,KAAK,EAAG,MAAM,CAAC,CAAC,CAAyB,CAAC,IAAI;yBAC/C,CAAC;qBACH;iBACF;aACF;SACF;KACF;IACD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACzB,CAAC;AAnBD,8CAmBC;AACD,SAAgB,gBAAgB,CAAC,SAA6B;;IAC5D,OAAO,MAAC,MAAC,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,UAAsC,0CAAE,MAA8B,0CAAE,IAAI,CAAC;AACnG,CAAC;AAFD,4CAEC;AAED,SAAgB,uBAAuB,CAAC,IAA8B;IACpE,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IACjC,MAAM,UAAU,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;QAC1C,OAAS,MAAoE,CAAC,GAA2B,CAAC,IAAI,CAAC;IACjH,CAAC,CAAC,CAAC;IACH,OAAO,UAAU,CAAC;AACpB,CAAC;AAND,0DAMC"}
@@ -1,6 +0,0 @@
1
- import { TSESTree } from '@typescript-eslint/typescript-estree';
2
- export declare function create(context: any): {
3
- ImportDeclaration(node: TSESTree.ImportDeclaration): void;
4
- ClassDeclaration(node: TSESTree.ClassDeclaration): void;
5
- };
6
- //# sourceMappingURL=createFunction.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createFunction.d.ts","sourceRoot":"","sources":["../../../eslint/undefinedDependencies/createFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAC;AAWhE,wBAAgB,MAAM,CAAC,OAAO,EAAE,GAAG;4BAKR,SAAS,iBAAiB;2BAG3B,SAAS,gBAAgB;EAyBlD"}
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.create = void 0;
4
- const ASTFunctions_1 = require("./ASTFunctions");
5
- function create(context) {
6
- const imports = [];
7
- const dependencies = [];
8
- return {
9
- ImportDeclaration(node) {
10
- imports.push(node);
11
- },
12
- ClassDeclaration(node) {
13
- const { decorators } = node;
14
- if (decorators) {
15
- const decoratorNames = decorators.map((decorator) => (0, ASTFunctions_1.getDecoratorName)(decorator));
16
- if (decoratorNames.includes('Graph')) {
17
- const subGraphs = (0, ASTFunctions_1.getSubGraphs)(decorators);
18
- if (subGraphs.length > 0) {
19
- dependencies.push(...(0, ASTFunctions_1.getDependenciesFromSubgraphs)(imports, subGraphs, context));
20
- }
21
- dependencies.push(...(0, ASTFunctions_1.mapFunctions)(node));
22
- dependencies.push(...(0, ASTFunctions_1.getPropertyDeclarations)(node));
23
- const check = (0, ASTFunctions_1.checkDependencies)(node, dependencies);
24
- if (!(check === null || check === void 0 ? void 0 : check.value)) {
25
- context.report({
26
- node,
27
- messageId: 'undefinedDependency',
28
- data: {
29
- dependencyName: check.param,
30
- },
31
- });
32
- }
33
- }
34
- }
35
- },
36
- };
37
- }
38
- exports.create = create;
39
- //# sourceMappingURL=createFunction.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createFunction.js","sourceRoot":"","sources":["../../../eslint/undefinedDependencies/createFunction.ts"],"names":[],"mappings":";;;AAEA,iDAOwB;AAExB,SAAgB,MAAM,CAAC,OAAY;IACjC,MAAM,OAAO,GAAgC,EAAE,CAAC;IAChD,MAAM,YAAY,GAAY,EAAE,CAAC;IAEjC,OAAO;QACL,iBAAiB,CAAC,IAA+B;YAC/C,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC;QACD,gBAAgB,CAAC,IAA8B;YAC7C,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;YAC5B,IAAI,UAAU,EAAE;gBACd,MAAM,cAAc,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,IAAA,+BAAgB,EAAC,SAAS,CAAC,CAAC,CAAC;gBAClF,IAAI,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;oBACpC,MAAM,SAAS,GAAG,IAAA,2BAAY,EAAC,UAAU,CAAC,CAAC;oBAC3C,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE;wBACxB,YAAY,CAAC,IAAI,CAAC,GAAG,IAAA,2CAA4B,EAAC,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;qBACjF;oBACD,YAAY,CAAC,IAAI,CAAC,GAAG,IAAA,2BAAY,EAAC,IAAI,CAAC,CAAC,CAAC;oBACzC,YAAY,CAAC,IAAI,CAAC,GAAG,IAAA,sCAAuB,EAAC,IAAI,CAAC,CAAC,CAAC;oBACpD,MAAM,KAAK,GAAG,IAAA,gCAAiB,EAAC,IAAI,EAAE,YAAY,CAAC,CAAC;oBACpD,IAAI,CAAC,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,CAAA,EAAE;wBACjB,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI;4BACJ,SAAS,EAAE,qBAAqB;4BAChC,IAAI,EAAE;gCACJ,cAAc,EAAE,KAAK,CAAC,KAAK;6BAC5B;yBACF,CAAC,CAAC;qBACJ;iBACF;aACF;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAjCD,wBAiCC"}
@@ -1,3 +0,0 @@
1
- export declare const invalidGraph = "import { Graph, ObjectGraph, Provides } from 'src';\n\n@Graph()\nexport default class SimpleGraph extends ObjectGraph {\n @Provides()\n instanceId(id:string): string {\n return id;\n }\n}";
2
- export declare const invalidGraphWithSubgraph = "import {\n Graph,\n ObjectGraph,\n Provides,\n} from 'src';\nimport Subgraph from './subgraph';\n\n@Graph({ subgraphs: [Subgraph] })\nexport default class SimpleGraphWithSubgraph extends ObjectGraph {\n @Provides()\n someClass(wrongDep:string): string {\n return wrongDep;\n }\n}";
3
- //# sourceMappingURL=invalidGraphs.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"invalidGraphs.d.ts","sourceRoot":"","sources":["../../../eslint/undefinedDependencies/invalidGraphs.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,sMAQvB,CAAC;AAEH,eAAO,MAAM,wBAAwB,sSAanC,CAAC"}
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.invalidGraphWithSubgraph = exports.invalidGraph = void 0;
4
- exports.invalidGraph = `import { Graph, ObjectGraph, Provides } from 'src';
5
-
6
- @Graph()
7
- export default class SimpleGraph extends ObjectGraph {
8
- @Provides()
9
- instanceId(id:string): string {
10
- return id;
11
- }
12
- }`;
13
- exports.invalidGraphWithSubgraph = `import {
14
- Graph,
15
- ObjectGraph,
16
- Provides,
17
- } from 'src';
18
- import Subgraph from './subgraph';
19
-
20
- @Graph({ subgraphs: [Subgraph] })
21
- export default class SimpleGraphWithSubgraph extends ObjectGraph {
22
- @Provides()
23
- someClass(wrongDep:string): string {
24
- return wrongDep;
25
- }
26
- }`;
27
- //# sourceMappingURL=invalidGraphs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"invalidGraphs.js","sourceRoot":"","sources":["../../../eslint/undefinedDependencies/invalidGraphs.ts"],"names":[],"mappings":";;;AAAa,QAAA,YAAY,GAAG;;;;;;;;EAQ1B,CAAC;AAEU,QAAA,wBAAwB,GAAG;;;;;;;;;;;;;EAatC,CAAC"}
@@ -1,3 +0,0 @@
1
- import { RuleModule } from '@typescript-eslint/utils/ts-eslint';
2
- export declare const undefinedDependencies: RuleModule<'undefinedDependency'>;
3
- //# sourceMappingURL=ruleConfiguration.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ruleConfiguration.d.ts","sourceRoot":"","sources":["../../../eslint/undefinedDependencies/ruleConfiguration.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAOhE,eAAO,MAAM,qBAAqB,EAAE,UAAU,CAAC,qBAAqB,CAelE,CAAC"}
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.undefinedDependencies = void 0;
4
- const utils_1 = require("@typescript-eslint/utils");
5
- const createFunction_1 = require("./createFunction");
6
- const createRule = utils_1.ESLintUtils.RuleCreator((name) => `https://example.com/rule/${name}`);
7
- exports.undefinedDependencies = createRule({
8
- create: createFunction_1.create,
9
- name: 'undefined-dependency',
10
- meta: {
11
- docs: {
12
- description: 'The dependency must be defined',
13
- recommended: 'strict',
14
- },
15
- messages: {
16
- undefinedDependency: 'Dependency {{ dependencyName }} is undefined',
17
- },
18
- schema: [],
19
- type: 'problem',
20
- },
21
- defaultOptions: [],
22
- });
23
- //# sourceMappingURL=ruleConfiguration.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ruleConfiguration.js","sourceRoot":"","sources":["../../../eslint/undefinedDependencies/ruleConfiguration.ts"],"names":[],"mappings":";;;AAAA,oDAAuD;AAEvD,qDAA0C;AAE1C,MAAM,UAAU,GAAG,mBAAW,CAAC,WAAW,CACxC,CAAC,IAAI,EAAE,EAAE,CAAC,4BAA4B,IAAI,EAAE,CAC7C,CAAC;AAEW,QAAA,qBAAqB,GAAsC,UAAU,CAAC;IACjF,MAAM,EAAN,uBAAM;IACN,IAAI,EAAE,sBAAsB;IAC5B,IAAI,EAAE;QACJ,IAAI,EAAE;YACJ,WAAW,EAAE,gCAAgC;YAC7C,WAAW,EAAE,QAAQ;SACtB;QACD,QAAQ,EAAE;YACR,mBAAmB,EAAE,8CAA8C;SACpE;QACD,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,SAAS;KAChB;IACD,cAAc,EAAE,EAAQ;CACzB,CAAC,CAAC"}
@@ -1,6 +0,0 @@
1
- import { ObjectGraph } from 'src';
2
- export default class Subgraph extends ObjectGraph {
3
- unusedDependency(): string;
4
- instanceId(): string;
5
- }
6
- //# sourceMappingURL=subgraph.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"subgraph.d.ts","sourceRoot":"","sources":["../../../../eslint/undefinedDependencies/testUtils/subgraph.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,WAAW,EAAY,MAAM,KAAK,CAAC;AAGnD,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,WAAW;IAE/C,gBAAgB,IAAI,MAAM;IAK1B,UAAU,IAAI,MAAM;CAGrB"}
@@ -1,38 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const lodash_1 = require("lodash");
13
- const src_1 = require("src");
14
- let Subgraph = class Subgraph extends src_1.ObjectGraph {
15
- unusedDependency() {
16
- throw Error('This dependency should not have been resolved since it is not required by anyone.');
17
- }
18
- instanceId() {
19
- return (0, lodash_1.uniqueId)('graph');
20
- }
21
- };
22
- __decorate([
23
- (0, src_1.Provides)(),
24
- __metadata("design:type", Function),
25
- __metadata("design:paramtypes", []),
26
- __metadata("design:returntype", String)
27
- ], Subgraph.prototype, "unusedDependency", null);
28
- __decorate([
29
- (0, src_1.Provides)(),
30
- __metadata("design:type", Function),
31
- __metadata("design:paramtypes", []),
32
- __metadata("design:returntype", String)
33
- ], Subgraph.prototype, "instanceId", null);
34
- Subgraph = __decorate([
35
- (0, src_1.Graph)()
36
- ], Subgraph);
37
- exports.default = Subgraph;
38
- //# sourceMappingURL=subgraph.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"subgraph.js","sourceRoot":"","sources":["../../../../eslint/undefinedDependencies/testUtils/subgraph.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,mCAAkC;AAClC,6BAAmD;AAGpC,IAAM,QAAQ,GAAd,MAAM,QAAS,SAAQ,iBAAW;IAE/C,gBAAgB;QACd,MAAM,KAAK,CAAC,mFAAmF,CAAC,CAAC;IACnG,CAAC;IAGD,UAAU;QACR,OAAO,IAAA,iBAAQ,EAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;CACF,CAAA;AATC;IAAC,IAAA,cAAQ,GAAE;;;;gDAGV;AAED;IAAC,IAAA,cAAQ,GAAE;;;;0CAGV;AATkB,QAAQ;IAD5B,IAAA,WAAK,GAAE;GACa,QAAQ,CAU5B;kBAVoB,QAAQ"}
@@ -1,3 +0,0 @@
1
- export declare const validGraphSimple = "import { uniqueId } from 'lodash';\nimport { Graph, ObjectGraph, Provides } from 'src';\n\n@Graph()\nexport default class SimpleGraph extends ObjectGraph {\n @Provides()\n instanceId(): string {\n return 'graph';\n }\n}";
2
- export declare const validGraphWithSubgraph = "import {\n Graph,\n ObjectGraph,\n Provides,\n} from 'src';\nimport Subgraph from './subgraph';\n\n\n@Graph({ subgraphs: [Subgraph] })\nexport default class SimpleGraphWithSubgraph extends ObjectGraph {\n @Provides()\n someClass(instanceId:string): string {\n return instanceId;\n }\n}";
3
- //# sourceMappingURL=validGraphs.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validGraphs.d.ts","sourceRoot":"","sources":["../../../../eslint/undefinedDependencies/testUtils/validGraphs.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,sOAS3B,CAAC;AAEH,eAAO,MAAM,sBAAsB,4SAcjC,CAAC"}
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validGraphWithSubgraph = exports.validGraphSimple = void 0;
4
- exports.validGraphSimple = `import { uniqueId } from 'lodash';
5
- import { Graph, ObjectGraph, Provides } from 'src';
6
-
7
- @Graph()
8
- export default class SimpleGraph extends ObjectGraph {
9
- @Provides()
10
- instanceId(): string {
11
- return 'graph';
12
- }
13
- }`;
14
- exports.validGraphWithSubgraph = `import {
15
- Graph,
16
- ObjectGraph,
17
- Provides,
18
- } from 'src';
19
- import Subgraph from './subgraph';
20
-
21
-
22
- @Graph({ subgraphs: [Subgraph] })
23
- export default class SimpleGraphWithSubgraph extends ObjectGraph {
24
- @Provides()
25
- someClass(instanceId:string): string {
26
- return instanceId;
27
- }
28
- }`;
29
- //# sourceMappingURL=validGraphs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validGraphs.js","sourceRoot":"","sources":["../../../../eslint/undefinedDependencies/testUtils/validGraphs.ts"],"names":[],"mappings":";;;AAAa,QAAA,gBAAgB,GAAG;;;;;;;;;EAS9B,CAAC;AAEU,QAAA,sBAAsB,GAAG;;;;;;;;;;;;;;EAcpC,CAAC"}
@@ -1,115 +0,0 @@
1
- import { TSESTree } from '@typescript-eslint/typescript-estree';
2
- import * as fs from 'fs';
3
- import { parse } from '@typescript-eslint/parser';
4
- import path= require('path') ;
5
- import { TSESLint } from '@typescript-eslint/utils';
6
-
7
- export type MessageIds = 'undefinedDependency';
8
-
9
- export function getSubGraphs(decorators: TSESTree.Decorator[]) {
10
- const args = (decorators[0].expression as TSESTree.CallExpression).arguments;
11
- if (args) {
12
- for (let i = 0; i < args.length; i++) {
13
- if (args[i].type === TSESTree.AST_NODE_TYPES.ObjectExpression) {
14
- const { properties } = (args[i] as TSESTree.ObjectExpression);
15
- if (properties) {
16
- for (let j = 0; j < properties.length; j++) {
17
- if (((properties[j] as TSESTree.Property).key as TSESTree.Identifier).name === 'subgraphs') {
18
- return ((properties[j] as TSESTree.Property).value as TSESTree.ArrayExpression)
19
- .elements.map((subGraph) => (subGraph as TSESTree.Identifier).name);
20
- }
21
- }
22
- }
23
- }
24
- }
25
- }
26
- return [];
27
- }
28
-
29
- export function getDependenciesFromSubgraphs(
30
- imports: TSESTree.ImportDeclaration[],
31
- subGraphs:string[],
32
- context:Readonly<TSESLint.RuleContext<MessageIds, []>>,
33
- ) {
34
- const paths:Record<string, string>[] = [];
35
- const dependencies: string[] = [];
36
- imports.forEach((el) => {
37
- el.specifiers.forEach((specifier) => {
38
- if (subGraphs.includes(specifier.local.name)) {
39
- paths.push({ path: el.source.value, import: specifier.local.name });
40
- }
41
- });
42
- });
43
- paths.forEach((el) => {
44
- const filePath = path.join(path.dirname(context.getFilename()), `${el['path']}.ts`);
45
- const fileContent = fs.readFileSync(filePath, 'utf8');
46
- const fileAST = parse(
47
- fileContent,
48
- {
49
- ecmaVersion: 9,
50
- ecmaFeatures: {
51
- globalReturn: false,
52
- jsx: true,
53
- },
54
- sourceType: 'module',
55
- comment: true,
56
- attachComment: true,
57
- tokens: true,
58
- loc: true,
59
- range: true,
60
- filePath,
61
- },
62
- );
63
- dependencies.push(...mapFunctions(
64
- (fileAST.body[fileAST.body.length - 1] as TSESTree.ExportDefaultDeclaration)
65
- .declaration as TSESTree.ClassDeclaration,
66
- ));
67
- });
68
- return dependencies;
69
- }
70
- export function mapFunctions(node: TSESTree.ClassDeclaration) {
71
- const { body } = node.body;
72
- const existingDependencies: string[] = [];
73
- body.forEach((el) => {
74
- if (el.type === TSESTree.AST_NODE_TYPES.MethodDefinition) {
75
- const decorators = (el)?.decorators;
76
- if (decorators) {
77
- if (decorators.map((decorator) => getDecoratorName(decorator)).includes('Provides')) {
78
- existingDependencies.push(((el as TSESTree.MethodDefinition).key as TSESTree.Identifier).name);
79
- }
80
- }
81
- }
82
- });
83
- return existingDependencies;
84
- }
85
- export function checkDependencies(node: TSESTree.ClassDeclaration, existingDependencies: string[]) {
86
- const body = node?.body?.body;
87
- for (let j = 0; j < body.length; j++) {
88
- if (body[j].type === TSESTree.AST_NODE_TYPES.MethodDefinition
89
- && ((body[j] as TSESTree.MethodDefinition).key as TSESTree.Identifier).name !== 'constructor') {
90
- const params = (body[j] as TSESTree.MethodDefinition).value?.params;
91
- if (params) {
92
- for (let i = 0; i < params.length; i++) {
93
- if (!existingDependencies.includes((params[i] as TSESTree.Identifier).name)) {
94
- return {
95
- value: false,
96
- param: (params[i] as TSESTree.Identifier).name,
97
- };
98
- }
99
- }
100
- }
101
- }
102
- }
103
- return { value: true };
104
- }
105
- export function getDecoratorName(decorator: TSESTree.Decorator) {
106
- return ((decorator?.expression as TSESTree.CallExpression)?.callee as TSESTree.Identifier)?.name;
107
- }
108
-
109
- export function getPropertyDeclarations(node:TSESTree.ClassDeclaration) {
110
- const classBody = node.body.body;
111
- const properties = classBody.map((method) => {
112
- return ((method as (TSESTree.PropertyDefinition | TSESTree.MethodDefinition)).key as TSESTree.Identifier).name;
113
- });
114
- return properties;
115
- }
@@ -1,45 +0,0 @@
1
- import { TSESTree } from '@typescript-eslint/typescript-estree';
2
-
3
- import {
4
- getSubGraphs,
5
- getDependenciesFromSubgraphs,
6
- mapFunctions,
7
- checkDependencies,
8
- getDecoratorName,
9
- getPropertyDeclarations,
10
- } from './ASTFunctions';
11
-
12
- export function create(context: any) {
13
- const imports:TSESTree.ImportDeclaration[] = [];
14
- const dependencies:string[] = [];
15
-
16
- return {
17
- ImportDeclaration(node:TSESTree.ImportDeclaration) {
18
- imports.push(node);
19
- },
20
- ClassDeclaration(node:TSESTree.ClassDeclaration) {
21
- const { decorators } = node;
22
- if (decorators) {
23
- const decoratorNames = decorators.map((decorator) => getDecoratorName(decorator));
24
- if (decoratorNames.includes('Graph')) {
25
- const subGraphs = getSubGraphs(decorators);
26
- if (subGraphs.length > 0) {
27
- dependencies.push(...getDependenciesFromSubgraphs(imports, subGraphs, context));
28
- }
29
- dependencies.push(...mapFunctions(node));
30
- dependencies.push(...getPropertyDeclarations(node));
31
- const check = checkDependencies(node, dependencies);
32
- if (!check?.value) {
33
- context.report({
34
- node,
35
- messageId: 'undefinedDependency',
36
- data: {
37
- dependencyName: check.param,
38
- },
39
- });
40
- }
41
- }
42
- }
43
- },
44
- };
45
- }
@@ -1,24 +0,0 @@
1
- export const invalidGraph = `import { Graph, ObjectGraph, Provides } from 'src';
2
-
3
- @Graph()
4
- export default class SimpleGraph extends ObjectGraph {
5
- @Provides()
6
- instanceId(id:string): string {
7
- return id;
8
- }
9
- }`;
10
-
11
- export const invalidGraphWithSubgraph = `import {
12
- Graph,
13
- ObjectGraph,
14
- Provides,
15
- } from 'src';
16
- import Subgraph from './subgraph';
17
-
18
- @Graph({ subgraphs: [Subgraph] })
19
- export default class SimpleGraphWithSubgraph extends ObjectGraph {
20
- @Provides()
21
- someClass(wrongDep:string): string {
22
- return wrongDep;
23
- }
24
- }`;
@@ -1,24 +0,0 @@
1
- import { ESLintUtils } from '@typescript-eslint/utils';
2
- import { RuleModule } from '@typescript-eslint/utils/ts-eslint';
3
- import { create } from './createFunction';
4
-
5
- const createRule = ESLintUtils.RuleCreator(
6
- (name) => `https://example.com/rule/${name}`,
7
- );
8
-
9
- export const undefinedDependencies: RuleModule<'undefinedDependency'> = createRule({
10
- create,
11
- name: 'undefined-dependency',
12
- meta: {
13
- docs: {
14
- description: 'The dependency must be defined',
15
- recommended: 'strict',
16
- },
17
- messages: {
18
- undefinedDependency: 'Dependency {{ dependencyName }} is undefined',
19
- },
20
- schema: [],
21
- type: 'problem',
22
- },
23
- defaultOptions: [] as [],
24
- });
@@ -1,15 +0,0 @@
1
- import { uniqueId } from 'lodash';
2
- import { Graph, ObjectGraph, Provides } from 'src';
3
-
4
- @Graph()
5
- export default class Subgraph extends ObjectGraph {
6
- @Provides()
7
- unusedDependency(): string {
8
- throw Error('This dependency should not have been resolved since it is not required by anyone.');
9
- }
10
-
11
- @Provides()
12
- instanceId(): string {
13
- return uniqueId('graph');
14
- }
15
- }
@@ -1,26 +0,0 @@
1
- export const validGraphSimple = `import { uniqueId } from 'lodash';
2
- import { Graph, ObjectGraph, Provides } from 'src';
3
-
4
- @Graph()
5
- export default class SimpleGraph extends ObjectGraph {
6
- @Provides()
7
- instanceId(): string {
8
- return 'graph';
9
- }
10
- }`;
11
-
12
- export const validGraphWithSubgraph = `import {
13
- Graph,
14
- ObjectGraph,
15
- Provides,
16
- } from 'src';
17
- import Subgraph from './subgraph';
18
-
19
-
20
- @Graph({ subgraphs: [Subgraph] })
21
- export default class SimpleGraphWithSubgraph extends ObjectGraph {
22
- @Provides()
23
- someClass(instanceId:string): string {
24
- return instanceId;
25
- }
26
- }`;