@daldalso/eslint-plugin 1.2.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.
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useTypeChecker = useTypeChecker;
4
+ exports.getTSTypeByNode = getTSTypeByNode;
5
+ exports.getTSSymbolByNode = getTSSymbolByNode;
6
+ exports.getTSTypeBySymbol = getTSTypeBySymbol;
7
+ exports.typeToString = typeToString;
8
+ exports.getFunctionParameters = getFunctionParameters;
9
+ exports.getFunctionReturnType = getFunctionReturnType;
10
+ exports.getObjectProperties = getObjectProperties;
11
+ exports.isDOMReturningFunction = isDOMReturningFunction;
12
+ exports.isRestParameter = isRestParameter;
13
+ var utils_1 = require("@typescript-eslint/utils");
14
+ function useTypeChecker(context) {
15
+ context.settings.service = utils_1.ESLintUtils.getParserServices(context);
16
+ context.settings.typeChecker = context.settings.service.program.getTypeChecker();
17
+ return { service: context.settings.service, typeChecker: context.settings.typeChecker };
18
+ }
19
+ function getTSTypeByNode(context, target) {
20
+ var _a = context.settings, service = _a.service, typeChecker = _a.typeChecker;
21
+ var tsNode = service.esTreeNodeToTSNodeMap.get(target);
22
+ var type = typeChecker.getTypeAtLocation(tsNode);
23
+ return type;
24
+ }
25
+ function getTSSymbolByNode(context, target) {
26
+ var _a = context.settings, service = _a.service, typeChecker = _a.typeChecker;
27
+ var tsNode = service.esTreeNodeToTSNodeMap.get(target);
28
+ var symbol = typeChecker.getSymbolAtLocation(tsNode);
29
+ return symbol;
30
+ }
31
+ function getTSTypeBySymbol(context, target, location) {
32
+ var _a = context.settings, service = _a.service, typeChecker = _a.typeChecker;
33
+ var tsNode = service.esTreeNodeToTSNodeMap.get(location);
34
+ var type = typeChecker.getTypeOfSymbolAtLocation(target, tsNode);
35
+ if (type['intrinsicName'] === "error") {
36
+ throw Error("Unexpected intrinsicName from the target: ".concat(target.name));
37
+ }
38
+ return type;
39
+ }
40
+ function typeToString(context, type) {
41
+ return context.settings.typeChecker.typeToString(type);
42
+ }
43
+ function getFunctionParameters(context, callLikeExpression) {
44
+ var _a = context.settings, service = _a.service, typeChecker = _a.typeChecker;
45
+ var tsNode = service.esTreeNodeToTSNodeMap.get(callLikeExpression);
46
+ var signature = typeChecker.getResolvedSignature(tsNode);
47
+ if (!signature)
48
+ return null;
49
+ return signature.parameters;
50
+ }
51
+ function getFunctionReturnType(context, declaration) {
52
+ var _a;
53
+ var _b = context.settings, service = _b.service, typeChecker = _b.typeChecker;
54
+ var tsNode = service.esTreeNodeToTSNodeMap.get(declaration);
55
+ var signature = typeChecker.getSignatureFromDeclaration(tsNode);
56
+ if (!signature) {
57
+ throw Error("No signature available from the declaration: ".concat((_a = declaration.id) === null || _a === void 0 ? void 0 : _a.name));
58
+ }
59
+ return typeChecker.getReturnTypeOfSignature(signature);
60
+ }
61
+ function getObjectProperties(context, node) {
62
+ return getTSTypeByNode(context, node).getProperties();
63
+ }
64
+ function isDOMReturningFunction(context, type, domTypePatterns) {
65
+ var callSignatures = type.getCallSignatures();
66
+ if (!callSignatures.length)
67
+ return false;
68
+ var returnType = context.settings.typeChecker.getReturnTypeOfSignature(callSignatures[0]).getNonNullableType();
69
+ var actualReturnTypes = returnType.isUnion() ? returnType.types : [returnType];
70
+ return actualReturnTypes.some(function (v) {
71
+ var returnTypeSymbol = v.getSymbol();
72
+ if (!returnTypeSymbol)
73
+ return false;
74
+ var returnTypeName = context.settings.typeChecker.getFullyQualifiedName(returnTypeSymbol);
75
+ return domTypePatterns.some(function (w) { return w.test(returnTypeName); });
76
+ });
77
+ }
78
+ function isRestParameter(context, symbol) {
79
+ var typeChecker = context.settings.typeChecker;
80
+ var parameterDeclaration = typeChecker.symbolToParameterDeclaration(symbol, undefined, undefined);
81
+ return Boolean(parameterDeclaration === null || parameterDeclaration === void 0 ? void 0 : parameterDeclaration.dotDotDotToken);
82
+ }
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@daldalso/eslint-plugin",
3
+ "version": "1.2.0",
4
+ "main": "./dist/index.js",
5
+ "repository": {
6
+ "url": "git+https://github.com/JJoriping/eslint-plugin.git"
7
+ },
8
+ "author": "JJoriping <op@jjo.kr>",
9
+ "license": "MIT",
10
+ "scripts": {
11
+ "build": "tsc -b",
12
+ "watch": "tsc --watch",
13
+ "test": "eslint --parser-options={\"project\":\"./test.tsconfig.json\"}"
14
+ },
15
+ "files": [
16
+ "/LICENSE",
17
+ "/README.md",
18
+ "/dist/"
19
+ ],
20
+ "devDependencies": {
21
+ "@daldalso/eslint-plugin": "link:.",
22
+ "@types/node": "^18.0.0",
23
+ "@types/react": "^18.0.0",
24
+ "eslint": "^8.0.0"
25
+ },
26
+ "dependencies": {
27
+ "@typescript-eslint/types": "^5.40.0",
28
+ "@typescript-eslint/eslint-plugin": "^5",
29
+ "@typescript-eslint/parser": "^5",
30
+ "@typescript-eslint/utils": "^5",
31
+ "eslint-plugin-import": "^2",
32
+ "eslint-plugin-react": "^7",
33
+ "eslint-plugin-react-hooks": "^4",
34
+ "eslint-plugin-unicorn": "*",
35
+ "typescript": "^5"
36
+ },
37
+ "peerDependencies": {
38
+ "eslint": "^8"
39
+ }
40
+ }