Skip to content

Conversation

@turadg
Copy link
Member

@turadg turadg commented Sep 17, 2025

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

@turadg turadg requested review from erights and kriskowal September 17, 2025 22:02
@turadg turadg requested a review from a team as a code owner September 17, 2025 22:02
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Sep 17, 2025

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0395b45
Status: ✅  Deploy successful!
Preview URL: https://97b94ebd.agoric-sdk.pages.dev
Branch Preview URL: https://ta-eslint-typedef-imports.agoric-sdk.pages.dev

View logs

Copy link
Member

@erights erights left a comment

Choose a reason for hiding this comment

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

LGTM with the following caveats, so I'll leave it to @kriskowal to approve. @kriskowal , feel free to approve after reviewing only my caveats since I really do approve the rest

There's one reason to disable the rule, which is documented and demonstrated

  • I saw one file disabling the rule, which puzzled me and which I commented on. Where do I find the reason to disable the rule? Is it somewhere others are likely to find?
  • I don't know enough about the internals of eslint to confidently review the code of no-typedef-import.js. I am confident I understand what this code is trying to achieve, which LGTM. I'm just not yet confident in the implementation. (Btw, I sure wish long JS regexps were easier to read and review, but I do not suggest any changes to your code because of this.)

@@ -1,3 +1,4 @@
/* eslint-disable @agoric/no-typedef-import -- it's the only way to re-export with JSDoc */
Copy link
Member

Choose a reason for hiding this comment

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

Skimming, mostly I see imports without typedefs and typedefs without imports. I do some combinations like

 * @typedef { import('@agoric/swingset-liveslots').VatDeliveryObject } VatDeliveryObject
 * @typedef { import('@agoric/swingset-liveslots').VatDeliveryResult } VatDeliveryResult
 * @typedef { import('@agoric/swingset-liveslots').VatSyscallObject } VatSyscallObject
 * @typedef { import('@agoric/swingset-liveslots').VatSyscallResult } VatSyscallResult

But why do we want to preserve that form rather than applying your fix? AFAICT, your fix would work, be meaning preserving, and be as much of an improvement here as it is where you do apply it.

Copy link
Member

Choose a reason for hiding this comment

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

See #11949 (comment) below

Copy link
Member Author

Choose a reason for hiding this comment

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

"it's the only way to re-export with JSDoc"

Could you explain this? Why do these lines uniquely suffer from this problem?

These lines are here because other modules import the above types from this module.

In .ts files we'd just use export but there's nothing like that for JSDoc because this issue is open,

In practice I think it's fine to have this rule and expect that type rollups in .js files will reduce over time.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation. No objections.

"clean": "rm -rf xsnap-native/xsnap/build",
"lint": "yarn run -T run-s --continue-on-error 'lint:*'",
"lint:js": "eslint 'src/**/*.js' 'test/**/*.js' api.js",
"lint:eslint": "yarn run -T eslint 'src/**/*.js' 'test/**/*.js' api.js",
Copy link
Member

Choose a reason for hiding this comment

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

Why the change from lint:js to lint:eslint? I don't mind the change, but I am curious.

Copy link
Member Author

@turadg turadg Sep 17, 2025

Choose a reason for hiding this comment

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

the :eslint is for consistency with other packages. the yarn run -T is so the command can be run from CLI (rather tha only by run-s 'lint:*')

Copy link
Member

Choose a reason for hiding this comment

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

Good, thanks.

@erights
Copy link
Member

erights commented Sep 17, 2025

Ah. To answer my own question, I do see

"it's the only way to re-export with JSDoc"

Could you explain this? Why do these lines uniquely suffer from this problem?

if (node.name.includes('$')) {
context.report({
node,
message: 'Avoid using $ in identifiers',
Copy link
Member

Choose a reason for hiding this comment

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

Is the dollar-sign avoidance an orthogonal improvement, or are these somehow coupled?

Copy link
Member Author

Choose a reason for hiding this comment

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

it was part of the scaffold. a subsequent commit removed it

@erights
Copy link
Member

erights commented Sep 17, 2025

unplanned

Curious: why? With this PR, all the hard and time consuming work is already behind you, and the readability benefit is huge.

Separately, any reason we should not lift this and apply directly to the endo repo?

@turadg
Copy link
Member Author

turadg commented Sep 17, 2025

unplanned

Curious: why? With this PR, all the hard and time consuming work is already behind you, and the readability benefit is huge.

I just meant that it didn't have an issue and wasn't in any schedule. I intend to merge it once approved.

Separately, any reason we should not lift this and apply directly to the endo repo?

I don't object to someone doing that.

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.

3 participants