Skip to content

Commit 872e5b6

Browse files
authored
Set up an eslint&prettier config to standardize style. Automatically fix lint warnings and manually fix others (#88)
* Set up an eslint&prettier config to standardize style. This is done for the following reasons: - Remove unused imports and detect unused variables (skip warning about unused parameters). - Start standardizing the existing code style - Make code style guidelines less subjective for existing/new contributors to save time and avoid distractions reviewing spacing/indentation in the future, and focus on semantics of changes - Remove `use strict`, it's redundant in JS modules. https://stackoverflow.com/questions/49386015/javascript-use-strict-is-unnecessary-inside-of-modules * Run `eslint --fix .`, `npm run prettier` * Update github workflows, test with node 16, publish with node 12 * Run prettier on mock/test folder * Only fix style issues that are less subjective
1 parent 06a916e commit 872e5b6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2750
-2353
lines changed

.eslintrc.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module.exports = {
2+
env: {
3+
commonjs: true,
4+
es2021: true,
5+
node: true,
6+
mocha: true,
7+
},
8+
extends: [
9+
'eslint:recommended',
10+
],
11+
parserOptions: {
12+
ecmaVersion: 13,
13+
sourceType: 'module',
14+
},
15+
rules: {
16+
/* Check variables but not function arguments. */
17+
'eol-last': 2,
18+
'linebreak-style': ['error', 'unix'],
19+
'no-multiple-empty-lines': 1,
20+
'no-trailing-spaces': 2,
21+
'no-unused-vars': ['error', {args: 'none'}],
22+
'no-var': 'error',
23+
'prefer-const': 'error',
24+
'require-atomic-updates': 'off',
25+
'space-infix-ops': 'error',
26+
'space-in-parens': ['error', 'never'],
27+
'strict': ['error', 'never'],
28+
},
29+
};

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ jobs:
1515
NODE_VERSION: 12
1616
- name: Node.js 14
1717
NODE_VERSION: 14
18+
- name: Node.js 16
19+
NODE_VERSION: 16
1820
runs-on: ubuntu-18.04
1921
timeout-minutes: 30
2022
steps:
@@ -31,5 +33,6 @@ jobs:
3133
restore-keys: |
3234
${{ runner.os }}-node-${{ matrix.NODE_VERSION }}-
3335
- run: npm ci
36+
- run: npm run lint
3437
- run: npm run coverage
3538
- run: bash <(curl -s https://codecov.io/bash)

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
semi: true
2+
trailingComma: "es5"
3+
singleQuote: true
4+
arrowParens: "avoid"
5+
printWidth: 100

examples/sending-multiple-notifications.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
"use strict";
2-
31
/**
42
53
Send individualised notifications
64
75
i.e. Account updates for users with one-or-more device tokens
86
*/
97

10-
const apn = require("apn");
8+
const apn = require('@parse/node-apn');
119

12-
let users = [
13-
{ name: "Wendy", "devices": ["<insert device token>", "<insert device token>"]},
14-
{ name: "John", "devices": ["<insert device token>"]},
10+
const users = [
11+
{ name: 'Wendy', devices: ['<insert device token>', '<insert device token>'] },
12+
{ name: 'John', devices: ['<insert device token>'] },
1513
];
1614

17-
let service = new apn.Provider({
18-
cert: "certificates/cert.pem",
19-
key: "certificates/key.pem",
15+
const service = new apn.Provider({
16+
cert: 'certificates/cert.pem',
17+
key: 'certificates/key.pem',
2018
});
2119

22-
Promise.all(users.map(user => {
23-
let note = new apn.Notification();
24-
note.alert = `Hey ${user.name}, I just sent my first Push Notification`;
20+
Promise.all(
21+
users.map(user => {
22+
const note = new apn.Notification();
23+
note.alert = `Hey ${user.name}, I just sent my first Push Notification`;
2524

26-
// The topic is usually the bundle identifier of your application.
27-
note.topic = "<bundle identifier>";
25+
// The topic is usually the bundle identifier of your application.
26+
note.topic = '<bundle identifier>';
2827

29-
console.log(`Sending: ${note.compile()} to ${user.devices}`);
28+
console.log(`Sending: ${note.compile()} to ${user.devices}`);
3029

31-
return service.send(note, user.devices).then( result => {
32-
console.log("sent:", result.sent.length);
33-
console.log("failed:", result.failed.length);
30+
return service.send(note, user.devices).then(result => {
31+
console.log('sent:', result.sent.length);
32+
console.log('failed:', result.failed.length);
3433
console.log(result.failed);
35-
});
36-
})).then(() => {
34+
});
35+
})
36+
).then(() => {
3737
// For one-shot notification tasks you may wish to shutdown the connection
3838
// after everything is sent, but only call shutdown if you need your
3939
// application to terminate.
Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"use strict";
2-
31
/**
42
53
Send an identical notification to multiple devices.
@@ -11,30 +9,30 @@ Possible use cases:
119
- Sport results
1210
*/
1311

14-
const apn = require("apn");
12+
const apn = require('@parse/node-apn');
1513

16-
let tokens = ["<insert token here>", "<insert token here>"];
14+
const tokens = ['<insert token here>', '<insert token here>'];
1715

18-
let service = new apn.Provider({
19-
cert: "certificates/cert.pem",
20-
key: "certificates/key.pem",
16+
const service = new apn.Provider({
17+
cert: 'certificates/cert.pem',
18+
key: 'certificates/key.pem',
2119
});
2220

23-
let note = new apn.Notification({
24-
alert: "Breaking News: I just sent my first Push Notification",
21+
const note = new apn.Notification({
22+
alert: 'Breaking News: I just sent my first Push Notification',
2523
});
2624

2725
// The topic is usually the bundle identifier of your application.
28-
note.topic = "<bundle identifier>";
26+
note.topic = '<bundle identifier>';
2927

3028
console.log(`Sending: ${note.compile()} to ${tokens}`);
3129
service.send(note, tokens).then(result => {
32-
console.log("sent:", result.sent.length);
33-
console.log("failed:", result.failed.length);
34-
console.log(result.failed);
35-
36-
// For one-shot notification tasks you may wish to shutdown the connection
37-
// after everything is sent, but only call shutdown if you need your
38-
// application to terminate.
39-
service.shutdown();
30+
console.log('sent:', result.sent.length);
31+
console.log('failed:', result.failed.length);
32+
console.log(result.failed);
33+
34+
// For one-shot notification tasks you may wish to shutdown the connection
35+
// after everything is sent, but only call shutdown if you need your
36+
// application to terminate.
37+
service.shutdown();
4038
});

index.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
const debug = require("debug")("apn");
1+
const http2 = require('http2');
2+
const debug = require('debug')('apn');
3+
24
debug.log = console.log.bind(console);
35

4-
const credentials = require("./lib/credentials")({
5-
logger: debug
6+
const credentials = require('./lib/credentials')({
7+
logger: debug,
68
});
79

8-
const config = require("./lib/config")({
10+
const config = require('./lib/config')({
911
logger: debug,
1012
prepareCertificate: credentials.certificate,
1113
prepareToken: credentials.token,
1214
prepareCA: credentials.ca,
1315
});
1416

15-
const http2 = require("http2");
16-
17-
const Client = require("./lib/client")({
17+
const Client = require('./lib/client')({
1818
logger: debug,
1919
config,
2020
http2,
2121
});
2222

23-
const MultiClient = require("./lib/multiclient")({
23+
const MultiClient = require('./lib/multiclient')({
2424
Client,
2525
});
2626

27-
const Provider = require("./lib/provider")({
27+
const Provider = require('./lib/provider')({
2828
logger: debug,
2929
Client,
3030
});
3131

32-
const MultiProvider = require("./lib/provider")({
32+
const MultiProvider = require('./lib/provider')({
3333
logger: debug,
3434
Client: MultiClient,
3535
});
3636

37-
const Notification = require("./lib/notification");
37+
const Notification = require('./lib/notification');
3838

39-
const token = require("./lib/token");
39+
const token = require('./lib/token');
4040

4141
module.exports = {
4242
Provider,

0 commit comments

Comments
 (0)