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

feat(eslint-plugin): [no-import-type-side-effects] add rule to warn against runtime side effects with verbatimModuleSyntax #6394

Merged
merged 7 commits into from Feb 1, 2023

Conversation

bradzacher
Copy link
Member

PR Checklist

Overview

Pretty straight-forward rule to implement with a fixer.

@bradzacher bradzacher added the enhancement: new plugin rule New rule request for eslint-plugin label Jan 31, 2023
@typescript-eslint
Copy link
Contributor

Thanks for the PR, @bradzacher!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint.

@nx-cloud
Copy link

nx-cloud bot commented Jan 31, 2023

☁️ Nx Cloud Report

CI is running/has finished running commands for commit da7b02f. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 47 targets

Sent with 💌 from NxCloud.

@netlify
Copy link

netlify bot commented Jan 31, 2023

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit da7b02f
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/63d9e9a66f25590008200914
😎 Deploy Preview https://deploy-preview-6394--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@codecov
Copy link

codecov bot commented Jan 31, 2023

Codecov Report

Merging #6394 (da7b02f) into main (202d9fb) will increase coverage by 0.15%.
The diff coverage is 91.66%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6394      +/-   ##
==========================================
+ Coverage   91.37%   91.52%   +0.15%     
==========================================
  Files         368      371       +3     
  Lines       12596    12649      +53     
  Branches     3709     3714       +5     
==========================================
+ Hits        11509    11577      +68     
+ Misses        772      755      -17     
- Partials      315      317       +2     
Flag Coverage Δ
unittest 91.52% <91.66%> (+0.15%) ⬆️

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

Impacted Files Coverage Δ
packages/utils/src/ts-eslint/SourceCode.ts 50.00% <ø> (ø)
packages/utils/src/ast-utils/predicates.ts 51.02% <50.00%> (-0.10%) ⬇️
...eslint-plugin/src/rules/consistent-type-imports.ts 94.50% <100.00%> (-0.04%) ⬇️
...nt-plugin/src/rules/no-import-type-side-effects.ts 100.00% <100.00%> (ø)
...ges/typescript-estree/src/create-program/shared.ts 80.43% <0.00%> (-2.90%) ⬇️
...s/eslint-plugin/src/rules/prefer-optional-chain.ts 97.50% <0.00%> (-1.18%) ⬇️
packages/eslint-plugin/src/util/misc.ts 97.01% <0.00%> (ø)
packages/eslint-plugin/src/rules/prefer-for-of.ts 91.42% <0.00%> (ø)
...ges/scope-manager/src/referencer/PatternVisitor.ts 68.29% <0.00%> (ø)
...es/eslint-plugin/src/rules/prefer-function-type.ts 97.18% <0.00%> (ø)
... and 7 more

Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Great! Nothing blocking from me, only suggestions (and most of them teeny nitpicks). ✨

@bradzacher bradzacher changed the title feat(eslint-plugin): add rule to warn against runtime side effects with verbatimModuleSyntax feat(eslint-plugin): [no-type-imports-with-verbatim-side-effects] add rule to warn against runtime side effects with verbatimModuleSyntax Jan 31, 2023
Co-authored-by: Josh Goldberg <git@joshuakgoldberg.com>
(cherry picked from commit 3848375)
@bradzacher bradzacher force-pushed the 6382-rule-against-inline-type-specifiers branch from 3848375 to 3162d56 Compare February 1, 2023 02:33
@bradzacher bradzacher changed the title feat(eslint-plugin): [no-type-imports-with-verbatim-side-effects] add rule to warn against runtime side effects with verbatimModuleSyntax feat(eslint-plugin): [no-import-type-side-effects] add rule to warn against runtime side effects with verbatimModuleSyntax Feb 1, 2023
@bradzacher bradzacher merged commit b14d3be into main Feb 1, 2023
@bradzacher bradzacher deleted the 6382-rule-against-inline-type-specifiers branch February 1, 2023 04:42
@bradzacher
Copy link
Member Author

cc @DanielRosenwasser / @andrewbranch
This rule will be released next Monday.

@andrewbranch
Copy link

Awesome, thank you!

@thenbe
Copy link

thenbe commented Feb 7, 2023

Hi. Just wondering if the following behavior in this new rule is intentional or working as intended. Currently, it's flagging all side-effect imports. Meanwhile, the docs describe the rule as:

Enforce the use of top-level import type qualifier when an import only has specifiers with inline type qualifiers

It doesn't say anything about imports that have neither top-level nor inline type specifiers, such as side-effect imports.

If this is intentional, and this rule does act on side-effect imports, should we mention that in the docs? Else, would it make sense for this rule to have an option to not act on side-effect imports? Or is explicitly ignoring this rule for every instance the recommended approach?

Repro: https://stackblitz.com/edit/repro-side-effect-lint?file=README.md

@JoshuaKGoldberg
Copy link
Member

@ambiguous48 please file an issue using one of our issue templates (I'm guessing 🐛 Report a Bug With a Rule). That'll help us address it more quickly, spotlight any missing info, and help us track which version(s) bugs & fixes appear in. Thanks!

@JoshuaKGoldberg
Copy link
Member

Ah, someone already did! #6431

Which is another point in favor of using the templates. They have useful links around searching for duplicate issues.

@bradzacher
Copy link
Member Author

Yup - as per our contributing guide, comments on closed PRs are not the way to ask questions or report bugs.

https://typescript-eslint.io/contributing/issues#commenting

As Josh pointed out - this bug has already been reported.

@typescript-eslint typescript-eslint locked and limited conversation to collaborators Feb 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: new plugin rule New rule request for eslint-plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule proposal: warn against import declarations with no value specifiers and only inline type specifiers
4 participants