Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

fix `prefer-destructuring` errors

Jason Kent441a50517295
diff --git a/.eslintrc b/.eslintrc
index a45d1016d..2312cdaf4 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -79,8 +79,8 @@
"no-nested-ternary": "warn",
"no-shadow": "warn",
"prefer-const": "warn",
- "prefer-destructuring": "warn",
"class-methods-use-this": "warn",
+ "no-plusplus": "warn", // 50 errors (set to WARN)
"max-len": "off",
"no-multi-assign": "off",
@@ -90,7 +90,7 @@
"func-names": "off",
"no-param-reassign": "off",
"no-use-before-define": "off",
- "no-plusplus": "off",
+
"prefer-rest-params": "off",
// Import rules overrides
@@ -112,13 +112,14 @@
// React rules overrides
"react/jsx-props-no-spreading": "warn",
+ "react/destructuring-assignment": "off", // 464 errors (Set to WARN)
+ "react/no-unused-state": "warn", // 38 errors
"react/jsx-filename-extension": "off",
"react/sort-comp": "off",
- "react/no-unused-state": "warn", // 38 errors
+
"react/no-unused-prop-types": "warn", // 66 errors
"react/forbid-prop-types": "off", // 216 errors
- "react/require-default-props": "off", // 965 errors
- "react/destructuring-assignment": "off" // 464 errors (Set to warn)
+ "react/require-default-props": "off" // 965 errors
}
}
]
diff --git a/web/js/components/layer/product-picker/category-layer-row.js b/web/js/components/layer/product-picker/category-layer-row.js
index 91d801f15..56b747873 100644
--- a/web/js/components/layer/product-picker/category-layer-row.js
+++ b/web/js/components/layer/product-picker/category-layer-row.js
@@ -94,7 +94,8 @@ class CategoryLayerRow extends React.Component {
if (layer.title.indexOf('(') !== -1) {
const regExp = /\(([^)]+)\)/;
const matches = regExp.exec(layer.title);
- orbitTitle = matches[1];
+ // eslint-disable-next-line prefer-destructuring
+ [, orbitTitle] = matches;
}
}
});
diff --git a/web/js/components/layer/product-picker/product-picker.js b/web/js/components/layer/product-picker/product-picker.js
index 65a2bff19..aa8df1059 100644
--- a/web/js/components/layer/product-picker/product-picker.js
+++ b/web/js/components/layer/product-picker/product-picker.js
@@ -133,7 +133,7 @@ class ProductPicker extends React.Component {
&& !!filteredRows.find((layer) => layer.id === selectedLayer.id);
if (filteredRows.length === 1) {
- newSelectedLayer = filteredRows[0];
+ [newSelectedLayer] = filteredRows;
} else if (selectedLayerInResults) {
newSelectedLayer = selectedLayer;
}
diff --git a/web/js/components/layer/settings/settings.js b/web/js/components/layer/settings/settings.js
index 6c8453914..f24afe9be 100644
--- a/web/js/components/layer/settings/settings.js
+++ b/web/js/components/layer/settings/settings.js
@@ -241,7 +241,7 @@ class LayerSettings extends React.Component {
} = this.props;
let customStyle;
if (layer.custom && layer.custom[0]) {
- customStyle = layer.custom[0];
+ [customStyle] = layer.custom;
}
return (
<>
diff --git a/web/js/components/layer/settings/vector-style.js b/web/js/components/layer/settings/vector-style.js
index 0878cedb0..ed03b4e0e 100644
--- a/web/js/components/layer/settings/vector-style.js
+++ b/web/js/components/layer/settings/vector-style.js
@@ -55,6 +55,7 @@ class VectorStyleSelect extends React.Component {
* @param {String} id | colormap Id
* @param {String} description | Colormap name
*/
+ // eslint-disable-next-line class-methods-use-this
renderLegendMultiItem(vectorStyle, vectorStyleId, description) {
const caseDefaultClassName = 'wv-palette-selector-row ';
const array = Array.from(vectorStyle.paint['line-color'] || vectorStyle.paint['circle-color'] || vectorStyle.paint['fill-color']);
@@ -71,8 +72,7 @@ class VectorStyleSelect extends React.Component {
&& typeof temp[0][2] === 'string'
&& typeof temp[1] === 'string'
) {
- obj.label = temp[0][2];
- obj.color = temp[1];
+ [[,, obj.label], obj.color] = temp;
organizedArray.push(obj);
} else {
console.warn('Irregular conditional');
diff --git a/web/js/components/timeline/timeline-axis/grid-range/tile-text.js b/web/js/components/timeline/timeline-axis/grid-range/tile-text.js
index a2ad23077..21f357f27 100644
--- a/web/js/components/timeline/timeline-axis/grid-range/tile-text.js
+++ b/web/js/components/timeline/timeline-axis/grid-range/tile-text.js
@@ -13,8 +13,7 @@ const axisScaleTextElementWrapper = (item, index, gridWidth) => {
// TODO: may need to expand for subdaily to differentiate time units
if (item.timeScale === 'day') {
const dateSplit = item.date.split(' ');
- dateText = dateSplit[0];
- dateTextYear = dateSplit[1];
+ [dateText, dateTextYear] = dateSplit;
} else {
dateText = item.date;
}
diff --git a/web/js/map/compare/opacity.js b/web/js/map/compare/opacity.js
index f23e4d60c..55a7e6307 100644
--- a/web/js/map/compare/opacity.js
+++ b/web/js/map/compare/opacity.js
@@ -23,8 +23,7 @@ export class Opacity {
* Refresh secondLayer layer group (after date change for example)
*/
update() {
- this.secondLayer = this.map.getLayers().getArray()[1];
- this.firstLayer = this.map.getLayers().getArray()[0];
+ [this.firstLayer, this.secondLayer] = this.map.getLayers().getArray();
this.oninput(value);
}
@@ -42,9 +41,7 @@ export class Opacity {
* @param {Object} secondLayer | Second layer group on Map
*/
createSlider(layerArray) {
- this.firstLayer = layerArray[0];
- this.secondLayer = layerArray[1];
-
+ [this.firstLayer, this.secondLayer] = layerArray;
this.mapCase = document.getElementById('wv-map');
const Props = {
onSlide: this.oninput.bind(this),
diff --git a/web/js/map/data/ui.js b/web/js/map/data/ui.js
index 107d1a6cc..6ed1f30ea 100644
--- a/web/js/map/data/ui.js
+++ b/web/js/map/data/ui.js
@@ -73,6 +73,8 @@ export function dataUi(store, ui, config) {
case SELECT_DATE:
case DATA_CONSTANTS.SELECT_PRODUCT:
return query();
+ default:
+ break;
}
};
const changeProjection = function() {
@@ -536,6 +538,7 @@ const dataUiDownloadListPanel = function(config, store) {
.split('.')
.slice(-1);
if (hrefExt && hrefExt.length > 0) {
+ // eslint-disable-next-line prefer-destructuring
hrefExt = hrefExt[0];
}
if (
diff --git a/web/js/map/datelinebuilder.js b/web/js/map/datelinebuilder.js
index 37b0fc260..2e0e5b50e 100644
--- a/web/js/map/datelinebuilder.js
+++ b/web/js/map/datelinebuilder.js
@@ -68,7 +68,7 @@ export function mapDateLineBuilder(models, config, store, ui) {
let dimensions;
map = olMap;
drawDatelines(map, date);
- self.date = date.toISOString().split('T')[0];
+ [self.date] = date.toISOString().split('T');
proj = store.getState().proj.id;
Parent.events.on('moveend', () => {
@@ -349,14 +349,14 @@ export function mapDateLineBuilder(models, config, store, ui) {
if (startY > 90) {
startY = 90;
- topY = map.getPixelFromCoordinate([extent[2], 90])[1];
+ [, topY] = map.getPixelFromCoordinate([extent[2], 90]);
} else {
- topY = map.getPixelFromCoordinate(top)[1];
+ [, topY] = map.getPixelFromCoordinate(top);
}
if (extent[1] > -90) {
- bottomY = map.getPixelFromCoordinate(bottom)[1];
+ [, bottomY] = map.getPixelFromCoordinate(bottom);
} else {
- bottomY = map.getPixelFromCoordinate([extent[2], -90])[1];
+ [, bottomY] = map.getPixelFromCoordinate([extent[2], -90]);
}
height = Math.round(Math.abs(bottomY - topY));
return [height, startY];
diff --git a/web/js/map/natural-events/ui.js b/web/js/map/natural-events/ui.js
index f5eee569e..698d5d630 100644
--- a/web/js/map/natural-events/ui.js
+++ b/web/js/map/natural-events/ui.js
@@ -73,6 +73,8 @@ export default function naturalEventsUI(ui, config, store, models) {
return;
case CHANGE_PROJECTION:
return !isLoading ? onProjChange(action.id) : '';
+ default:
+ break;
}
};
@@ -320,7 +322,7 @@ export default function naturalEventsUI(ui, config, store, models) {
const today = new Date().toISOString().split('T')[0];
// For storms that happened today, get previous date
if (date === today && category === 'Severe Storms') {
- date = new Date(event.geometries[1].date).toISOString().split('T')[0];
+ [date] = new Date(event.geometries[1].date).toISOString().split('T');
}
return date;
};
diff --git a/web/js/map/runningdata.js b/web/js/map/runningdata.js
index 2b1cad9c9..4ff521cf3 100644
--- a/web/js/map/runningdata.js
+++ b/web/js/map/runningdata.js
@@ -71,7 +71,7 @@ export function MapRunningData(models, compareUi, store) {
const colorIndex = tooltips.indexOf(value.toLowerCase().replace(/\s/g, ''));
color = legend.colors[colorIndex];
} else if (legend.colors.length === 1) {
- color = legend.colors[0];
+ [color] = legend.colors;
}
activeLayerObj[layerId] = {
paletteLegends,
diff --git a/web/js/modules/data/selectors.js b/web/js/modules/data/selectors.js
index 0b999901c..88df598f4 100644
--- a/web/js/modules/data/selectors.js
+++ b/web/js/modules/data/selectors.js
@@ -130,6 +130,7 @@ export function findAvailableProduct(layers) {
foundProduct = layers[i].product;
// If the layer has more than one product, select the first.
if (Array.isArray(foundProduct)) {
+ // eslint-disable-next-line prefer-destructuring
foundProduct = foundProduct[0];
}
}
diff --git a/web/js/modules/natural-events/selectors.js b/web/js/modules/natural-events/selectors.js
index e5fab7cd1..26c4c9872 100644
--- a/web/js/modules/natural-events/selectors.js
+++ b/web/js/modules/natural-events/selectors.js
@@ -58,13 +58,13 @@ export function getEventsWithinExtent(
return visibleListEvents;
}
export function getDefaultEventDate(event) {
- let date = new Date(event.geometries[0].date).toISOString().split('T')[0];
+ let [date] = new Date(event.geometries[0].date).toISOString().split('T');
if (event.geometries.length < 2) return date;
const category = event.categories.title || event.categories[0].title;
const today = new Date().toISOString().split('T')[0];
// For storms that happened today, get previous date
if (date === today && category === 'Severe Storms') {
- date = new Date(event.geometries[1].date).toISOString().split('T')[0];
+ [date] = new Date(event.geometries[1].date).toISOString().split('T');
}
return date;
}
diff --git a/web/js/modules/notifications/util.js b/web/js/modules/notifications/util.js
index 5f4a2adca..932c760d5 100644
--- a/web/js/modules/notifications/util.js
+++ b/web/js/modules/notifications/util.js
@@ -68,13 +68,10 @@ export function localStorageValueMatches(property, value) {
* @returns {void}
*/
export function getPriority(sortedNotifications) {
- let priority; let message; let outage; let
- alert;
-
- priority = '';
- message = sortedNotifications.messages[0];
- outage = sortedNotifications.outages[0];
- alert = sortedNotifications.alerts[0];
+ let priority = '';
+ const [message] = sortedNotifications.messages;
+ const [outage] = sortedNotifications.outages;
+ const [alert] = sortedNotifications.alerts;
if (message && !objectAlreadySeen(message)) {
priority = 'message';