@atlaspack/eslint-plugin 2.14.2-typescript-8a6ec6c8b.0 → 2.14.2-unified-e330ff3d9.0
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.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;
|
|
1
|
+
{"mappings":";;AGGA,OAAO,mCAEyD,CAAC;AAEjE,OAAO,MAAM;;;CAGZ,CAAC;AAUF,OAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;CAYT,CAAC;AAYX,OAAO,MAAM;;;;;;;;;;;;;;;;;CAAwB,CAAC;AAEtC,eAAe,MAAM,CAAC","sources":["packages/core/eslint-plugin/src/packages/core/eslint-plugin/src/utils/index.ts","packages/core/eslint-plugin/src/packages/core/eslint-plugin/src/rules/importcond-type-annotations/index.ts","packages/core/eslint-plugin/src/packages/core/eslint-plugin/src/rules/no-importcond-exports/index.ts","packages/core/eslint-plugin/src/packages/core/eslint-plugin/src/index.ts","packages/core/eslint-plugin/src/index.ts"],"sourcesContent":[null,null,null,null,"import importCondTypeAnnotationsRule from './rules/importcond-type-annotations';\nimport noImportCondExportsRule from './rules/no-importcond-exports';\n\nexport const {name, version} =\n // eslint-disable-next-line @typescript-eslint/no-var-requires\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"],"names":[],"version":3,"file":"index.d.ts.map","sourceRoot":"../../../../"}
|
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-
|
|
46
|
+
module.exports = JSON.parse("{\"name\":\"@atlaspack/eslint-plugin\",\"version\":\"2.14.2-unified-e330ff3d9.0\",\"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\":\"e330ff3d90fbf336f87439a65e312d698433990b\"}");
|
|
47
47
|
|
|
48
48
|
});
|
|
49
49
|
|
|
@@ -56,7 +56,7 @@ $parcel$export(module.exports, "rules", () => $3f52bc2bbb9aa3d8$export$354076178
|
|
|
56
56
|
$parcel$export(module.exports, "plugin", () => $3f52bc2bbb9aa3d8$export$ca524d3785e2543);
|
|
57
57
|
$parcel$export(module.exports, "configs", () => $3f52bc2bbb9aa3d8$export$c884d9dcb329c3c);
|
|
58
58
|
$parcel$export(module.exports, "default", () => $3f52bc2bbb9aa3d8$export$2e2bcd8739ae039);
|
|
59
|
-
/**
|
|
59
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */ /**
|
|
60
60
|
* @file Automatically adds type annotations for conditional import (importCond) usages
|
|
61
61
|
*/
|
|
62
62
|
const $2f8f3cc371e6d9a5$export$56e87122f905fac0 = (0, $kWQCm$typescripteslintutils.ESLintUtils).RuleCreator((name)=>`https://github.com/atlassian-labs/atlaspack/tree/main/packages/core/eslint-plugin/src/rules/${name}/README.md`);
|
|
@@ -69,8 +69,7 @@ const $62ed09825cfca72a$export$defe85febe8b728c = {
|
|
|
69
69
|
suggestTypeAnnotation: 'Fix the type annotation for this conditional import usage.'
|
|
70
70
|
}; // satisfies Record<string, string>; // Uncomment this line once prettier is updated to a version that supports it
|
|
71
71
|
const $62ed09825cfca72a$var$generateFix = (firstArgText, secondArgText, thirdArgText)=>{
|
|
72
|
-
|
|
73
|
-
return `importCond${correctTypeAnnotation}(${firstArgText}, ${secondArgText}, ${thirdArgText})`;
|
|
72
|
+
return `importCond${`<typeof import(${secondArgText}), typeof import(${thirdArgText})>`}(${firstArgText}, ${secondArgText}, ${thirdArgText})`;
|
|
74
73
|
};
|
|
75
74
|
const $62ed09825cfca72a$var$rule = (0, $2f8f3cc371e6d9a5$export$56e87122f905fac0)({
|
|
76
75
|
name: $62ed09825cfca72a$export$16059a9982ca14f7,
|
|
@@ -115,7 +114,9 @@ const $62ed09825cfca72a$var$rule = (0, $2f8f3cc371e6d9a5$export$56e87122f905fac0
|
|
|
115
114
|
return fixer.replaceText(node, fixedCode);
|
|
116
115
|
}
|
|
117
116
|
});
|
|
118
|
-
else if (typeArguments.params.length !== 2 ||
|
|
117
|
+
else if (typeArguments.params.length !== 2 || // @ts-ignore Argument of type 'TypeNode' is not assignable to parameter of type 'Node | Token | undefined'.
|
|
118
|
+
sourceCode.getText(typeArguments.params[0]) !== `typeof import(${secondArgText})` || // @ts-ignore Argument of type 'TypeNode' is not assignable to parameter of type 'Node | Token | undefined'.
|
|
119
|
+
sourceCode.getText(typeArguments.params[1]) !== `typeof import(${thirdArgText})`) // Type annotation is present, but incorrect
|
|
119
120
|
context.report({
|
|
120
121
|
node: node,
|
|
121
122
|
messageId: 'wrongTypeAnnotation',
|
|
@@ -167,7 +168,8 @@ const $f0c6a78c725779ec$var$rule = (0, $2f8f3cc371e6d9a5$export$56e87122f905fac0
|
|
|
167
168
|
if (node.init && node.init.type === 'CallExpression' && node.init.callee.type === 'Identifier' && node.init.callee.name === 'importCond' && node.id.type === 'Identifier') // Add the variable name to the tracked set
|
|
168
169
|
importCondVariables.add(node.id.name);
|
|
169
170
|
},
|
|
170
|
-
|
|
171
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
172
|
+
'Program:exit' () {
|
|
171
173
|
// Check if any named export references a tracked variable
|
|
172
174
|
for (const exportStatement of namedExportStatements)exportStatement.specifiers.forEach((specifier)=>{
|
|
173
175
|
if (specifier.type === 'ExportSpecifier' && specifier.local.type === 'Identifier' && importCondVariables.has(specifier.local.name)) context.report({
|
|
@@ -205,7 +207,8 @@ var $f0c6a78c725779ec$export$2e2bcd8739ae039 = $f0c6a78c725779ec$var$rule;
|
|
|
205
207
|
|
|
206
208
|
|
|
207
209
|
|
|
208
|
-
const { name: $3f52bc2bbb9aa3d8$export$a8ff84c12d48cfa6, version: $3f52bc2bbb9aa3d8$export$83d89fbfd8236492 } =
|
|
210
|
+
const { name: $3f52bc2bbb9aa3d8$export$a8ff84c12d48cfa6, version: $3f52bc2bbb9aa3d8$export$83d89fbfd8236492 } = // eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
211
|
+
(parcelRequire("ge4Mt"));
|
|
209
212
|
const $3f52bc2bbb9aa3d8$export$354076178bdef094 = {
|
|
210
213
|
'importcond-type-annotations': (0, $62ed09825cfca72a$export$2e2bcd8739ae039),
|
|
211
214
|
'no-importcond-exports': (0, $f0c6a78c725779ec$export$2e2bcd8739ae039)
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAAA,iBAAiBE,KAAKC,KAAK,CAAC;;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C,QAAQgB,MAAM,CAAC;wBACbd,MAAM4C;wBACN7B,WAAW;oBACb;gBAEJ;qBAEAa,sBAAsBO,GAAG,CAACnC;YAE9B;YACA+B,0BAAyB/B,IAAI;gBAC3B,4EAAA;gBACA,IACEA,KAAK4C,WAAW,CAACnD,IAAI,KAAK,oBAC1BO,KAAK4C,WAAW,CAAC3C,MAAM,CAACR,IAAI,KAAK,gBACjCO,KAAK4C,WAAW,CAAC3C,MAAM,CAACpC,IAAI,KAAK,cAEjCiC,QAAQgB,MAAM,CAAC;0BACbd;oBACAe,WAAW;gBACb;qBAEAe,wBAAwBK,GAAG,CAACnC;YAEhC;QACF;IACF;AACF;IAEA,2CAAeZ;;;;AHrHR,MAAM,QAACvB,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-typescript-8a6ec6c8b.0\",\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\": \"8a6ec6c8bed0bbf5461f5b0f899577a576906051\"\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","correctTypeAnnotation","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","_node","exportStatement","specifiers","forEach","specifier","local","has","declaration","declarations"],"version":3,"file":"index.js.map","sourceRoot":"../../../../"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAAA,iBAAiBE,KAAKC,KAAK,CAAC;;;;;;;;;;;;;AEA5B,oDAAA,GAEA;;;ACKO,MAAMe,4CAAa4C,CAAAA,GAAAA,wCAAAA,EAAYC,WAAW,CAC9CzD,CAAAA,OACE,CAAA,4FAAA,EAA8FA,KAAK,UAAA,CACxG;;CDNA;AAKO,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;kBACAU;QACAY,QAAQ,EAAE;QACVC,MAAM;QACNC,SAAS;QACTC,gBAAgB;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C;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-unified-e330ff3d9.0\",\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\": \"e330ff3d90fbf336f87439a65e312d698433990b\"\n}\n","import importCondTypeAnnotationsRule from './rules/importcond-type-annotations';\nimport noImportCondExportsRule from './rules/no-importcond-exports';\n\nexport const {name, version} =\n // eslint-disable-next-line @typescript-eslint/no-var-requires\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","/* eslint-disable @typescript-eslint/ban-ts-comment */\n\n/**\n * @file Automatically adds type annotations for conditional import (importCond) usages\n */\n\nimport type {TSESTree} from '@typescript-eslint/types';\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\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 // @ts-ignore Argument of type 'TypeNode' is not assignable to parameter of type 'Node | Token | undefined'.\n sourceCode.getText(typeArguments.params[0]) !==\n `typeof import(${secondArgText})` ||\n // @ts-ignore Argument of type 'TypeNode' is not assignable to parameter of type 'Node | Token | undefined'.\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 // eslint-disable-next-line @typescript-eslint/no-unused-vars\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-
|
|
3
|
+
"version": "2.14.2-unified-e330ff3d9.0",
|
|
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": "
|
|
28
|
+
"gitHead": "e330ff3d90fbf336f87439a65e312d698433990b"
|
|
29
29
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import importCondTypeAnnotationsRule from './rules/importcond-type-annotations';
|
|
2
2
|
import noImportCondExportsRule from './rules/no-importcond-exports';
|
|
3
3
|
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
5
4
|
export const {name, version} =
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
6
6
|
require('../package.json') as typeof import('../package.json');
|
|
7
7
|
|
|
8
8
|
export const rules = {
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* @file Automatically adds type annotations for conditional import (importCond) usages
|
|
3
5
|
*/
|
|
4
|
-
|
|
6
|
+
|
|
7
|
+
import type {TSESTree} from '@typescript-eslint/types';
|
|
5
8
|
import {createRule} from '../../utils/index';
|
|
6
9
|
|
|
7
10
|
export const RULE_NAME = 'importcond-type-annotations';
|
|
@@ -70,6 +73,7 @@ const rule = createRule<Options, keyof typeof messages>({
|
|
|
70
73
|
// Whether it's called typeArguments or typeParameters depends on the version of typescript-eslint
|
|
71
74
|
const typeArguments:
|
|
72
75
|
| TSESTree.TSTypeParameterInstantiation
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
77
|
| undefined = node.typeArguments ?? (node as any).typeParameters;
|
|
74
78
|
if (!typeArguments) {
|
|
75
79
|
// No type annotation exists at all
|
|
@@ -88,8 +92,10 @@ const rule = createRule<Options, keyof typeof messages>({
|
|
|
88
92
|
});
|
|
89
93
|
} else if (
|
|
90
94
|
typeArguments.params.length !== 2 ||
|
|
95
|
+
// @ts-ignore Argument of type 'TypeNode' is not assignable to parameter of type 'Node | Token | undefined'.
|
|
91
96
|
sourceCode.getText(typeArguments.params[0]) !==
|
|
92
97
|
`typeof import(${secondArgText})` ||
|
|
98
|
+
// @ts-ignore Argument of type 'TypeNode' is not assignable to parameter of type 'Node | Token | undefined'.
|
|
93
99
|
sourceCode.getText(typeArguments.params[1]) !==
|
|
94
100
|
`typeof import(${thirdArgText})`
|
|
95
101
|
) {
|
|
@@ -47,6 +47,7 @@ const rule = createRule<Options, keyof typeof messages>({
|
|
|
47
47
|
importCondVariables.add(node.id.name);
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
50
51
|
'Program:exit'(_node) {
|
|
51
52
|
// Check if any named export references a tracked variable
|
|
52
53
|
for (const exportStatement of namedExportStatements) {
|
package/test/utils.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as mocha from 'mocha';
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2
3
|
import tseslint from 'typescript-eslint';
|
|
3
4
|
import {RuleTester} from '@typescript-eslint/rule-tester';
|
|
4
|
-
import path from 'node:path';
|
|
5
5
|
|
|
6
6
|
RuleTester.afterAll = mocha.after;
|
|
7
7
|
|