Skip to content

Commit

Permalink
removed tslint comments and fixed code to eslint standards
Browse files Browse the repository at this point in the history
  • Loading branch information
jina2k committed Mar 28, 2022
1 parent e293a13 commit 6c6d51a
Show file tree
Hide file tree
Showing 18 changed files with 25 additions and 111 deletions.
2 changes: 0 additions & 2 deletions src/client/app/actions/barReadings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ function fetchGroupBarReadings(groupIDs: number[], timeInterval: TimeInterval):
export function fetchNeededBarReadings(timeInterval: TimeInterval): Thunk {
return (dispatch: Dispatch, getState: GetState) => {
const state = getState();
/* tslint:disable:array-type */
const promises: Array<Promise<any>> = [];
/* tslint:enable:array-type */

// Determine which meters are missing data for this time interval
const meterIDsToFetchForBar = state.graph.selectedMeters.filter(
Expand Down
2 changes: 0 additions & 2 deletions src/client/app/actions/compareReadings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ export function fetchNeededCompareReadings(comparePeriod: ComparePeriod): Thunk
const state = getState();
const compareShift = calculateCompareShift(comparePeriod);
const timeInterval = state.graph.compareTimeInterval;
/* tslint:disable:array-type */
const promises: Array<Promise<any>> = [];
/* tslint:enable:array-type */

// Determine which meters are missing data for this time interval
const meterIDsToFetchForCompare = state.graph.selectedMeters.filter(
Expand Down
1 change: 0 additions & 1 deletion src/client/app/actions/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ export interface LinkOptions {
*/
export function changeOptionsFromLink(options: LinkOptions) {
const dispatchFirst: Thunk[] = [setHotlinkedAsync(true)];
/* tslint:disable:array-type */
const dispatchSecond: Array<Thunk | t.ChangeChartToRenderAction | t.ChangeBarStackingAction
| t.ChangeGraphZoomAction |t.ChangeCompareSortingOrderAction | t.SetOptionsVisibility
| m.UpdateSelectedMapAction > = [];
Expand Down
2 changes: 0 additions & 2 deletions src/client/app/actions/lineReadings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ function fetchGroupLineReadings(groupIDs: number[], timeInterval: TimeInterval):
export function fetchNeededLineReadings(timeInterval: TimeInterval): Thunk {
return (dispatch: Dispatch, getState: GetState) => {
const state = getState();
/* tslint:disable:array-type */
const promises: Array<Promise<any>> = [];
/* tslint:enable:array-type */

// Determine which meters are missing data for this time interval
const meterIDsToFetchForLine = state.graph.selectedMeters.filter(
Expand Down
12 changes: 8 additions & 4 deletions src/client/app/actions/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ function updateCalibrationSet(calibratedPoint: CalibratedPoint): t.AppendCalibra
*/
function isReadyForCalculation(state: State): boolean {
const calibrationThreshold = 3;
// @ts-ignore
return state.maps.editedMaps[state.maps.calibratingMap].calibrationSet.length >= calibrationThreshold;
// assume calibrationSet is defined, as offerCurrentGPS indicates through point that the map is defined.
/* eslint-disable @typescript-eslint/no-non-null-assertion */
return state.maps.editedMaps[state.maps.calibratingMap].calibrationSet!.length >= calibrationThreshold;
/* eslint-enable @typescript-eslint/no-non-null-assertion */
}

/**
Expand All @@ -182,9 +184,11 @@ function prepareDataToCalculation(state: State): CalibrationResult {
width: mp.image.width,
height: mp.image.height
};
// @ts-ignore
const result = calibrate(mp.calibrationSet, imageDimensions, mp.northAngle);
// Since mp is defined above, calibrationSet is defined.
/* eslint-disable @typescript-eslint/no-non-null-assertion */
const result = calibrate(mp.calibrationSet!, imageDimensions, mp.northAngle);
return result;
/* eslint-enable @typescript-eslint/no-non-null-assertion */
}

function updateResult(result: CalibrationResult): t.UpdateCalibrationResultAction {
Expand Down
4 changes: 0 additions & 4 deletions src/client/app/components/MultiSelectComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ import { SelectOption } from '../types/items';

interface MultiSelectProps<I> {
placeholder: string;
/* tslint:disable:array-type */
options: Array<SelectOption & I>;
selectedOptions: Array<SelectOption & I> | undefined;
singleSelect?: boolean;
onValuesChange(values: Array<SelectOption & I>): void;
/* tslint:enable:array-type */
}

interface MultiSelectState {
Expand Down Expand Up @@ -50,9 +48,7 @@ export default class MultiSelectComponent<I> extends React.Component<MultiSelect
);
}

/* tslint:disable:array-type */
private onValuesChangeInternal(items: Array<SelectOption & I>) {
/* tslint:enable:array-type */
// Defer to the underlying MultiSelect when it has a state change
// Note that the MSC state selectedOptions is in fact the canonical source of truth
this.setState({ selectedOptions: items });
Expand Down
5 changes: 0 additions & 5 deletions src/client/app/components/groups/DatasourceBoxComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type DatasourceBoxPropsWithIntl = DatasourceBoxProps & WrappedComponentProps;

// This is just an alias, so it's ok to have it in this file.
// Aliasing this specialization is required because the meaning of < and > conflict in TypeScript and JSX.
// tslint:disable max-classes-per-file
class MultiSelectDatasourceComponent extends MultiSelectComponent<DatasourceID> { }

class DatasourceBoxComponent extends React.Component<DatasourceBoxPropsWithIntl> {
Expand All @@ -36,18 +35,14 @@ class DatasourceBoxComponent extends React.Component<DatasourceBoxPropsWithIntl>
type = DataType.Meter;
}

/* tslint:disable:array-type */
const options: Array<SelectOption & DatasourceID> = this.props.datasource.map((element: NamedIDItem) => (
/* tslint:enable:array-type */
{
label: element.name,
type,
value: element.id
}
));
/* tslint:disable:array-type */
let selectedOptions: Array<SelectOption & DatasourceID> | undefined;
/* tslint:enable:array-type */
if (this.props.selectedOptions) {
selectedOptions = this.props.selectedOptions.map((element: NamedIDItem) => (
{
Expand Down
4 changes: 1 addition & 3 deletions src/client/app/components/groups/GroupSidebarComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import { ChangeDisplayedGroupsAction } from '../../types/redux/groups';
import { Link } from 'react-router-dom';

interface GroupSidebarProps {
/* tslint:disable:array-type */
groups: Array<{ id: number, name: string }>;
loggedInAsAdmin: boolean;
/* tslint:enable:array-type */
selectGroups(groups: number[]): ChangeDisplayedGroupsAction;
}

Expand Down Expand Up @@ -58,7 +56,7 @@ export default class GroupSidebarComponent extends React.Component<GroupSidebarP
const options = e.target.options;
const selectedGroups: number[] = [];
// We can't map or for-of here because this is a collection of DOM elements, not an array.
for (let i = 0; i < options.length; i++) { // tslint:disable-line prefer-for-of
for (let i = 0; i < options.length; i++) {
if (options[i].selected) {
selectedGroups.push(parseInt(options[i].value));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ class MapCalibrationInitiateComponent extends React.Component<MapInitiatePropsWi
const file = this.fileInput.current.files[0];
const fileReader = new FileReader();
fileReader.onloadend = () => {
// @ts-ignore
resolve(fileReader.result);
if (typeof fileReader.result === 'string') {
resolve(fileReader.result);
}
};
fileReader.onerror = reject;
fileReader.readAsDataURL(file);
Expand Down
8 changes: 0 additions & 8 deletions src/client/app/containers/ExportContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ function mapStateToProps(state: State) {
throw new Error('Unacceptable condition: readingsData.readings is undefined.');
}

/* tslint:disable:array-type */
const dataPoints: Array<{ x: number, y: number, z: number }> = _.values(readingsData.readings)
.map(transformLineReadingToLegacy)
.map((v: [number, number, number]) => ({ x: v[0], y: v[1], z: v[2] })
);
/* tslint:enable:array-type */
datasets.push({
label,
id: state.groups.byGroupID[groupID].id,
Expand All @@ -65,13 +63,11 @@ function mapStateToProps(state: State) {
throw new Error('Unacceptable condition: readingsData.readings is undefined.');
}

/* tslint:disable:array-type */
const dataPoints: Array<{ x: number, y: number, z: number }> = _.values(readingsData.readings)
.map(transformLineReadingToLegacy)
.map(
(v: [number, number, number]) => ({ x: v[0], y: v[1], z: v[2] })
);
/* tslint:enable:array-type */
datasets.push({
label,
id: state.meters.byMeterID[meterID].id,
Expand All @@ -94,12 +90,10 @@ function mapStateToProps(state: State) {
throw new Error('Unacceptable condition: readingsData.readings is undefined.');
}

/* tslint:disable:array-type */
const dataPoints: Array<{ x: number, y: number, z: number }> = _.values(readingsData.readings)
.map(transformBarReadingToLegacy)
.map((v: [number, number, number]) => ({ x: v[0], y: v[1], z: v[2] })
);
/* tslint:enable:array-type */
datasets.push({
label,
id: state.groups.byGroupID[groupID].id,
Expand All @@ -122,12 +116,10 @@ function mapStateToProps(state: State) {
throw new Error('Unacceptable condition: readingsData.readings is undefined.');
}

/* tslint:disable:array-type */
const dataPoints: Array<{ x: number, y: number, z: number }> = _.values(readingsData.readings)
.map(transformBarReadingToLegacy)
.map((v: [number, number, number]) => ({ x: v[0], y: v[1], z: v[2] })
);
/* tslint:enable:array-type */
datasets.push({
label,
id: state.meters.byMeterID[meterID].id,
Expand Down
2 changes: 0 additions & 2 deletions src/client/app/containers/LineChartContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ function mapStateToProps(state: State) {
let minTimestamp: string = '';
let maxTimestamp: string = '';
if (readings.length > 0) {
/* tslint:disable:no-string-literal */
minTimestamp = readings[0]['startTimestamp'].toString();
maxTimestamp = readings[readings.length - 1]['startTimestamp'].toString();
/* tslint:enable:no-string-literal */
}
const root: any = document.getElementById('root');
root.setAttribute('min-timestamp', minTimestamp);
Expand Down
2 changes: 2 additions & 0 deletions src/client/app/containers/MultiCompareChartContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ function getDataForIDs(ids: number[], isGroup: boolean, state: State): CompareEn
readingsData = getMeterReadingsData(state, id, timeInterval, compareShift);
}
if (isReadingsDataValid(readingsData)) {
/* eslint-disable @typescript-eslint/no-non-null-assertion */
const currUsage = readingsData!.curr_use!;
const prevUsage = readingsData!.prev_use!;
const change = calculateChange(currUsage, prevUsage);
const entity: CompareEntity = {id, isGroup, name, change, currUsage, prevUsage};
entities.push(entity);
/* eslint-enable @typescript-eslint/no-non-null-assertion */
}
}
return entities;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ function mapStateToProps(state: State) {
*/
function createBackgroundTrace(imageDimensions: Dimensions, settings: CalibrationSettings) {
// define the grid of heatmap
const x = [];
const y = [];
const x: number[] = [];
const y: number[] = [];
// bound the grid to image dimensions to avoid clicking outside of the map
for (let i = 0; i <= Math.ceil(imageDimensions.width); i = i + 1) {
x.push(i);
Expand All @@ -116,10 +116,10 @@ function createBackgroundTrace(imageDimensions: Dimensions, settings: Calibratio
y.push(j);
}
// define the actual points of the graph, numbers in the array are used to designate different colors;
const z = [];
for (const {} of y) {
const z: number[][] = [];
for (let ind1 = 0; ind1 < y.length; ++ind1) {
const temp = [];
for (const {} of x) {
for (let ind2 = 0; ind2 < x.length; ++ind2) {
temp.push(0);
}
z.push(temp);
Expand Down
1 change: 0 additions & 1 deletion src/client/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import * as React from 'react';
import * as _ from 'lodash';
import thunkMiddleware from 'redux-thunk';
import { render } from 'react-dom';
import { createStore, applyMiddleware } from 'redux';
Expand Down
3 changes: 2 additions & 1 deletion src/client/app/reducers/meters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function meters(state = defaultState, action: MetersAction) {
...state,
submitting
};
case ActionType.ConfirmEditedMeter:
case ActionType.ConfirmEditedMeter: {
submitting = state.submitting;
submitting.splice(submitting.indexOf(action.meter));

Expand All @@ -63,6 +63,7 @@ export default function meters(state = defaultState, action: MetersAction) {
editedMeters,
byMeterID
};
}
default:
return state;
}
Expand Down
4 changes: 0 additions & 4 deletions src/client/app/types/readings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ export interface LineReadings {
* The type of bar readings in actions.
*/
export interface BarReadings {
/* tslint:disable:array-type */
[id: number]: Array<[number, number]>;
/* tslint:enable:array-type */
}

export interface CompareReading {
Expand All @@ -35,9 +33,7 @@ export interface ExportDataSet {
label: string;
id: number;
currentChart: ChartTypes;
/* tslint:disable:array-type */
exportVals: Array<{ x: number, y: number, z: number }>;
/* tslint:enable:array-type */
}

export interface RawReadings {
Expand Down
4 changes: 4 additions & 0 deletions src/client/app/utils/exportData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export default function graphExport(dataSets: ExportDataSet[], name: string) {
* @param items list of readings directly from the database
* @param defaultLanguage the preferred localization to use for date/time formatting
*/
// below comment should be removed when we either remove defaultLanguage or implement it into the following function
/* eslint-disable @typescript-eslint/no-unused-vars */
export function downloadRawCSV(items: RawReadings[], defaultLanguage: string) {
// note that utc() is not needed
let csvOutput = 'Label,Readings,Start Timestamp,End Timestamp\n';
Expand All @@ -76,6 +78,8 @@ export function downloadRawCSV(items: RawReadings[], defaultLanguage: string) {
const filename = `oedRawExport_line_${startTime}_to_${endTime}.csv`;
downloadCSV(csvOutput, filename);
}
/* eslint-enable @typescript-eslint/no-unused-vars */
// as well as above comment

/**
* Function that adds a div to handle exporting raw data
Expand Down
65 changes: 0 additions & 65 deletions tslint.json

This file was deleted.

0 comments on commit 6c6d51a

Please sign in to comment.