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(eslint-plugin): [no-empty-interface] disable autofix for declaration merging with class #5920

Merged
merged 5 commits into from Nov 18, 2022

Conversation

yeonjuan
Copy link
Contributor

@yeonjuan yeonjuan commented Nov 2, 2022

PR Checklist

Overview

@nx-cloud
Copy link

nx-cloud bot commented Nov 2, 2022

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 1e4f021. 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 46 targets

Sent with 💌 from NxCloud.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @yeonjuan!

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.

@netlify
Copy link

netlify bot commented Nov 2, 2022

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 1e4f021
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/6377a8eeee47cf000944e738
😎 Deploy Preview https://deploy-preview-5920--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 Nov 2, 2022

Codecov Report

Merging #5920 (1e4f021) into main (7a10707) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5920   +/-   ##
=======================================
  Coverage   91.27%   91.28%           
=======================================
  Files         366      366           
  Lines       12348    12352    +4     
  Branches     3610     3612    +2     
=======================================
+ Hits        11271    11275    +4     
  Misses        768      768           
  Partials      309      309           
Flag Coverage Δ
unittest 91.28% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
...ages/eslint-plugin/src/rules/no-empty-interface.ts 100.00% <100.00%> (ø)

@yeonjuan yeonjuan marked this pull request as ready for review November 3, 2022 08:52
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 stuff, thanks for sending this in @yeonjuan! 🎊

Mostly requesting changes on getting more test coverage. Would be nice to see a bit of refactoring to reduce the lines of code too.

@@ -76,26 +77,41 @@ export default util.createRule<Options, MessageIds>({

// Check if interface is within ambient declaration
let useAutoFix = true;
let hasSuggest = true;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I found it confusing how the previous variable starts with use but this starts with has, even though they're pretty much the same thing. Can we make the names more similar?

Suggested change
let hasSuggest = true;
let useSuggestion = true;

Note: after applying the refactor I suggest later in the file, the variable might be unnecessary.

if (util.isDefinitionFile(filename)) {
const scope = context.getScope();
if (scope.type === 'tsModule' && scope.block.declare) {
Copy link
Member

Choose a reason for hiding this comment

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

[Nit] Now that the const scope = ... line is earlier, these two if statements can be combined:

if (
  util.isDefinitionFile(filename) &&
  scope.type === "tsModule" &&
  scope.block.declare
) {
  useAutoFix = false;
}

...so the code can be simplified a bit more, to give useAutoFix an initial value:

let useAutoFix = ...;

I would even suggest making a separate variable for whether it's merged with a class declaration:

const mergedWithClassDeclaration = scope.set
  .get(node.id.name)
  ?.defs?.some((def) => def.node.type === AST_NODE_TYPES.ClassDeclaration);

const useAutoFix =
  !mergedWithClassDeclaration && ...;

Thoughts?

@JoshuaKGoldberg JoshuaKGoldberg added the awaiting response Issues waiting for a reply from the OP or another party label Nov 15, 2022
@yeonjuan
Copy link
Contributor Author

@JoshuaKGoldberg Thanks for the review!. I fixed it and add some test cases

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.

Fantastic, thanks for iterating on this with me @yeonjuan! It looks great

@JoshuaKGoldberg JoshuaKGoldberg merged commit a4f85b8 into typescript-eslint:main Nov 18, 2022
40 checks passed
omril1 pushed a commit to omril1/typescript-eslint that referenced this pull request Nov 23, 2022
…ion merging with class (typescript-eslint#5920)

* fix(eslint-plugin): [no-empty-interface] disable autofix for declaration merging with class

* fix comment

* fix lint

* Apply review
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting response Issues waiting for a reply from the OP or another party
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: [no-empty-interface] autofix break typescript
2 participants