aboutsummaryrefslogtreecommitdiff
path: root/tools/eslint/lib/rules/prefer-numeric-literals.js
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2016-10-15 11:30:25 -0700
committerRich Trott <rtrott@gmail.com>2016-10-18 15:28:21 -0700
commit2981f24f926da32d708c8bb39d90fff5aa73bc3f (patch)
treee154567c25398160dfe9ac8e27dd79c65a436272 /tools/eslint/lib/rules/prefer-numeric-literals.js
parent150dc5c2e6a848aa49bb95f4e6c0cbf0da5d0e73 (diff)
downloadandroid-node-v8-2981f24f926da32d708c8bb39d90fff5aa73bc3f.tar.gz
android-node-v8-2981f24f926da32d708c8bb39d90fff5aa73bc3f.tar.bz2
android-node-v8-2981f24f926da32d708c8bb39d90fff5aa73bc3f.zip
tools: update ESLint to v3.8.0
Update ESLint to v3.8.0. * Installed with `npm install --production` to avoid installing unnecessary dev files * Used `dmn -f clean` to further eliminate unneeded files PR-URL: https://github.com/nodejs/node/pull/9112 Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
Diffstat (limited to 'tools/eslint/lib/rules/prefer-numeric-literals.js')
-rw-r--r--tools/eslint/lib/rules/prefer-numeric-literals.js21
1 files changed, 20 insertions, 1 deletions
diff --git a/tools/eslint/lib/rules/prefer-numeric-literals.js b/tools/eslint/lib/rules/prefer-numeric-literals.js
index 1e3bed5915..ed84ce6a9f 100644
--- a/tools/eslint/lib/rules/prefer-numeric-literals.js
+++ b/tools/eslint/lib/rules/prefer-numeric-literals.js
@@ -17,7 +17,9 @@ module.exports = {
recommended: false
},
- schema: []
+ schema: [],
+
+ fixable: "code"
},
create(context) {
@@ -27,6 +29,12 @@ module.exports = {
16: "hexadecimal"
};
+ const prefixMap = {
+ 2: "0b",
+ 8: "0o",
+ 16: "0x"
+ };
+
//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------
@@ -53,6 +61,17 @@ module.exports = {
message: "Use {{radixName}} literals instead of parseInt().",
data: {
radixName
+ },
+ fix(fixer) {
+ const newPrefix = prefixMap[node.arguments[1].value];
+
+ if (+(newPrefix + node.arguments[0].value) !== parseInt(node.arguments[0].value, node.arguments[1].value)) {
+
+ // If the newly-produced literal would be invalid, (e.g. 0b1234),
+ // or it would yield an incorrect parseInt result for some other reason, don't make a fix.
+ return null;
+ }
+ return fixer.replaceText(node, prefixMap[node.arguments[1].value] + node.arguments[0].value);
}
});
}