Skip to content

Commit

Permalink
chore: add eslint and fix problems
Browse files Browse the repository at this point in the history
  • Loading branch information
usefulthink committed Oct 12, 2023
1 parent 3a37454 commit 44ed812
Show file tree
Hide file tree
Showing 54 changed files with 1,659 additions and 291 deletions.
7 changes: 7 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
bazel-*
coverage/
dist/
docs/
lib/
node_modules/
public/
34 changes: 34 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": ["jest"],
"rules": {
"no-var": 2,
"prefer-arrow-callback": 2
},
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": ["plugin:@typescript-eslint/recommended"],
"rules": {
"@typescript-eslint/ban-ts-comment": 0,
"@typescript-eslint/ban-types": 1,
"@typescript-eslint/no-empty-function": 1,
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/member-ordering": 1
}
}
],
"env": {
"browser": false,
"node": true,
"es6": true,
"jest/globals": true
},
"globals": { "google": "readonly" }
}
7 changes: 6 additions & 1 deletion e2e/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
* limitations under the License.
*/

import { Client, defaultAxiosInstance, defaultHttpsAgent, type ElevationResponse } from "../src";
import {
Client,
defaultAxiosInstance,
defaultHttpsAgent,
type ElevationResponse,
} from "../src";
import { AxiosError } from "axios";

test("client should work with defaults", async () => {
Expand Down
9 changes: 5 additions & 4 deletions e2e/compression.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test("server responds with compressed content", async () => {
origin: "Seattle, WA",
destination: "San Francisco, CA",
waypoints: [{ lat: 40, lng: -120 }],
key: process.env.GOOGLE_MAPS_API_KEY
key: process.env.GOOGLE_MAPS_API_KEY,
};

// Use of directions here is entirely arbitrary and any API that supports
Expand All @@ -36,9 +36,10 @@ test("server responds with compressed content", async () => {
// that the server responds with a compressed response must be done via the
// raw headers.

const {rawHeaders} = r.request.res;
const contentEncodingIndex = rawHeaders
.findIndex(i => i.toLowerCase() === "content-encoding");
const { rawHeaders } = r.request.res;
const contentEncodingIndex = rawHeaders.findIndex(
(i) => i.toLowerCase() === "content-encoding"
);

expect(contentEncodingIndex).not.toBe(-1);
expect(rawHeaders[contentEncodingIndex + 1]).toBe("gzip");
Expand Down
7 changes: 3 additions & 4 deletions e2e/elevation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
* limitations under the License.
*/

import axios from "axios";
import { elevation } from "../src/elevation";

test("elevation should return correct result", async () => {
const location = { lat: 10, lng: 20 };

const params = {
locations: [location, location],
key: process.env.GOOGLE_MAPS_API_KEY
key: process.env.GOOGLE_MAPS_API_KEY,
};

const r = await elevation({ params: params });
Expand All @@ -33,13 +32,13 @@ test("elevation should return correct result", async () => {
test("elevation should return correct result with path params", async () => {
const path = [
{ lat: 35, lng: -110 },
{ lat: 45, lng: -110 }
{ lat: 45, lng: -110 },
];

const params = {
path: path,
samples: 10,
key: process.env.GOOGLE_MAPS_API_KEY
key: process.env.GOOGLE_MAPS_API_KEY,
};

const r = await elevation({ params: params });
Expand Down
6 changes: 3 additions & 3 deletions e2e/geocode/geocode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
* limitations under the License.
*/

import { geocode, GeocodeRequest } from "../../src/geocode/geocode";
import { geocode } from "../../src/geocode/geocode";

test("geocode should call axios correctly", async () => {
const params = {
address: "Seattle",
components: { country: "us" },
bounds: {
northeast: { lat: 50, lng: -110 },
southwest: { lat: 35, lng: -130 }
southwest: { lat: 35, lng: -130 },
},
key: process.env.GOOGLE_MAPS_API_KEY
key: process.env.GOOGLE_MAPS_API_KEY,
};

const r = await geocode({ params: params });
Expand Down
6 changes: 3 additions & 3 deletions e2e/geocode/reversegeocode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ test("reverseGeocode should return correct response", async () => {
const params = {
latlng: {
lat: 60.168997,
lng: 24.9433353
lng: 24.9433353,
},
key: process.env.GOOGLE_MAPS_API_KEY
key: process.env.GOOGLE_MAPS_API_KEY,
};
const r = await reverseGeocode({ params: params });
expect(r.data.results.length).toBeTruthy();
Expand All @@ -31,7 +31,7 @@ test("reverseGeocode should return correct response", async () => {
test("reverseGeocode should return correct response using place_id", async () => {
const params = {
place_id: "ChIJKxDbe_lYwokRVf__s8CPn-o",
key: process.env.GOOGLE_MAPS_API_KEY
key: process.env.GOOGLE_MAPS_API_KEY,
};
const r = await reverseGeocode({ params: params });
expect(r.data.results.length).toBeTruthy();
Expand Down
2 changes: 1 addition & 1 deletion e2e/roads/nearestroads.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { LatLng } from "../../src/common";
test("nearestRoads should return correct response", async () => {
const params = {
points: [[60.17088, 24.942795] as LatLng],
key: process.env.GOOGLE_MAPS_API_KEY
key: process.env.GOOGLE_MAPS_API_KEY,
};

const r = await nearestRoads({ params: params });
Expand Down
4 changes: 2 additions & 2 deletions e2e/roads/snaptoroads.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ test("snapToRoads should have corect result", async () => {
path: [
[60.17088, 24.942795] as LatLng,
[60.170879, 24.942796] as LatLng,
[60.170877, 24.942796] as LatLng
[60.170877, 24.942796] as LatLng,
],
interpolate: false,
key: process.env.GOOGLE_MAPS_API_KEY
key: process.env.GOOGLE_MAPS_API_KEY,
};

const r = await snapToRoads({ params: params });
Expand Down
2 changes: 1 addition & 1 deletion e2e/timezone.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test("elevation should get an ok response", async () => {
location: "30, 50",
timestamp: new Date(),
language: Language.en,
key: process.env.GOOGLE_MAPS_API_KEY
key: process.env.GOOGLE_MAPS_API_KEY,
};
const r = await timezone({ params: params });

Expand Down
6 changes: 4 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ module.exports = {
preset: "ts-jest/presets/js-with-ts",
testEnvironment: "node",
// some dependencies are esm and need to be compiled to work in jest
transformIgnorePatterns: ['/node_modules/(?!(axios|retry-axios|query-string|decode-uri-component|split-on-first|filter-obj)/)'],
transformIgnorePatterns: [
"/node_modules/(?!(axios|retry-axios|query-string|decode-uri-component|split-on-first|filter-obj)/)",
],
collectCoverage: true,
collectCoverageFrom: ["src/**/([a-zA-Z_]*).{js,ts}", "!**/*.test.{js,ts}"]
collectCoverageFrom: ["src/**/([a-zA-Z_]*).{js,ts}", "!**/*.test.{js,ts}"],
};
Loading

0 comments on commit 44ed812

Please sign in to comment.