Skip to content

Commit dca7314

Browse files
committed
Merge pull request #172 from plotly/eslint
Lint with eslint
2 parents e66a234 + 2daa656 commit dca7314

File tree

176 files changed

+1664
-1555
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+1664
-1555
lines changed

.eslintignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules
2+
dist
3+
build
4+
5+
test/jasmine/assets/jquery-1.8.3.min.js
6+
src/plots/polar/micropolar.js
7+
src/plots/geo/projections.js

.eslintrc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"root": true,
3+
"extends": [
4+
"eslint:recommended",
5+
],
6+
"env": {
7+
"commonjs": true
8+
},
9+
"rules": {
10+
"no-trailing-spaces": [2],
11+
"no-multiple-empty-lines": [2, {"max": 3, "maxEOF": 1}],
12+
"linebreak-style": [2, "unix"],
13+
"indent": [2, 4, {"SwitchCase": 1}],
14+
"max-len": [0, 80],
15+
"brace-style": [0, "stroustrup", {"allowSingleLine": true}],
16+
"curly": [0, "multi"],
17+
"camelcase": [0, {"properties": "never"}],
18+
"comma-spacing": [0, {"before": false, "after": true}],
19+
"comma-style": [2, "last"],
20+
"semi": [2],
21+
"semi-spacing": [2, {"before": false, "after": true}],
22+
"key-spacing": [0, {"beforeColon": false, "afterColon": true}],
23+
"no-spaced-func": [2],
24+
"space-in-parens": [2, "never"],
25+
"space-before-function-paren": [2, "never"],
26+
"no-multi-spaces": [2],
27+
"space-infix-ops": [0, {"int32Hint": false}],
28+
"quotes": [2, "single"],
29+
"dot-notation": [2, {"allowKeywords": false}],
30+
"eqeqeq": [2],
31+
"new-cap": [0],
32+
"no-redeclare": [2, {"builtinGlobals": true}],
33+
"no-shadow": [0, {"builtinGlobals": true}],
34+
"block-scoped-var": [2],
35+
"no-unused-vars": [2],
36+
"no-use-before-define": [2, "nofunc"],
37+
"no-loop-func": [2],
38+
"no-console": [0]
39+
},
40+
}

.jshintrc

Lines changed: 0 additions & 72 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ To view the results of a run on CircleCI, download the `build/test_images/` and
116116

117117
### Coding style
118118

119-
- 4-space indentation
120-
- semi-colons are required
121-
- trailing commas
122-
123119
Check if ok, with `npm run lint`
120+
121+
- See [eslintrc](https://github.com/plotly/plotly.js/blob/master/.eslintrc) and
122+
the eslint [list of rules](http://eslint.org/docs/rules/) for more details.
123+
- Rules listed in the eslintrc file with the ignore flag `0` are the recommended
124+
rules for new code added.

devtools/.eslintrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../.eslintrc",
3+
"env": {
4+
"node": true,
5+
"browser": true
6+
}
7+
}

devtools/image_viewer/viewer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function createButton(imageName) {
3737
button.style.height = '40px';
3838
button.innerHTML = imageName;
3939

40-
button.addEventListener('click', function () {
40+
button.addEventListener('click', function() {
4141
var imgBaseline = createImg(dirBaseline, imageName),
4242
imgTest = createImg(dirTest, imageName),
4343
imgDiff = createImg(dirDiff, 'diff-' + imageName);
@@ -50,7 +50,7 @@ function createButton(imageName) {
5050

5151
$mock.innerHTML = '';
5252
$mock.appendChild(createJSONview(mock));
53-
});
53+
});
5454
});
5555

5656
return button;

devtools/test_dashboard/buttons.js

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* global Plotly:false Tabs:false */
2+
13
var plotlist = document.getElementById('plot-list');
24
var anchor = document.getElementById('embedded-graph');
35
var image = document.getElementById('embedded-image');
@@ -11,7 +13,7 @@ anchor.style.width = '1000px';
1113

1214
function plotButtons(plots, figDir) {
1315

14-
Object.keys(plots).forEach( function (plotname) {
16+
Object.keys(plots).forEach(function(plotname) {
1517

1618
var button = document.createElement('button');
1719

@@ -23,7 +25,7 @@ function plotButtons(plots, figDir) {
2325

2426
plotlist.appendChild(button);
2527

26-
button.addEventListener('click', function () {
28+
button.addEventListener('click', function() {
2729

2830
var myImage = new Image();
2931
myImage.src = figDir + plotname + '.png';
@@ -55,7 +57,7 @@ function plotButtons(plots, figDir) {
5557

5658
plotlist.appendChild(snapshot);
5759

58-
snapshot.addEventListener('click', function () {
60+
snapshot.addEventListener('click', function() {
5961

6062
/*
6163
* Grab the currently loaded plot and make an image - replacing the plot.
@@ -67,7 +69,7 @@ function plotButtons(plots, figDir) {
6769

6870
if (!layout || !data) return;
6971

70-
Plotly.Plots.getSubplotIds(gd._fullLayout, 'gl3d').forEach( function (key) {
72+
Plotly.Plots.getSubplotIds(gd._fullLayout, 'gl3d').forEach(function(key) {
7173
var scene = gd._fullLayout[key]._scene;
7274
scene.destroy();
7375
});
@@ -80,23 +82,23 @@ function plotButtons(plots, figDir) {
8082
/*
8183
* Replot with staticPlot
8284
*/
83-
Plotly.plot(gd, data, layout, {staticPlot: true, plotGlPixelRatio: 2}).then( function () {
84-
Plotly.Plots.getSubplotIds(gd._fullLayout, 'gl3d').forEach( function (key) {
85-
var scene = gd._fullLayout[key]._scene;
86-
var dataURL = scene.toImage();
87-
88-
var myImage = new Image();
89-
myImage.src = dataURL;
90-
91-
myImage.onload = function () {
92-
myImage.height = scene.container.clientHeight;
93-
myImage.width = scene.container.clientWidth;
94-
};
95-
96-
image.innerHTML = '';
97-
image.appendChild(myImage);
98-
});
99-
})
85+
Plotly.plot(gd, data, layout, {staticPlot: true, plotGlPixelRatio: 2}).then(function() {
86+
Plotly.Plots.getSubplotIds(gd._fullLayout, 'gl3d').forEach(function(key) {
87+
var scene = gd._fullLayout[key]._scene;
88+
var dataURL = scene.toImage();
89+
90+
var myImage = new Image();
91+
myImage.src = dataURL;
92+
93+
myImage.onload = function() {
94+
myImage.height = scene.container.clientHeight;
95+
myImage.width = scene.container.clientWidth;
96+
};
97+
98+
image.innerHTML = '';
99+
image.appendChild(myImage);
100+
});
101+
});
100102
});
101103

102104
var pummelButton = document.createElement('button');
@@ -112,17 +114,17 @@ function plotButtons(plots, figDir) {
112114
var mock = require('@mocks/gl3d_marker-color.json');
113115
var statusDiv = document.getElementById('status-info');
114116

115-
pummelButton.addEventListener('click', function () {
116-
setInterval(function () {
117+
pummelButton.addEventListener('click', function() {
118+
setInterval(function() {
117119
var plotDiv = document.createElement('div');
118120
window.plotDiv = plotDiv;
119121

120122
plotDiv.id = 'div' + i;
121123
document.body.appendChild(plotDiv);
122124

123-
Plotly.plot(plotDiv, mock.data, mock.layout, {staticPlot: true}).then(function () {
125+
Plotly.plot(plotDiv, mock.data, mock.layout, {staticPlot: true}).then(function() {
124126

125-
Plotly.Plots.getSubplotIds(plotDiv._fullLayout, 'gl3d').forEach( function (key) {
127+
Plotly.Plots.getSubplotIds(plotDiv._fullLayout, 'gl3d').forEach(function(key) {
126128
var scene = plotDiv._fullLayout[key]._scene;
127129
scene.destroy();
128130
i ++;
@@ -144,7 +146,7 @@ function plotButtons(plots, figDir) {
144146
scrapeButton.style.background = 'blue';
145147
plotlist.appendChild(scrapeButton);
146148

147-
scrapeButton.addEventListener('click', function () {
149+
scrapeButton.addEventListener('click', function() {
148150
Plotly.Snapshot.toSVG(Tabs.get());
149151
return;
150152
});

devtools/test_dashboard/server.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ var testFile;
1818
switch(process.argv[2]) {
1919
case 'cartesian':
2020
testFile = 'test_cartesian';
21-
break;
21+
break;
2222
case 'geo':
2323
testFile = 'test_geo';
24-
break;
24+
break;
2525
case 'gl3d':
2626
testFile = 'test_gl3d';
27-
break;
27+
break;
2828
default:
2929
testFile = 'test_gl2d';
3030
}

devtools/test_dashboard/test_cartesian.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/*eslint dot-notation: 0*/
2+
13
var plotButtons = require('./buttons');
24

35
var figDir = '../../test/image/baselines/';

devtools/test_dashboard/test_geo.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/*eslint dot-notation: 0*/
2+
13
var plotButtons = require('./buttons');
24

35
var figDir = '../../test/image/baselines/geo_';

devtools/test_dashboard/test_gl2d.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/*eslint dot-notation: 0*/
2+
13
var plotButtons = require('./buttons');
24

35
var figDir = '../../test/image/baselines/gl2d_';

devtools/test_dashboard/test_gl3d.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/*eslint dot-notation: 0*/
2+
13
var plotButtons = require('./buttons');
24

35
var figDir = '../../test/image/baselines/gl3d_';

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"build": "npm run preprocess && npm run bundle && npm run header",
2828
"cibuild": "node tasks/cibundle.js",
2929
"watch": "node tasks/watch_plotly.js",
30-
"lint": "cd src && jshint . || true",
30+
"lint": "eslint . || true",
3131
"test-jasmine": "karma start test/jasmine/karma.conf.js",
3232
"citest-jasmine": "karma start test/jasmine/karma.ciconf.js",
3333
"test-image": "./tasks/test_image.sh",
@@ -84,7 +84,6 @@
8484
"falafel": "^1.2.0",
8585
"glob": "^6.0.1",
8686
"jasmine-core": "^2.3.4",
87-
"jshint": "^2.8.0",
8887
"karma": "^0.13.15",
8988
"karma-browserify": "^4.4.1",
9089
"karma-chrome-launcher": "^0.2.1",

src/.eslintrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "../.eslintrc",
3+
"env": {
4+
"browser": true
5+
},
6+
"rules": {
7+
"strict": [2, "global"]
8+
}
9+
}

src/assets/geo_assets.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9+
'use strict';
910

1011
var saneTopojson = require('sane-topojson');
1112

13+
1214
// export the version found in the package.json
1315
exports.version = require('../../package.json').version;
1416

src/components/annotations/arrow_paths.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9+
'use strict';
910

1011
/**
1112
* centerx is a center of scaling tuned for maximum scalability of
@@ -17,6 +18,7 @@
1718
* TODO: option to have the pointed-to point a little in front of the
1819
* end of the line, as people tend to want a bit of a gap there...
1920
*/
21+
2022
module.exports = [
2123
// no arrow
2224
'',

src/components/annotations/attributes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9+
'use strict';
910

1011
var Plotly = require('../../plotly');
1112
var ARROWPATHS = require('./arrow_paths');
1213
var fontAttrs = require('../../plots/font_attributes');
1314
var extendFlat = require('../../lib/extend').extendFlat;
1415

16+
1517
module.exports = {
1618
_isLinkedToArray: true,
1719

0 commit comments

Comments
 (0)