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): [padding-line-between-statements] make function overloading is also processed #4345

Conversation

lonyele
Copy link
Contributor

@lonyele lonyele commented Dec 25, 2021

PR Checklist

Overview

Problem

normal function overloading was not processed at all because TSDeclareFunction was not called at all. Cases such as below should have made error that there is a blank space expected

options: [{ blankLine: 'always', prev: '*', next: 'block-like' }],

function bar(arg: number): number;
function bar(arg: string | number) {
  return arg;
}

What I did

  1. make TSDeclareFunction is also processed.
  2. I added test case for already working export function overloading case

Context

I may be wrong because as I think more about it new approaches showing up but let's give it a shot

Issue provided 3 cases

options: [{ blankLine: 'always', prev: '*', next: 'block-like' }],

Case - 1 (error. Not expected)
export function bar(arg: number): number;
export function bar(arg: string | number) {
  return arg;
}

Case - 2 (no error, Expected)
function bar(arg: number): number;
function bar(arg: string | number) {
  return arg;
}

Case - 3 (no error, Expected)
class Foo {
  bar(arg: number): number;
  bar(arg: string | number) {
    return arg;
  }
}

  • Case 1 is WAI,
    because block-like(curly brace at last token) and * are matched thus rule applies. To make this work like issue is saying, I think this option can override the option with block-like
options: [
  { blankLine: 'always', prev: '*', next: 'block-like' },
  { blankLine: 'never', prev: '*', next: 'export' }
]
  • Case 2 should have errored.
    But It wasn't because TSDeclareFunction was ignored for this rule. This PR fixes it. This option can be used to work as issuer intended
options: [
  { blankLine: 'always', prev: '*', next: 'block-like' },
  { blankLine: 'never', prev: '*', next: 'function' }
]
  • Case 3 is not related to this rule?
    I found this lines-between-class-members rule and it is the one that is taking care of the lines inside of class

@nx-cloud
Copy link

nx-cloud bot commented Dec 25, 2021

☁️ Nx Cloud Report

CI ran the following commands for commit d6f38f1. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 44 targets

Sent with 💌 from NxCloud.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @lonyele!

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. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day.

@netlify
Copy link

netlify bot commented Dec 25, 2021

❌ Deploy Preview for typescript-eslint failed.

🔨 Explore the source changes: d6f38f1

🔍 Inspect the deploy log: https://app.netlify.com/sites/typescript-eslint/deploys/61c6f4ef126b8a0007a6b806

@codecov
Copy link

codecov bot commented Dec 25, 2021

Codecov Report

Merging #4345 (d6f38f1) into main (bade083) will increase coverage by 0.31%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main    #4345      +/-   ##
==========================================
+ Coverage   93.88%   94.20%   +0.31%     
==========================================
  Files         297      152     -145     
  Lines       11179     8104    -3075     
  Branches     3246     2592     -654     
==========================================
- Hits        10495     7634    -2861     
+ Misses        416      266     -150     
+ Partials      268      204      -64     
Flag Coverage Δ
unittest 94.20% <ø> (+0.31%) ⬆️

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

Impacted Files Coverage Δ
...lugin/src/rules/padding-line-between-statements.ts 93.83% <ø> (ø)
packages/scope-manager/src/lib/webworker.ts
packages/scope-manager/src/lib/es2015.symbol.ts
...e-manager/src/definition/FunctionNameDefinition.ts
...es/scope-manager/src/scope/ConditionalTypeScope.ts
packages/scope-manager/src/referencer/index.ts
...kages/scope-manager/src/referencer/ClassVisitor.ts
...ges/scope-manager/src/referencer/PatternVisitor.ts
packages/scope-manager/src/lib/es2015.generator.ts
packages/scope-manager/src/lib/es2019.symbol.ts
... and 136 more

@bradzacher bradzacher added the bug Something isn't working label Dec 26, 2021
Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

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

thanks for this!

@bradzacher bradzacher merged commit d31ec26 into typescript-eslint:main Dec 27, 2021
@lonyele lonyele deleted the fix/make-function-overloading-working branch December 27, 2021 09:00
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[padding-line-between-statements] wrong blank line in overloaded exported functions
2 participants