Skip to content

Commit

Permalink
Enforce spaces around infix/unary words operators (chartjs#4547)
Browse files Browse the repository at this point in the history
Enable ESLint `space-infix-ops` and `space-unary-ops` (for words only) rules. Also added `samples` to the linting task to match Code Climate expectations.

http://eslint.org/docs/rules/space-infix-ops
http://eslint.org/docs/rules/space-unary-ops
  • Loading branch information
simonbrunel committed Jul 22, 2017
1 parent 1c6eecf commit dbe24ce
Show file tree
Hide file tree
Showing 35 changed files with 149 additions and 149 deletions.
4 changes: 2 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ rules:
space-before-blocks: [2, always]
space-before-function-paren: [2, never]
space-in-parens: [2, never]
space-infix-ops: 0
space-unary-ops: 0
space-infix-ops: 2
space-unary-ops: [2, {words: true, nonwords: false}]
spaced-comment: [2, always]
unicode-bom: 0
wrap-regex: 2
Expand Down
10 changes: 5 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ var package = require('./package.json');

var srcDir = './src/';
var outDir = './dist/';
var testDir = './test/';

var header = "/*!\n" +
" * Chart.js\n" +
Expand Down Expand Up @@ -128,8 +127,9 @@ function packageTask() {

function lintTask() {
var files = [
srcDir + '**/*.js',
testDir + '**/*.js'
'samples/**/*.js',
'src/**/*.js',
'test/**/*.js'
];

// NOTE(SB) codeclimate has 'complexity' and 'max-statements' eslint rules way too strict
Expand Down Expand Up @@ -174,8 +174,8 @@ function startTest() {
'./test/jasmine.index.js',
'./src/**/*.js',
].concat(
argv.inputs?
argv.inputs.split(';'):
argv.inputs ?
argv.inputs.split(';') :
['./test/specs/**/*.js']
);
}
Expand Down
2 changes: 1 addition & 1 deletion samples/charts/area/analyser.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
return;
}

for (i=0, ilen=datasets.length; i<ilen; ++i) {
for (i = 0, ilen = datasets.length; i < ilen; ++i) {
meta = chart.getDatasetMeta(i).$filler;
if (meta) {
dataset = datasets[i];
Expand Down
16 changes: 8 additions & 8 deletions samples/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ window.randomScalingFactor = function() {

rand: function(min, max) {
var seed = this._seed;
min = min === undefined? 0 : min;
max = max === undefined? 1 : max;
min = min === undefined ? 0 : min;
max = max === undefined ? 1 : max;
this._seed = (seed * 9301 + 49297) % 233280;
return min + (this._seed / 233280) * (max - min);
},
Expand All @@ -59,7 +59,7 @@ window.randomScalingFactor = function() {
var data = [];
var i, value;

for (i=0; i<count; ++i) {
for (i = 0; i < count; ++i) {
value = (from[i] || 0) + this.rand(min, max);
if (this.rand() <= continuity) {
data.push(Math.round(dfactor * value) / dfactor);
Expand All @@ -76,14 +76,14 @@ window.randomScalingFactor = function() {
var min = cfg.min || 0;
var max = cfg.max || 100;
var count = cfg.count || 8;
var step = (max-min) / count;
var step = (max - min) / count;
var decimals = cfg.decimals || 8;
var dfactor = Math.pow(10, decimals) || 0;
var prefix = cfg.prefix || '';
var values = [];
var i;

for (i=min; i<max; i+=step) {
for (i = min; i < max; i += step) {
values.push(prefix + Math.round(dfactor * i) / dfactor);
}

Expand All @@ -97,16 +97,16 @@ window.randomScalingFactor = function() {
var values = [];
var i, value;

for (i=0; i<count; ++i) {
value = Months[Math.ceil(i)%12];
for (i = 0; i < count; ++i) {
value = Months[Math.ceil(i) % 12];
values.push(value.substring(0, section));
}

return values;
},

transparentize: function(color, opacity) {
var alpha = opacity === undefined? 0.5 : 1 - opacity;
var alpha = opacity === undefined ? 0.5 : 1 - opacity;
return Chart.helpers.color(color).alpha(alpha).rgbString();
},

Expand Down
18 changes: 9 additions & 9 deletions src/controllers/controller.bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ module.exports = function(Chart) {
var ipixels = me.calculateBarIndexPixels(me.index, index, ruler);

model.horizontal = horizontal;
model.base = reset? base : vpixels.base;
model.x = horizontal? reset? base : vpixels.head : ipixels.center;
model.y = horizontal? ipixels.center : reset? base : vpixels.head;
model.height = horizontal? ipixels.size : undefined;
model.width = horizontal? undefined : ipixels.size;
model.base = reset ? base : vpixels.base;
model.x = horizontal ? reset ? base : vpixels.head : ipixels.center;
model.y = horizontal ? ipixels.center : reset ? base : vpixels.head;
model.height = horizontal ? ipixels.size : undefined;
model.width = horizontal ? undefined : ipixels.size;
},

/**
Expand Down Expand Up @@ -200,7 +200,7 @@ module.exports = function(Chart) {
var chart = me.chart;
var scale = me.getIndexScale();
var stacked = scale.options.stacked;
var ilen = last === undefined? chart.data.datasets.length : last + 1;
var ilen = last === undefined ? chart.data.datasets.length : last + 1;
var stacks = [];
var i, meta;

Expand Down Expand Up @@ -233,7 +233,7 @@ module.exports = function(Chart) {
var scale = me.getIndexScale();
var options = scale.options;
var stackCount = me.getStackCount();
var fullSize = scale.isHorizontal()? scale.width : scale.height;
var fullSize = scale.isHorizontal() ? scale.width : scale.height;
var tickSize = fullSize / scale.ticks.length;
var categorySize = tickSize * options.categoryPercentage;
var fullBarSize = categorySize / stackCount;
Expand Down Expand Up @@ -311,7 +311,7 @@ module.exports = function(Chart) {
var base = scale.getPixelForValue(null, index, datasetIndex, isCombo);
var size = ruler.barSize;

base -= isCombo? ruler.tickSize / 2 : 0;
base -= isCombo ? ruler.tickSize / 2 : 0;
base += ruler.fullBarSize * stackIndex;
base += ruler.categorySpacing / 2;
base += ruler.barSpacing / 2;
Expand All @@ -335,7 +335,7 @@ module.exports = function(Chart) {

helpers.canvas.clipArea(chart.ctx, chart.chartArea);

for (; i<ilen; ++i) {
for (; i < ilen; ++i) {
d = dataset.data[i];
if (d !== null && d !== undefined && !isNaN(d)) {
rects[i].draw();
Expand Down
6 changes: 3 additions & 3 deletions src/controllers/controller.line.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module.exports = function(Chart) {
}

// Update Points
for (i=0, ilen=points.length; i<ilen; ++i) {
for (i = 0, ilen = points.length; i < ilen; ++i) {
me.updateElement(points[i], i, reset);
}

Expand All @@ -95,7 +95,7 @@ module.exports = function(Chart) {
}

// Now pivot the point for animation
for (i=0, ilen=points.length; i<ilen; ++i) {
for (i = 0, ilen = points.length; i < ilen; ++i) {
points[i].pivot();
}
},
Expand Down Expand Up @@ -296,7 +296,7 @@ module.exports = function(Chart) {
helpers.canvas.unclipArea(chart.ctx);

// Draw the points
for (; i<ilen; ++i) {
for (; i < ilen; ++i) {
points[i].draw(area);
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/core/core.animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports = function(Chart) {
chart.animating = true;
}

for (i=0, ilen=animations.length; i < ilen; ++i) {
for (i = 0, ilen = animations.length; i < ilen; ++i) {
if (animations[i].chart === chart) {
animations[i] = animation;
return;
Expand Down
14 changes: 7 additions & 7 deletions src/core/core.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ module.exports = function(Chart) {
me.config = config;
me.width = width;
me.height = height;
me.aspectRatio = height? width / height : null;
me.aspectRatio = height ? width / height : null;
me.options = config.options;
me._bufferedRender = false;

Expand Down Expand Up @@ -546,7 +546,7 @@ module.exports = function(Chart) {
transition: function(easingValue) {
var me = this;

for (var i=0, ilen=(me.data.datasets || []).length; i<ilen; ++i) {
for (var i = 0, ilen = (me.data.datasets || []).length; i < ilen; ++i) {
if (me.isDatasetVisible(i)) {
me.getDatasetMeta(i).controller.transition(easingValue);
}
Expand All @@ -568,7 +568,7 @@ module.exports = function(Chart) {
}

// Draw datasets reversed to support proper line stacking
for (var i=(me.data.datasets || []).length - 1; i >= 0; --i) {
for (var i = (me.data.datasets || []).length - 1; i >= 0; --i) {
if (me.isDatasetVisible(i)) {
me.drawDataset(i, easingValue);
}
Expand Down Expand Up @@ -652,7 +652,7 @@ module.exports = function(Chart) {

getVisibleDatasetCount: function() {
var count = 0;
for (var i = 0, ilen = this.data.datasets.length; i<ilen; ++i) {
for (var i = 0, ilen = this.data.datasets.length; i < ilen; ++i) {
if (this.isDatasetVisible(i)) {
count++;
}
Expand All @@ -665,7 +665,7 @@ module.exports = function(Chart) {

// meta.hidden is a per chart dataset hidden flag override with 3 states: if true or false,
// the dataset.hidden value is ignored, else if null, the dataset hidden state is returned.
return typeof meta.hidden === 'boolean'? !meta.hidden : !this.data.datasets[datasetIndex].hidden;
return typeof meta.hidden === 'boolean' ? !meta.hidden : !this.data.datasets[datasetIndex].hidden;
},

generateLegend: function() {
Expand Down Expand Up @@ -762,10 +762,10 @@ module.exports = function(Chart) {
},

updateHoverStyle: function(elements, mode, enabled) {
var method = enabled? 'setHoverStyle' : 'removeHoverStyle';
var method = enabled ? 'setHoverStyle' : 'removeHoverStyle';
var element, i, ilen;

for (i=0, ilen=elements.length; i<ilen; ++i) {
for (i = 0, ilen = elements.length; i < ilen; ++i) {
element = elements[i];
if (element) {
this.getDatasetMeta(element._datasetIndex).controller[method](element);
Expand Down
10 changes: 5 additions & 5 deletions src/core/core.datasetController.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ module.exports = function(Chart) {
var metaData = meta.data;
var i, ilen;

for (i=0, ilen=data.length; i<ilen; ++i) {
for (i = 0, ilen = data.length; i < ilen; ++i) {
metaData[i] = metaData[i] || me.createMetaData(i);
}

Expand Down Expand Up @@ -214,7 +214,7 @@ module.exports = function(Chart) {
var ilen = elements.length;
var i = 0;

for (; i<ilen; ++i) {
for (; i < ilen; ++i) {
elements[i].transition(easingValue);
}

Expand All @@ -233,7 +233,7 @@ module.exports = function(Chart) {
meta.dataset.draw();
}

for (; i<ilen; ++i) {
for (; i < ilen; ++i) {
elements[i].draw();
}
},
Expand Down Expand Up @@ -284,7 +284,7 @@ module.exports = function(Chart) {
* @private
*/
insertElements: function(start, count) {
for (var i=0; i<count; ++i) {
for (var i = 0; i < count; ++i) {
this.addElementAndReset(start + i);
}
},
Expand All @@ -293,7 +293,7 @@ module.exports = function(Chart) {
* @private
*/
onDataPush: function() {
this.insertElements(this.getDataset().data.length-1, arguments.length);
this.insertElements(this.getDataset().data.length - 1, arguments.length);
},

/**
Expand Down
6 changes: 3 additions & 3 deletions src/core/core.element.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function interpolate(start, view, model, ease) {
var keys = Object.keys(model);
var i, ilen, key, actual, origin, target, type, c0, c1;

for (i=0, ilen=keys.length; i<ilen; ++i) {
for (i = 0, ilen = keys.length; i < ilen; ++i) {
key = keys[i];

target = model[key];
Expand All @@ -30,9 +30,9 @@ function interpolate(start, view, model, ease) {

origin = start[key];

type = typeof(target);
type = typeof target;

if (type === typeof(origin)) {
if (type === typeof origin) {
if (type === 'string') {
c0 = color(origin);
if (c0.valid) {
Expand Down
Loading

0 comments on commit dbe24ce

Please sign in to comment.