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

fix: Forbid self package import #1498

Closed

Conversation

bmingles
Copy link
Contributor

@bmingles bmingles commented Sep 8, 2023

  • Custom eslint rule to forbid importing from package name of package containing the module
  • Fixed offending SessionUtils

I tested this by running npm run test:lint. It showed expected linting error before fixing SessionUtils. Fixing SessionUtils made error go away. Also tested in vscode. Error shows up in the editor as expected.

fixes: #1497

@codecov
Copy link

codecov bot commented Sep 8, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.02% ⚠️

Comparison is base (02841b5) 45.77% compared to head (91182bb) 45.76%.
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1498      +/-   ##
==========================================
- Coverage   45.77%   45.76%   -0.02%     
==========================================
  Files         517      517              
  Lines       35116    35162      +46     
  Branches     8792     8802      +10     
==========================================
+ Hits        16076    16092      +16     
- Misses      18989    19019      +30     
  Partials       51       51              
Flag Coverage Δ
unit 45.76% <ø> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
packages/jsapi-utils/src/SessionUtils.ts 2.63% <ø> (ø)

... and 9 files with indirect coverage changes

☔ View full report in Codecov by Sentry.

📢 Have feedback on the report? Share it here.

Comment on lines +17 to +19
"devDependencies": {
"eslint-plugin-deephaven": "file:./plugin"
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like you don't need to do it this way. You can import the plugin directly

https://eslint.org/docs/latest/extend/custom-rule-tutorial#step-7-bundle-the-custom-rule-in-a-plugin

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This doesn't work if you try to add it to an array of plugins since the plugins array only supports string names. Granted the current config only has 1 plugin, this will be more future proof.

That said if you find a way to get it working alongside other plugins, I'd love to see how. I was not able to get it working.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bmingles bmingles requested a review from mattrunyon September 8, 2023 17:19
return null;
}

return `@deephaven/${packageFolderName}`;
Copy link
Member

Choose a reason for hiding this comment

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

One thing I'm not crazy about is this rule is not generic; even when we include this eslint config from Enterprise it won't technically be correct. We should also be using the path package to resolve paths rather than manipulating the string directly, as there's probably some edge cases you're missing here (e.g. what if I had Enterprise using this eslint config and it was in a folder like ~/deephaven/packages/app/..., then it would think the package name was @deephaven/app).
Getting the package name from the package.json should be doable, though I do also wonder about performance and how we can cache results (since this will be called on every import in every file, don't want to have to traverse and read package.json every time...). I'd rather check in the fix first without the eslint rule than check it in with specific @deephaven logic.

Copy link
Contributor Author

@bmingles bmingles Sep 8, 2023

Choose a reason for hiding this comment

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

@mofojed This "shouldn't" ever actually be used in enterprise since it doesn't really apply. It is currently consumed via the top level Community package so doesn't get pulled in with the shared config. It really is scoped to @deephaven community packages. Does this alleviate any of your concern?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm actually second guessing the approach of using this plugin now. Since it's not actually configured in the shared package and not really useful elsewhere, maybe the top level community config should be fully responsible for it. Would be easy to just get the list of packages and build a rule array there

@bmingles bmingles requested a review from mofojed September 8, 2023 18:00
@mofojed
Copy link
Member

mofojed commented Sep 8, 2023

Superceded by #1499

@mofojed mofojed closed this Sep 8, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Sep 8, 2023
@bmingles bmingles deleted the 1497-forbid-self-package-import branch September 8, 2023 19:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SessionUtils has a self package import from @deephaven/jsapi-utils
3 participants