Skip to content

Commit

Permalink
Fix CSV creation (#67)
Browse files Browse the repository at this point in the history
* fix csv creation; add basic csv test

* Changes

* fix issue: program.getResolvedModule can be undefined

---------

Co-authored-by: Ben Polinsky <ben-polinsky@users.noreply.github.com>
  • Loading branch information
ben-polinsky and ben-polinsky committed May 7, 2024
1 parent 8d7d517 commit 55b81ba
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 12 deletions.
4 changes: 1 addition & 3 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix csv output generation",
"packageName": "@itwin/eslint-plugin",
"email": "ben-polinsky@users.noreply.github.com",
"dependentChangeType": "patch"
}
2 changes: 1 addition & 1 deletion dist/rules/no-internal-barrel-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ const rule = {
program.getResolvedModule(
sourceFile,
moduleSpecifierText
).resolvedModule;
)?.resolvedModule;
}

if (typeof node.source.value !== "string")
Expand Down
13 changes: 5 additions & 8 deletions dist/rules/public-extension-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
Empty file added lib/.gitkeep
Empty file.
16 changes: 16 additions & 0 deletions tests/public-extension-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 55b81ba

Please sign in to comment.