'use strict';
import { ESLintUtils } from '@typescript-eslint/utils';
import { nodeTypes, isPseudoEnumType } from '@flint/infra/analysis';
import { ruleTypes, url } from '@flint/infra/constants/rules-meta';

const ruleName='must-not-use-negation-with-enums';const constants={'messageIds':{'mustNotUseNegationWithEnums':'mustNotUseNegationWithEnums'},'meta':{'type':ruleTypes['problem'],'docs':{'description':'Must\x20not\x20use\x20the\x20!\x20operator\x20with\x20enum\x20types,\x20including\x20as\x20const\x20enum-like\x20objects.'},'messages':{'mustNotUseNegationWithEnums':'must-not-use-negation-with-enums\x0a###\x20**Must\x20not**\x20use\x20the\x20\x27!\x27\x20operator\x20with\x20enum\x20types.\x0a\x0aAvoid\x20using\x20the\x20logical\x20negation\x20operator\x20`!`\x20on\x20pseudo-enum\x20objects.\x20This\x20can\x20lead\x20to\x20misleading\x20or\x20incorrect\x20logic\x20since\x20pseudo-enums\x20are\x20not\x20booleans.\x0a\x0a####\x20Wrong\x0a\x0aconst\x20Status\x20=\x20{\x0a\x20\x20Active:\x201,\x0a\x20\x20Inactive:\x200,\x0a}\x20as\x20const;\x0a\x0aif\x20(!Status.Active)\x20{\x0a\x20\x20//\x20This\x20condition\x20will\x20never\x20trigger\x20as\x201\x20is\x20truthy.\x0a}\x0a\x0a####\x20Correct\x0a\x0aconst\x20Status\x20=\x20{\x0a\x20\x20Active:\x201,\x0a\x20\x20Inactive:\x200,\x0a}\x20as\x20const;\x0a\x0aconst\x20isActive\x20=\x20user.status\x20===\x20Status.Active;\x0aif\x20(!isActive)\x20{\x0a\x20\x20//\x20Now\x20this\x20makes\x20sense.\x0a}\x0a\x0a####\x20Why\x0a\x0aNegating\x20pseudo-enums\x20like\x20!Status.Active\x20coerces\x20numbers\x20to\x20booleans,\x20which\x20is\x20usually\x20not\x20intended.'},'schema':[]}},createRule=ESLintUtils['RuleCreator'](_0x1e074d=>''+url+_0x1e074d),mustNotUseNegationWithEnums=createRule({'name':ruleName,'meta':constants['meta'],'defaultOptions':[],'create'(_0x2bf5b2){const _0x187a0f=_0x2bf5b2['sourceCode']['parserServices'];if(!_0x187a0f?.['program']||!_0x187a0f['esTreeNodeToTSNodeMap'])return {};const _0x5b393c=_0x187a0f['program']['getTypeChecker'](),_0x4039d5=_0x187a0f['esTreeNodeToTSNodeMap'];return {'UnaryExpression'(_0x1a60a6){if(_0x1a60a6['operator']!=='!')return;const _0x47aafc=_0x4039d5['get'](_0x1a60a6['argument']);if(!_0x47aafc)return;if(_0x1a60a6['argument']['type']===nodeTypes['memberExpression']&&_0x1a60a6['argument']['property']['type']===nodeTypes['identifier']){const _0x58dc29=_0x4039d5['get'](_0x1a60a6['argument']['object']);if(_0x58dc29){const _0x271330=_0x5b393c['getTypeAtLocation'](_0x58dc29);if(isPseudoEnumType(_0x271330,_0x5b393c)){_0x2bf5b2['report']({'node':_0x1a60a6,'messageId':constants['messageIds']['mustNotUseNegationWithEnums']});return;}}}const _0x58bd59=_0x5b393c['getTypeAtLocation'](_0x47aafc);isPseudoEnumType(_0x58bd59,_0x5b393c)&&_0x2bf5b2['report']({'node':_0x1a60a6,'messageId':constants['messageIds']['mustNotUseNegationWithEnums']});}};}});

export { mustNotUseNegationWithEnums as default, ruleName };
