Skip to content

Commit

Permalink
ci: Require code to be linted
Browse files Browse the repository at this point in the history
  • Loading branch information
shrink committed Nov 13, 2024
1 parent 089af58 commit 53f1335
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 56 deletions.
56 changes: 28 additions & 28 deletions .github/workflows/cd_npm.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
name: Release package to npm

on:
push:
tags:
- 'v*'
push:
tags:
- "v*"

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- run: npm ci
- run: npm test
env:
IPINFO_TOKEN: ${{secrets.IPINFO_TOKEN}}
publish:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm run build
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- run: npm ci
- run: npm test
env:
IPINFO_TOKEN: ${{secrets.IPINFO_TOKEN}}
publish:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm run build
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
17 changes: 17 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: "Lint Code"

on:
push:
workflow_dispatch:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "latest"
- run: npm ci
- run: npx prettier . --check
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/*.md
config/**/*
package-lock.json
1 change: 0 additions & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module.exports = {
jsxSingleQuote: false,
trailingComma: "none",
bracketSpacing: true,
jsxBracketSameLine: false,
arrowParens: "always",
rangeStart: 0,
rangeEnd: Infinity,
Expand Down
6 changes: 4 additions & 2 deletions __tests__/ipinfoWrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ describe("IPinfoWrapper", () => {
expect(data.countryCode).toEqual("US");
expect(data.countryFlag.emoji).toEqual("🇺🇸");
expect(data.countryFlag.unicode).toEqual("U+1F1FA U+1F1F8");
expect(data.countryFlagURL).toEqual("https://cdn.ipinfo.io/static/images/countries-flags/US.svg");
expect(data.countryFlagURL).toEqual(
"https://cdn.ipinfo.io/static/images/countries-flags/US.svg"
);
expect(data.countryCurrency.code).toEqual("USD");
expect(data.countryCurrency.symbol).toEqual("$");
expect(data.continent.code).toEqual("NA");
Expand Down Expand Up @@ -152,7 +154,7 @@ describe("IPinfoWrapper", () => {
"safermoto.com",
"progeni.com",
"grahamhostedservices.com",
"bhcentral.tech",
"bhcentral.tech"
]
},
countryCode: "ID"
Expand Down
57 changes: 36 additions & 21 deletions src/ipinfoWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,30 @@ export default class IPinfoWrapper {
cache?: Cache,
timeout?: number,
i18nData?: {
countries?: any,
countriesFlags?: any,
countriesCurrencies?: any,
continents?: any,
euCountries?: Array<string>,
countries?: any;
countriesFlags?: any;
countriesCurrencies?: any;
continents?: any;
euCountries?: Array<string>;
}
) {
this.token = token;
this.countries = i18nData?.countries ? i18nData.countries : defaultCountries;
this.countriesFlags = i18nData?.countriesFlags ? i18nData.countriesFlags: defaultCountriesFlags;
this.countriesCurrencies = i18nData?.countriesCurrencies ? i18nData.countriesCurrencies: defaultCountriesCurrencies;
this.continents = i18nData?.continents ? i18nData.continents : defaultContinents;
this.countries = i18nData?.countries
? i18nData.countries
: defaultCountries;
this.countriesFlags = i18nData?.countriesFlags
? i18nData.countriesFlags
: defaultCountriesFlags;
this.countriesCurrencies = i18nData?.countriesCurrencies
? i18nData.countriesCurrencies
: defaultCountriesCurrencies;
this.continents = i18nData?.continents
? i18nData.continents
: defaultContinents;
this.euCountries =
i18nData?.euCountries && i18nData?.euCountries.length !== 0
? i18nData.euCountries : defaultEuCountries;
? i18nData.euCountries
: defaultEuCountries;
this.cache = cache ? cache : new LruCache();
this.timeout =
timeout === null || timeout === undefined
Expand Down Expand Up @@ -131,11 +140,13 @@ export default class IPinfoWrapper {
res.on("close", () => {
let ipinfo: IPinfo;
try {
ipinfo = JSON.parse(data)
ipinfo = JSON.parse(data);
} catch {
reject(new Error("error parsing JSON response"));
reject(
new Error("error parsing JSON response")
);
return;
};
}

/* convert country code to full country name */
// NOTE: always do this _before_ setting cache.
Expand Down Expand Up @@ -238,11 +249,13 @@ export default class IPinfoWrapper {
res.on("close", () => {
let asnResp: AsnResponse;
try {
asnResp = JSON.parse(data)
asnResp = JSON.parse(data);
} catch {
reject(new Error("error parsing JSON response"));
reject(
new Error("error parsing JSON response")
);
return;
};
}

/* convert country code to full country name */
// NOTE: always do this _before_ setting cache.
Expand Down Expand Up @@ -331,11 +344,13 @@ export default class IPinfoWrapper {
res.on("close", () => {
let response;
try {
response = JSON.parse(data)
response = JSON.parse(data);
} catch {
reject(new Error("error parsing JSON response"));
reject(
new Error("error parsing JSON response")
);
return;
};
}

resolve(response);
});
Expand Down Expand Up @@ -503,8 +518,8 @@ export default class IPinfoWrapper {
try {
batchResp = JSON.parse(el);
} catch {
batchResp = {}
};
batchResp = {};
}

for (var key in batchResp) {
if (batchResp.hasOwnProperty(key)) {
Expand Down
4 changes: 2 additions & 2 deletions test-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ let { IPinfoWrapper, LruCache } = require("node-ipinfo");

let cacheOptions = {
max: 5000,
ttl: 24 * 1000 * 60 * 60,
ttl: 24 * 1000 * 60 * 60
};
let cache = new LruCache(cacheOptions);

let token = process.env.IPINFO_TOKEN
let token = process.env.IPINFO_TOKEN;
let ipinfo = new IPinfoWrapper(token, cache);

ipinfo.lookupIp("1.1.1.1").then((response) => {
Expand Down
9 changes: 7 additions & 2 deletions test-app/ipinfo.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import IPinfoWrapper, { LruCache, Options, IPinfo, AsnResponse } from "node-ipinfo";
import IPinfoWrapper, {
LruCache,
Options,
IPinfo,
AsnResponse
} from "node-ipinfo";

const cacheOptions: Options<string, any> = {
max: 5000,
ttl: 24 * 1000 * 60 * 60,
ttl: 24 * 1000 * 60 * 60
};
const cache = new LruCache(cacheOptions);

Expand Down

0 comments on commit 53f1335

Please sign in to comment.