{"version":3,"file":"prefer_ecma_privacy.mjs","sources":["../../src/rules/prefer_ecma_privacy.ts"],"sourcesContent":["/**\n * @module @nhtio/eslint-config/rules/prefer_ecma_privacy\n */\n\nimport { createRule } from './common'\n\nimport type { TSESTree } from '@typescript-eslint/utils'\n\ntype NodeWithAccessibility = TSESTree.MethodDefinition | TSESTree.PropertyDefinition\n\nconst preferEcmaPrivacyRule = createRule({\n  name: 'preferEcmaPrivacy',\n  meta: {\n    type: 'suggestion',\n    docs: {\n      description:\n        'Disallow TypeScript `private` modifier; use ECMAScript `#` private fields instead',\n    },\n    hasSuggestions: true,\n    schema: [],\n    messages: {\n      preferEcmaPrivacy:\n        'Use ECMAScript private fields (`#name`) instead of the TypeScript `private` modifier. ' +\n        'The `private` modifier is a compile-time-only annotation and provides no runtime enforcement.',\n      suggestRename:\n        'Rename to `#{{name}}` (you will also need to update all references to this member)',\n    },\n  },\n  create(context) {\n    function checkNode(node: NodeWithAccessibility) {\n      if (node.accessibility !== 'private') return\n\n      const memberNode = node.key\n      const name = memberNode.type === 'Identifier' ? memberNode.name : null\n\n      context.report({\n        node,\n        messageId: 'preferEcmaPrivacy',\n        suggest: name\n          ? [\n              {\n                messageId: 'suggestRename',\n                data: { name },\n                fix(fixer) {\n                  const fixes = []\n                  const sourceCode = context.sourceCode\n                  const privateToken = sourceCode.getFirstToken(node, (t) => t.value === 'private')\n                  if (privateToken) {\n                    fixes.push(\n                      fixer.removeRange([privateToken.range[0], privateToken.range[1] + 1])\n                    )\n                  }\n                  fixes.push(fixer.insertTextBefore(memberNode, '#'))\n                  return fixes\n                },\n              },\n            ]\n          : [],\n      })\n    }\n\n    return {\n      MethodDefinition: checkNode,\n      PropertyDefinition: checkNode,\n    }\n  },\n  defaultOptions: [],\n})\n\nexport default preferEcmaPrivacyRule\n"],"names":["preferEcmaPrivacyRule","createRule","context","checkNode","node","memberNode","name","fixer","fixes","privateToken","t"],"mappings":";AAUA,MAAMA,IAAwBC,EAAW;AAAA,EACvC,MAAM;AAAA,EACN,MAAM;AAAA,IACJ,MAAM;AAAA,IACN,MAAM;AAAA,MACJ,aACE;AAAA,IAAA;AAAA,IAEJ,gBAAgB;AAAA,IAChB,QAAQ,CAAA;AAAA,IACR,UAAU;AAAA,MACR,mBACE;AAAA,MAEF,eACE;AAAA,IAAA;AAAA,EACJ;AAAA,EAEF,OAAOC,GAAS;AACd,aAASC,EAAUC,GAA6B;AAC9C,UAAIA,EAAK,kBAAkB,UAAW;AAEtC,YAAMC,IAAaD,EAAK,KAClBE,IAAOD,EAAW,SAAS,eAAeA,EAAW,OAAO;AAElE,MAAAH,EAAQ,OAAO;AAAA,QACb,MAAAE;AAAA,QACA,WAAW;AAAA,QACX,SAASE,IACL;AAAA,UACE;AAAA,YACE,WAAW;AAAA,YACX,MAAM,EAAE,MAAAA,EAAA;AAAA,YACR,IAAIC,GAAO;AACT,oBAAMC,IAAQ,CAAA,GAERC,IADaP,EAAQ,WACK,cAAcE,GAAM,CAACM,MAAMA,EAAE,UAAU,SAAS;AAChF,qBAAID,KACFD,EAAM;AAAA,gBACJD,EAAM,YAAY,CAACE,EAAa,MAAM,CAAC,GAAGA,EAAa,MAAM,CAAC,IAAI,CAAC,CAAC;AAAA,cAAA,GAGxED,EAAM,KAAKD,EAAM,iBAAiBF,GAAY,GAAG,CAAC,GAC3CG;AAAA,YACT;AAAA,UAAA;AAAA,QACF,IAEF,CAAA;AAAA,MAAC,CACN;AAAA,IACH;AAEA,WAAO;AAAA,MACL,kBAAkBL;AAAA,MAClB,oBAAoBA;AAAA,IAAA;AAAA,EAExB;AAAA,EACA,gBAAgB,CAAA;AAClB,CAAC;"}