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

refactor(semantic/jsdoc): JSDocTag parser rework #2765

Merged
merged 14 commits into from
Mar 22, 2024
Merged

Conversation

leaysgur
Copy link
Contributor

@leaysgur leaysgur commented Mar 19, 2024

Address #2642 (comment)

// Initially, I attempted to parse into specific structures such as:
// - `@param {type} name comment`: `JSDocParameterTag { type, name, comment }`
// - `@returns {type} comment`: `JSDocReturnsTag { type, comment }`
// - `@whatever comment`: `JSDocUnknownTag { comment }`
// - etc...
//
// However, I discovered that some use cases, like `eslint-plugin-jsdoc`, provide an option to create an alias for the tag kind.
// .e.g. Preferring `@foo` instead of `@param`
//
// This means that:
// - We cannot parse a tag exactly as it was written
// - We cannot assume that `@param` will always map to `JSDocParameterTag`
//
// Therefore, I decided to provide a generic structure with helper methods to parse the tag according to the needs.
//
// I also considered providing an API with methods like `as_param() -> JSDocParameterTag` or `as_return() -> JSDocReturnTag`, etc.
//
// However:
// - There are many kinds of tags, but most of them have a similar structure
// - JSDoc is not a strict format; it's just a comment
// - Users can invent their own tags like `@whatever {type}` and may want to parse its type
//
// As a result, I ended up providing helper methods that are fit for purpose.

@github-actions github-actions bot added the A-semantic Area - Semantic label Mar 19, 2024
Copy link

codspeed-hq bot commented Mar 19, 2024

CodSpeed Performance Report

Merging #2765 will improve performances by 3.01%

Comparing jsdoc_tag-rework (0fd67cb) with main (3c9e77d)

Summary

⚡ 1 improvements
✅ 33 untouched benchmarks

Benchmarks breakdown

Benchmark main jsdoc_tag-rework Change
parser_napi[pdf.mjs] 76.5 ms 74.3 ms +3.01%

@leaysgur leaysgur marked this pull request as ready for review March 21, 2024 03:51
Copy link
Member

@Boshen Boshen left a comment

Choose a reason for hiding this comment

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

Thank you!

@Boshen Boshen merged commit 4a42c5f into main Mar 22, 2024
31 checks passed
@Boshen Boshen deleted the jsdoc_tag-rework branch March 22, 2024 16:17
Boshen pushed a commit that referenced this pull request Apr 4, 2024
Part of #1170, Finally... 🗻 

Some preparation PRs may be needed in advance.

- [x] settings.jsdoc #2706 
- [x] new struct design #2765
- [x] handle `Span` for diagnostics #2815

Implement plugin itself.

-
https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/check-access.md
-
https://github.com/gajus/eslint-plugin-jsdoc/blob/main/src/rules/checkAccess.js

I'll send a PR to make this plugin public after confirming that a few
more rules can be implemented without any problems.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-semantic Area - Semantic
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants