Skip to content

Commit

Permalink
number-literal-case: Refactor to make logic more clear (#834)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Sep 26, 2020
1 parent f141d08 commit e29d7c0
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions rules/number-literal-case.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
'use strict';
const getDocumentationUrl = require('./utils/get-documentation-url');

const fix = (raw, isBigInt) => {
const fix = raw => {
let fixed = raw.toLowerCase();
if (fixed.startsWith('0x')) {
fixed = '0x' + fixed.slice(2).toUpperCase();

if (isBigInt) {
fixed = fixed.slice(0, -1) + 'n';
}
}

return fixed;
Expand All @@ -18,14 +14,14 @@ const create = context => {
return {
Literal: node => {
const {value, raw, bigint} = node;
const isBigInt = Boolean(bigint);

if (typeof value !== 'number' && !isBigInt) {
return;
let fixed = raw;
if (typeof value === 'number') {
fixed = fix(raw);
} else if (bigint) {
fixed = fix(raw.slice(0, -1)) + 'n';
}

const fixed = fix(raw, isBigInt);

if (raw !== fixed) {
context.report({
node,
Expand Down

0 comments on commit e29d7c0

Please sign in to comment.