Skip to content

Commit

Permalink
Re-enable rule no-else-return
Browse files Browse the repository at this point in the history
  • Loading branch information
kgabryje committed Sep 14, 2020
1 parent 7f10123 commit 1966ce4
Show file tree
Hide file tree
Showing 31 changed files with 136 additions and 71 deletions.
4 changes: 1 addition & 3 deletions superset-frontend/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ module.exports = {
'new-cap': 0,
'no-bitwise': 0,
'no-continue': 0,
'no-else-return': 0, // disabled temporarily
'no-mixed-operators': 0,
'no-multi-assign': 0,
'no-multi-spaces': 0,
Expand Down Expand Up @@ -208,8 +207,7 @@ module.exports = {
'jsx-a11y/mouse-events-have-key-events': 0, // re-enable up for discussion
'lines-between-class-members': 0, // disabled temporarily
'new-cap': 0,
'no-restricted-globals': 0, // disabled temporarily
'no-else-return': 0, // disabled temporarily
'no-restricted-globals': 0,
'no-bitwise': 0,
'no-continue': 0,
'no-mixed-operators': 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class EstimateQueryCostButton extends React.PureComponent {
{this.props.queryCostEstimate.error}
</Alert>
);
} else if (this.props.queryCostEstimate.completed) {
}
if (this.props.queryCostEstimate.completed) {
return (
<Table
className="table cost-estimate"
Expand Down
15 changes: 10 additions & 5 deletions superset-frontend/src/SqlLab/components/ResultSet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ export default class ResultSet extends React.PureComponent<

if (query.state === 'stopped') {
return <Alert bsStyle="warning">Query was stopped</Alert>;
} else if (query.state === 'failed') {
}
if (query.state === 'failed') {
return (
<div className="result-set-error-message">
<ErrorMessageWithStackTrace
Expand All @@ -227,7 +228,8 @@ export default class ResultSet extends React.PureComponent<
/>
</div>
);
} else if (query.state === 'success' && query.ctas) {
}
if (query.state === 'success' && query.ctas) {
const { tempSchema, tempTable } = query;
let object = 'Table';
if (query.ctas_method === CtasEnum.VIEW) {
Expand Down Expand Up @@ -262,7 +264,8 @@ export default class ResultSet extends React.PureComponent<
</Alert>
</div>
);
} else if (query.state === 'success' && query.results) {
}
if (query.state === 'success' && query.results) {
const { results } = query;
let data;
if (this.props.cache && query.cached) {
Expand All @@ -287,7 +290,8 @@ export default class ResultSet extends React.PureComponent<
/>
</>
);
} else if (data && data.length === 0) {
}
if (data && data.length === 0) {
return (
<Alert bsStyle="warning">{t('The query returned no data')}</Alert>
);
Expand All @@ -310,7 +314,8 @@ export default class ResultSet extends React.PureComponent<
{t('Fetch data preview')}
</Button>
);
} else if (query.resultsKey) {
}
if (query.resultsKey) {
return (
<Button
buttonSize="sm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ const RunQueryActionButton = ({
<i className="fa fa-stop" /> {t('Stop')}
</Button>
);
} else if (allowAsync) {
}
if (allowAsync) {
return (
<Button
{...commonBtnProps}
Expand Down
3 changes: 2 additions & 1 deletion superset-frontend/src/SqlLab/components/TableElement.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ class TableElement extends React.PureComponent {
const colB = b.name.toUpperCase();
if (colA < colB) {
return -1;
} else if (colA > colB) {
}
if (colA > colB) {
return 1;
}
return 0;
Expand Down
3 changes: 2 additions & 1 deletion superset-frontend/src/chart/chartReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ export default function chartReducer(charts = {}, action) {
if (action.type === actions.REMOVE_CHART) {
delete charts[action.key];
return charts;
} else if (action.type === actions.UPDATE_CHART_ID) {
}
if (action.type === actions.UPDATE_CHART_ID) {
const { newId, key } = action;
charts[newId] = {
...charts[key],
Expand Down
24 changes: 16 additions & 8 deletions superset-frontend/src/components/AlteredSliceTag.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ function alterForComparison(value) {
// for this purpose
if (value === undefined || value === null || value === '') {
return null;
} else if (typeof value === 'object') {
}
if (typeof value === 'object') {
if (Array.isArray(value) && value.length === 0) {
return null;
}
Expand Down Expand Up @@ -100,9 +101,11 @@ export default class AlteredSliceTag extends React.Component {
// or the value type
if (value === undefined) {
return 'N/A';
} else if (value === null) {
}
if (value === null) {
return 'null';
} else if (
}
if (
this.state.controlsMap[key] &&
this.state.controlsMap[key].type === 'AdhocFilterControl'
) {
Expand All @@ -118,21 +121,26 @@ export default class AlteredSliceTag extends React.Component {
return `${v.subject} ${v.operator} ${filterVal}`;
})
.join(', ');
} else if (
}
if (
this.state.controlsMap[key] &&
this.state.controlsMap[key].type === 'BoundsControl'
) {
return `Min: ${value[0]}, Max: ${value[1]}`;
} else if (
}
if (
this.state.controlsMap[key] &&
this.state.controlsMap[key].type === 'CollectionControl'
) {
return value.map(v => safeStringify(v)).join(', ');
} else if (typeof value === 'boolean') {
}
if (typeof value === 'boolean') {
return value ? 'true' : 'false';
} else if (value.constructor === Array) {
}
if (value.constructor === Array) {
return value.length ? value.join(', ') : '[]';
} else if (typeof value === 'string' || typeof value === 'number') {
}
if (typeof value === 'string' || typeof value === 'number') {
return value;
}
return safeStringify(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,15 @@ export default class FilterableTable extends PureComponent<
if (aValue === bValue) {
// equal items sort equally
return 0;
} else if (aValue === null) {
}
if (aValue === null) {
// nulls sort after anything else
return 1;
} else if (bValue === null) {
}
if (bValue === null) {
return -1;
} else if (descending) {
}
if (descending) {
return aValue < bValue ? 1 : -1;
}
return aValue < bValue ? -1 : 1;
Expand Down
3 changes: 2 additions & 1 deletion superset-frontend/src/components/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ export function Menu({
className="settings-divider"
/>
);
} else if (section.isHeader) {
}
if (section.isHeader) {
return (
<MenuItem key={`${section.label}`} disabled>
{section.label}
Expand Down
3 changes: 2 additions & 1 deletion superset-frontend/src/components/Menu/MenuObject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export default function MenuObject({
{childs?.map((child: MenuObjectChildProps | string, index1: number) => {
if (typeof child === 'string' && child === '-') {
return <MenuItem key={`$${index1}`} divider />;
} else if (typeof child !== 'string') {
}
if (typeof child !== 'string') {
return (
<MenuItem
key={`${child.label}`}
Expand Down
3 changes: 2 additions & 1 deletion superset-frontend/src/components/ModalTrigger.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ export default class ModalTrigger extends React.Component {
{this.renderModal()}
</>
);
} else if (this.props.isMenuItem) {
}
if (this.props.isMenuItem) {
return (
<>
<MenuItem onClick={this.open}>{this.props.triggerNode}</MenuItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ function sortByIndicatorLabel(indicator1, indicator2) {
const s2 = (indicator2.label || indicator2.name).toLowerCase();
if (s1 < s2) {
return -1;
} else if (s1 > s2) {
}
if (s1 > s2) {
return 1;
}
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default class PublishedStatus extends React.Component {
}

// Show the published badge for the owner of the dashboard to toggle
else if (this.props.canEdit && this.props.canSave) {
if (this.props.canEdit && this.props.canSave) {
return (
<TooltipWrapper
label="Published Dashboard"
Expand Down
3 changes: 2 additions & 1 deletion superset-frontend/src/dashboard/components/SliceAdder.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class SliceAdder extends React.Component {
return (a, b) => {
if (a[attr] < b[attr]) {
return -1 * desc;
} else if (a[attr] > b[attr]) {
}
if (a[attr] > b[attr]) {
return 1 * desc;
}
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ class Markdown extends React.PureComponent {
markdownSource: nextComponent.meta.code,
hasError: false,
};
} else if (
}
if (
!hasError &&
editorMode === 'preview' &&
nextComponent.meta.code !== markdownSource
Expand Down
9 changes: 6 additions & 3 deletions superset-frontend/src/dashboard/reducers/dashboardFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ export default function dashboardFiltersReducer(dashboardFilters = {}, action) {
components: action.components,
});
return dashboardFilters;
} else if (action.type === UPDATE_DASHBOARD_FILTERS_SCOPE) {
}
if (action.type === UPDATE_DASHBOARD_FILTERS_SCOPE) {
const allDashboardFiltersScope = action.scopes;
// update filter scope for each filter field
const updatedFilters = Object.entries(allDashboardFiltersScope).reduce(
Expand All @@ -153,14 +154,16 @@ export default function dashboardFiltersReducer(dashboardFilters = {}, action) {

buildActiveFilters({ dashboardFilters: updatedFilters });
return updatedFilters;
} else if (action.type === REMOVE_FILTER) {
}
if (action.type === REMOVE_FILTER) {
const { chartId } = action;
const { [chartId]: deletedFilter, ...updatedFilters } = dashboardFilters;
buildActiveFilters({ dashboardFilters: updatedFilters });
buildFilterColorMap(updatedFilters);

return updatedFilters;
} else if (action.type in actionHandlers) {
}
if (action.type in actionHandlers) {
const updatedFilters = {
...dashboardFilters,
[action.chartId]: actionHandlers[action.type](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ export default function getComponentWidthFromDrop({

if (isNaN(destinationCapacity) || isNaN(draggingWidth.width)) {
return draggingWidth.width;
} else if (destinationCapacity >= draggingWidth.width) {
}
if (destinationCapacity >= draggingWidth.width) {
return draggingWidth.width;
} else if (destinationCapacity >= draggingWidth.minimumWidth) {
}
if (destinationCapacity >= draggingWidth.minimumWidth) {
return destinationCapacity;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ let cachedIdsLookup = {};
export default function findNonTabChildChartIdsWithCache({ id, layout }) {
if (cachedLayout === layout && cachedIdsLookup[id]) {
return cachedIdsLookup[id];
} else if (layout !== cachedLayout) {
}
if (layout !== cachedLayout) {
cachedLayout = layout;
cachedIdsLookup = {};
}
Expand Down
3 changes: 2 additions & 1 deletion superset-frontend/src/explore/AdhocFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ function translateToSql(adhocMetric, { useSimple } = {}) {
return `${subject} ${operator} ${isMulti ? "('" : ''}${comparator}${
isMulti ? "')" : ''
}`;
} else if (adhocMetric.expressionType === EXPRESSION_TYPES.SQL) {
}
if (adhocMetric.expressionType === EXPRESSION_TYPES.SQL) {
return adhocMetric.sqlExpression;
}
return '';
Expand Down
6 changes: 4 additions & 2 deletions superset-frontend/src/explore/AdhocMetric.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ export default class AdhocMetric {
return `${this.aggregate || ''}(${
(this.column && this.column.column_name) || ''
})`;
} else if (this.expressionType === EXPRESSION_TYPES.SQL) {
}
if (this.expressionType === EXPRESSION_TYPES.SQL) {
return this.sqlExpression;
}
return '';
Expand Down Expand Up @@ -125,7 +126,8 @@ export default class AdhocMetric {
isValid() {
if (this.expressionType === EXPRESSION_TYPES.SIMPLE) {
return !!(this.column && this.aggregate);
} else if (this.expressionType === EXPRESSION_TYPES.SQL) {
}
if (this.expressionType === EXPRESSION_TYPES.SQL) {
return !!this.sqlExpression;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ const defaultProps = {
function translateOperator(operator) {
if (operator === OPERATORS['==']) {
return 'equals';
} else if (operator === OPERATORS['!=']) {
}
if (operator === OPERATORS['!=']) {
return 'not equal to';
} else if (operator === OPERATORS.LIKE) {
}
if (operator === OPERATORS.LIKE) {
return 'like';
} else if (operator === OPERATORS['LATEST PARTITION']) {
}
if (operator === OPERATORS['LATEST PARTITION']) {
return 'use latest_partition template';
}
return operator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,12 @@ class ControlPanelsContainer extends React.Component {
if (!controlItem) {
// When the item is invalid
return null;
} else if (React.isValidElement(controlItem)) {
}
if (React.isValidElement(controlItem)) {
// When the item is a React element
return controlItem;
} else if (controlItem.name && controlItem.config) {
}
if (controlItem.name && controlItem.config) {
return this.renderControl(controlItem);
}
return null;
Expand Down
Loading

0 comments on commit 1966ce4

Please sign in to comment.