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): add extension rule no-loss-of-precision #2196

Merged
merged 9 commits into from Jun 16, 2020
Merged

feat(eslint-plugin): add extension rule no-loss-of-precision #2196

merged 9 commits into from Jun 16, 2020

Conversation

yeonjuan
Copy link
Contributor

@yeonjuan yeonjuan commented Jun 9, 2020

Fixes #2076

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

@yeonjuan
Copy link
Contributor Author

yeonjuan commented Jun 9, 2020

The CI is failed because "typescript-eslint" use eslint v7.0.0.
May I create another PR for upgrade eslint to v7.2.0?

@bradzacher bradzacher added the bug Something isn't working label Jun 9, 2020
@bradzacher
Copy link
Member

feel free to bump the version in this PR - it's only a minor bump so it's safe.

@codecov
Copy link

codecov bot commented Jun 9, 2020

Codecov Report

Merging #2196 into master will decrease coverage by 0.00%.
The diff coverage is 91.66%.

@@            Coverage Diff             @@
##           master    #2196      +/-   ##
==========================================
- Coverage   93.39%   93.39%   -0.01%     
==========================================
  Files         173      174       +1     
  Lines        7871     7883      +12     
  Branches     2247     2251       +4     
==========================================
+ Hits         7351     7362      +11     
  Misses        247      247              
- Partials      273      274       +1     
Flag Coverage Δ
#unittest 93.39% <91.66%> (-0.01%) ⬇️
Impacted Files Coverage Δ
packages/eslint-plugin/src/configs/all.ts 100.00% <ø> (ø)
...es/eslint-plugin/src/rules/no-loss-of-precision.ts 91.66% <91.66%> (ø)

packages/eslint-plugin/docs/rules/no-loss-of-precision.md Outdated Show resolved Hide resolved
@@ -0,0 +1,41 @@
import { TSESTree } from '@typescript-eslint/experimental-utils';
import baseRule from 'eslint/lib/rules/no-loss-of-precision';
Copy link
Member

Choose a reason for hiding this comment

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

We need to guard against this not existing in <7.2.0, so that it only errors if a user attempts to actually use the rule in an old version of ESLint, and not if the user attempts to use the plugin.

This is why the integration test is failing.

Something like this (hack) will probably do:

import BaseRuleType from 'eslint/lib/rules/no-loss-of-precision';
import * as util from '../util';

const baseRule = ((): BaseRuleType | null => {
  try {
    return require('eslint/lib/rules/no-loss-of-precision');
  } catch {
    return null;
  }
}());

// ...
create(context) {
  if (baseRule == null) {
    throw new Error('@typescript-eslint/no-loss-of-precision requires at least ESLint v7.2.0');
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bradzacher thanks for the solution. :)

@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label Jun 9, 2020
@bradzacher bradzacher added enhancement: new base rule extension New base rule extension required to handle a TS specific case and removed awaiting response Issues waiting for a reply from the OP or another party bug Something isn't working labels Jun 10, 2020
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!

@bradzacher bradzacher merged commit 535b0f2 into typescript-eslint:master Jun 16, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: new base rule extension New base rule extension required to handle a TS specific case
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ESLint 7.1.0 no-loss-of-precision: false positives for values with numeric separators
2 participants