Skip to content

Commit f5e8968

Browse files
committed
chore: improve linting
1 parent c5f88d7 commit f5e8968

File tree

6 files changed

+71
-16
lines changed

6 files changed

+71
-16
lines changed

.github/workflows/lint.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
build:
13+
runs-on: macOS-latest
14+
steps:
15+
- uses: actions/checkout@master
16+
- name: Use Node.js 12.x
17+
uses: actions/setup-node@v1
18+
with:
19+
version: 12.x
20+
- name: Lint
21+
run: |
22+
npm install
23+
npm run lint

.github/workflows/nodejs.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: Test
22

3-
on: [push]
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
410

511
jobs:
612
build:

.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"trailingComma": "all",
3+
"tabWidth": 2,
4+
"semi": false,
5+
"singleQuote": true,
6+
"printWidth": 100,
7+
"endOfLine": "lf"
8+
}

index.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@ function addNewContact(contact) {
1717
const hasPhoneNumbers = contact.hasOwnProperty('phoneNumbers')
1818
const hasEmailAddresses = contact.hasOwnProperty('emailAddresses')
1919

20-
if (hasFirstName && typeof contact.firstName !== 'string') throw new TypeError('firstName must be a string')
21-
if (hasLastName && typeof contact.lastName !== 'string') throw new TypeError('lastName must be a string')
22-
if (hasNickname && typeof contact.nickname !== 'string') throw new TypeError('nickname must be a string')
23-
if (hasPhoneNumbers && !Array.isArray(contact.phoneNumbers)) throw new TypeError('phoneNumbers must be an array')
24-
if (hasEmailAddresses && !Array.isArray(contact.emailAddresses)) throw new TypeError('emailAddresses must be an array')
20+
if (hasFirstName && typeof contact.firstName !== 'string')
21+
throw new TypeError('firstName must be a string')
22+
if (hasLastName && typeof contact.lastName !== 'string')
23+
throw new TypeError('lastName must be a string')
24+
if (hasNickname && typeof contact.nickname !== 'string')
25+
throw new TypeError('nickname must be a string')
26+
if (hasPhoneNumbers && !Array.isArray(contact.phoneNumbers))
27+
throw new TypeError('phoneNumbers must be an array')
28+
if (hasEmailAddresses && !Array.isArray(contact.emailAddresses))
29+
throw new TypeError('emailAddresses must be an array')
2530

2631
if (hasBirthday) {
2732
const datePattern = /^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$/
@@ -47,11 +52,16 @@ function updateContact(contact) {
4752
const hasPhoneNumbers = contact.hasOwnProperty('phoneNumbers')
4853
const hasEmailAddresses = contact.hasOwnProperty('emailAddresses')
4954

50-
if (hasFirstName && typeof contact.firstName !== 'string') throw new TypeError('firstName must be a string')
51-
if (hasLastName && typeof contact.lastName !== 'string') throw new TypeError('lastName must be a string')
52-
if (hasNickname && typeof contact.nickname !== 'string') throw new TypeError('nickname must be a string')
53-
if (hasPhoneNumbers && !Array.isArray(contact.phoneNumbers)) throw new TypeError('phoneNumbers must be an array')
54-
if (hasEmailAddresses && !Array.isArray(contact.emailAddresses)) throw new TypeError('emailAddresses must be an array')
55+
if (hasFirstName && typeof contact.firstName !== 'string')
56+
throw new TypeError('firstName must be a string')
57+
if (hasLastName && typeof contact.lastName !== 'string')
58+
throw new TypeError('lastName must be a string')
59+
if (hasNickname && typeof contact.nickname !== 'string')
60+
throw new TypeError('nickname must be a string')
61+
if (hasPhoneNumbers && !Array.isArray(contact.phoneNumbers))
62+
throw new TypeError('phoneNumbers must be an array')
63+
if (hasEmailAddresses && !Array.isArray(contact.emailAddresses))
64+
throw new TypeError('emailAddresses must be an array')
5565

5666
if (hasBirthday) {
5767
const datePattern = /^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$/
@@ -78,5 +88,5 @@ module.exports = {
7888
getContactsByName,
7989
addNewContact,
8090
deleteContact,
81-
updateContact
82-
}
91+
updateContact,
92+
}

package-lock.json

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"scripts": {
77
"build": "node-gyp rebuild",
88
"clean": "node-gyp clean",
9-
"format": "clang-format -i contacts.mm",
9+
"lint": "prettier --check index.js",
10+
"format": "clang-format -i contacts.mm && prettier --write index.js",
1011
"test": "./node_modules/.bin/mocha --reporter spec"
1112
},
1213
"repository": {
@@ -30,7 +31,8 @@
3031
"chai": "^4.2.0",
3132
"clang-format": "^1.3.0",
3233
"mocha": "^6.2.0",
33-
"node-gyp": "^5.0.3"
34+
"node-gyp": "^5.0.3",
35+
"prettier": "^2.0.4"
3436
},
3537
"dependencies": {
3638
"bindings": "^1.5.0",

0 commit comments

Comments
 (0)