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

Add more precise types in the JSDoc #818

Merged
merged 6 commits into from
Sep 3, 2024
Merged

Conversation

stof
Copy link
Member

@stof stof commented Aug 3, 2020

These are the type improvements coming from my investigation in #816 (and then pushed until the end rather than stopping at a few methods for the experiment)

@stof
Copy link
Member Author

stof commented Aug 4, 2020

The failing tests seem unrelated to my PR. I'm changing only comments

@stof
Copy link
Member Author

stof commented Aug 4, 2020

hmm, looks like the jsdoc parser of eslint does not like the object types defining properties. And given that the valid-jsdoc rule is deprecated and the corresponding parser is unmaintained, it is unlikely to be fixed.

@Lyrkan @weaverryan should we disable that rule ?

@stof
Copy link
Member Author

stof commented Aug 4, 2020

Or maybe we should migrate to https://github.com/gajus/eslint-plugin-jsdoc

Copy link
Collaborator

@Lyrkan Lyrkan left a comment

Choose a reason for hiding this comment

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

Sorry for not looking at this sooner, those are some great changes :)

@Lyrkan @weaverryan should we disable that rule ?
Or maybe we should migrate to gajus/eslint-plugin-jsdoc

We could try gajus/eslint-plugin-jsdoc but I wouldn't mind disabling valid-jsdoc entirely either tbh.

@weaverryan weaverryan changed the base branch from master to main November 18, 2020 18:17
@weaverryan
Copy link
Member

My preference would be to remove our valid-jsdoc and try https://github.com/gajus/eslint-plugin-jsdoc - it looks high quality, and i do kinda like our very-complete (and validated with eslint) jsdoc.

@stof
Copy link
Member Author

stof commented Dec 3, 2020

@Lyrkan @weaverryan I made the migration to eslint-plugin-jsdoc (and I fixed all the extra things it reports, which were not detected by valid-jsdoc)

@stof
Copy link
Member Author

stof commented Dec 3, 2020

The failure for the job Lowest versions of the dependencies is unrelated to my change. that's also broken in the main branch.

@stof stof requested review from Lyrkan and weaverryan December 5, 2020 14:52
@Kocal
Copy link
Member

Kocal commented Aug 26, 2024

Hey, what about using TypeScript to check types?
No transpilation, just checking types on .js files with allowJs/checkJs options, some JSDoc, and tsc --noEmit?

@stof
Copy link
Member Author

stof commented Aug 30, 2024

@Kocal using typescript to check types on our own codebase could be a next step after that. But it would require having types defined properly for all our code, while this PR was focusing on what impacts our public API.
The goal was to allow downstream projects to use typescript to check types on their webpack.config.js file.

I should definitely revive that PR as it would be a nice addition.

@Kocal
Copy link
Member

Kocal commented Aug 30, 2024

@stof you're right, that makes sense.

I should definitely revive that PR as it would be a nice addition.

Totally! :)

@stof
Copy link
Member Author

stof commented Sep 2, 2024

I updated the PR (it will conflict with #1313 though).

I used object for the configuration in a bunch of cases to keep our types free from adding new dependencies (many of our features rely on optional dependencies, but the types of the main public API cannot). There's also a few of our dependencies that don't provide type declarations for their configuration (css-loader and style-loader for instance).

I also kept object for the configuration of SplitChunksPlugin because the types used for the options of this plugin are not exported. I was able to write a type that would work for type checking our project but would prevent using --emitDeclarationOnly due to the usage of private types (and so would block #816)

stof added 4 commits September 2, 2024 18:35
This documents the value type for arrays of strings in arguments.
webpack provides type definitions for their whole API, so we can
reference their type rather than specifying a generic "object" type.
Referencing the webpack types was already done for the returned
configuration.
Most of them are documented as receiving an object and returning an
object or void. But some callbacks dealing with parts of the webpack
configuration itself have a more precise type for the options object.
This brings the list of supported options in the type definitions with
their type, which lets IDEs provide autocompletion for them.
@stof stof requested review from Kocal and removed request for weaverryan and Lyrkan September 2, 2024 16:49
Copy link
Member

@Kocal Kocal left a comment

Choose a reason for hiding this comment

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

Wow 🤩

That's will definitely increase DX for end-users and for us, just a minor comment tho

@@ -16,13 +16,17 @@ const { fileURLToPath } = require('url');
/**
* Inlined version of the package "package-up" (ESM only).
*
* @param {string} cwd The directory to start searching from.
* @param {{cwd: string}} options The directory to start searching from.
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we keep the previous syntax? Here the description "The directory (...)" refers to the options object, and not to cwd right?

Or we can remove the description, since it's super internal, I don't really have a strong opinion on this.

Copy link
Member Author

Choose a reason for hiding this comment

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

The previous syntax describes a cwd argument which does not exist (there is a cwd property in the first argument instead).

Copy link
Member Author

Choose a reason for hiding this comment

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

I updated the JSDoc to use the alternative syntax allowing to put a description on properties (this was already used later in the file)

@stof stof merged commit 903aaa6 into symfony:main Sep 3, 2024
28 checks passed
@stof stof deleted the improve_js_doc branch September 3, 2024 08:21
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.

4 participants