Skip to content

Commit 56accc1

Browse files
committed
fix lint errors
apply optional chaining mark unused function params with `_`
1 parent 1154171 commit 56accc1

File tree

6 files changed

+24
-26
lines changed

6 files changed

+24
-26
lines changed

lib/service/graphhopper/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function extractDirections(result, { details, distance, instructions, points, ti
116116
}
117117

118118
function getStatus(st, response) {
119-
st = st && st.status;
119+
st = st?.status;
120120
if (!(st || response)) {
121121
return;
122122
}
@@ -245,7 +245,7 @@ function init(options) {
245245
query,
246246
provider: options.name
247247
};
248-
const paths = response && response.paths;
248+
const paths = response?.paths;
249249
if (paths) {
250250
directions.routes = [];
251251
if (query.turnbyturn || query.path === pathType.smooth || query.path === pathType.coarse) {

lib/service/mapquest/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ function extractDirections(result, leg) {
8080
return result;
8181
}
8282

83-
function getStatus(err, response) {
83+
function getStatus(_err, response) {
8484
if (!response) {
8585
return;
8686
}
8787
const { info, route } = response;
88-
const st = info && info.statuscode;
88+
const st = info?.statuscode;
8989
if (st === 403 || st === 500) {
9090
// assume its because we exceeded the limit
9191
return status.failure;
@@ -157,16 +157,16 @@ function init(options) {
157157
}
158158

159159
function processResponse(response, query) {
160-
if (response && response.info) {
160+
if (response?.info) {
161161
const { statuscode: st } = response.info;
162162
if (st === 402 || st > 600) {
163163
// let it cascade to the next service
164164
return;
165165
}
166166
}
167167

168-
const route = response && response.route;
169-
if (!(route && route.legs && route.legs.length)) {
168+
const route = response?.route;
169+
if (!route?.legs?.length) {
170170
// shouldn't happen
171171
return;
172172
}
@@ -185,9 +185,9 @@ function init(options) {
185185
route.legs.reduce(extractDirections, {
186186
directions,
187187
unitMultiplier: query.units === 'km' ? util.metersInKm : util.metersInMile,
188-
maneuverIndexes: route.shape && route.shape.maneuverIndexes,
189-
legIndexes: route.shape && route.shape.legIndexes,
190-
path: route.shape && route.shape.shapePoints.reduce(addPoint, []),
188+
maneuverIndexes: route.shape?.maneuverIndexes,
189+
legIndexes: route.shape?.legIndexes,
190+
path: route.shape?.shapePoints.reduce(addPoint, []),
191191
fullPath
192192
});
193193
if (fullPath) {

lib/service/osrm/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ function convertRoute({ legs }) {
4545
}
4646

4747
// response codes: http://project-osrm.org/docs/v5.5.2/api/#responses
48-
function getStatus(err, response) {
49-
const code = response && response.code;
48+
function getStatus(_err, response) {
49+
const code = response?.code;
5050
if (!response) {
5151
return;
5252
}

lib/service/partition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const util = require('./util');
33
module.exports = partition;
44

55
function distanceSquare(p1, p2) {
6-
return Math.pow(p1[0] - p2[0], 2) + Math.pow(p1[1] - p2[1], 2);
6+
return (p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2;
77
}
88

99
function pointOnLine(point, p1, p2) {

lib/service/valhalla/index.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function extractSegment(
6666
const seg = {
6767
duration,
6868
distance,
69-
path: path && path.slice(begin_shape_index, end_shape_index),
69+
path: path?.slice(begin_shape_index, end_shape_index),
7070
instructions: instruction
7171
};
7272
if (rough) {
@@ -95,8 +95,8 @@ function extractDirections(result, leg) {
9595
const { directions } = result;
9696
result.path = util.decode(leg.shape, { factor: 1e6 });
9797
const route = {
98-
duration: (leg.summary && leg.summary.time) || 0,
99-
distance: Math.round(((leg.summary && leg.summary.length) || 0) * result.unitMultiplier)
98+
duration: leg.summary?.time || 0,
99+
distance: Math.round((leg.summary?.length || 0) * result.unitMultiplier)
100100
};
101101
if (result.fullPath) {
102102
route.path = result.path;
@@ -138,8 +138,8 @@ function directDistance(locations, units) {
138138
);
139139
}
140140

141-
function getStatus(err, response) {
142-
let st = response && response.status_code;
141+
function getStatus(_err, response) {
142+
let st = response?.status_code;
143143
if (!response) {
144144
return;
145145
}
@@ -152,9 +152,9 @@ function getStatus(err, response) {
152152
// no route
153153
return status.empty;
154154
}
155-
st = response.trip && response.trip.status;
155+
st = response.trip?.status;
156156
if (st === 0) {
157-
if (response.trip.legs && response.trip.legs.length) {
157+
if (response.trip.legs?.length) {
158158
const { length, time } = response.trip.summary;
159159
const distance = directDistance(response.trip.locations, response.trip.units);
160160
// make sure points are not too far from roads
@@ -229,8 +229,8 @@ function init(options) {
229229
}
230230

231231
function processResponse(response, query) {
232-
const trip = response && response.trip;
233-
if (trip && trip.legs && trip.legs.length) {
232+
const trip = response?.trip;
233+
if (trip?.legs?.length) {
234234
const directions = {
235235
query,
236236
provider: options.name,

test/service/simplify.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,13 @@ describe('simplify', function () {
7373
];
7474

7575
let path = [];
76-
let i;
77-
let segments;
7876

79-
for (i = 0; i < 200; i += 1) {
77+
for (let i = 0; i < 200; i += 1) {
8078
path.push([i / 10, i / 10]);
8179
}
8280
routes[0].distance = distance(path);
8381

84-
segments = [
82+
const segments = [
8583
{
8684
path: path.slice(0, 30)
8785
},

0 commit comments

Comments
 (0)