Skip to content

Commit

Permalink
More auto fix eslint rules (#1399)
Browse files Browse the repository at this point in the history
* Enable a few more eslint rules

* Enable the object-curly-spacing rule
  • Loading branch information
amanmahajan7 authored Nov 26, 2018
1 parent fd6bed9 commit f169977
Show file tree
Hide file tree
Showing 74 changed files with 462 additions and 447 deletions.
15 changes: 15 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
}],
"no-use-before-define": 2, // http://eslint.org/docs/rules/no-use-before-define,
"no-undef": 2,
"no-delete-var": 2,
"no-label-var": 2,

/**
* Possible errors
Expand All @@ -71,6 +73,10 @@
"no-unreachable": 2, // http://eslint.org/docs/rules/no-unreachable
"use-isnan": 2, // http://eslint.org/docs/rules/use-isnan
"block-scoped-var": 2, // http://eslint.org/docs/rules/block-scoped-var
"no-dupe-args": 2,
"no-template-curly-in-string": 2,
"valid-typeof": [2, { "requireStringLiterals": true }],

/**
* Best practices
*/
Expand Down Expand Up @@ -114,6 +120,13 @@
"wrap-iife": [2, "any"], // http://eslint.org/docs/rules/wrap-iife
"yoda": 2, // http://eslint.org/docs/rules/yoda,
"prefer-const": 2,
"no-empty-pattern": 2,
"no-extra-label": 2,
"no-global-assign": 2,
"no-self-assign": 2,
"no-unmodified-loop-condition": 2,
"no-unused-expressions": [2, { "allowShortCircuit": true }],
"no-useless-call": 2,

/**
* Style
Expand Down Expand Up @@ -166,6 +179,8 @@
"keyword-spacing": 0, // http://eslint.org/docs/rules/space-return-throw-case
"spaced-comment": 2, // http://eslint.org/docs/rules/spaced-comment,
"no-whitespace-before-property": 2,
"no-array-constructor": 2,
"object-curly-spacing": [1, "always"],

/**
* JSX style
Expand Down
6 changes: 3 additions & 3 deletions packages/common/cells/headerCells/FilterableHeaderCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class FilterableHeaderCell extends React.Component {
column: PropTypes.shape(Column)
};

state = {filterTerm: ''};
state = { filterTerm: '' };

handleChange = (e) => {
const val = e.target.value;
this.setState({filterTerm: val });
this.props.onChange({filterTerm: val, column: this.props.column});
this.setState({ filterTerm: val });
this.props.onChange({ filterTerm: val, column: this.props.column });
};

renderInput = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/cells/headerCells/SortableHeaderCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class SortableHeaderCell extends React.Component {
return (
<div className={className}
onClick={this.onClick}
style={{cursor: 'pointer'}}>
style={{ cursor: 'pointer' }}>
<span className="pull-right">{this.getSortByText()}</span>
{content}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import SortableHeaderCell, {DEFINE_SORT} from '../SortableHeaderCell';
import SortableHeaderCell, { DEFINE_SORT } from '../SortableHeaderCell';
import { shallow } from 'enzyme';

const defaultProps = {
Expand Down Expand Up @@ -31,7 +31,7 @@ describe('<SortableHeaderCell/>', () => {

describe('When sortDescendingFirst is true', () => {
it('should set sort descending first when clicked', () => {
const { wrapper, props } = setup({sortDescendingFirst: true});
const { wrapper, props } = setup({ sortDescendingFirst: true });
wrapper.simulate('click');
expect(props.onSort).toHaveBeenCalledWith(props.columnKey, DEFINE_SORT.DESC);
});
Expand All @@ -40,7 +40,7 @@ describe('<SortableHeaderCell/>', () => {
describe('When headerRenderer of column is set', () => {
it('should render the header renderer', () => {
const HeaderRenderer = () => (<span>Custom</span>);
const { wrapper } = setup({headerRenderer: <HeaderRenderer/>});
const { wrapper } = setup({ headerRenderer: <HeaderRenderer/> });
expect(wrapper.find(HeaderRenderer).length).toBe(1);
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/common/editors/__tests__/CheckboxEditor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('CheckboxEditor', () => {
});

it('should not be selected if value prop is false', () => {
componentWrapper.setProps({value: false});
componentWrapper.setProps({ value: false });
const Input = TestUtils.findRenderedDOMComponentWithTag(component, 'input');
const checkboxNode = ReactDOM.findDOMNode(Input);
expect(checkboxNode.checked).toBe(false);
Expand Down
2 changes: 1 addition & 1 deletion packages/common/editors/__tests__/SimpleTextEditor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('SimpleTextEditor', () => {
describe('Basic tests', () => {
let component;

const fakeColumn = { key: 'text', name: 'name', width: 0};
const fakeColumn = { key: 'text', name: 'name', width: 0 };
function fakeBlurCb() { return true; }
function fakeFunction() { }
beforeEach(() => {
Expand Down
48 changes: 24 additions & 24 deletions packages/react-data-grid-addons/src/__tests__/Grid.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ const { mount } = require('enzyme');
describe('Grid', function() {
beforeEach(function() {
this.columns = [
{ key: 'id', name: 'ID', width: 100, events: { onClick: () => {}} },
{ key: 'id', name: 'ID', width: 100, events: { onClick: () => {} } },
{ key: 'title', name: 'Title', width: 100 },
{ key: 'count', name: 'Count', width: 100 },
{ key: 'country', name: 'Country', width: 100, events: { onClick: () => {}, onDoubleClick: () => {}, onDragOver: () => {}}}
{ key: 'country', name: 'Country', width: 100, events: { onClick: () => {}, onDoubleClick: () => {}, onDragOver: () => {} } }
];

this._rows = [];
Expand Down Expand Up @@ -199,7 +199,7 @@ describe('Grid', function() {

describe('When row selection enabled', function() {
beforeEach(function() {
this.component = this.createComponent({ enableRowSelect: true}).instance();
this.component = this.createComponent({ enableRowSelect: true }).instance();
this.baseGrid = this.getBaseGrid();
this.selectRowCol = this.baseGrid.props.columnMetrics.columns[0];
});
Expand Down Expand Up @@ -246,7 +246,7 @@ describe('Grid', function() {

describe('when selected is false', function() {
beforeEach(function() {
this.component.setState({selectedRows: [{id: 0, isSelected: false}, {id: 1, isSelected: false}, {id: 2, isSelected: false}, {id: 3, isSelected: false}]});
this.component.setState({ selectedRows: [{ id: 0, isSelected: false }, { id: 1, isSelected: false }, { id: 2, isSelected: false }, { id: 3, isSelected: false }] });
const selectRowCol = this.baseGrid.props.columnMetrics.columns[0];
selectRowCol.onCellChange(3, 'select-row', this._rows[3], this.buildFakeEvent());
});
Expand All @@ -258,7 +258,7 @@ describe('Grid', function() {

describe('when selected is null', function() {
beforeEach(function() {
this.component.setState({selectedRows: [{id: 0, isSelected: null}, {id: 1, isSelected: null}, {id: 2, isSelected: null}, {id: 3, isSelected: null}]});
this.component.setState({ selectedRows: [{ id: 0, isSelected: null }, { id: 1, isSelected: null }, { id: 2, isSelected: null }, { id: 3, isSelected: null }] });
const selectRowCol = this.baseGrid.props.columnMetrics.columns[0];
selectRowCol.onCellChange(2, 'select-row', this._rows[2], this.buildFakeEvent());
});
Expand All @@ -270,7 +270,7 @@ describe('Grid', function() {

describe('when selected is true', function() {
beforeEach(function() {
this.component.setState({selectedRows: [{id: 0, isSelected: null}, {id: 1, isSelected: true}, {id: 2, isSelected: true}, {id: 3, isSelected: true}]});
this.component.setState({ selectedRows: [{ id: 0, isSelected: null }, { id: 1, isSelected: true }, { id: 2, isSelected: true }, { id: 3, isSelected: true }] });
const selectRowCol = this.baseGrid.props.columnMetrics.columns[0];
selectRowCol.onCellChange(3, 'select-row', this._rows[3], this.buildFakeEvent());
});
Expand All @@ -287,19 +287,19 @@ describe('Grid', function() {
const self = this;
this._selectedRows = [];
this._deselectedRows = [];
this.rows = [{id: '1', isSelected: true}, {id: '2', isSelected: false}, {id: '3', isSelected: false}, {id: '4', isSelected: false}];
const columns = [{name: 'Id', key: 'id'}];
this.rows = [{ id: '1', isSelected: true }, { id: '2', isSelected: false }, { id: '3', isSelected: false }, { id: '4', isSelected: false }];
const columns = [{ name: 'Id', key: 'id' }];
const rowGetter = function(i) {
return self.rows[i];
};
this.component = this.createComponent({ rowsCount: this.rows.length, rowGetter: rowGetter, columns: columns, rowSelection: {enableShiftSelect: true, selectBy: {isSelectedKey: 'isSelected'},
this.component = this.createComponent({ rowsCount: this.rows.length, rowGetter: rowGetter, columns: columns, rowSelection: { enableShiftSelect: true, selectBy: { isSelectedKey: 'isSelected' },
onRowsSelected: function(selectedRows) {
self._selectedRows = selectedRows;
},
onRowsDeselected: function(deselectedRows) {
self._deselectedRows = deselectedRows;
}
}}).instance();
} }).instance();
this.baseGrid = this.getBaseGrid();
this.selectRowCol = this.baseGrid.props.columnMetrics.columns[0];
});
Expand Down Expand Up @@ -348,19 +348,19 @@ describe('Grid', function() {
const self = this;
this._selectedRows = [];
this._deselectedRows = [];
this.rows = [{id: '1'}, {id: '2'}];
const columns = [{name: 'Id', key: 'id'}];
this.rows = [{ id: '1' }, { id: '2' }];
const columns = [{ name: 'Id', key: 'id' }];
const rowGetter = function(i) {
return self.rows[i];
};
this.component = this.createComponent({ enableRowSelect: true, rowsCount: this.rows.length, rowGetter: rowGetter, columns: columns, rowSelection: {selectBy: {indexes: []},
this.component = this.createComponent({ enableRowSelect: true, rowsCount: this.rows.length, rowGetter: rowGetter, columns: columns, rowSelection: { selectBy: { indexes: [] },
onRowsSelected: function(selectedRows) {
self._selectedRows = selectedRows;
},
onRowsDeselected: function(deselectedRows) {
self._deselectedRows = deselectedRows;
}
}}).instance();
} }).instance();

this.baseGrid = this.getBaseGrid();
this.selectRowCol = this.baseGrid.props.columnMetrics.columns[0];
Expand All @@ -385,19 +385,19 @@ describe('Grid', function() {
const self = this;
this._selectedRows = [];
this._deselectedRows = [];
this.rows = [{id: '1'}, {id: '2'}];
const columns = [{name: 'Id', key: 'id'}];
this.rows = [{ id: '1' }, { id: '2' }];
const columns = [{ name: 'Id', key: 'id' }];
const rowGetter = function(i) {
return self.rows[i];
};
this.component = this.createComponent({ enableRowSelect: true, rowsCount: this.rows.length, rowGetter: rowGetter, columns: columns, rowSelection: {selectBy: {indexes: [0, 1]},
this.component = this.createComponent({ enableRowSelect: true, rowsCount: this.rows.length, rowGetter: rowGetter, columns: columns, rowSelection: { selectBy: { indexes: [0, 1] },
onRowsSelected: function(selectedRows) {
self._selectedRows = selectedRows;
},
onRowsDeselected: function(deselectedRows) {
self._deselectedRows = deselectedRows;
}
}}).instance();
} }).instance();

this.baseGrid = this.getBaseGrid();
this.selectRowCol = this.baseGrid.props.columnMetrics.columns[0];
Expand Down Expand Up @@ -467,23 +467,23 @@ describe('Grid', function() {
describe('onRowClick handler', function() {
beforeEach(function() {
const self = this;
this.rows = [{id: '1', isSelected: true}, {id: '2', isSelected: false}];
const columns = [{name: 'Id', key: 'id'}, {name: 'Title', key: 'title', width: 100 }];
this.rows = [{ id: '1', isSelected: true }, { id: '2', isSelected: false }];
const columns = [{ name: 'Id', key: 'id' }, { name: 'Title', key: 'title', width: 100 }];
const rowGetter = function(i) {
return self.rows[i];
};

this.rowClicked = {};
this.rowClicks = 0;

this.component = this.createComponent({rowsCount: this.rows.length, rowGetter: rowGetter, columns: columns, onRowClick: function(rowIdx, row, column) {
self.rowClicked = {row, column};
this.component = this.createComponent({ rowsCount: this.rows.length, rowGetter: rowGetter, columns: columns, onRowClick: function(rowIdx, row, column) {
self.rowClicked = { row, column };
self.rowClicks++;
}}).instance();
} }).instance();
});

it('calls handler when row (cell) clicked', function() {
this.getCellMetaData().onCellClick({ idx: 1, rowIdx: 1});
this.getCellMetaData().onCellClick({ idx: 1, rowIdx: 1 });
expect(this.rowClicks).toBe(1);
const { row, column } = this.rowClicked;
expect(row).toEqual(jasmine.objectContaining(this.rows[1]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'react-select/dist/react-select.css';
import React from 'react';
import PropTypes from 'prop-types';
import Select from 'react-select';
import {isEmptyArray} from 'common/utils';
import { isEmptyArray } from 'common/utils';
import Column from 'common/prop-shapes/Column';

class AutoCompleteFilter extends React.Component {
Expand All @@ -11,11 +11,11 @@ class AutoCompleteFilter extends React.Component {
this.getOptions = this.getOptions.bind(this);
this.handleChange = this.handleChange.bind(this);
this.filterValues = this.filterValues.bind(this);
this.state = {options: this.getOptions(), rawValue: '', placeholder: 'Search'};
this.state = { options: this.getOptions(), rawValue: '', placeholder: 'Search' };
}

componentWillReceiveProps(newProps) {
this.setState({options: this.getOptions(newProps)});
this.setState({ options: this.getOptions(newProps) });
}

getOptions(newProps) {
Expand Down Expand Up @@ -58,8 +58,8 @@ class AutoCompleteFilter extends React.Component {

handleChange(value) {
const filters = value;
this.setState({filters});
this.props.onChange({filterTerm: filters, column: this.props.column, rawValue: value, filterValues: this.filterValues });
this.setState({ filters });
this.props.onChange({ filterTerm: filters, column: this.props.column, rawValue: value, filterValues: this.filterValues });
}

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class NumericFilter extends React.Component {
handleChange(e) {
const value = e.target.value;
const filters = this.getRules(value);
this.props.onChange({filterTerm: (filters.length > 0 ? filters : null), column: this.props.column, rawValue: value, filterValues: this.filterValues });
this.props.onChange({ filterTerm: (filters.length > 0 ? filters : null), column: this.props.column, rawValue: value, filterValues: this.filterValues });
}

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,77 +74,77 @@ describe('AutoCompleteFilter', () => {
});

it('should filter valid values', () => {
const columnFilter = { filterTerm: [ {value: '1'} ] };
const columnFilter = { filterTerm: [ { value: '1' } ] };
const request = filterValues(columnFilter);
expect(request).toBeTruthy();
});

it('should handle invalid values', () => {
const columnFilter = { filterTerm: [ {value: '3'} ] };
const columnFilter = { filterTerm: [ { value: '3' } ] };
const request = filterValues(columnFilter);
expect(request).toBeFalsy();
});

it('should handle empty values', () => {
const columnFilter = { filterTerm: [ {value: ''} ] };
const columnFilter = { filterTerm: [ { value: '' } ] };
const request = filterValues(columnFilter);
expect(request).toBeFalsy();
});

it('should be a full match when filter match is the first word', () => {
const columnFilter = { filterTerm: [ {value: 'Title 1'} ] };
const columnFilter = { filterTerm: [ { value: 'Title 1' } ] };
const request = filterValues(columnFilter);
expect(request).toBeFalsy();
});

it('should transform Integers into string to compare', () => {
const columnFilter = { filterTerm: [ {value: 1} ] };
const columnFilter = { filterTerm: [ { value: 1 } ] };
const request = filterValues(columnFilter);
expect(request).toBeTruthy();
});

it('should transform Float into string to compare', () => {
const columnFilter = { filterTerm: [ {value: 1.1} ] };
const columnFilter = { filterTerm: [ { value: 1.1 } ] };
const request = filterValues(columnFilter);
expect(request).toBeFalsy();
});

it('should transform row values into string to compare data (returns true)', () => {
rows = [{ id: 1, title: 0.15, count: 1 }];
const columnFilter = { filterTerm: [ {value: '0.15'} ] };
const columnFilter = { filterTerm: [ { value: '0.15' } ] };
const request = filterValues(columnFilter);
expect(request).toBeTruthy();
});

it('should transform row values into string to compare data (returns false)', () => {
rows = [{ id: 1, title: 0.15, count: 1 }];
const columnFilter = { filterTerm: [ {value: '0.10'} ] };
const columnFilter = { filterTerm: [ { value: '0.10' } ] };
const request = filterValues(columnFilter);
expect(request).toBeFalsy();
});

it('should transform row and filter values into string to compare data', () => {
rows = [{ id: 1, title: 0.15, count: 1 }];
const columnFilter = { filterTerm: [ {value: 0.15} ] };
const columnFilter = { filterTerm: [ { value: 0.15 } ] };
const request = filterValues(columnFilter);
expect(request).toBeTruthy();
});

it('should trim spaces of the filterTerm values', () => {
const columnFilter = { filterTerm: [ {value: ' 1 '} ] };
const columnFilter = { filterTerm: [ { value: ' 1 ' } ] };
const request = filterValues(columnFilter);
expect(request).toBeTruthy();
});

it('should handle undefined row values', () => {
rows = [{ id: 1, title: undefined, count: 1 }];
const columnFilter = { filterTerm: [ {value: 1} ] };
const columnFilter = { filterTerm: [ { value: 1 } ] };
const request = filterValues(columnFilter);
expect(request).toBeFalsy();
});

it('should handle undefined filter values', () => {
const columnFilter = { filterTerm: [ {value: undefined} ] };
const columnFilter = { filterTerm: [ { value: undefined } ] };
const request = filterValues(columnFilter);
expect(request).toBeFalsy();
});
Expand Down
Loading

0 comments on commit f169977

Please sign in to comment.