'use strict';
import { createEslintRule } from '@flint/infra/create-eslint-rule';
import { nodeTypes, hasArrayReturn, collectBareReturns } from '@flint/infra/analysis';
import { eslintFixTypeNames } from '../../../base-repo/constants/internal-common-strings.js';

var __defProp=Object['defineProperty'],__name=(_0x2fd742,_0x23a9a8)=>__defProp(_0x2fd742,'name',{'value':_0x23a9a8,'configurable':!![]});const ruleName='must-return-empty-array';const anyFunctionSelector=[nodeTypes['functionDeclaration'],nodeTypes['functionExpression'],nodeTypes['arrowFunctionExpression']]['join'](',\x20'),ruleContent='\x0a###\x20**Must**\x20return\x20an\x20empty\x20array\x20instead\x20of\x20`undefined`\x20in\x20functions\x20that\x20return\x20arrays.\x0a\x0a####\x20Wrong\x0a\x0afunction\x20getFoos(bar?:\x20string)\x20{\x0a\x20\x20\x20\x20if\x20(!bar)\x20return;\x0a\x0a\x20\x20\x20\x20return\x20[bar];\x0a}\x0a\x0a####\x20Correct\x0a\x0afunction\x20getFoos(bar?:\x20string)\x20{\x0a\x20\x20\x20\x20if\x20(!bar)\x20return\x20[];\x0a\x0a\x20\x20\x20\x20return\x20[bar];\x0a}\x0a\x0a####\x20Why\x0a\x0aReturning\x20an\x20empty\x20array\x20ensures\x20consistent\x20behavior\x20and\x20avoids\x20the\x20need\x20to\x20check\x20for\x20undefined,\x20improving\x20readability\x20and\x20reducing\x20potential\x20errors.',skippedReturnTypeNames=['TSESTree.ArrayExpression','TSESTree.ObjectPattern'];var mustReturnEmptyArray = createEslintRule(ruleName,ruleContent,__name(function create(_0x2c44ef){return {[anyFunctionSelector](_0x237cf3){const _0x368ee6=getFunctionBodyStatements(_0x237cf3),_0x1f8797=_0x237cf3['returnType']?.['typeAnnotation'];let _0x312aaf=!![];_0x1f8797&&shouldSkipReturnTypeText(_0x2c44ef['sourceCode']['getText'](_0x1f8797))&&(_0x312aaf=![]);if(!_0x368ee6)return;if(_0x312aaf&&hasArrayReturn(_0x237cf3)){const _0x514b47=collectBareReturns(_0x368ee6);for(const _0x3e4032 of _0x514b47){_0x2c44ef['report']({'node':_0x3e4032,'messageId':ruleName,'fix'(_0x1e2f70){return _0x1e2f70['replaceText'](_0x3e4032,'return\x20[];');}});}}}};},'create'),{'fixable':eslintFixTypeNames['code']});function getFunctionBodyStatements(_0x1d0048){if(_0x1d0048['body']?.['type']!==nodeTypes['blockStatement'])return void(0x4ad+-0x176+-0x337);return _0x1d0048['body']['body'];}__name(getFunctionBodyStatements,'getFunctionBodyStatements');function shouldSkipReturnTypeText(_0x177af4){return skippedReturnTypeNames['some'](_0x2836a4=>_0x177af4['includes'](_0x2836a4));}__name(shouldSkipReturnTypeText,'shouldSkipReturnTypeText');

export { mustReturnEmptyArray as default, ruleName };
