-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): add extension rule no-loss-of-precision
#2196
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
Conversation
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. |
The CI is failed because "typescript-eslint" use eslint v7.0.0. |
feel free to bump the version in this PR - it's only a minor bump so it's safe. |
Codecov Report
@@ 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
|
@@ -0,0 +1,41 @@ | |||
import { TSESTree } from '@typescript-eslint/experimental-utils'; | |||
import baseRule from 'eslint/lib/rules/no-loss-of-precision'; |
There was a problem hiding this comment.
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');
}
}
There was a problem hiding this comment.
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. :)
Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - thanks!
Fixes #2076