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): [explicit-function-return-type] allow as const arrow functions #876

Merged
merged 3 commits into from Aug 19, 2019

Conversation

Zzzen
Copy link
Contributor

@Zzzen Zzzen commented Aug 18, 2019

add an option allowDirectConstAssertionInArrowFunctions to allow bodyless arrow functions which return as const.

closes #653

add an option `allowDirectConstAssertionInArrowFunctions` to allow bodyless arrow functions which return `as const`
@typescript-eslint
Copy link
Contributor

Thanks for the PR, @Zzzen!

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

@bradzacher bradzacher changed the title feat: [no-unnecessary-type-assertion] allow as const arrow functions feat: [explicit-function-return-type] allow as const arrow functions Aug 18, 2019
@bradzacher bradzacher changed the title feat: [explicit-function-return-type] allow as const arrow functions feat(eslint-plugin): [explicit-function-return-type] allow as const arrow functions Aug 18, 2019
@bradzacher bradzacher added the enhancement: plugin rule option New rule option for an existing eslint-plugin rule label Aug 18, 2019
Copy link
Member

@JamesHenry JamesHenry left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Copy link
Member

@JamesHenry JamesHenry left a comment

Choose a reason for hiding this comment

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

Actually, sorry might have changed my mind:

Currently in this PR:

This would be fine:

const foo = () => {
  return {
    bar: true
  } as const;
}

But this wouldn't:

function foo() {
  return {
    bar: true
  } as const;
}

This feels very arbitrary to me... Why do we want to limit this to ArrowFunctionExpressions?

cc @bradzacher as you did also explicitly mention arrow functions on the original issue

@Zzzen
Copy link
Contributor Author

Zzzen commented Aug 19, 2019

IMO, this is tricky.
if this one is fine,

function foo() {
  return {
    bar: true
  } as const;
}

should this one pass too?

function foo() {
  if (x) {
    return { bar: true } as const;
  } else {
    return { foo: true } as const;
  }
}

@JamesHenry
Copy link
Member

@Zzzen Apologies, I was actually incorrect with my previous comment:

const foo = () => {
  return {
    bar: true
  } as const;
}

This would not actually be ok with your PR, because the body would be a BlockStatement, so the PR is fine for what it is trying to achieve. Sorry for the confusion!

@codecov
Copy link

codecov bot commented Aug 19, 2019

Codecov Report

Merging #876 into master will increase coverage by 0.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master     #876      +/-   ##
==========================================
+ Coverage   94.16%   94.18%   +0.01%     
==========================================
  Files         113      113              
  Lines        4870     4882      +12     
  Branches     1355     1361       +6     
==========================================
+ Hits         4586     4598      +12     
  Misses        163      163              
  Partials      121      121
Impacted Files Coverage Δ
...-plugin/src/rules/explicit-function-return-type.ts 100% <100%> (ø) ⬆️

@JamesHenry JamesHenry merged commit 14c6f80 into typescript-eslint:master Aug 19, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[explicit-function-return-type] Allow bodyless arrow functions which return as const
3 participants