eslint-plugin-zod-to-openapi
Advanced tools
Comparing version 0.0.19 to 0.0.20
@@ -10,2 +10,10 @@ "use strict"; | ||
const traverse_1 = require("./traverse"); | ||
const getPropType = (checker, nodeType, property) => { | ||
const prop = nodeType.getProperty(property); | ||
if (!prop) { | ||
return; | ||
} | ||
const propSymbol = checker.getTypeOfSymbolAtLocation(prop, prop.valueDeclaration); | ||
return checker.typeToString(propSymbol); | ||
}; | ||
const getType = (node, context) => { | ||
@@ -18,9 +26,21 @@ // 1. Grab the TypeScript program from parser services | ||
const nodeType = checker.getTypeAtLocation(originalNode); | ||
if (!nodeType.symbol) { | ||
const defType = getPropType(checker, nodeType, '_def'); | ||
if (!defType) { | ||
return; | ||
} | ||
const type = checker.typeToString(checker.getTypeOfSymbolAtLocation(nodeType.symbol, nodeType.symbol.valueDeclaration)); | ||
const name = nodeType.symbol.getName(); | ||
const maybeUnwrapType = getPropType(checker, nodeType, 'unwrap'); | ||
const unwrapType = maybeUnwrapType?.startsWith('() => ') | ||
? maybeUnwrapType.slice(6) | ||
: undefined; | ||
const symbol = nodeType.getSymbol(); | ||
if (!symbol) { | ||
return; | ||
} | ||
const constructorType = checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration); | ||
const type = checker.typeToString(constructorType); | ||
const name = symbol.getName(); | ||
return { | ||
name: nodeType.symbol.getName(), | ||
defType, | ||
unwrapType, | ||
name, | ||
type, | ||
@@ -33,3 +53,3 @@ isZodType: name.includes('Zod'), | ||
'ZodRecord', | ||
].includes(name), | ||
].includes(unwrapType ?? name), | ||
}; | ||
@@ -36,0 +56,0 @@ }; |
import { TSESLint, TSESTree } from '@typescript-eslint/utils'; | ||
declare const getType: <T extends TSESTree.Node>(node: T, context: Readonly<TSESLint.RuleContext<any, any>>) => { | ||
defType: string; | ||
unwrapType: string | undefined; | ||
name: string; | ||
@@ -4,0 +6,0 @@ type: string; |
{ | ||
"name": "eslint-plugin-zod-to-openapi", | ||
"version": "0.0.19", | ||
"version": "0.0.20", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "Eslint rules for zod-to-openapi", |
Sorry, the diff of this file is not supported yet
58955
789