'use strict';
import { ESLintUtils } from '@typescript-eslint/utils';
import { nodeTypes } from '@flint/infra/analysis';
import { ruleRecommendationLevels, ruleTypes, url } from '@flint/infra/constants/rules-meta';
import { jsBasicTypes } from '../../../base-repo/constants/basic-types.js';
import { eslintFixTypeNames } from '../../../base-repo/constants/internal-common-strings.js';

const ruleName='must-not-use-null';const constants={'undefinedKeyword':jsBasicTypes['undefined'],'unionTypeSeparator':'\x20|\x20','messageIds':{'mustNotUseNull':'mustNotUseNull'},'meta':{'type':ruleTypes['problem'],'docs':{'description':'Disallow\x20use\x20of\x20`null`\x20and\x20`|\x20null`\x20in\x20TypeScript\x20types.\x20Prefer\x20`undefined`\x20and\x20optional\x20properties.','recommended':ruleRecommendationLevels['error']},'messages':{'mustNotUseNull':'must-not-use-null\x0a{{message}}\x0a\x0a###\x20**Must\x20not**\x20use\x20\x22null\x22.\x0a\x0a####\x20Wrong\x0a\x0aif\x20(!data)\x20{\x0a\x20\x20result\x20=\x20null;\x0a\x0ainterface\x20Props\x20{\x0a\x20\x20\x20\x20foo:\x20string\x20|\x20null;\x0a}\x0a\x0a####\x20Correct\x0a\x0aif\x20(!data)\x20{\x0a\x20\x20result\x20=\x20undefined;\x0a\x0ainterface\x20Props\x20{\x0a\x20\x20\x20\x20foo?:\x20string;\x0a}\x0a\x0a####\x20Why\x0a\x0aOptional\x20operator\x20\x22?\x22\x20only\x20uses\x20undefined\x20as\x20a\x20fallback,\x20if\x20the\x20value\x20isn’t\x20provided.\x20For\x20null\x20you\x20should\x20explicitly\x20set\x20null\x20as\x20a\x20value,\x20so\x20it\x20should\x20be\x20avoided.'},'schema':[],'fixable':eslintFixTypeNames['code']}},createRule=ESLintUtils['RuleCreator'](_0x29420f=>''+url+_0x29420f),mustNotUseNull=createRule({'name':ruleName,'meta':constants['meta'],'defaultOptions':[],'create'(_0xeb7c77){return {'Literal'(_0x35dbd7){_0x35dbd7['value']===null&&_0xeb7c77['report']({'node':_0x35dbd7,'messageId':constants['messageIds']['mustNotUseNull'],'data':{'message':'Using\x20`null`\x20literal\x20is\x20not\x20allowed.\x20Use\x20`undefined`\x20instead.'},'fix'(_0x1bf1df){return _0x1bf1df['replaceText'](_0x35dbd7,constants['undefinedKeyword']);}});},'TSNullKeyword'(_0x8e5298){const _0x13606b=_0xeb7c77['sourceCode'],_0x389928=_0x8e5298['parent'];_0xeb7c77['report']({'node':_0x8e5298,'messageId':constants['messageIds']['mustNotUseNull'],'data':{'message':'Using\x20`|\x20null`\x20in\x20types\x20is\x20not\x20allowed.\x20Use\x20optional\x20property\x20`?`\x20instead.'},'fix'(_0x5b60ae){if(_0x389928?.['type']===nodeTypes['TSUnionType']){const _0x45dab6=_0x389928['types'],_0x7cda4a=_0x45dab6['some'](_0x2d4689=>_0x2d4689['type']===nodeTypes['TSUndefinedKeyword']);if(_0x7cda4a){const _0x2a9d01=_0x45dab6['filter'](_0xf6f0a2=>_0xf6f0a2!==_0x8e5298),_0x541d42=_0x2a9d01['map'](_0x14f0fe=>_0x13606b['getText'](_0x14f0fe));return _0x5b60ae['replaceText'](_0x389928,_0x541d42['join']('\x20|\x20'));}}return _0x5b60ae['replaceText'](_0x8e5298,constants['undefinedKeyword']);}});}};}});

export { mustNotUseNull as default, ruleName };
