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

feat(tools): add import path check in docs #2820

Merged
merged 26 commits into from
Nov 1, 2022

Conversation

schwarzkopfb
Copy link
Contributor

Add tool to check import paths in JSDoc comments and readme files across std to help standardize them as suggested in #2772. Enforcing that all imports in examples are from https://deno.land/std@$STD_VERSION/*

Screenshot 2022-10-28 at 3 55 10

@iuioiua
Copy link
Contributor

iuioiua commented Oct 28, 2022

Nice! I'm not a maintainer, but a few concerns:

  1. Is the CI step you were supposed to add be deno task lint:doc-imports instead of deno task lint:deprecations?
  2. Could walk() from std/fs replace your walk()?
  3. IMO, regex is fairly complex. Is there a simpler alternative?

@schwarzkopfb
Copy link
Contributor Author

@iuioiua Thanks for the great suggestions!

  1. that was a dumb mistake, thanks for catching it
  2. you're absolutely right, std's built-in walk() is perfectly fine and makes the code much cleaner
  3. I'll spend some time to think/experiment on how could that be simplified, probably there is room to cut off some parts of that

@schwarzkopfb
Copy link
Contributor Author

@iuioiua I came up with some changes based on your comments. WDYT?

@cjihrig
Copy link
Contributor

cjihrig commented Oct 28, 2022

This looks like something that will be nice to have. My only concerns are:

  • The complexity of the regular expressions if we need to do any maintenance on them. I'm not sure how much we can do about that though.
  • Since there is nothing to report in the codebase right now, I guess we just have to take your word for it that it works based on your screenshots 😄

@timreichen
Copy link
Contributor

  • The complexity of the regular expressions if we need to do any maintenance on them. I'm not sure how much we can do about that though.

I think the solution is to use a proper ast tree walker. That would also be great to establish for future tools.

The typescript module works for creating and walking ast trees, but there is also deno_ast, which is a rust mod but could (and imo should) be made runnable in deno scripts, like deno_doc is.

So the task could be done like so:
deno_doc: get jsdoc comments -> deno_ast: walk code from comments, find and verify imports, log warnings

@iuioiua
Copy link
Contributor

iuioiua commented Oct 29, 2022

@iuioiua I came up with some changes based on your comments. WDYT?

Looking better! However, I'm still wondering whether countChecked is needed...

@schwarzkopfb
Copy link
Contributor Author

schwarzkopfb commented Oct 29, 2022

@timreichen I implemented the AST-based approach using the typescript module. I think it's good for a first iteration until denoland/deno_ast#120 gets resolved. Later we can upgrade to the Rust-based, more performant AST generation subsystem.

@cjihrig I added some tests so we have a better proof than just my words for that it's working. 😀 On windows it's failing for some weird, file path related issue. I'll investigate that soon, but until then FIXED I'd appreciate any feedback on the implementation.

@iuioiua The counter is only used to display a message on exit which informs the user about that something happened, but no error raised in mora handy way than just exiting with 0 or a non-zero exit code. Just like deno fmt or deno lint does. Also can be useful when someone adjusts the EXCLUDE_PATHS and can easily see a stat on how many files included in the scan.

@iuioiua
Copy link
Contributor

iuioiua commented Oct 30, 2022

Also can be useful when someone adjusts the EXCLUDE_PATHS and can easily see a stat on how many files included in the scan.

In this case, seeing a change in the number of files justifies the existence of the variable, IMO. Well explained.

@iuioiua
Copy link
Contributor

iuioiua commented Oct 30, 2022

Would it perhaps be better to use Deno.spawn over Deno.run? That's where things are moving towards.

@schwarzkopfb
Copy link
Contributor Author

Would it perhaps be better to use Deno.spawn over Deno.run? That's where things are moving towards.

Great suggestion, makes it a bit less messy, applied. Thanks!

@schwarzkopfb
Copy link
Contributor Author

@timreichen FYI: I also made an experiment which is using deno_doc for jsDoc parsing that produced surprising results. It is orders of magnitude slower even with a smaller set of files to work with. And it breaks if I run the scan on the whole std repo. So for now I stick with the regexp for identifying comments and extracting code blocks from it and then using the AST generated by the TypeScript compiler to check import statements.

Screenshot 2022-10-30 at 11 10 12

Screenshot 2022-10-30 at 11 10 28

Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

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

LGTM

@cjihrig cjihrig merged commit bc544b7 into denoland:main Nov 1, 2022
@schwarzkopfb schwarzkopfb deleted the tools_doc_import_check branch November 1, 2022 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants