'use strict';
import { createEslintRule } from '@flint/infra/create-eslint-rule';
import { isNameMatch, isMemberExpression, nodeTypes } from '@flint/infra/analysis';
import { mutationActionNames } from '../../../base-repo/constants/internal-common-strings.js';
import { files } from '../../../base-repo/app-constants/project-paths.js';
import { flintRuleIdentifiers } from '@flint/infra/constants/shared-string-identifiers';

var __defProp=Object['defineProperty'],__name=(_0x29d541,_0x6a0797)=>__defProp(_0x29d541,'name',{'value':_0x6a0797,'configurable':!![]});const ruleName='must-not-use-process-env';const ruleContent='\x0a###\x20**Must\x20not**\x20use\x20\x27process.env[...]\x27\x20to\x20read\x20environment\x20variables.\x0a\x0a####\x20Wrong\x0a\x0aconst\x20foo\x20=\x20process.env[bar];\x0a\x0a####\x20Correct\x0a\x0aimport\x20{\x0a\x20\x20\x20\x20getStringEnvSetting,\x0a\x20\x20\x20\x20getRequiredStringEnvSetting,\x0a\x20\x20\x20\x20getNumberEnvSetting,\x0a\x20\x20\x20\x20getBooleanEnvSetting,\x0a}\x20from\x20\x22@fd-toolbox/infra/env-functions\x22;\x0a\x0aconst\x20foo\x20=\x20getStringEnvSetting(bar);\x20\x20\x20\x20\x20\x20\x20\x20\x20//\x20if\x20(string\x20|\x20undefined)\x0aor\x0aconst\x20foo\x20=\x20getRequiredStringEnvSetting(bar);\x20//\x20if\x20(string)\x20-\x20throws\x20if\x20missing\x0aor\x0aconst\x20foo\x20=\x20getNumberEnvSetting(bar);\x20\x20\x20\x20\x20\x20\x20\x20\x20//\x20if\x20(number\x20|\x20undefined)\x0aor\x0aconst\x20foo\x20=\x20getBooleanEnvSetting(bar);\x20\x20\x20\x20\x20\x20\x20\x20//\x20if\x20(boolean)\x20-\x20defaults\x20to\x20false\x0a\x0a####\x20Why\x0a\x0aDirectly\x20reading\x20from\x20\x27process.env\x27\x20can\x20lead\x20to\x20missing\x20variables\x20or\x20values\x20of\x20the\x20wrong\x20type.\x0aUse\x20the\x20typed\x20helpers\x20above\x20to\x20get\x20proper\x20type\x20validation\x20and\x20error\x20handling\x20out\x20of\x20the\x20box.';var mustNotUseProcessEnv = createEslintRule(ruleName,ruleContent,__name(function create(_0x3d7ad4){return {'MemberExpression'(_0x10915f){isNameMatch(_0x10915f['object'],flintRuleIdentifiers['process'])&&isNameMatch(_0x10915f['property'],files['env'])&&isMemberExpression(_0x10915f['parent'])&&!isWriteContext(_0x10915f['parent'])&&_0x3d7ad4['report']({'node':_0x10915f,'messageId':ruleName});}};},'create'));function isWriteContext(_0x4f7165){const _0x1b16c9=_0x4f7165['parent'];if(_0x1b16c9['type']===nodeTypes['unaryExpression']&&_0x1b16c9['operator']===mutationActionNames['delete'])return !![];if(_0x1b16c9['type']===nodeTypes['assignmentExpression']&&_0x1b16c9['left']===_0x4f7165)return !![];return ![];}__name(isWriteContext,'isWriteContext');

export { mustNotUseProcessEnv as default, ruleName };
