eslint-plugin-obsidian 2.5.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 (30) hide show
  1. package/LICENSE +7 -0
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +9 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/unresolvedProviderDependencies/ASTFunctions.d.ts +16 -0
  7. package/dist/unresolvedProviderDependencies/ASTFunctions.d.ts.map +1 -0
  8. package/dist/unresolvedProviderDependencies/ASTFunctions.js +137 -0
  9. package/dist/unresolvedProviderDependencies/ASTFunctions.js.map +1 -0
  10. package/dist/unresolvedProviderDependencies/createFunction.d.ts +7 -0
  11. package/dist/unresolvedProviderDependencies/createFunction.d.ts.map +1 -0
  12. package/dist/unresolvedProviderDependencies/createFunction.js +39 -0
  13. package/dist/unresolvedProviderDependencies/createFunction.js.map +1 -0
  14. package/dist/unresolvedProviderDependencies/index.d.ts +5 -0
  15. package/dist/unresolvedProviderDependencies/index.d.ts.map +1 -0
  16. package/dist/unresolvedProviderDependencies/index.js +23 -0
  17. package/dist/unresolvedProviderDependencies/index.js.map +1 -0
  18. package/dist/unresolvedProviderDependencies/invalidGraphs.d.ts +3 -0
  19. package/dist/unresolvedProviderDependencies/invalidGraphs.d.ts.map +1 -0
  20. package/dist/unresolvedProviderDependencies/invalidGraphs.js +27 -0
  21. package/dist/unresolvedProviderDependencies/invalidGraphs.js.map +1 -0
  22. package/dist/unresolvedProviderDependencies/testUtils/subgraph.d.ts +6 -0
  23. package/dist/unresolvedProviderDependencies/testUtils/subgraph.d.ts.map +1 -0
  24. package/dist/unresolvedProviderDependencies/testUtils/subgraph.js +38 -0
  25. package/dist/unresolvedProviderDependencies/testUtils/subgraph.js.map +1 -0
  26. package/dist/unresolvedProviderDependencies/testUtils/validGraphs.d.ts +3 -0
  27. package/dist/unresolvedProviderDependencies/testUtils/validGraphs.d.ts.map +1 -0
  28. package/dist/unresolvedProviderDependencies/testUtils/validGraphs.js +29 -0
  29. package/dist/unresolvedProviderDependencies/testUtils/validGraphs.js.map +1 -0
  30. package/package.json +63 -0
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2021 by Guy Carmeli
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../rules/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const { unresolvedProviderDependencies } = require('./unresolvedProviderDependencies');
4
+ module.exports = {
5
+ rules: {
6
+ 'unresolved-provider-dependencies': unresolvedProviderDependencies,
7
+ },
8
+ };
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../rules/index.ts"],"names":[],"mappings":";;AAAA,MAAM,EAAE,8BAA8B,EAAE,GAAG,OAAO,CAAC,kCAAkC,CAAC,CAAC;AAEvF,MAAM,CAAC,OAAO,GAAG;IACf,KAAK,EAAE;QACL,kCAAkC,EAAE,8BAA8B;KACnE;CACF,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { TSESTree } from '@typescript-eslint/types';
2
+ import type { RuleContext } from '@typescript-eslint/utils/ts-eslint';
3
+ export type MessageIds = 'unresolved-provider-dependencies';
4
+ export declare function getSubGraphs(decorators: TSESTree.Decorator[]): string[];
5
+ export declare function getDependenciesFromSubgraphs(imports: TSESTree.ImportDeclaration[], subGraphs: string[], context: RuleContext<'unresolved-provider-dependencies', []>): 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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ASTFunctions.d.ts","sourceRoot":"","sources":["../../rules/unresolvedProviderDependencies/ASTFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAIpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAEtE,MAAM,MAAM,UAAU,GAAG,kCAAkC,CAAC;AAE5D,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,WAAW,CAAC,kCAAkC,EAAE,EAAE,CAAC,YAsC5D;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"}
@@ -0,0 +1,137 @@
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 types_1 = require("@typescript-eslint/types");
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 === types_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
+ // eslint-disable-next-line dot-notation
63
+ const filePath = path.join(path.dirname(context.getFilename()), `${el['path']}.ts`);
64
+ const fileContent = fs.readFileSync(filePath, 'utf8');
65
+ const fileAST = (0, parser_1.parse)(fileContent, {
66
+ ecmaVersion: 9,
67
+ ecmaFeatures: {
68
+ globalReturn: false,
69
+ jsx: true,
70
+ },
71
+ sourceType: 'module',
72
+ comment: true,
73
+ attachComment: true,
74
+ tokens: true,
75
+ loc: true,
76
+ range: true,
77
+ filePath,
78
+ });
79
+ dependencies.push(...mapFunctions(fileAST.body[fileAST.body.length - 1]
80
+ .declaration));
81
+ });
82
+ return dependencies;
83
+ }
84
+ exports.getDependenciesFromSubgraphs = getDependenciesFromSubgraphs;
85
+ function mapFunctions(node) {
86
+ const { body } = node.body;
87
+ const existingDependencies = [];
88
+ body.forEach((el) => {
89
+ var _a;
90
+ if (el.type === types_1.TSESTree.AST_NODE_TYPES.MethodDefinition) {
91
+ const decorators = (_a = (el)) === null || _a === void 0 ? void 0 : _a.decorators;
92
+ if (decorators) {
93
+ if (decorators.map((decorator) => getDecoratorName(decorator)).includes('Provides')) {
94
+ existingDependencies.push(el.key.name);
95
+ }
96
+ }
97
+ }
98
+ });
99
+ return existingDependencies;
100
+ }
101
+ exports.mapFunctions = mapFunctions;
102
+ function checkDependencies(node, existingDependencies) {
103
+ var _a, _b;
104
+ const body = (_a = node === null || node === void 0 ? void 0 : node.body) === null || _a === void 0 ? void 0 : _a.body;
105
+ for (let j = 0; j < body.length; j++) {
106
+ if (body[j].type === types_1.TSESTree.AST_NODE_TYPES.MethodDefinition
107
+ && body[j].key.name !== 'constructor') {
108
+ const params = (_b = body[j].value) === null || _b === void 0 ? void 0 : _b.params;
109
+ if (params) {
110
+ for (let i = 0; i < params.length; i++) {
111
+ if (!existingDependencies.includes(params[i].name)) {
112
+ return {
113
+ value: false,
114
+ param: params[i].name,
115
+ };
116
+ }
117
+ }
118
+ }
119
+ }
120
+ }
121
+ return { value: true };
122
+ }
123
+ exports.checkDependencies = checkDependencies;
124
+ function getDecoratorName(decorator) {
125
+ var _a, _b;
126
+ 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;
127
+ }
128
+ exports.getDecoratorName = getDecoratorName;
129
+ function getPropertyDeclarations(node) {
130
+ const classBody = node.body.body;
131
+ const properties = classBody.map((method) => {
132
+ return method.key.name;
133
+ });
134
+ return properties;
135
+ }
136
+ exports.getPropertyDeclarations = getPropertyDeclarations;
137
+ //# sourceMappingURL=ASTFunctions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ASTFunctions.js","sourceRoot":"","sources":["../../rules/unresolvedProviderDependencies/ASTFunctions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAoD;AACpD,uCAAyB;AACzB,sDAAkD;AAClD,6BAA+B;AAK/B,SAAgB,YAAY,CAAC,UAAgC;IAC3D,MAAM,IAAI,GAAI,UAAU,CAAC,CAAC,CAAC,CAAC,UAAsC,CAAC,SAAS,CAAC;IAC7E,IAAI,IAAI,EAAE;QACR,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,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AAsC,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,MAAW,EAAE,EAAE;QAC/C,OAAS,MAAoE,CAAC,GAA2B,CAAC,IAAI,CAAC;IACjH,CAAC,CAAC,CAAC;IACH,OAAO,UAAU,CAAC;AACpB,CAAC;AAND,0DAMC"}
@@ -0,0 +1,7 @@
1
+ import type { RuleContext } from '@typescript-eslint/utils/ts-eslint';
2
+ import type { TSESTree } from '@typescript-eslint/types';
3
+ export declare function create(context: RuleContext<'unresolved-provider-dependencies', []>): {
4
+ ImportDeclaration(node: TSESTree.ImportDeclaration): void;
5
+ ClassDeclaration(node: TSESTree.ClassDeclaration): void;
6
+ };
7
+ //# sourceMappingURL=createFunction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createFunction.d.ts","sourceRoot":"","sources":["../../rules/unresolvedProviderDependencies/createFunction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAUzD,wBAAgB,MAAM,CAAC,OAAO,EAAE,WAAW,CAAC,kCAAkC,EAAE,EAAE,CAAC;4BAKvD,SAAS,iBAAiB;2BAG3B,SAAS,gBAAgB;EAyBnD"}
@@ -0,0 +1,39 @@
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: 'unresolved-provider-dependencies',
28
+ data: {
29
+ dependencyName: check.param,
30
+ },
31
+ });
32
+ }
33
+ }
34
+ }
35
+ },
36
+ };
37
+ }
38
+ exports.create = create;
39
+ //# sourceMappingURL=createFunction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createFunction.js","sourceRoot":"","sources":["../../rules/unresolvedProviderDependencies/createFunction.ts"],"names":[],"mappings":";;;AAEA,iDAOwB;AAExB,SAAgB,MAAM,CAAC,OAA4D;IACjF,MAAM,OAAO,GAAgC,EAAE,CAAC;IAChD,MAAM,YAAY,GAAY,EAAE,CAAC;IAEjC,OAAO;QACL,iBAAiB,CAAC,IAAgC;YAChD,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC;QACD,gBAAgB,CAAC,IAA+B;YAC9C,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;YAC5B,IAAI,UAAU,EAAE;gBACd,MAAM,cAAc,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,SAA6B,EAAE,EAAE,CAAC,IAAA,+BAAgB,EAAC,SAAS,CAAC,CAAC,CAAC;gBACtG,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,kCAAkC;4BAC7C,IAAI,EAAE;gCACJ,cAAc,EAAE,KAAK,CAAC,KAAK;6BAC5B;yBACF,CAAC,CAAC;qBACJ;iBACF;aACF;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAjCD,wBAiCC"}
@@ -0,0 +1,5 @@
1
+ import { type TSESLint } from '@typescript-eslint/utils';
2
+ type Rule = TSESLint.RuleModule<'unresolved-provider-dependencies', []>;
3
+ export declare const unresolvedProviderDependencies: Rule;
4
+ export {};
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../rules/unresolvedProviderDependencies/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAOtE,KAAK,IAAI,GAAG,QAAQ,CAAC,UAAU,CAAC,kCAAkC,EAAE,EAAE,CAAC,CAAC;AAGxE,eAAO,MAAM,8BAA8B,EAAE,IAe3C,CAAC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unresolvedProviderDependencies = 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://wix-incubator.github.io/obsidian/docs/documentation/meta/eslint#${name}`);
7
+ exports.unresolvedProviderDependencies = createRule({
8
+ create: createFunction_1.create,
9
+ name: 'unresolved-provider-dependencies',
10
+ meta: {
11
+ docs: {
12
+ description: 'Dependencies must be defined in the graph or its subgraphs.',
13
+ recommended: 'strict',
14
+ },
15
+ messages: {
16
+ 'unresolved-provider-dependencies': 'Dependency {{ dependencyName }} is unresolved.',
17
+ },
18
+ schema: [],
19
+ type: 'problem',
20
+ },
21
+ defaultOptions: [],
22
+ });
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../rules/unresolvedProviderDependencies/index.ts"],"names":[],"mappings":";;;AAAA,oDAAsE;AACtE,qDAA0C;AAE1C,MAAM,UAAU,GAAG,mBAAW,CAAC,WAAW,CACxC,CAAC,IAAI,EAAE,EAAE,CAAC,2EAA2E,IAAI,EAAE,CAC5F,CAAC;AAKW,QAAA,8BAA8B,GAAS,UAAU,CAAC;IAC7D,MAAM,EAAN,uBAAM;IACN,IAAI,EAAE,kCAAkC;IACxC,IAAI,EAAE;QACJ,IAAI,EAAE;YACJ,WAAW,EAAE,6DAA6D;YAC1E,WAAW,EAAE,QAAQ;SACtB;QACD,QAAQ,EAAE;YACR,kCAAkC,EAAE,gDAAgD;SACrF;QACD,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,SAAS;KAChB;IACD,cAAc,EAAE,EAAE;CACnB,CAAC,CAAC"}
@@ -0,0 +1,3 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invalidGraphs.d.ts","sourceRoot":"","sources":["../../rules/unresolvedProviderDependencies/invalidGraphs.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,sMAQvB,CAAC;AAEH,eAAO,MAAM,wBAAwB,sSAanC,CAAC"}
@@ -0,0 +1,27 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invalidGraphs.js","sourceRoot":"","sources":["../../rules/unresolvedProviderDependencies/invalidGraphs.ts"],"names":[],"mappings":";;;AAAa,QAAA,YAAY,GAAG;;;;;;;;EAQ1B,CAAC;AAEU,QAAA,wBAAwB,GAAG;;;;;;;;;;;;;EAatC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { ObjectGraph } from 'react-obsidian';
2
+ export default class Subgraph extends ObjectGraph {
3
+ unusedDependency(): string;
4
+ instanceId(): string;
5
+ }
6
+ //# sourceMappingURL=subgraph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subgraph.d.ts","sourceRoot":"","sources":["../../../rules/unresolvedProviderDependencies/testUtils/subgraph.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,WAAW,EAAY,MAAM,gBAAgB,CAAC;AAG9D,MAAM,CAAC,OAAO,OAAO,QAAS,SAAQ,WAAW;IAE/C,gBAAgB,IAAI,MAAM;IAK1B,UAAU,IAAI,MAAM;CAGrB"}
@@ -0,0 +1,38 @@
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 react_obsidian_1 = require("react-obsidian");
14
+ let Subgraph = class Subgraph extends react_obsidian_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, react_obsidian_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, react_obsidian_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, react_obsidian_1.Graph)()
36
+ ], Subgraph);
37
+ exports.default = Subgraph;
38
+ //# sourceMappingURL=subgraph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subgraph.js","sourceRoot":"","sources":["../../../rules/unresolvedProviderDependencies/testUtils/subgraph.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,mCAAkC;AAClC,mDAA8D;AAG/C,IAAM,QAAQ,GAAd,MAAM,QAAS,SAAQ,4BAAW;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,yBAAQ,GAAE;;;;gDAGV;AAED;IAAC,IAAA,yBAAQ,GAAE;;;;0CAGV;AATkB,QAAQ;IAD5B,IAAA,sBAAK,GAAE;GACa,QAAQ,CAU5B;kBAVoB,QAAQ"}
@@ -0,0 +1,3 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validGraphs.d.ts","sourceRoot":"","sources":["../../../rules/unresolvedProviderDependencies/testUtils/validGraphs.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,sOAS3B,CAAC;AAEH,eAAO,MAAM,sBAAsB,4SAcjC,CAAC"}
@@ -0,0 +1,29 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validGraphs.js","sourceRoot":"","sources":["../../../rules/unresolvedProviderDependencies/testUtils/validGraphs.ts"],"names":[],"mappings":";;;AAAa,QAAA,gBAAgB,GAAG;;;;;;;;;EAS9B,CAAC;AAEU,QAAA,sBAAsB,GAAG;;;;;;;;;;;;;;EAcpC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "eslint-plugin-obsidian",
3
+ "description": "ESLint rules for Obsidian",
4
+ "main": "dist/index.js",
5
+ "version": "2.5.0",
6
+ "scripts": {
7
+ "build": "npx tsc",
8
+ "test": "npx jest",
9
+ "lint": "eslint rules --ignore-pattern '*.d.ts' --ext .ts,.tsx,.js"
10
+ },
11
+ "author": "Orly Dadashev",
12
+ "files": [
13
+ "dist",
14
+ "package.json",
15
+ "LICENSE"
16
+ ],
17
+ "peerDependencies": {
18
+ "eslint": "8.x.x"
19
+ },
20
+ "dependencies": {
21
+ "@typescript-eslint/parser": "6.6.x",
22
+ "@typescript-eslint/utils": "6.6.x",
23
+ "lodash": "^4.17.21"
24
+ },
25
+ "devDependencies": {
26
+ "@babel/core": "7.22.x",
27
+ "@babel/eslint-parser": "7.22.x",
28
+ "@babel/plugin-proposal-decorators": "7.22.x",
29
+ "@babel/plugin-transform-class-properties": "7.22.x",
30
+ "@babel/preset-env": "7.22.x",
31
+ "@babel/preset-react": "7.22.x",
32
+ "@babel/preset-typescript": "7.22.x",
33
+ "@babel/types": "7.24.x",
34
+ "@eslint/eslintrc": "^3.0.2",
35
+ "@eslint/js": "8.x.x",
36
+ "@stylistic/eslint-plugin": "^1.7.0",
37
+ "@types/eslint": "8.4.9",
38
+ "@types/node": "18.x.x",
39
+ "@typescript-eslint/eslint-plugin": "6.6.x",
40
+ "@typescript-eslint/rule-tester": "6.6.x",
41
+ "@typescript-eslint/types": "6.6.x",
42
+ "@typescript-eslint/typescript-estree": "6.6.x",
43
+ "cross-env": "^7.0.3",
44
+ "eslint": "8.x.x",
45
+ "eslint-plugin-import": "^2.25.2",
46
+ "eslint-plugin-import-newlines": "^1.1.5",
47
+ "eslint-plugin-jest-formatting": "^3.1.0",
48
+ "eslint-plugin-unused-imports": "3.1.x",
49
+ "jest": "29.5.x",
50
+ "jest-extended": "^4.0.0",
51
+ "react-obsidian": "2.x.x",
52
+ "typescript": "^4.5.4"
53
+ },
54
+ "keywords": [
55
+ "react-obsidian",
56
+ "dependency-injection",
57
+ "ioc",
58
+ "eslint",
59
+ "eslintplugin",
60
+ "eslint-plugin"
61
+ ],
62
+ "license": "ISC"
63
+ }