From 55b81ba2c366205e468dffdd4cc5504064c5df98 Mon Sep 17 00:00:00 2001 From: Ben Polinsky <78756012+ben-polinsky@users.noreply.github.com> Date: Tue, 7 May 2024 16:47:19 -0400 Subject: [PATCH] Fix CSV creation (#67) * fix csv creation; add basic csv test * Changes * fix issue: program.getResolvedModule can be undefined --------- Co-authored-by: Ben Polinsky --- .github/CODEOWNERS | 4 +--- .gitignore | 3 +++ ...gin-bb1fb98c-b50a-4871-b228-aa0aad43691e.json | 7 +++++++ dist/rules/no-internal-barrel-imports.js | 2 +- dist/rules/public-extension-exports.js | 13 +++++-------- lib/.gitkeep | 0 tests/public-extension-exports.js | 16 ++++++++++++++++ 7 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 change/@itwin-eslint-plugin-bb1fb98c-b50a-4871-b228-aa0aad43691e.json create mode 100644 lib/.gitkeep diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 9a14699..aabd131 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -9,6 +9,4 @@ # review when someone opens a pull request. # Assign ownership of the entire repository to -* @paulius-valiunas @MichaelBelousov @ben-polinsky @aruniverse - - +* @paulius-valiunas @ben-polinsky @aruniverse @anmolshres98 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 8c8619c..cf5a742 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ package-lock.json # Mac specfic **/.DS_Store + +# tests - when testing for csv output, we write the actual file because we cannot mock in eslint tests +lib/*.csv diff --git a/change/@itwin-eslint-plugin-bb1fb98c-b50a-4871-b228-aa0aad43691e.json b/change/@itwin-eslint-plugin-bb1fb98c-b50a-4871-b228-aa0aad43691e.json new file mode 100644 index 0000000..a023c7f --- /dev/null +++ b/change/@itwin-eslint-plugin-bb1fb98c-b50a-4871-b228-aa0aad43691e.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "fix csv output generation", + "packageName": "@itwin/eslint-plugin", + "email": "ben-polinsky@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/dist/rules/no-internal-barrel-imports.js b/dist/rules/no-internal-barrel-imports.js index b497377..77fbf8c 100644 --- a/dist/rules/no-internal-barrel-imports.js +++ b/dist/rules/no-internal-barrel-imports.js @@ -156,7 +156,7 @@ const rule = { program.getResolvedModule( sourceFile, moduleSpecifierText - ).resolvedModule; + )?.resolvedModule; } if (typeof node.source.value !== "string") diff --git a/dist/rules/public-extension-exports.js b/dist/rules/public-extension-exports.js index 629d7f7..6bb3ca3 100644 --- a/dist/rules/public-extension-exports.js +++ b/dist/rules/public-extension-exports.js @@ -86,16 +86,12 @@ module.exports = { } } - function addToApiList(declaration, tags) { + function addToApiList(declaration) { if (!outputApiFile) { return; } - const validReleaseTag = tags.find((tag) => - releaseTags.includes(tag.tagName.escapedText) - ); - const createCsvString = (name, kind) => - `${name},${kind},${validReleaseTag}\n`; + const createCsvString = (name, kind) => `${name},${kind},Public\n`; const names = declaration.kind === ts.SyntaxKind.VariableStatement @@ -184,12 +180,13 @@ module.exports = { }; if (hasExtensionTag) { - addToApiList(declaration, tags); - if (!hasPublicTag) + if (!hasPublicTag) { context.report({ ...commonReport, messageId: "missingExtensionReleaseTag", }); + } + addToApiList(declaration); return true; } return false; diff --git a/lib/.gitkeep b/lib/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/public-extension-exports.js b/tests/public-extension-exports.js index e22578b..d84c7c1 100644 --- a/tests/public-extension-exports.js +++ b/tests/public-extension-exports.js @@ -91,6 +91,22 @@ tester.run("public-extension-exports", PublicExtensionsExports, { } `, }, + /** + * CSV Output: + * NOTE: There's not a great way to test this programmatically from within the eslint test runner. + * Please check that the lib/GeneratedExtensionApi.csv file is created and contains the expected data after your test runs. + */ + { + code: ` + /** + * @extensions + * @public + */ + export function destroyAllIModels(): void{ + } + `, + options: [{ outputApiFile: true }], + }, ], invalid: [ // extensions require public tag.