'use strict';
import { createEslintRule } from '@flint/infra/create-eslint-rule';
import { isObjectPattern, isVariableDeclaration, isCallLikeExpression, isAwaitExpression } from '@flint/infra/analysis';
import { astStructuralKeys, eslintProperties } from '@flint/infra/constants/rules-meta';

var __defProp=Object['defineProperty'],__name=(_0x90f907,_0x306155)=>__defProp(_0x90f907,'name',{'value':_0x306155,'configurable':!![]});const ruleName='no-useless-destructing';const ruleContent='\x0a###\x20**Must**\x20avoid\x20useless\x20destructuring.\x0a\x0a####\x20Wrong\x0a\x0aconst\x20{\x20bar\x20}\x20=\x20foo;\x0aqux(bar);\x0a\x0aconst\x20{\x20baz,\x20bar\x20}\x20=\x20foo;\x0aqux(bar);\x0aqux(baz);\x0a\x0aconst\x20{\x20baz,\x20bar\x20}\x20=\x20await\x20foo;\x0aqux(bar);\x0aqux(baz);\x0a\x0a####\x20Correct\x0a\x0aconst\x20{\x20bar\x20}\x20=\x20foo();\x0aqux(bar);\x0a\x0aqux(foo.bar);\x0aqux(foo.baz);\x0a\x0aconst\x20{\x20baz,\x20bar\x20}\x20=\x20foo();\x0aqux(bar);\x0aqux(baz);\x0a\x0aconst\x20waldo\x20=\x20foo();\x0aqux(waldo.bar);\x0aqux(waldo.baz);\x0a\x0a####\x20Why\x0a\x0aUseless\x20destructuring\x20makes\x20code\x20harder\x20to\x20read\x20and\x20adds\x20unnecessary\x20complexity.';var noUselessDestructing = createEslintRule(ruleName,ruleContent,_0x1f33a1=>{return {'VariableDeclarator'(_0x5cc178){if(!isObjectPattern(_0x5cc178['id'])||!_0x5cc178['init'])return;reportIfDisallowedSource(_0x5cc178['id'],_0x1f33a1,_0x5cc178['init']);},'AssignmentExpression'(_0x5e5b5f){if(!isObjectPattern(_0x5e5b5f['left']))return;reportIfDisallowedSource(_0x5e5b5f['left'],_0x1f33a1,_0x5e5b5f['right']);},'CatchClause'(_0x1e654d){if(!_0x1e654d['param']||!isObjectPattern(_0x1e654d['param']))return;reportIfDisallowedSource(_0x1e654d['param'],_0x1f33a1);},'ForOfStatement'(_0x552c2e){handleLoopStatement(_0x552c2e,_0x1f33a1);},'ForInStatement'(_0x1bd0fd){handleLoopStatement(_0x1bd0fd,_0x1f33a1);}};},{'dynamicMessage':'Useless\x20destructuring\x20\x27{{code}}\x27\x20used.'});function reportIfDisallowedSource(_0x3299c9,_0x5a3bc4,_0x40e005){if(!hasAtLeastOneDestructuredProperty(_0x3299c9['properties']))return;if(!isDisallowedDestructingSource(_0x40e005))return;_0x5a3bc4['report']({'node':_0x3299c9,'messageId':ruleName,'data':{'code':_0x5a3bc4['sourceCode']['getText'](_0x3299c9)}});}__name(reportIfDisallowedSource,'reportIfDisallowedSource');function getObjectPatternFromLoopLeft(_0x51224c){if(isObjectPattern(_0x51224c))return _0x51224c;if(isVariableDeclaration(_0x51224c)){const [_0x10e5a4]=_0x51224c['declarations'];if(_0x10e5a4&&isObjectPattern(_0x10e5a4['id']))return _0x10e5a4['id'];}return void(-0x997+0x1492*0x1+-0xafb);}__name(getObjectPatternFromLoopLeft,'getObjectPatternFromLoopLeft');function handleLoopStatement(_0x459dfa,_0x274d6b){const _0x307b60=getObjectPatternFromLoopLeft(_0x459dfa['left']);if(!_0x307b60)return;reportIfDisallowedSource(_0x307b60,_0x274d6b,_0x459dfa['right']);}__name(handleLoopStatement,'handleLoopStatement');function hasAtLeastOneDestructuredProperty(_0x52611a){return _0x52611a['some'](_0x3a125b=>astStructuralKeys['key']in _0x3a125b&&eslintProperties['value']in _0x3a125b);}__name(hasAtLeastOneDestructuredProperty,'hasAtLeastOneDestructuredProperty');function isDisallowedDestructingSource(_0x3d12d7){if(!_0x3d12d7)return !![];return !(isCallLikeExpression(_0x3d12d7)||isAwaitOfCallExpression(_0x3d12d7));}__name(isDisallowedDestructingSource,'isDisallowedDestructingSource');function isAwaitOfCallExpression(_0x15360c){return isAwaitExpression(_0x15360c)&&isCallLikeExpression(_0x15360c['argument']);}__name(isAwaitOfCallExpression,'isAwaitOfCallExpression');

export { noUselessDestructing as default, ruleName };
