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-magic-numbers] Support negative numbers #1072

Conversation

a-tarasyuk
Copy link
Contributor

Fixes #1070

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @a-tarasyuk!

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.

@a-tarasyuk a-tarasyuk force-pushed the bug/1070-no-magic-numbers-false-positive-for-negative-readonly-class-properties branch from d6979f7 to 4597e36 Compare October 11, 2019 19:53
@bradzacher bradzacher added the bug Something isn't working label Oct 11, 2019
@bradzacher
Copy link
Member

did we want to handle explicitly positive numbers at the same time?
It's probably a rare case, but it might be worth chucking the handling in to make sure nobody ever complains about it?

(I don't use this rule, so IDK if it's worth the effort)
WDYT?

@a-tarasyuk a-tarasyuk closed this Oct 12, 2019
@a-tarasyuk
Copy link
Contributor Author

@bradzacher

There are several Unary Operators which can potentially cause issues and which are all applied to numbers

class A {
  public readonly A = +127;
  public readonly B = -127;
  public readonly C = ~127;
  public readonly D = ++127;
  public readonly D = --127;
}

Does that make sense to handle all of them?

@bradzacher
Copy link
Member

I don't think that people will use anything other than +/- when delcaring a constant.

++/-- form an UpdateExpression instead.
~ is a bitwise operator which I don't think is useful for defining magic number constants.

@a-tarasyuk a-tarasyuk reopened this Oct 16, 2019
@a-tarasyuk a-tarasyuk force-pushed the bug/1070-no-magic-numbers-false-positive-for-negative-readonly-class-properties branch from 4597e36 to 278cb38 Compare October 16, 2019 12:43
@a-tarasyuk
Copy link
Contributor Author

@bradzacher ok, added +.

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.

LGTM, thanks for doing this

@codecov
Copy link

codecov bot commented Oct 16, 2019

Codecov Report

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

@@            Coverage Diff             @@
##           master    #1072      +/-   ##
==========================================
+ Coverage   94.01%   94.02%   +0.01%     
==========================================
  Files         115      115              
  Lines        5110     5123      +13     
  Branches     1429     1434       +5     
==========================================
+ Hits         4804     4817      +13     
  Misses        177      177              
  Partials      129      129
Impacted Files Coverage Δ
...ckages/eslint-plugin/src/rules/no-magic-numbers.ts 94.33% <100%> (+1.83%) ⬆️

@bradzacher bradzacher changed the title fix(eslint-plugin): #1070 [no-magic-numbers] False positive for negative readonly class properties fix(eslint-plugin): [no-magic-numbers] False positive for negative readonly class properties Oct 16, 2019
@bradzacher bradzacher changed the title fix(eslint-plugin): [no-magic-numbers] False positive for negative readonly class properties fix(eslint-plugin): [no-magic-numbers] Support negative numbers Oct 16, 2019
@bradzacher bradzacher merged commit 0c85ac3 into typescript-eslint:master Oct 16, 2019
@orlov-vo
Copy link

It seems like it doesn't work in enums:

enum Status {
    NONE = 0,
    START = 1,
    ERROR_DNS = -2,
    ERROR_INSTALL = -6
}

@bradzacher
Copy link
Member

Please raise a new issue. Commenting on an old, closed PR is bad way to let us know of bugs.

@typescript-eslint typescript-eslint locked as resolved and limited conversation to collaborators Nov 25, 2019
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.

[no-magic-numbers] False positive for negative readonly class properties
3 participants