Skip to content

Commit

Permalink
The lint warnings from transition-common (other than "unexpected any"…
Browse files Browse the repository at this point in the history
…) have been removed.

65 warnings got removed (143 to 78)
  • Loading branch information
GabrielBruno24 committed Dec 16, 2024
1 parent ee4cddb commit a0d1ef7
Show file tree
Hide file tree
Showing 34 changed files with 36 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const evolutionaryAlgorithmFactory: SimulationAlgorithmFactory<EvolutionA
simulationRun: SimulationRun
): EvolutionaryAlgorithm => new EvolutionaryAlgorithm(options, simulationRun);

export class EvolutionaryAlgorithm implements SimulationAlgorithm<EvolutionAlgorithmOptions> {
export class EvolutionaryAlgorithm implements SimulationAlgorithm {
private currentIteration = 1;

constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import config from 'chaire-lib-backend/lib/config/server.config';
* @interface SimulationAlgorithm
* @template T The type of options
*/
export type SimulationAlgorithmFactory<T> = (options: T, simulationRun: SimulationRun) => SimulationAlgorithm<T>;
export type SimulationAlgorithmFactory<T> = (options: T, simulationRun: SimulationRun) => SimulationAlgorithm;

const ALGORITHMS_FACTORY: { [key: string]: SimulationAlgorithmFactory<any> } = {};
export const registerAlgorithmFactory = (name: string, algorithmFactory: SimulationAlgorithmFactory<any>): void => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface AlgorithmStubOptions {
booleanOption?: boolean;
}

export class SimulationAlgorithmStub implements SimulationAlgorithm<AlgorithmStubOptions> {
export class SimulationAlgorithmStub implements SimulationAlgorithm {

constructor(private options: AlgorithmStubOptions) {

Expand Down
2 changes: 2 additions & 0 deletions packages/transition-common/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* License text available at https://opensource.org/licenses/MIT
*/
/* eslint-disable n/no-unpublished-require */
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-require-imports */
const baseConfig = require('../../tests/jest.config.base');

module.exports = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
PlaceDetailedCategory
} from 'chaire-lib-common/lib/config/osm/osmMappingDetailedCategoryToCategory';
import NodeCollection from '../nodes/NodeCollection';
import { placesInWalkingTravelTimeRadiusSeconds } from '../nodes/NodeGeographyUtils';
import { _isBlank } from 'chaire-lib-common/lib/utils/LodashExtensions';

export interface TransitAccessibilityMapResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* This file is licensed under the MIT License.
* License text available at https://opensource.org/licenses/MIT
*/
import _get from 'lodash/get';
import _cloneDeep from 'lodash/cloneDeep';

import { featureCollection as turfFeatureCollection, point as turfPoint } from '@turf/turf';
Expand All @@ -13,7 +12,7 @@ import { GenericAttributes } from 'chaire-lib-common/lib/utils/objects/GenericOb
import { ObjectWithHistory } from 'chaire-lib-common/lib/utils/objects/ObjectWithHistory';
import Preferences from 'chaire-lib-common/lib/config/Preferences';
import serviceLocator from 'chaire-lib-common/lib/utils/ServiceLocator';
import { _toInteger, _isBlank } from 'chaire-lib-common/lib/utils/LodashExtensions';
import { _isBlank } from 'chaire-lib-common/lib/utils/LodashExtensions';
import { validateTrQueryAttributes } from '../transitRouting/TransitRoutingQueryAttributes';
import { TransitQueryAttributes } from 'chaire-lib-common/lib/services/routing/types';

Expand Down
3 changes: 1 addition & 2 deletions packages/transition-common/src/services/agency/Agency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* This file is licensed under the MIT License.
* License text available at https://opensource.org/licenses/MIT
*/
import _cloneDeep from 'lodash/cloneDeep';
import { Agency as GtfsAgency } from 'gtfs-types';

import * as Status from 'chaire-lib-common/lib/utils/Status';
Expand Down Expand Up @@ -303,7 +302,7 @@ export class Agency extends ObjectWithHistory<AgencyAttributes> implements Savea
const firstLine = this.getLines()[0];
const customCachePath = firstLine ? firstLine.getData('customCachePath', null) : undefined;

return new Promise((resolve, reject) => {
return new Promise((resolve, _reject) => {
socket.emit('transitLine.deleteMultipleCache', lineIds, customCachePath, (linesCacheDeleteResponse) => {
if (!linesCacheDeleteResponse.error) {
SaveUtils.delete(this, socket, 'transitAgency', this._collectionManager?.get('agencies')).then(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* This file is licensed under the MIT License.
* License text available at https://opensource.org/licenses/MIT
*/
import _get from 'lodash/get';

import Agency from './Agency';
import CollectionCacheable from 'chaire-lib-common/lib/services/objects/CollectionCacheable';
import CollectionManager from 'chaire-lib-common/lib/utils/objects/CollectionManager';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
* This file is licensed under the MIT License.
* License text available at https://opensource.org/licenses/MIT
*/
import _cloneDeep from 'lodash/cloneDeep';
import { _isBlank } from 'chaire-lib-common/lib/utils/LodashExtensions';

import { Agency, AgencyAttributes } from './Agency';
import { duplicateService } from '../service/ServiceDuplicator';
import { duplicateLine } from '../line/LineDuplicator';
Expand Down
3 changes: 0 additions & 3 deletions packages/transition-common/src/services/gtfs/GtfsExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
* This file is licensed under the MIT License.
* License text available at https://opensource.org/licenses/MIT
*/
import _get from 'lodash/get';
import _cloneDeep from 'lodash/cloneDeep';

import { GenericAttributes } from 'chaire-lib-common/lib/utils/objects/GenericObject';
import { ObjectWithHistory } from 'chaire-lib-common/lib/utils/objects/ObjectWithHistory';
import serviceLocator from 'chaire-lib-common/lib/utils/ServiceLocator';
Expand Down
3 changes: 2 additions & 1 deletion packages/transition-common/src/services/line/Line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ export class Line extends ObjectWithHistory<LineAttributes> implements Saveable
*/
}

async calculateDeadHeadTravelTimesBetweenPaths(socket) {
//TODO: Add functionality to the _socket argument, or remove it.
async calculateDeadHeadTravelTimesBetweenPaths(_socket) {
this.refreshPaths();
const completePaths = this.getCompletePaths();
const deadHeadTravelTimesBetweenPathsByPathId = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* This file is licensed under the MIT License.
* License text available at https://opensource.org/licenses/MIT
*/
import { _isBlank } from 'chaire-lib-common/lib/utils/LodashExtensions';

import { Line } from './Line';
import { Path as TransitPath } from '../path/Path';
import { duplicateService } from '../service/ServiceDuplicator';
Expand Down
13 changes: 6 additions & 7 deletions packages/transition-common/src/services/nodes/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* This file is licensed under the MIT License.
* License text available at https://opensource.org/licenses/MIT
*/
import _cloneDeep from 'lodash/cloneDeep';
import _get from 'lodash/get';
import _isEqual from 'lodash/isEqual';
import * as turf from '@turf/turf';
Expand All @@ -13,7 +12,6 @@ import * as GtfsTypes from 'gtfs-types';
import * as Status from 'chaire-lib-common/lib/utils/Status';
import { GenericPlace, GenericPlaceAttributes } from 'chaire-lib-common/lib/utils/objects/GenericPlace';
import Preferences from 'chaire-lib-common/lib/config/Preferences';
import TrError from 'chaire-lib-common/lib/utils/TrError';
import SaveUtils from 'chaire-lib-common/lib/services/objects/SaveUtils';
import Saveable from 'chaire-lib-common/lib/utils/objects/Saveable';
import { _isBlank } from 'chaire-lib-common/lib/utils/LodashExtensions';
Expand Down Expand Up @@ -219,7 +217,8 @@ export class Node extends GenericPlace<NodeAttributes> implements Saveable {
return routingRadiusInPixels;
}

calculateOdTripsWeight(dataSourceId) {
//TODO: Implement this function, or remove it.
calculateOdTripsWeight(_dataSourceId) {
// Nothing to do. Why?
}

Expand Down Expand Up @@ -275,9 +274,9 @@ export class Node extends GenericPlace<NodeAttributes> implements Saveable {
}

async getIsochroneGeojson(
socket,
mode = 'walking',
durationsMinutes = [5, 10, 15, 20]
_socket,
_mode = 'walking',
_durationsMinutes = [5, 10, 15, 20]
): Promise<{ [key: string]: any }> {
return {};
/* TODO Disabled since valhalla is broken
Expand Down Expand Up @@ -463,7 +462,7 @@ export class Node extends GenericPlace<NodeAttributes> implements Saveable {
}

async delete(socket: EventEmitter): Promise<Status.Status<{ id: string | undefined }>> {
return new Promise((resolve, reject) => {
return new Promise((resolve, _reject) => {
SaveUtils.delete(this, socket, 'transitNode', this._collectionManager?.get('nodes')).then(
(response: Status.Status<{ id: string | undefined }>) => {
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* This file is licensed under the MIT License.
* License text available at https://opensource.org/licenses/MIT
*/
import _get from 'lodash/get';
import snakeCase from 'lodash/snakeCase';
import camelCase from 'lodash/camelCase';

Expand Down Expand Up @@ -67,15 +66,15 @@ export class NodeCollection extends GenericPlaceCollection<NodeAttributes, Node>
}

updateOdTripsWeights(socket, dataSourceId): Promise<void> {
return new Promise((resolve, reject) => {
return new Promise((resolve, _reject) => {
socket.emit('nodes.calculateOdTripsWeights', dataSourceId, () => {
resolve();
});
});
}

updateOdTripsAccessibleNodes(socket, dataSourceId): Promise<void> {
return new Promise((resolve, reject) => {
return new Promise((resolve, _reject) => {
socket.emit('odTrips.updateAccessibleNodes', dataSourceId, () => {
resolve();
});
Expand All @@ -88,7 +87,7 @@ export class NodeCollection extends GenericPlaceCollection<NodeAttributes, Node>

setNetworkTravelTimesForBirdDistanceAccessibleNodes(object, geojson, prefix, mode: RoutingMode = 'walking') {
// geojson: origin or destination geojson
return new Promise((resolve, reject) => {
return new Promise((resolve, _reject) => {
if (_isBlank(geojson) && typeof object.toGeojson === 'function') {
geojson = object.toGeojson();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export const proposeNames = async (
let radiusAroundMeters = 100;
const nodeGeojson = node.toGeojson();
while (intersectionNames !== undefined && intersectionNames.length < 2 && radiusAroundMeters <= maxRadiusMeters) {
intersectionNames = await new Promise((resolve, reject) => {
intersectionNames = await new Promise((resolve, _reject) => {
socket.emit(
'osm.streetsAroundPoint',
nodeGeojson,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class BaseOdTripCollection extends GenericObjectCollection<BaseOdTrip> implement
});
}

newObject(attribs: Partial<GenericAttributes>, isNew = false, collectionManager?: CollectionManager): BaseOdTrip {
//TODO: Add functionality to the _collectionManager argument, or remove it.
newObject(attribs: Partial<GenericAttributes>, isNew = false, _collectionManager?: CollectionManager): BaseOdTrip {
return new BaseOdTrip(attribs, isNew);
}

Expand Down
8 changes: 4 additions & 4 deletions packages/transition-common/src/services/path/Path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,7 @@ export class Path extends MapObject<GeoJSON.LineString, PathAttributes> implemen
}

delete(socket): Promise<Status.Status<{ id: string | undefined }>> {
return new Promise((resolve, reject) => {
return new Promise((resolve, _reject) => {
const line: any = this.getLine();
SaveUtils.delete(this, socket, 'transitPath', this._collectionManager?.get('paths')).then(
(response: Status.Status<{ id: string | undefined }>) => {
Expand All @@ -1375,7 +1375,7 @@ export class Path extends MapObject<GeoJSON.LineString, PathAttributes> implemen
});
line.refreshPaths();
line.refreshStats();
line.save(socket).then((lineSaveResponse) => {
line.save(socket).then((_lineSaveResponse) => {
resolve(response);
});
} else {
Expand All @@ -1392,7 +1392,7 @@ export class Path extends MapObject<GeoJSON.LineString, PathAttributes> implemen
public async save(socket: EventEmitter) {
if (this.hasChanged() || this.isNew()) {
this.refreshStats();
return new Promise((resolve, reject) => {
return new Promise((resolve, _reject) => {
const line: any = this.getLine();
this.attributes.mode = this.getMode(); // force add mode since it could have been removed when updating
SaveUtils.save(this, socket, 'transitPath', this._collectionManager?.get('paths')).then(
Expand All @@ -1409,7 +1409,7 @@ export class Path extends MapObject<GeoJSON.LineString, PathAttributes> implemen
// TODO Use an update callback
line.refreshPaths();
line.refreshStats();
line.save(socket).then((lineSaveResponse) => {
line.save(socket).then((_lineSaveResponse) => {
resolve(response);
});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@
* This file is licensed under the MIT License.
* License text available at https://opensource.org/licenses/MIT
*/
import _get from 'lodash/get';
import geobuf from 'geobuf';
import Pbf from 'pbf';

import { Path, PathAttributes } from './Path';
import CollectionCacheable from 'chaire-lib-common/lib/services/objects/CollectionCacheable';
import CollectionLoadable from 'chaire-lib-common/lib/services/objects/CollectionLoadable';
import GenericMapObjectCollection from 'chaire-lib-common/lib/utils/objects/GenericMapObjectCollection';
import Progressable from 'chaire-lib-common/lib/utils/objects/Progressable';
import { EventManager } from 'chaire-lib-common/lib/services/events/EventManager';
import { _isBlank } from 'chaire-lib-common/lib/utils/LodashExtensions';
import TrError from 'chaire-lib-common/lib/utils/TrError';

/**
* A collection of transit paths
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class PathGeographyUtils {
let routingSegmentGeojson: FeatureCollection<Point> = this.initializePointGeojsonCollection();
let lastRoutingType = routingEngine;

nodesAndWaypointsGeojsons.features.forEach((geojson, geojsonIndex) => {
nodesAndWaypointsGeojsons.features.forEach((geojson, _geojsonIndex) => {
const nodeRoutingType = routingEngine === 'manual' ? 'manual' : geojson.properties?.type || lastRoutingType;

if (nodeRoutingType !== lastRoutingType && routingSegmentGeojson.features.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion packages/transition-common/src/services/places/Place.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class Place extends GenericPlace<PlaceAttributes> implements Saveable {
}

async delete(socket: EventEmitter): Promise<Status.Status<{ id: string | undefined }>> {
return new Promise((resolve, reject) => {
return new Promise((resolve, _reject) => {
SaveUtils.delete(this, socket, 'Place', this._collectionManager?.get('places')).then(
(response: Status.Status<{ id: string | undefined }>) => {
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ class Schedule extends ObjectWithHistory<ScheduleAttributes> implements Saveable
// todo
const period = this.getPeriod(periodShortname);
if (period) {
const minInterval = Infinity;
const trips = period.trips;
if (trips && trips.length > 0) {
for (let i = 0, count = trips.length; i < count - 1; i++) {
Expand Down Expand Up @@ -366,7 +365,7 @@ class Schedule extends ObjectWithHistory<ScheduleAttributes> implements Saveable
unitReadyAt: unit.isReadyAtTimeSeconds
};
return trip;
} catch (error) {
} catch {
throw `The path ${path.getId()} for line ${path.getLine()?.getAttributes().shortname} (${
path.attributes.line_id
}) is not valid. Please recalculate routing for this path`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
* This file is licensed under the MIT License.
* License text available at https://opensource.org/licenses/MIT
*/
import _cloneDeep from 'lodash/cloneDeep';
import { v4 as uuidV4 } from 'uuid';
import { _isBlank } from 'chaire-lib-common/lib/utils/LodashExtensions';

import Schedule from './Schedule';

Expand Down
1 change: 0 additions & 1 deletion packages/transition-common/src/services/service/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import SaveUtils from 'chaire-lib-common/lib/services/objects/SaveUtils';
import Saveable from 'chaire-lib-common/lib/utils/objects/Saveable';
import { GenericAttributes } from 'chaire-lib-common/lib/utils/objects/GenericObject';
import serviceLocator from 'chaire-lib-common/lib/utils/ServiceLocator';
import { _isBlank } from 'chaire-lib-common/lib/utils/LodashExtensions';
import Line from '../line/Line';

export const serviceDays = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* This file is licensed under the MIT License.
* License text available at https://opensource.org/licenses/MIT
*/
import _get from 'lodash/get';

import Service from './Service';
import CollectionCacheable from 'chaire-lib-common/lib/services/objects/CollectionCacheable';
import CollectionManager from 'chaire-lib-common/lib/utils/objects/CollectionManager';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* This file is licensed under the MIT License.
* License text available at https://opensource.org/licenses/MIT
*/
import _cloneDeep from 'lodash/cloneDeep';

import Service from './Service';
import { _isBlank } from 'chaire-lib-common/lib/utils/LodashExtensions';
import ServiceCollection from './ServiceCollection';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import CollectionManager from 'chaire-lib-common/lib/utils/objects/CollectionMan
import { ObjectWithHistory } from 'chaire-lib-common/lib/utils/objects/ObjectWithHistory';
import SaveUtils from 'chaire-lib-common/lib/services/objects/SaveUtils';
import Saveable from 'chaire-lib-common/lib/utils/objects/Saveable';
import { _isBlank } from 'chaire-lib-common/lib/utils/LodashExtensions';
import { GenericAttributes } from 'chaire-lib-common/lib/utils/objects/GenericObject';
import serviceLocator from 'chaire-lib-common/lib/utils/ServiceLocator';
import { validateTrBaseAttributes } from '../transitRouting/TransitRoutingQueryAttributes';
Expand Down Expand Up @@ -172,12 +171,10 @@ class Simulation extends ObjectWithHistory<SimulationAttributes> implements Save
if (shortname) {
return slugify(`${shortname}${showId ? '_' + this.id : ''}`, {
replacement: '_',
remove: /[/^*=;:#$%?&\|\[\]{}\+~.\(\)'"!\\@]/g
remove: /[/^*=;:#$%?&|[\]{}+~.()'"!\\@]/g
}); // regex for valid filenames
}
return showId
? slugify(this.id, { replacement: '_', remove: /[/^*=;:#$%?&\|\[\]{}\+~.\(\)'"!\\@]/g })
: undefined; // regex for valid filenames
return showId ? slugify(this.id, { replacement: '_', remove: /[/^*=;:#$%?&|[\]{}+~.()'"!\\@]/g }) : undefined; // regex for valid filenames
}

getAlgorithmDescriptor(): SimulationAlgorithmDescriptor<any> | undefined {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import ServiceCollection from '../service/ServiceCollection';
*
* @export
* @interface SimulationAlgorithm
* @template T The type of options
*/
export interface SimulationAlgorithm<T> {
// This interface used to have a type variable <T> that was documented as "The type of options".
// This was completely unused so it was removed, but a comment is left here in case we ever want to implement it again.
export interface SimulationAlgorithm {
run: (
socket: EventEmitter,
collections: { lines: LineCollection; agencies: AgencyCollection; services: ServiceCollection }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { EventEmitter } from 'events';

import SaveUtils from 'chaire-lib-common/lib/services/objects/SaveUtils';
import Saveable from 'chaire-lib-common/lib/utils/objects/Saveable';
import { _isBlank } from 'chaire-lib-common/lib/utils/LodashExtensions';
import { GenericAttributes, GenericObject } from 'chaire-lib-common/lib/utils/objects/GenericObject';
import { AlgorithmConfiguration } from './Simulation';
import { SimulationParameters } from './SimulationParameters';
Expand Down
Loading

0 comments on commit a0d1ef7

Please sign in to comment.