-
Notifications
You must be signed in to change notification settings - Fork 254
group JSDoc imports #10665
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
group JSDoc imports #10665
Conversation
Deploying agoric-sdk with
|
| Latest commit: |
9f7af83
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://d3c8bc43.agoric-sdk.pages.dev |
| Branch Preview URL: | https://ta-eslint-plugin.agoric-sdk.pages.dev |
b4a8a4f to
f041d17
Compare
closes: #XXXX refs: #11173 #10665 ## Description We have two styles of type import in our js/jsdoc code. - at each point of use ```js @param {import('@agoric/base-zone').Zone} issuerZone ``` - once per module ```js @import {Zone} from '@agoric/base-zone'; ``` followed by using the simple name at each point of use ```js @import {Zone} from '@agoric/base-zone'; ``` We have not yet discussed this, so I am not yet proposing that we adopt one style over the other. However, for code that I'm editing, particularly when I need to think about these jsdoc-imported types, I find the "once per module style" easier to read and think about. It factors out into the header of the module all the inter-module type dependencies. Thus, for such modules, I "correct" these when I notice them. I noticed the ones in this PR while working on #11173. In addition, while I was at it, I also removed some unused type declarations and added in some missing ones. This should all be a pure refactoring. None should have observable runtime effect. - [x] file issues for actually resolving these as company-wide styles, and "enforce" them with additional lint rules. - At #11243 (comment) below, @turadg explains that he's already in progress on this at #10665 . With this, I do not expect any controversy on adopting this as a company-wide style rule, so am checking this box. Unfortunately, we need to go in the other direction, doing type imports at the point of use, in *.d.ts modules. See the comment at the top of packages/vats/src/core/types-ambient.d.ts ```js // Ambient type defs. Cannot use top-level import() because that would turn it into a module. ``` - [ ] Is there some way to factor out type imports in *.d.ts modules? ### Security Considerations Improvements in code understanding helps security. Especially about inter-package and inter-module dependencies. ### Scaling Considerations none ### Documentation Considerations - [ ] See what effects these changes have on the jsdoc-generated documentation ### Testing Considerations None ### Upgrade Considerations In addition to purely static type refactoring, this PR makes some runtime changes - It omits `makeMintAndIssuer` because this seems globally unused. - [x] We could instead deprecate it in this PR and only remove it later once we're really confident no one uses it. - We are proceeding with this deleted.
9f7af83 to
9305ae1
Compare
_unplanned_ ## Description #10665 has been around a while and I thought it would be good to land a custom eslint-plugin so we could add rules more easily. This implements a simple rule to fix type imports that are done using `@typedef` because those create new types, breaking the type nav and documentation available on hover. ### Security Considerations none ### Scaling Considerations none ### Documentation Considerations There's one reason to disable the rule, which is documented and demonstrated. ### Testing Considerations CI ### Upgrade Considerations n/a
404be7c to
9ab5015
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements a new ESLint rule @agoric/group-jsdoc-imports that automatically moves inline JSDoc type imports (e.g., @type {import('@agoric/casting').FollowerOptions}) into a top-level JSDoc @import block, then references them by name (e.g., @type {FollowerOptions}). The rule is enabled at the warn level to allow autofixing, and the PR applies this autofix across the entire codebase.
Reviewed Changes
Copilot reviewed 300 out of 405 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/eslint-plugin/src/rules/group-jsdoc-imports.js | Implements the new ESLint rule for grouping JSDoc imports |
| packages/eslint-plugin/tests/rules/group-jsdoc-imports.test.js | Adds comprehensive tests for the new rule |
| packages/eslint-plugin/src/index.js | Registers the new rule and enables it in recommended config |
| packages/vats/src/core/demoIssuers.js | Applies the autofix to group JSDoc imports |
| packages/vat-data/src/exo-utils.js | Applies the autofix to group JSDoc imports |
| Multiple other files | Applies the autofix pattern across the codebase |
mhofman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change request is for the .ts files, which shouldn't get JSDoc comments. I suspect one case is a pre-existing incorrect @satisfies JSDoc, the other is for a @see which I'm not sure what the correct approach should be. In general, should this rule simply not apply to .ts files?
I am also concerned that using @import in files that declare ambient types will cause breakage, at least when .d.ts are generated and published.
Also, is there a rule to avoid duplicate @import comments with the same specifier? This seems to have created quite a few of those, and in general, I'd really like if we could lint to group multiple imports from the same file into a single directive. Not a blocker though.
_hygiene_ ## Description This one got stale, - #11879 But we can at least cut out some tests and the obsolete CLI commands. That should help CI some and also reduce maintenance costs. E.g. for, - #10665 ### Security Considerations none ### Scaling Considerations none ### Documentation Considerations none ### Testing Considerations CI ### Upgrade Considerations No on-chain changes. Tests are of chain code that has been taken out of service.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR highlighted some preexisting typeof problems. I ended up opening #12202 based on this to address. Feel free to incorporate in this PR, or land it after,
is there a rule to avoid duplicate
@importcomments with the same specifier? This seems to have created quite a few of those, and in general, I'd really like if we could lint to group multiple imports from the same file into a single directive.
I created #12203 for a possible follow up. This should probably be a separate rule anyway.
| * @param {Baggage} baggage | ||
| * @param {ZCF} zcf | ||
| * @param {MakeRecorderKit} makeRecorderKit | ||
| * @param {import('@agoric/zoe/src/contractSupport/recorder.js').MakeRecorderKit} makeRecorderKit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why keep/revert to inline import() here?
| */ | ||
| /** | ||
| * @import {SnapStoreInternal} from './snapStore.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, why place the @import in this block and not the other block that already contains an @import ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just expedient
| /** | ||
| * @import {SwingStoreInternal} from './internal.js'; | ||
| * @import {ArtifactMode} from './internal.js'; | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little strange to see the @import after the usage. I suspect because there is no preamble in this file?
| * @import {SlogSender} from '@agoric/telemetry'; | ||
| * @import {VatWarehousePolicy} from '../types-external.js'; | ||
| * @import {spawn} from 'child_process'; | ||
| * @import {makeXsnapBundleData} from './bundle-handler.js'; | ||
| * @import {BundleHandler} from './bundle-handler.js'; | ||
| * @import {default} from '../kernel/kernel.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, why revert these and go back to inline import?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the default doesn't work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting that default is a problem with @import.
Why revert the other imports?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to save time making line edits vs reverting on the CLI. this is a super lower priority project.
packages/inter-protocol/test/smartWallet/oracle-integration.test.js
Outdated
Show resolved
Hide resolved
refs: #10665 ## Description Reviewing #10665 made me realize we have a lot of broken type declarations using runtime values without `typeof`. These technically resolve to `any`, but sometimes tsc is smart enough to make the `typeof` implicit. It's hard to tell since we're not running tsc in strict mode (aka with implicit any allowed). This is mostly the result of a quick grep, and manual review, so I expect I missed some cases. ### Security Considerations None ### Scaling Considerations None ### Documentation Considerations None ### Testing Considerations I expect existing tests to keep passing. I haven't checked coverage before/after. ### Upgrade Considerations None
refs: #10665 Reviewing #10665 made me realize we have a lot of broken type declarations using runtime values without `typeof`. These technically resolve to `any`, but sometimes tsc is smart enough to make the `typeof` implicit. It's hard to tell since we're not running tsc in strict mode (aka with implicit any allowed). This is mostly the result of a quick grep, and manual review, so I expect I missed some cases. None None None I expect existing tests to keep passing. I haven't checked coverage before/after. None
9147722 to
027a93f
Compare
refs: #10665 Reviewing #10665 made me realize we have a lot of broken type declarations using runtime values without `typeof`. These technically resolve to `any`, but sometimes tsc is smart enough to make the `typeof` implicit. It's hard to tell since we're not running tsc in strict mode (aka with implicit any allowed). This is mostly the result of a quick grep, and manual review, so I expect I missed some cases. None None None I expect existing tests to keep passing. I haven't checked coverage before/after. None
027a93f to
d25bc69
Compare
|
It seems the latest changes re-introduced |
either ambients or the autofix doesn't work well
refs: #10665 Reviewing #10665 made me realize we have a lot of broken type declarations using runtime values without `typeof`. These technically resolve to `any`, but sometimes tsc is smart enough to make the `typeof` implicit. It's hard to tell since we're not running tsc in strict mode (aka with implicit any allowed). This is mostly the result of a quick grep, and manual review, so I expect I missed some cases. None None None I expect existing tests to keep passing. I haven't checked coverage before/after. None
d25bc69 to
fefed2c
Compare
refs: #10665 Reviewing #10665 made me realize we have a lot of broken type declarations using runtime values without `typeof`. These technically resolve to `any`, but sometimes tsc is smart enough to make the `typeof` implicit. It's hard to tell since we're not running tsc in strict mode (aka with implicit any allowed). This is mostly the result of a quick grep, and manual review, so I expect I missed some cases. None None None I expect existing tests to keep passing. I haven't checked coverage before/after. None
fefed2c to
24c2b95
Compare
part of #9005
Description
This adds a new rule
@agoric/group-jsdoc-importsand enables it atwarnlevel. That allows it to be autofixed, which this also does over the codebase. Then a few commits to clean things up.Security Considerations
n/a
Scaling Considerations
n/a
Documentation Considerations
Devs may see some warnings. They are pretty well explained
Testing Considerations
CI
Upgrade Considerations
n/a