@atlaspack/eslint-plugin 2.14.2-dev.3793 → 2.14.2-dev.3932

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -43,7 +43,7 @@ if (parcelRequire == null) {
43
43
 
44
44
  var parcelRegister = parcelRequire.register;
45
45
  parcelRegister("ge4Mt", function(module, exports) {
46
- module.exports = JSON.parse("{\"name\":\"@atlaspack/eslint-plugin\",\"version\":\"2.14.2-dev.3793+8c369e38c\",\"license\":\"(MIT OR Apache-2.0)\",\"main\":\"lib/index.js\",\"types\":\"lib/index.d.ts\",\"source\":\"src/index.ts\",\"repository\":{\"type\":\"git\",\"url\":\"https://github.com/atlassian-labs/atlaspack.git\"},\"publishConfig\":{\"access\":\"public\"},\"engines\":{\"node\":\">= 16.0.0\"},\"dependencies\":{\"@typescript-eslint/utils\":\"^8.31.1\"},\"devDependencies\":{\"@typescript-eslint/rule-tester\":\"^8.31.1\",\"typescript-eslint\":\"^8.31.1\"},\"peerDependencies\":{\"eslint\":\"^8.57.0 || ^9.0.0\"},\"gitHead\":\"8c369e38ccd428409811114aebd6044c27f90705\"}");
46
+ module.exports = JSON.parse("{\"name\":\"@atlaspack/eslint-plugin\",\"version\":\"2.14.2-dev.3932+fa4d24840\",\"license\":\"(MIT OR Apache-2.0)\",\"main\":\"lib/index.js\",\"types\":\"lib/index.d.ts\",\"source\":\"src/index.ts\",\"repository\":{\"type\":\"git\",\"url\":\"https://github.com/atlassian-labs/atlaspack.git\"},\"publishConfig\":{\"access\":\"public\"},\"engines\":{\"node\":\">= 16.0.0\"},\"dependencies\":{\"@typescript-eslint/utils\":\"^8.31.1\"},\"devDependencies\":{\"@typescript-eslint/rule-tester\":\"^8.31.1\",\"typescript-eslint\":\"^8.31.1\"},\"peerDependencies\":{\"eslint\":\"^8.57.0 || ^9.0.0\"},\"gitHead\":\"fa4d24840815e7048a21d74caf01e2df633fabe3\"}");
47
47
 
48
48
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D,YAAYV,IAAI,CAAChC,MAAM,CAACR,IAAI,KAAK,gBACjCkD,YAAYV,IAAI,CAAChC,MAAM,CAACnC,IAAI,KAAK,cAEjCgC,QAAQgB,MAAM,CAAC;wBACbd,MAAM2C;wBACN5B,WAAW;oBACb;gBAEJ;qBAEAa,sBAAsBO,GAAG,CAACnC;YAE9B;YACA+B,0BAAyB/B,IAAI;gBAC3B,4EAAA;gBACA,IACEA,KAAK2C,WAAW,CAAClD,IAAI,KAAK,oBAC1BO,KAAK2C,WAAW,CAAC1C,MAAM,CAACR,IAAI,KAAK,gBACjCO,KAAK2C,WAAW,CAAC1C,MAAM,CAACnC,IAAI,KAAK,cAEjCgC,QAAQgB,MAAM,CAAC;0BACbd;oBACAe,WAAW;gBACb;qBAEAe,wBAAwBK,GAAG,CAACnC;YAEhC;QACF;IACF;AACF;IAEA,2CAAeZ;;;;AHrHR,MAAM,QAACtB,yCAAI,WAAEC,yCAAAA,EAAQ,GAC1BC;AAEK,MAAMC,4CAAQ;IACnB,+BAA+BL,CAAAA,GAAAA,wCAAAA;IAC/B,yBAAyBC,CAAAA,GAAAA,wCAAzB;AACF;AAEA,MAAMK,oCAAc;IAClBC,SAAS;QAAC;KAAa;IACvBF,OAAO;QACL,0CAA0C;QAC1C,oCAAoC;IACtC;AACF;AAEO,MAAMI,2CAAS;IACpBC,MAAM;cACJR;iBACAC;IACF;WACAE;IACAM,SAAS;qBACPL;QACA,IAAI,sBAAqB;YACvB,OAAOO;QACT;IACF;AACF;AAEA,MAAMA,wCAAkB;IACtBN,SAAS;QACP,cAAcE;IAChB;IACAJ,OAAO;QACL,0CAA0C;QAC1C,oCAAoC;IACtC;AACF;AAEO,MAAMM,2CAAUF,yCAAOE,OAAO;IAErC,2CAAeF","sources":["packages/core/eslint-plugin/package.json","packages/core/eslint-plugin/src/index.ts","packages/core/eslint-plugin/src/rules/importcond-type-annotations/index.ts","packages/core/eslint-plugin/src/utils/index.ts","packages/core/eslint-plugin/src/rules/no-importcond-exports/index.ts"],"sourcesContent":["{\n \"name\": \"@atlaspack/eslint-plugin\",\n \"version\": \"2.14.2-dev.3793+8c369e38c\",\n \"license\": \"(MIT OR Apache-2.0)\",\n \"main\": \"lib/index.js\",\n \"types\": \"lib/index.d.ts\",\n \"source\": \"src/index.ts\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/atlassian-labs/atlaspack.git\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"engines\": {\n \"node\": \">= 16.0.0\"\n },\n \"dependencies\": {\n \"@typescript-eslint/utils\": \"^8.31.1\"\n },\n \"devDependencies\": {\n \"@typescript-eslint/rule-tester\": \"^8.31.1\",\n \"typescript-eslint\": \"^8.31.1\"\n },\n \"peerDependencies\": {\n \"eslint\": \"^8.57.0 || ^9.0.0\"\n },\n \"gitHead\": \"8c369e38ccd428409811114aebd6044c27f90705\"\n}\n","import importCondTypeAnnotationsRule from './rules/importcond-type-annotations';\nimport noImportCondExportsRule from './rules/no-importcond-exports';\n\n// eslint-disable-next-line @typescript-eslint/no-require-imports\nexport const {name, version} =\n require('../package.json') as typeof import('../package.json');\n\nexport const rules = {\n 'importcond-type-annotations': importCondTypeAnnotationsRule,\n 'no-importcond-exports': noImportCondExportsRule,\n};\n\nconst recommended = {\n plugins: ['@atlaspack'],\n rules: {\n '@atlaspack/importcond-type-annotations': 'error',\n '@atlaspack/no-importcond-exports': 'error',\n },\n} as const;\n\nexport const plugin = {\n meta: {\n name,\n version,\n },\n rules,\n configs: {\n recommended,\n get 'flat/recommended'() {\n return flatRecommended;\n },\n },\n} as const;\n\nconst flatRecommended = {\n plugins: {\n '@atlaspack': plugin,\n },\n rules: {\n '@atlaspack/importcond-type-annotations': 'error',\n '@atlaspack/no-importcond-exports': 'error',\n },\n} as const;\n\nexport const configs = plugin.configs;\n\nexport default plugin;\n","/**\n * @file Automatically adds type annotations for conditional import (importCond) usages\n */\nimport type {TSESTree} from '@typescript-eslint/utils';\nimport {createRule} from '../../utils/index';\n\nexport const RULE_NAME = 'importcond-type-annotations';\n\nexport const messages = {\n addTypeAnnotation:\n 'This conditional import usage needs a type annotation. Please apply the autofix so that the type annotation is correct.',\n wrongTypeAnnotation:\n 'The type annotation for this conditional import usage is incorrect. Please apply the suggestion to fix it.',\n suggestTypeAnnotation:\n 'Fix the type annotation for this conditional import usage.',\n}; // satisfies Record<string, string>; // Uncomment this line once prettier is updated to a version that supports it\n\nexport type Options = [];\n\nconst generateFix = (\n firstArgText: string,\n secondArgText: string,\n thirdArgText: string,\n): string => {\n const correctTypeAnnotation = `<typeof import(${secondArgText}), typeof import(${thirdArgText})>`;\n return `importCond${correctTypeAnnotation}(${firstArgText}, ${secondArgText}, ${thirdArgText})`;\n};\n\nconst rule = createRule<Options, keyof typeof messages>({\n name: RULE_NAME,\n meta: {\n docs: {\n description:\n 'Ensures that importCond function calls have correct type annotations.',\n recommended: true,\n },\n messages,\n schema: [],\n type: 'problem',\n fixable: 'code',\n hasSuggestions: true,\n },\n defaultOptions: [],\n create(context) {\n return {\n CallExpression(node) {\n // Check if the function being called is `importCond`\n // Note that this is a global, so we don't need to check the imports\n if (\n node.callee.type === 'Identifier' &&\n node.callee.name === 'importCond'\n ) {\n const args = node.arguments;\n\n // Ensure there are at least 3 arguments\n // If not, then there will be type-checking errors anyway\n if (args.length < 3) {\n return;\n }\n\n const [firstArg, secondArg, thirdArg] = args;\n\n // Get the source code for the arguments\n const {sourceCode} = context;\n const firstArgText = sourceCode.getText(firstArg);\n const secondArgText = sourceCode.getText(secondArg);\n const thirdArgText = sourceCode.getText(thirdArg);\n\n // Check if the type annotation is missing or incorrect\n // Whether it's called typeArguments or typeParameters depends on the version of typescript-eslint\n const typeArguments:\n | TSESTree.TSTypeParameterInstantiation\n | undefined = node.typeArguments ?? (node as any).typeParameters;\n if (!typeArguments) {\n // No type annotation exists at all\n context.report({\n node,\n messageId: 'addTypeAnnotation',\n // Apply autofix instead of suggestion, because there was no type annotation in the first place.\n fix: (fixer) => {\n const fixedCode = generateFix(\n firstArgText,\n secondArgText,\n thirdArgText,\n );\n return fixer.replaceText(node, fixedCode);\n },\n });\n } else if (\n typeArguments.params.length !== 2 ||\n sourceCode.getText(typeArguments.params[0]) !==\n `typeof import(${secondArgText})` ||\n sourceCode.getText(typeArguments.params[1]) !==\n `typeof import(${thirdArgText})`\n ) {\n // Type annotation is present, but incorrect\n context.report({\n node,\n messageId: 'wrongTypeAnnotation',\n // We should be more cautious here, so we make it a suggestion instead of an autofix\n suggest: [\n {\n messageId: 'suggestTypeAnnotation',\n fix: (fixer) => {\n const fixedCode = generateFix(\n firstArgText,\n secondArgText,\n thirdArgText,\n );\n return fixer.replaceText(node, fixedCode);\n },\n },\n ],\n });\n }\n }\n },\n };\n },\n});\n\nexport default rule;\n","import {ESLintUtils} from '@typescript-eslint/utils';\n\nexport interface PluginDocs {\n description: string;\n recommended?: boolean;\n}\n\nexport const createRule = ESLintUtils.RuleCreator<PluginDocs>(\n (name) =>\n `https://github.com/atlassian-labs/atlaspack/tree/main/packages/core/eslint-plugin/src/rules/${name}/README.md`,\n);\n","/**\n * @file Bans directly exporting Atlaspack conditional imports (importCond) from a file, as this is not expressly supported and will break in tests.\n */\nimport {createRule} from '../../utils/index';\nimport {TSESTree} from '@typescript-eslint/utils';\n\nexport const RULE_NAME = 'no-importcond-exports';\n\nexport const messages = {\n noImportCondExports:\n 'Directly exporting Atlaspack conditional imports (importCond) from a file is not supported and will break in tests. If you need the component for testing, please import the old and new versions of the components or modules directly in the test file instead.\\n\\n' +\n 'Does your use case require exporting the component? Reach out to #atlaspack-contextual-imports so we can help find a workaround.',\n}; // satisfies Record<string, string>; // Uncomment this line once prettier is updated to a version that supports it\n\nexport type Options = [];\n\nconst rule = createRule<Options, keyof typeof messages>({\n name: RULE_NAME,\n meta: {\n docs: {\n description:\n 'Bans directly exporting Atlaspack conditional imports (importCond) from a file, as this is not expressly supported and will break in tests.',\n recommended: true,\n },\n messages,\n schema: [],\n type: 'problem',\n },\n defaultOptions: [],\n create(context) {\n // Track variables initialized with `importCond`\n const importCondVariables = new Set<string>();\n const namedExportStatements = new Set<TSESTree.ExportNamedDeclaration>();\n const defaultExportStatements =\n new Set<TSESTree.ExportDefaultDeclaration>();\n\n return {\n VariableDeclarator(node) {\n if (\n node.init &&\n node.init.type === 'CallExpression' &&\n node.init.callee.type === 'Identifier' &&\n node.init.callee.name === 'importCond' &&\n node.id.type === 'Identifier'\n ) {\n // Add the variable name to the tracked set\n importCondVariables.add(node.id.name);\n }\n },\n 'Program:exit'(_node) {\n // Check if any named export references a tracked variable\n for (const exportStatement of namedExportStatements) {\n exportStatement.specifiers.forEach((specifier) => {\n if (\n specifier.type === 'ExportSpecifier' &&\n specifier.local.type === 'Identifier' &&\n importCondVariables.has(specifier.local.name)\n ) {\n context.report({\n node: specifier,\n messageId: 'noImportCondExports',\n });\n }\n });\n }\n\n for (const exportStatement of defaultExportStatements) {\n if (\n exportStatement.declaration.type === 'Identifier' &&\n importCondVariables.has(exportStatement.declaration.name)\n ) {\n context.report({\n node: exportStatement,\n messageId: 'noImportCondExports',\n });\n }\n }\n },\n ExportNamedDeclaration(node) {\n // Check if a variable declaration is directly exported\n if (\n node.declaration &&\n node.declaration.type === 'VariableDeclaration' &&\n node.declaration.declarations\n ) {\n node.declaration.declarations.forEach((declaration) => {\n if (\n declaration.init &&\n declaration.init.type === 'CallExpression' &&\n declaration.init.callee.type === 'Identifier' &&\n declaration.init.callee.name === 'importCond'\n ) {\n context.report({\n node: declaration,\n messageId: 'noImportCondExports',\n });\n }\n });\n } else {\n namedExportStatements.add(node);\n }\n },\n ExportDefaultDeclaration(node) {\n // Check if the default export is a tracked variable or an `importCond` call\n if (\n node.declaration.type === 'CallExpression' &&\n node.declaration.callee.type === 'Identifier' &&\n node.declaration.callee.name === 'importCond'\n ) {\n context.report({\n node,\n messageId: 'noImportCondExports',\n });\n } else {\n defaultExportStatements.add(node);\n }\n },\n };\n },\n});\n\nexport default rule;\n"],"names":["module","exports","JSON","parse","importCondTypeAnnotationsRule","noImportCondExportsRule","name","version","require","rules","recommended","plugins","const","plugin","meta","configs","flat/recommended","flatRecommended","createRule","RULE_NAME","messages","addTypeAnnotation","wrongTypeAnnotation","suggestTypeAnnotation","generateFix","firstArgText","secondArgText","thirdArgText","rule","Options","docs","description","schema","type","fixable","hasSuggestions","defaultOptions","create","context","CallExpression","node","callee","args","arguments","length","firstArg","secondArg","thirdArg","sourceCode","getText","typeArguments","TSESTree","TSTypeParameterInstantiation","typeParameters","report","messageId","fix","fixer","fixedCode","replaceText","params","suggest","ESLintUtils","RuleCreator","PluginDocs","noImportCondExports","importCondVariables","Set","namedExportStatements","ExportNamedDeclaration","defaultExportStatements","ExportDefaultDeclaration","VariableDeclarator","init","id","add","Program:exit","exportStatement","specifiers","forEach","specifier","local","has","declaration","declarations"],"version":3,"file":"index.js.map","sourceRoot":"../../../../"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAAA,iBAAiBE,KAAKC,KAAK,CAAC;;;;;;;;;;;;;AEA5B;;;ACOO,MAAMe,4CAAa4C,CAAAA,GAAAA,wCAAAA,EAAYC,WAAW,CAC9CzD,CAAAA,OACE,CAAA,4FAAA,EAA8FA,KAAK,UAAA,CACxG;;CDRA;AAIO,MAAMa,4CAAY;AAElB,MAAMC,4CAAW;IACtBC,mBACE;IACFC,qBACE;IACFC,uBACE;AACJ,GAAG,oHAAH;AAIA,MAAMC,oCAAcA,CAClBC,cACAC,eACAC;IAGA,OAAQ,CAAA,UAAA,EADuB,CAAA,eAAA,EAAiBD,cAAc,iBAAA,EAAmBC,aAAa,EAAA,CACpD,CAAA,CAAA,EAAGF,aAAa,EAAA,EAAIC,cAAc,EAAA,EAAIC,aAAa,CAAA,CAAE;AACjG;AAEA,MAAMC,6BAAOV,CAAAA,GAAAA,yCAAAA,EAA2C;IACtDZ,MAAMa;IACNL,MAAM;QACJgB,MAAM;YACJC,aACE;YACFrB,aAAa;QACf;kB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,SAAS;QAAC;KAAa;IACvBF,OAAO;QACL,0CAA0C;QAC1C,oCAAoC;IACtC;AACF;AAEO,MAAMI,2CAAS;IACpBC,MAAM;cACJR;iBACAC;IACF;WACAE;IACAM,SAAS;qBACPL;QACA,IAAI,sBAAqB;YACvB,OAAOO;QACT;IACF;AACF;AAEA,MAAMA,wCAAkB;IACtBN,SAAS;QACP,cAAcE;IAChB;IACAJ,OAAO;QACL,0CAA0C;QAC1C,oCAAoC;IACtC;AACF;AAEO,MAAMM,2CAAUF,yCAAOE,OAAO;IAErC,2CAAeF","sources":["packages/core/eslint-plugin/package.json","packages/core/eslint-plugin/src/index.ts","packages/core/eslint-plugin/src/rules/importcond-type-annotations/index.ts","packages/core/eslint-plugin/src/utils/index.ts","packages/core/eslint-plugin/src/rules/no-importcond-exports/index.ts"],"sourcesContent":["{\n \"name\": \"@atlaspack/eslint-plugin\",\n \"version\": \"2.14.2-dev.3932+fa4d24840\",\n \"license\": \"(MIT OR Apache-2.0)\",\n \"main\": \"lib/index.js\",\n \"types\": \"lib/index.d.ts\",\n \"source\": \"src/index.ts\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/atlassian-labs/atlaspack.git\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"engines\": {\n \"node\": \">= 16.0.0\"\n },\n \"dependencies\": {\n \"@typescript-eslint/utils\": \"^8.31.1\"\n },\n \"devDependencies\": {\n \"@typescript-eslint/rule-tester\": \"^8.31.1\",\n \"typescript-eslint\": \"^8.31.1\"\n },\n \"peerDependencies\": {\n \"eslint\": \"^8.57.0 || ^9.0.0\"\n },\n \"gitHead\": \"fa4d24840815e7048a21d74caf01e2df633fabe3\"\n}\n","import importCondTypeAnnotationsRule from './rules/importcond-type-annotations';\nimport noImportCondExportsRule from './rules/no-importcond-exports';\n\n// eslint-disable-next-line @typescript-eslint/no-require-imports\nexport const {name, version} =\n require('../package.json') as typeof import('../package.json');\n\nexport const rules = {\n 'importcond-type-annotations': importCondTypeAnnotationsRule,\n 'no-importcond-exports': noImportCondExportsRule,\n};\n\nconst recommended = {\n plugins: ['@atlaspack'],\n rules: {\n '@atlaspack/importcond-type-annotations': 'error',\n '@atlaspack/no-importcond-exports': 'error',\n },\n} as const;\n\nexport const plugin = {\n meta: {\n name,\n version,\n },\n rules,\n configs: {\n recommended,\n get 'flat/recommended'() {\n return flatRecommended;\n },\n },\n} as const;\n\nconst flatRecommended = {\n plugins: {\n '@atlaspack': plugin,\n },\n rules: {\n '@atlaspack/importcond-type-annotations': 'error',\n '@atlaspack/no-importcond-exports': 'error',\n },\n} as const;\n\nexport const configs = plugin.configs;\n\nexport default plugin;\n","/**\n * @file Automatically adds type annotations for conditional import (importCond) usages\n */\nimport type {TSESTree} from '@typescript-eslint/utils';\nimport {createRule} from '../../utils/index';\n\nexport const RULE_NAME = 'importcond-type-annotations';\n\nexport const messages = {\n addTypeAnnotation:\n 'This conditional import usage needs a type annotation. Please apply the autofix so that the type annotation is correct.',\n wrongTypeAnnotation:\n 'The type annotation for this conditional import usage is incorrect. Please apply the suggestion to fix it.',\n suggestTypeAnnotation:\n 'Fix the type annotation for this conditional import usage.',\n}; // satisfies Record<string, string>; // Uncomment this line once prettier is updated to a version that supports it\n\nexport type Options = [];\n\nconst generateFix = (\n firstArgText: string,\n secondArgText: string,\n thirdArgText: string,\n): string => {\n const correctTypeAnnotation = `<typeof import(${secondArgText}), typeof import(${thirdArgText})>`;\n return `importCond${correctTypeAnnotation}(${firstArgText}, ${secondArgText}, ${thirdArgText})`;\n};\n\nconst rule = createRule<Options, keyof typeof messages>({\n name: RULE_NAME,\n meta: {\n docs: {\n description:\n 'Ensures that importCond function calls have correct type annotations.',\n recommended: true,\n },\n messages,\n schema: [],\n type: 'problem',\n fixable: 'code',\n hasSuggestions: true,\n },\n defaultOptions: [],\n create(context) {\n return {\n CallExpression(node) {\n // Check if the function being called is `importCond`\n // Note that this is a global, so we don't need to check the imports\n if (\n node.callee.type === 'Identifier' &&\n node.callee.name === 'importCond'\n ) {\n const args = node.arguments;\n\n // Ensure there are at least 3 arguments\n // If not, then there will be type-checking errors anyway\n if (args.length < 3) {\n return;\n }\n\n const [firstArg, secondArg, thirdArg] = args;\n\n // Get the source code for the arguments\n const {sourceCode} = context;\n const firstArgText = sourceCode.getText(firstArg);\n const secondArgText = sourceCode.getText(secondArg);\n const thirdArgText = sourceCode.getText(thirdArg);\n\n // Check if the type annotation is missing or incorrect\n // Whether it's called typeArguments or typeParameters depends on the version of typescript-eslint\n const typeArguments:\n | TSESTree.TSTypeParameterInstantiation\n | undefined = node.typeArguments ?? (node as any).typeParameters;\n if (!typeArguments) {\n // No type annotation exists at all\n context.report({\n node,\n messageId: 'addTypeAnnotation',\n // Apply autofix instead of suggestion, because there was no type annotation in the first place.\n fix: (fixer) => {\n const fixedCode = generateFix(\n firstArgText,\n secondArgText,\n thirdArgText,\n );\n return fixer.replaceText(node, fixedCode);\n },\n });\n } else if (\n typeArguments.params.length !== 2 ||\n sourceCode.getText(typeArguments.params[0]) !==\n `typeof import(${secondArgText})` ||\n sourceCode.getText(typeArguments.params[1]) !==\n `typeof import(${thirdArgText})`\n ) {\n // Type annotation is present, but incorrect\n context.report({\n node,\n messageId: 'wrongTypeAnnotation',\n // We should be more cautious here, so we make it a suggestion instead of an autofix\n suggest: [\n {\n messageId: 'suggestTypeAnnotation',\n fix: (fixer) => {\n const fixedCode = generateFix(\n firstArgText,\n secondArgText,\n thirdArgText,\n );\n return fixer.replaceText(node, fixedCode);\n },\n },\n ],\n });\n }\n }\n },\n };\n },\n});\n\nexport default rule;\n","import {ESLintUtils} from '@typescript-eslint/utils';\n\nexport interface PluginDocs {\n description: string;\n recommended?: boolean;\n}\n\nexport const createRule = ESLintUtils.RuleCreator<PluginDocs>(\n (name) =>\n `https://github.com/atlassian-labs/atlaspack/tree/main/packages/core/eslint-plugin/src/rules/${name}/README.md`,\n);\n","/**\n * @file Bans directly exporting Atlaspack conditional imports (importCond) from a file, as this is not expressly supported and will break in tests.\n */\nimport {createRule} from '../../utils/index';\nimport {TSESTree} from '@typescript-eslint/utils';\n\nexport const RULE_NAME = 'no-importcond-exports';\n\nexport const messages = {\n noImportCondExports:\n 'Directly exporting Atlaspack conditional imports (importCond) from a file is not supported and will break in tests. If you need the component for testing, please import the old and new versions of the components or modules directly in the test file instead.\\n\\n' +\n 'Does your use case require exporting the component? Reach out to #atlaspack-contextual-imports so we can help find a workaround.',\n}; // satisfies Record<string, string>; // Uncomment this line once prettier is updated to a version that supports it\n\nexport type Options = [];\n\nconst rule = createRule<Options, keyof typeof messages>({\n name: RULE_NAME,\n meta: {\n docs: {\n description:\n 'Bans directly exporting Atlaspack conditional imports (importCond) from a file, as this is not expressly supported and will break in tests.',\n recommended: true,\n },\n messages,\n schema: [],\n type: 'problem',\n },\n defaultOptions: [],\n create(context) {\n // Track variables initialized with `importCond`\n const importCondVariables = new Set<string>();\n const namedExportStatements = new Set<TSESTree.ExportNamedDeclaration>();\n const defaultExportStatements =\n new Set<TSESTree.ExportDefaultDeclaration>();\n\n return {\n VariableDeclarator(node) {\n if (\n node.init &&\n node.init.type === 'CallExpression' &&\n node.init.callee.type === 'Identifier' &&\n node.init.callee.name === 'importCond' &&\n node.id.type === 'Identifier'\n ) {\n // Add the variable name to the tracked set\n importCondVariables.add(node.id.name);\n }\n },\n 'Program:exit'(_node) {\n // Check if any named export references a tracked variable\n for (const exportStatement of namedExportStatements) {\n exportStatement.specifiers.forEach((specifier) => {\n if (\n specifier.type === 'ExportSpecifier' &&\n specifier.local.type === 'Identifier' &&\n importCondVariables.has(specifier.local.name)\n ) {\n context.report({\n node: specifier,\n messageId: 'noImportCondExports',\n });\n }\n });\n }\n\n for (const exportStatement of defaultExportStatements) {\n if (\n exportStatement.declaration.type === 'Identifier' &&\n importCondVariables.has(exportStatement.declaration.name)\n ) {\n context.report({\n node: exportStatement,\n messageId: 'noImportCondExports',\n });\n }\n }\n },\n ExportNamedDeclaration(node) {\n // Check if a variable declaration is directly exported\n if (\n node.declaration &&\n node.declaration.type === 'VariableDeclaration' &&\n node.declaration.declarations\n ) {\n node.declaration.declarations.forEach((declaration) => {\n if (\n declaration.init &&\n declaration.init.type === 'CallExpression' &&\n declaration.init.callee.type === 'Identifier' &&\n declaration.init.callee.name === 'importCond'\n ) {\n context.report({\n node: declaration,\n messageId: 'noImportCondExports',\n });\n }\n });\n } else {\n namedExportStatements.add(node);\n }\n },\n ExportDefaultDeclaration(node) {\n // Check if the default export is a tracked variable or an `importCond` call\n if (\n node.declaration.type === 'CallExpression' &&\n node.declaration.callee.type === 'Identifier' &&\n node.declaration.callee.name === 'importCond'\n ) {\n context.report({\n node,\n messageId: 'noImportCondExports',\n });\n } else {\n defaultExportStatements.add(node);\n }\n },\n };\n },\n});\n\nexport default rule;\n"],"names":["module","exports","JSON","parse","importCondTypeAnnotationsRule","noImportCondExportsRule","name","version","require","rules","recommended","plugins","const","plugin","meta","configs","flat/recommended","flatRecommended","createRule","RULE_NAME","messages","addTypeAnnotation","wrongTypeAnnotation","suggestTypeAnnotation","generateFix","firstArgText","secondArgText","thirdArgText","rule","Options","docs","description","schema","type","fixable","hasSuggestions","defaultOptions","create","context","CallExpression","node","callee","args","arguments","length","firstArg","secondArg","thirdArg","sourceCode","getText","typeArguments","TSESTree","TSTypeParameterInstantiation","typeParameters","report","messageId","fix","fixer","fixedCode","replaceText","params","suggest","ESLintUtils","RuleCreator","PluginDocs","noImportCondExports","importCondVariables","Set","namedExportStatements","ExportNamedDeclaration","defaultExportStatements","ExportDefaultDeclaration","VariableDeclarator","init","id","add","Program:exit","exportStatement","specifiers","forEach","specifier","local","has","declaration","declarations"],"version":3,"file":"index.js.map","sourceRoot":"../../../../"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/eslint-plugin",
3
- "version": "2.14.2-dev.3793+8c369e38c",
3
+ "version": "2.14.2-dev.3932+fa4d24840",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -25,5 +25,5 @@
25
25
  "peerDependencies": {
26
26
  "eslint": "^8.57.0 || ^9.0.0"
27
27
  },
28
- "gitHead": "8c369e38ccd428409811114aebd6044c27f90705"
28
+ "gitHead": "fa4d24840815e7048a21d74caf01e2df633fabe3"
29
29
  }