Skip to content

Commit 7df39f1

Browse files
add eslint to CI check and lint codebase
1 parent f319f5f commit 7df39f1

27 files changed

+145
-111
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"make:dist:css": "mkdirp dist && node-sass --output-style compressed src/styles/main.scss > dist/react-plotly.js-editor.css",
2020
"prepublishOnly": "npm run make:lib",
2121
"lint": "prettier --write \"src/**/*.js\"",
22-
"test": "prettier -l \"src/**/*.js\" && jest",
22+
"test": "eslint src && prettier -l \"src/**/*.js\" && jest",
23+
"test-js": "jest",
2324
"watch": "nodemon --exec \"npm run make:lib\" -w src",
2425
"watch-test": "jest --watch",
2526
"eslint:check": "eslint --print-config .eslintrc | eslint-config-prettier-check"

src/DefaultEditor.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -258,21 +258,21 @@ class DefaultEditor extends Component {
258258
</Section>
259259
</AxesFold>
260260

261-
{/* <AxesFold name={_('Lines')}>
262-
<AxesSelector />
263-
</AxesFold>
264-
<AxesFold name={_('Tick Labels')}>
265-
<AxesSelector />
266-
</AxesFold>
267-
<AxesFold name={_('Tick Markers')}>
268-
<AxesSelector />
269-
</AxesFold>
270-
<AxesFold name={_('Zoom Interactivity')}>
271-
<AxesSelector />
272-
</AxesFold>
273-
<AxesFold name={_('Layout')}>
274-
<AxesSelector />
275-
</AxesFold> */}
261+
<AxesFold name={_('Lines')}>
262+
<AxesSelector />
263+
</AxesFold>
264+
<AxesFold name={_('Tick Labels')}>
265+
<AxesSelector />
266+
</AxesFold>
267+
<AxesFold name={_('Tick Markers')}>
268+
<AxesSelector />
269+
</AxesFold>
270+
<AxesFold name={_('Zoom Interactivity')}>
271+
<AxesSelector />
272+
</AxesFold>
273+
<AxesFold name={_('Layout')}>
274+
<AxesSelector />
275+
</AxesFold>
276276
</LayoutPanel>
277277

278278
<LayoutPanel group="Style" name={_('Legend')}>
@@ -382,6 +382,10 @@ class DefaultEditor extends Component {
382382
}
383383
}
384384

385+
DefaultEditor.propTypes = {
386+
localize: PropTypes.func,
387+
};
388+
385389
DefaultEditor.contextTypes = {
386390
dataSourceNames: PropTypes.array.isRequired,
387391
};

src/PlotlyEditor.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ class PlotlyEditor extends Component {
3838

3939
updateProp(event) {
4040
const {graphDiv} = this.props;
41-
this.props.onUpdate && this.props.onUpdate({graphDiv, ...event});
41+
if (this.props.onUpdate) {
42+
this.props.onUpdate({graphDiv, ...event});
43+
}
4244
}
4345

4446
render() {
@@ -52,11 +54,12 @@ class PlotlyEditor extends Component {
5254
}
5355

5456
PlotlyEditor.propTypes = {
55-
onUpdate: PropTypes.func,
56-
plotly: PropTypes.object,
57+
children: PropTypes.node,
58+
dataSources: PropTypes.object,
5759
graphDiv: PropTypes.object,
5860
locale: PropTypes.string,
59-
dataSources: PropTypes.object,
61+
onUpdate: PropTypes.func,
62+
plotly: PropTypes.object,
6063
};
6164

6265
PlotlyEditor.defaultProps = {

src/components/PanelMenuWrapper.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import SidebarGroup from './sidebar/SidebarGroup';
1+
import PropTypes from 'prop-types';
22
import React, {cloneElement, Component} from 'react';
3+
import SidebarGroup from './sidebar/SidebarGroup';
34
import {bem} from '../lib';
45

56
class PanelsWithSidebar extends Component {
@@ -87,4 +88,8 @@ class PanelsWithSidebar extends Component {
8788
}
8889
}
8990

91+
PanelsWithSidebar.propTypes = {
92+
children: PropTypes.node,
93+
};
94+
9095
export default PanelsWithSidebar;

src/components/containers/Fold.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import React, {Component} from 'react';
21
import PropTypes from 'prop-types';
2+
import React, {Component} from 'react';
33
import {bem} from '../../lib';
44

55
export default class Fold extends Component {
66
renderHeader() {
77
const {deleteContainer} = this.context;
8-
const {canDelete, name} = this.props;
8+
const {canDelete} = this.props;
99
const doDelete = canDelete && typeof deleteContainer === 'function';
1010
return (
1111
<div className={bem('fold', 'top', ['active'])}>
@@ -36,6 +36,7 @@ export default class Fold extends Component {
3636

3737
Fold.propTypes = {
3838
canDelete: PropTypes.bool,
39+
children: PropTypes.node,
3940
hideHeader: PropTypes.bool,
4041
name: PropTypes.string,
4142
};

src/components/containers/Panel.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ class Panel extends Component {
66
render() {
77
if (this.props.visible) {
88
return <div className={bem('panel')}>{this.props.children}</div>;
9-
} else {
10-
return <div />;
119
}
10+
return <div />;
1211
}
1312
}
1413

1514
Panel.propTypes = {
15+
children: PropTypes.node,
1616
visible: PropTypes.bool,
1717
};
1818

src/components/containers/__tests__/Layout-test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ Layouts.forEach(Layout => {
4141
.find('[attr="width"]')
4242
.find(NumericInput);
4343

44-
wrapper.prop('onChange')(200);
44+
const widthUpdate = 200;
45+
wrapper.prop('onChange')(widthUpdate);
4546
const event = onUpdate.mock.calls[0][0];
4647
expect(event.type).toBe(EDITOR_ACTIONS.UPDATE_LAYOUT);
47-
expect(event.payload).toEqual({update: {width: 200}});
48+
expect(event.payload).toEqual({update: {width: widthUpdate}});
4849
});
4950
});
5051
});

src/components/containers/__tests__/Section-test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ describe('Section', () => {
3333
expect(
3434
wrapper
3535
.find(Flaglist)
36-
.childAt(0) // unwrap higher-level component
36+
// unwrap higher-level component
37+
.childAt(0)
3738
.exists()
3839
).toBe(true);
3940
expect(
4041
wrapper
4142
.find(Numeric)
42-
.childAt(0) // unwrap higher-level component
43+
// unwrap higher-level component
44+
.childAt(0)
4345
.exists()
4446
).toBe(false);
4547
});

src/components/fields/Color.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ColorPicker from '../widgets/ColorPicker';
22
import Field from './Field';
33
import PropTypes from 'prop-types';
44
import React, {Component} from 'react';
5-
import {bem, connectToContainer} from '../../lib';
5+
import {connectToContainer} from '../../lib';
66

77
class Color extends Component {
88
render() {

src/components/fields/DataSelector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
33
import React, {Component} from 'react';
44
import Field from './Field';
55
import nestedProperty from 'plotly.js/src/lib/nested_property';
6-
import {connectToContainer, unpackPlotProps} from '../../lib';
6+
import {connectToContainer} from '../../lib';
77

88
function attributeIsData(meta = {}) {
99
return meta.valType === 'data_array' || meta.arrayOk;

src/components/fields/Flaglist.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Field from './Field';
22
import FlaglistCheckboxGroup from '../widgets/FlaglistCheckboxGroup';
33
import PropTypes from 'prop-types';
44
import React, {Component} from 'react';
5-
import {bem, connectToContainer} from '../../lib';
5+
import {connectToContainer} from '../../lib';
66

77
class Flaglist extends Component {
88
render() {

src/components/sidebar/SidebarGroup.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import PropTypes from 'prop-types';
12
import React, {Component} from 'react';
23
import {bem} from '../../lib';
34

@@ -58,6 +59,10 @@ export default class SidebarGroup extends Component {
5859
}
5960
}
6061

61-
SidebarGroup.defaultProps = {
62-
expanded: false,
62+
SidebarGroup.propTypes = {
63+
group: PropTypes.string,
64+
onChangeGroup: PropTypes.func,
65+
panels: PropTypes.array,
66+
selectedGroup: PropTypes.string,
67+
selectedPanel: PropTypes.string,
6368
};

src/components/sidebar/SidebarItem.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import PropTypes from 'prop-types';
12
import React, {Component} from 'react';
23
import {bem} from '../../lib';
34

@@ -13,3 +14,9 @@ export default class SidebarItem extends Component {
1314
);
1415
}
1516
}
17+
18+
SidebarItem.propTypes = {
19+
active: PropTypes.bool,
20+
label: PropTypes.string,
21+
onClick: PropTypes.func,
22+
};

src/components/widgets/ColorPicker.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import {CustomPicker as customPicker} from 'react-color';
1313
import {localize} from '../../lib';
1414

15+
/* eslint-disable no-inline-comments */
1516
const defaultColors = [
1617
'#444444',
1718
'#ffffff',
@@ -26,6 +27,7 @@ const defaultColors = [
2627
'#bcbd22', // curry yellow-green
2728
'#17becf', // blue-teal
2829
];
30+
/* eslint-enable no-inline-comments */
2931

3032
// Utility functions for converting ColorPicker color objects or raw strings
3133
// into TinyColor objects.

src/components/widgets/Dropdown.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import PropTypes from 'prop-types';
12
import React, {Component} from 'react';
23
import Select from 'react-select';
3-
import PropTypes from 'prop-types';
44

55
class Dropdown extends Component {
66
constructor(props) {
@@ -15,9 +15,8 @@ class Dropdown extends Component {
1515
if (!selection) {
1616
return onChange(null);
1717
} else if (multi) {
18-
console.log(valueKey, selection);
1918
throw new Error('TODO: de-ramda');
20-
//return onChange(map(prop(valueKey), selection));
19+
// return onChange(map(prop(valueKey), selection));
2120
}
2221

2322
return onChange(selection[valueKey]);

src/components/widgets/EditableText.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import React, {Component} from 'react';
21
import PropTypes from 'prop-types';
2+
import React, {Component} from 'react';
3+
4+
const ENTER_KEYCODE = 13;
35

46
// A generic component to handle text that can be edited when the user
57
// clicks on it.
@@ -41,7 +43,7 @@ class EditableText extends Component {
4143

4244
handleKeyPress(event) {
4345
// This will force handleUpdate to be called via the input's onBlur
44-
if ((event.keyCode || event.which) === 13) {
46+
if ((event.keyCode || event.which) === ENTER_KEYCODE) {
4547
this._ref.blur();
4648
}
4749
}

src/components/widgets/FlaglistCheckboxGroup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class FlaglistCheckboxGroup extends Component {
6868
renderCheckedOption() {
6969
const activeOptions = this.state.activeOption.split('+');
7070
const allOptions = this.props.options;
71-
let newOptions = [];
71+
const newOptions = [];
7272

7373
allOptions.map(option => {
7474
let currentChecked;

0 commit comments

Comments
 (0)