Skip to content

Commit 53f1335

Browse files
committed
ci: Require code to be linted
1 parent 089af58 commit 53f1335

File tree

8 files changed

+97
-56
lines changed

8 files changed

+97
-56
lines changed

.github/workflows/cd_npm.yml

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
name: Release package to npm
22

33
on:
4-
push:
5-
tags:
6-
- 'v*'
4+
push:
5+
tags:
6+
- "v*"
77

88
jobs:
9-
build:
10-
runs-on: ubuntu-latest
11-
steps:
12-
- uses: actions/checkout@v3
13-
- uses: actions/setup-node@v3
14-
with:
15-
node-version: 16
16-
- run: npm ci
17-
- run: npm test
18-
env:
19-
IPINFO_TOKEN: ${{secrets.IPINFO_TOKEN}}
20-
publish:
21-
needs: build
22-
runs-on: ubuntu-latest
23-
steps:
24-
- uses: actions/checkout@v3
25-
- uses: actions/setup-node@v3
26-
with:
27-
node-version: 16
28-
registry-url: https://registry.npmjs.org/
29-
- run: npm ci
30-
- run: npm run build
31-
- run: npm publish
32-
env:
33-
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-node@v3
14+
with:
15+
node-version: 16
16+
- run: npm ci
17+
- run: npm test
18+
env:
19+
IPINFO_TOKEN: ${{secrets.IPINFO_TOKEN}}
20+
publish:
21+
needs: build
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v3
25+
- uses: actions/setup-node@v3
26+
with:
27+
node-version: 16
28+
registry-url: https://registry.npmjs.org/
29+
- run: npm ci
30+
- run: npm run build
31+
- run: npm publish
32+
env:
33+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

.github/workflows/lint.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: "Lint Code"
2+
3+
on:
4+
push:
5+
workflow_dispatch:
6+
7+
jobs:
8+
lint:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
- uses: actions/setup-node@v4
14+
with:
15+
node-version: "latest"
16+
- run: npm ci
17+
- run: npx prettier . --check

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**/*.md
2+
config/**/*
3+
package-lock.json

.prettierrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ module.exports = {
88
jsxSingleQuote: false,
99
trailingComma: "none",
1010
bracketSpacing: true,
11-
jsxBracketSameLine: false,
1211
arrowParens: "always",
1312
rangeStart: 0,
1413
rangeEnd: Infinity,

__tests__/ipinfoWrapper.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ describe("IPinfoWrapper", () => {
2424
expect(data.countryCode).toEqual("US");
2525
expect(data.countryFlag.emoji).toEqual("🇺🇸");
2626
expect(data.countryFlag.unicode).toEqual("U+1F1FA U+1F1F8");
27-
expect(data.countryFlagURL).toEqual("https://cdn.ipinfo.io/static/images/countries-flags/US.svg");
27+
expect(data.countryFlagURL).toEqual(
28+
"https://cdn.ipinfo.io/static/images/countries-flags/US.svg"
29+
);
2830
expect(data.countryCurrency.code).toEqual("USD");
2931
expect(data.countryCurrency.symbol).toEqual("$");
3032
expect(data.continent.code).toEqual("NA");
@@ -152,7 +154,7 @@ describe("IPinfoWrapper", () => {
152154
"safermoto.com",
153155
"progeni.com",
154156
"grahamhostedservices.com",
155-
"bhcentral.tech",
157+
"bhcentral.tech"
156158
]
157159
},
158160
countryCode: "ID"

src/ipinfoWrapper.ts

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,30 @@ export default class IPinfoWrapper {
6060
cache?: Cache,
6161
timeout?: number,
6262
i18nData?: {
63-
countries?: any,
64-
countriesFlags?: any,
65-
countriesCurrencies?: any,
66-
continents?: any,
67-
euCountries?: Array<string>,
63+
countries?: any;
64+
countriesFlags?: any;
65+
countriesCurrencies?: any;
66+
continents?: any;
67+
euCountries?: Array<string>;
6868
}
6969
) {
7070
this.token = token;
71-
this.countries = i18nData?.countries ? i18nData.countries : defaultCountries;
72-
this.countriesFlags = i18nData?.countriesFlags ? i18nData.countriesFlags: defaultCountriesFlags;
73-
this.countriesCurrencies = i18nData?.countriesCurrencies ? i18nData.countriesCurrencies: defaultCountriesCurrencies;
74-
this.continents = i18nData?.continents ? i18nData.continents : defaultContinents;
71+
this.countries = i18nData?.countries
72+
? i18nData.countries
73+
: defaultCountries;
74+
this.countriesFlags = i18nData?.countriesFlags
75+
? i18nData.countriesFlags
76+
: defaultCountriesFlags;
77+
this.countriesCurrencies = i18nData?.countriesCurrencies
78+
? i18nData.countriesCurrencies
79+
: defaultCountriesCurrencies;
80+
this.continents = i18nData?.continents
81+
? i18nData.continents
82+
: defaultContinents;
7583
this.euCountries =
7684
i18nData?.euCountries && i18nData?.euCountries.length !== 0
77-
? i18nData.euCountries : defaultEuCountries;
85+
? i18nData.euCountries
86+
: defaultEuCountries;
7887
this.cache = cache ? cache : new LruCache();
7988
this.timeout =
8089
timeout === null || timeout === undefined
@@ -131,11 +140,13 @@ export default class IPinfoWrapper {
131140
res.on("close", () => {
132141
let ipinfo: IPinfo;
133142
try {
134-
ipinfo = JSON.parse(data)
143+
ipinfo = JSON.parse(data);
135144
} catch {
136-
reject(new Error("error parsing JSON response"));
145+
reject(
146+
new Error("error parsing JSON response")
147+
);
137148
return;
138-
};
149+
}
139150

140151
/* convert country code to full country name */
141152
// NOTE: always do this _before_ setting cache.
@@ -238,11 +249,13 @@ export default class IPinfoWrapper {
238249
res.on("close", () => {
239250
let asnResp: AsnResponse;
240251
try {
241-
asnResp = JSON.parse(data)
252+
asnResp = JSON.parse(data);
242253
} catch {
243-
reject(new Error("error parsing JSON response"));
254+
reject(
255+
new Error("error parsing JSON response")
256+
);
244257
return;
245-
};
258+
}
246259

247260
/* convert country code to full country name */
248261
// NOTE: always do this _before_ setting cache.
@@ -331,11 +344,13 @@ export default class IPinfoWrapper {
331344
res.on("close", () => {
332345
let response;
333346
try {
334-
response = JSON.parse(data)
347+
response = JSON.parse(data);
335348
} catch {
336-
reject(new Error("error parsing JSON response"));
349+
reject(
350+
new Error("error parsing JSON response")
351+
);
337352
return;
338-
};
353+
}
339354

340355
resolve(response);
341356
});
@@ -503,8 +518,8 @@ export default class IPinfoWrapper {
503518
try {
504519
batchResp = JSON.parse(el);
505520
} catch {
506-
batchResp = {}
507-
};
521+
batchResp = {};
522+
}
508523

509524
for (var key in batchResp) {
510525
if (batchResp.hasOwnProperty(key)) {

test-app/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ let { IPinfoWrapper, LruCache } = require("node-ipinfo");
22

33
let cacheOptions = {
44
max: 5000,
5-
ttl: 24 * 1000 * 60 * 60,
5+
ttl: 24 * 1000 * 60 * 60
66
};
77
let cache = new LruCache(cacheOptions);
88

9-
let token = process.env.IPINFO_TOKEN
9+
let token = process.env.IPINFO_TOKEN;
1010
let ipinfo = new IPinfoWrapper(token, cache);
1111

1212
ipinfo.lookupIp("1.1.1.1").then((response) => {

test-app/ipinfo.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
import IPinfoWrapper, { LruCache, Options, IPinfo, AsnResponse } from "node-ipinfo";
1+
import IPinfoWrapper, {
2+
LruCache,
3+
Options,
4+
IPinfo,
5+
AsnResponse
6+
} from "node-ipinfo";
27

38
const cacheOptions: Options<string, any> = {
49
max: 5000,
5-
ttl: 24 * 1000 * 60 * 60,
10+
ttl: 24 * 1000 * 60 * 60
611
};
712
const cache = new LruCache(cacheOptions);
813

0 commit comments

Comments
 (0)