Skip to content

Commit

Permalink
Merge pull request #13 from qlik-oss/feature/QPE-569-change-eslint-rules
Browse files Browse the repository at this point in the history
[QPE-569] Fix most of the eslint warnings
  • Loading branch information
lebond authored Feb 22, 2019
2 parents f843779 + 9809587 commit 6797f7d
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 55 deletions.
14 changes: 7 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ module.exports = {
"no-cond-assign": ["warn"],
"no-fallthrough": ["warn"],
"no-undef": ["error"],
"no-unused-vars": ["warn"],
"no-use-before-define": ["warn", { "functions": false, "classes": false, "variables": false }],
"no-unused-vars": ["error"],
"no-use-before-define": ["error", { "functions": false, "classes": false, "variables": false }],
"no-useless-escape": ["warn"],
"no-useless-return": ["warn"],
"no-underscore-dangle": ["warn", { "allow": ["_id"] }],
"no-redeclare": ["warn"],
"no-redeclare": ["error"],
"no-restricted-syntax": ["warn"],
"operator-linebreak": ["warn", "before"],
"prefer-promise-reject-errors": ["warn"],
Expand All @@ -63,11 +63,11 @@ module.exports = {
"complexity": ["warn"],
"camelcase": ["warn"],
"max-statements": ["off"], // marks the entire functions, a bit too noisy
"sort-vars": ["warn"],
"sort-vars": ["off"], // not much value for the work
"init-declarations": ["off"],
"capitalized-comments": ["off"],
"one-var": ["off"],
"no-var": ["warn"],
"no-var": ["error"],
"no-plusplus": ["warn"],
"vars-on-top": ["off"],
"no-magic-numbers": ["off"], // useful, but also complains for reasonable checks with actual numbers
Expand All @@ -80,7 +80,7 @@ module.exports = {
"quote-props": ["off"],
"prefer-template": ["warn"],
"no-lonely-if": ["warn"],
"sort-keys": ["warn"],
"sort-keys": ["off"], // not much value for the work
"no-implicit-coercion": ["warn"],
"no-inline-comments": ["off"],
"spaced-comment": ["warn"],
Expand All @@ -107,7 +107,7 @@ module.exports = {
"strict": ["warn"],
"no-ternary": ["off"],
"multiline-ternary": ["off"],
"no-param-reassign": ["warn"],
"no-param-reassign": ["error"],
"prefer-destructuring": ["warn"],
"arrow-parens": ["off"],
"no-array-constructor": ["warn"],
Expand Down
1 change: 0 additions & 1 deletion src/data-table/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import PropTypes from 'prop-types';
import StyleBuilder from '../style-builder';
import DataCell from './data-cell.jsx';
import HeaderPadding from './header-padding.jsx';
import RowHeader from './row-header.jsx';
import { injectSeparators } from '../utilities';

Expand Down
4 changes: 2 additions & 2 deletions src/definition/formatted.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const formatted = {
],
defaultValue: 'Clean',
show (data) {
return data.customfilebool == false;
return !data.customfilebool;
}
},
BodyTextColor: {
Expand Down Expand Up @@ -130,7 +130,7 @@ const formatted = {
],
defaultValue: 'Black',
show (data) {
return data.customfilebool == false;
return !data.customfilebool;
}
},
FontFamily: {
Expand Down
2 changes: 1 addition & 1 deletion src/definition/metric-semaphores.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const metricSemaphores = {
type: 'string',
defaultValue: '0',
show (data) {
return data.allmetrics == false;
return !data.allmetrics;
}
},
MetricStatus1: {
Expand Down
67 changes: 34 additions & 33 deletions src/masking.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function ApplyPreMask (mask, value) { // aqui
case '+#,##0':
return (addSeparators(value, ',', '.', 0));
default:
return (ApplyMask(mask.substring(0, mask.indexOf(';')), value));
return (applyMask(mask.substring(0, mask.indexOf(';')), value));
}
} else {
const vMyValue = value * -1;
Expand All @@ -30,46 +30,47 @@ export function ApplyPreMask (mask, value) { // aqui
case '-#,##0':
return (`(${addSeparators(vMyValue, ',', '.', 0)})`);
default:
return (`(${ApplyMask(vMyMask, vMyValue)})`);
return (`(${applyMask(vMyMask, vMyValue)})`);
}
}
} else {
return (ApplyMask(mask, value));
return (applyMask(mask, value));
}
}

function ApplyMask (mask, value) {
if (!mask || isNaN(Number(value))) {
return value; // return as it is.
function applyMask (originalMask, originalValue) {
if (!originalMask || isNaN(Number(originalValue))) {
return originalValue;
}

let isNegative, result, decimal, group, posLeadZero, posTrailZero, posSeparator,
part, szSep, integer,

// find prefix/suffix
len = mask.length,
start = mask.search(/[0-9\-\+#]/),
prefix = start > 0 ? mask.substring(0, start) : '',
// reverse string: not an ideal method if there are surrogate pairs
str = mask.split('').reverse()
.join(''),
end = str.search(/[0-9\-\+#]/),
offset = len - end,
substr = mask.substring(offset, offset + 1),
indx = offset + ((substr === '.' || (substr === ',')) ? 1 : 0),
suffix = end > 0 ? mask.substring(indx, len) : '';
let isNegative;
let result;
let integer;
// find prefix/suffix
let len = originalMask.length;
const start = originalMask.search(/[0-9\-\+#]/);
const prefix = start > 0 ? originalMask.substring(0, start) : '';
// reverse string: not an ideal method if there are surrogate pairs
let str = originalMask.split('')
.reverse()
.join('');
const end = str.search(/[0-9\-\+#]/);
let offset = len - end;
const substr = originalMask.substring(offset, offset + 1);
let index = offset + ((substr === '.' || (substr === ',')) ? 1 : 0);
const suffix = end > 0 ? originalMask.substring(index, len) : '';

// mask with prefix & suffix removed
mask = mask.substring(start, indx);
let mask = originalMask.substring(start, index);

// convert any string to number according to formation sign.
value = mask.charAt(0) === '-' ? -value : Number(value);
let value = mask.charAt(0) === '-' ? -originalValue : Number(originalValue);
isNegative = value < 0 ? value = -value : 0; // process only abs(), and turn on flag.

// search for separator for grp & decimal, anything not digit, not +/- sign, not #.
result = mask.match(/[^\d\-\+#]/g);
decimal = (result && result[result.length - 1]) || '.'; // treat the right most symbol as decimal
group = (result && result[1] && result[0]) || ','; // treat the left most symbol as group separator
const decimal = (result && result[result.length - 1]) || '.'; // treat the right most symbol as decimal
const group = (result && result[1] && result[0]) || ','; // treat the left most symbol as group separator

// split the decimal for the format string if any.
mask = mask.split(decimal);
Expand All @@ -78,16 +79,16 @@ function ApplyMask (mask, value) {
value = String(Number(value)); // convert number to string to trim off *all* trailing decimal zero(es)

// fill back any trailing zero according to format
posTrailZero = mask[1] && mask[1].lastIndexOf('0'); // look for last zero in format
part = value.split('.');
const posTrailZero = mask[1] && mask[1].lastIndexOf('0'); // look for last zero in format
const part = value.split('.');
// integer will get !part[1]
if (!part[1] || (part[1] && part[1].length <= posTrailZero)) {
value = (Number(value)).toFixed(posTrailZero + 1);
}
szSep = mask[0].split(group); // look for separator
const szSep = mask[0].split(group); // look for separator
mask[0] = szSep.join(''); // join back without separator for counting the pos of any leading 0.

posLeadZero = mask[0] && mask[0].indexOf('0');
const posLeadZero = mask[0] && mask[0].indexOf('0');
if (posLeadZero > -1) {
while (part[0].length < (mask[0].length - posLeadZero)) {
part[0] = `0${part[0]}`;
Expand All @@ -101,17 +102,17 @@ function ApplyMask (mask, value) {

// process the first group separator from decimal (.) only, the rest ignore.
// get the length of the last slice of split result.
posSeparator = (szSep[1] && szSep[szSep.length - 1].length);
const posSeparator = (szSep[1] && szSep[szSep.length - 1].length);
if (posSeparator) {
integer = value[0];
str = '';
offset = integer.length % posSeparator;
len = integer.length;
for (indx = 0; indx < len; indx++) {
str += integer.charAt(indx); // ie6 only support charAt for sz.
for (index = 0; index < len; index++) {
str += integer.charAt(index); // ie6 only support charAt for sz.
// -posSeparator so that won't trail separator on full length
// jshint -W018
if (!((indx - offset + 1) % posSeparator) && indx < len - posSeparator) {
if (!((index - offset + 1) % posSeparator) && index < len - posSeparator) {
str += group;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/paint.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import $ from 'jquery';
import $ from 'jquery'; // eslint-disable-line id-length
import initializeStore from './store';
import React from 'react';
import ReactDOM from 'react-dom';
Expand Down
22 changes: 12 additions & 10 deletions src/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ export function distinctArray (array) {
.map(entry => JSON.parse(entry));
}

export function addSeparators (nStr, thousandsSep, decimalSep, numDecimals) {
let x1;
nStr = nStr.toFixed(numDecimals);
const x = nStr.split('.');
x1 = x[0];
const x2 = x.length > 1 ? decimalSep + x[1] : '';
const rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, `$1${thousandsSep}$2`);
export function addSeparators (number, thousandSeparator, decimalSeparator, numberOfDecimals) {
const numberString = number.toFixed(numberOfDecimals);
const numberStringParts = numberString.split('.');
let [
wholeNumber,
decimal
] = numberStringParts;
decimal = numberStringParts.length > 1 ? decimalSeparator + decimal : '';
const regexCheckForThousand = /(\d+)(\d{3})/;
while (regexCheckForThousand.test(wholeNumber)) {
wholeNumber = wholeNumber.replace(regexCheckForThousand, `$1${thousandSeparator}$2`);
}
return x1 + x2;
return wholeNumber + decimal;
}

export function Deferred () {
Expand Down

0 comments on commit 6797f7d

Please sign in to comment.