UNPKG

eslint-plugin-type-graphql

Version:
41 lines 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const createRule_1 = require("../util/createRule"); const experimental_utils_1 = require("@typescript-eslint/experimental-utils"); const typeGraphQLUtil_1 = require("../util/typeGraphQLUtil"); exports.default = createRule_1.createRule({ name: 'prefer-null-over-undefined', meta: { docs: { description: 'Warns when undefined is used in a type that is decorated with a TypeGraphQL decorator', category: 'Best Practices', recommended: 'warn', requiresTypeChecking: true, }, messages: { preferNullOverUndefined: 'Prefer null over undefined in types that are exposed in the GraphQL schema', }, schema: [], type: 'problem', }, defaultOptions: [], create(context) { const parserServices = experimental_utils_1.ESLintUtils.getParserServices(context); const checker = parserServices.program.getTypeChecker(); return typeGraphQLUtil_1.getTypeGraphQLVisitors(checker, parserServices, ({ decoratorProps, decoratedProps }) => { var _a; // Check whether the decorated type is known and valid if (!((_a = decoratedProps.type) === null || _a === void 0 ? void 0 : _a.isValid)) { return; } if (decoratedProps.type.isUndefinable || decoratedProps.type.isArrayUndefinable) { // This type uses undefined context.report({ node: decoratorProps.node, messageId: 'preferNullOverUndefined', }); } }); }, }); //# sourceMappingURL=prefer-null-over-undefined.js.map