Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC for JSDoc extraction #182

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions extract.js
@@ -0,0 +1,16 @@
import {Project} from 'ts-morph';

const project = new Project({
tsConfigFilePath: 'tsconfig.json',
});
const testSourceFiles = project.getSourceFile('index.ts');
for (const tag of testSourceFiles.getSymbol('isRepo').getExport('isRepo').getJsDocTags()) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given testSourceFiles.getSymbol('isRepo').getExport('isRepo'), I can't reach the FunctionDeclaration to then call addJsDoc 🤷‍♂️

I knew function expressions were a mistake, I think testSourceFiles.getExportDeclaration('isRepo') would have gotten me there.

if (tag.getName() !== 'example') {
continue;
}

const contents = tag.getText().at(0).text;
if (contents.startsWith('http')) {
console.log(contents);
}
}
4 changes: 4 additions & 0 deletions index.ts
Expand Up @@ -344,6 +344,10 @@ addTests('isEditingWikiPage', [
export const hasWikiPageEditor = (url: URL | HTMLAnchorElement | Location = location): boolean => isEditingWikiPage(url) || isNewWikiPage(url);
addTests('hasWikiPageEditor', combinedTestOnly);

/**
* @example https://github.com/sindresorhus/refined-github/blame/master/package.json
* @example https://github.com/sindresorhus/notifications/
*/
export const isRepo = (url: URL | HTMLAnchorElement | Location = location): boolean => /^[^/]+\/[^/]+/.test(getCleanPathname(url))
&& !reservedNames.includes(url.pathname.split('/', 2)[1]!)
&& !isDashboard(url)
Expand Down
74 changes: 74 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -80,6 +80,7 @@
"strip-indent": "^4.0.0",
"svelte": "^4.1.2",
"svelte-check": "^3.4.6",
"ts-morph": "^19.0.0",
"typescript": "^5.1.6",
"vite": "^4.4.7",
"xo": "^0.55.0"
Expand Down