Skip to content

Commit b2250b7

Browse files
committed
Restore prettier + integrate with ESLint
1 parent 968a9fa commit b2250b7

Some content is hidden

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

56 files changed

+411
-764
lines changed

.eslintrc

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
{
22
"extends": [
3-
"@mollie/eslint-config-typescript"
3+
"@mollie/eslint-config-typescript",
4+
"plugin:prettier/recommended"
45
],
56
"rules": {
6-
"max-len": ["warn", { "code": 140, "comments": 400 }],
77
"no-underscore-dangle": "off",
88
"import/prefer-default-export": "off",
99
"no-plusplus": "off",
1010
"no-shadow": "off",
1111
"@typescript-eslint/no-explicit-any": "off",
12-
"no-console": "off"
12+
"no-console": "off",
13+
"@typescript-eslint/indent": "off"
1314
},
1415
"settings": {
1516
"import/resolver": {

.prettierrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"printWidth": 200,
3+
"singleQuote": true,
4+
"trailingComma": "all",
5+
"bracketSpacing": true,
6+
"arrowParens": "avoid"
7+
}

examples/with-express/01-new-payment.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ app.get('/', (req, res) => {
1919
webhookUrl: `http://example.org/webhook?orderId=${orderId}`,
2020
metadata: { orderId },
2121
})
22-
.then((payment) => {
22+
.then(payment => {
2323
// Redirect the consumer to complete the payment using `payment.getPaymentUrl()`.
2424
res.redirect(payment.getPaymentUrl());
2525
})
26-
.catch((error) => {
26+
.catch(error => {
2727
// Do some proper error handling.
2828
res.send(error);
2929
});

examples/with-express/02-webhook-verification.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ const mollieClient = mollie({ apiKey: 'test_buC3bBQfSQhd4dDUeMctJjDCn3GhP4' });
1818
app.post('/webhook', (req, res) => {
1919
mollieClient.payments
2020
.get(req.body.id)
21-
.then((payment) => {
21+
.then(payment => {
2222
if (payment.isPaid()) {
2323
// Hooray, you've received a payment! You can start shipping to the consumer.
2424
} else if (!payment.isOpen()) {
2525
// The payment isn't paid and has expired. We can assume it was aborted.
2626
}
2727
res.send(payment.status);
2828
})
29-
.catch((error) => {
29+
.catch(error => {
3030
// Do some proper error handling.
3131
res.send(error);
3232
});

examples/with-express/03-return-page.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ app.get('/return-page', (req, res) => {
2020

2121
mollieClient.payments
2222
.get(order.paymentId)
23-
.then((payment) => {
23+
.then(payment => {
2424
// Show the consumer the status of the payment using `payment.status`.
2525
res.send(payment.status);
2626
})
27-
.catch((error) => {
27+
.catch(error => {
2828
// Do some proper error handling.
2929
res.send(error);
3030
});

examples/with-express/04-ideal-payment.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,13 @@ app.get('/', (req, res) => {
1616
mollieClient.methods
1717
.all({ include: 'issuers' })
1818
.then(methods => methods.filter(({ id }) => id === 'ideal'))
19-
.then((methods) => {
19+
.then(methods => {
2020
res.send(`<form>
21-
${methods.map(
22-
method => `
23-
<h2>Select ${method.description} issuer</h2>
24-
<select name="issuer">${method.issuers.map(issuer => `<option value="${issuer.id}">${issuer.name}</option>`)}</select>
25-
`,
26-
)}
21+
${methods.map(method => `<h2>Select ${method.description} issuer</h2><select name="issuer">${method.issuers.map(issuer => `<option value="${issuer.id}">${issuer.name}</option>`)}</select>`)}
2722
<button>Select issuer</button>
2823
</form>`);
2924
})
30-
.catch((error) => {
25+
.catch(error => {
3126
// Do some proper error handling.
3227
res.send(error);
3328
});
@@ -48,11 +43,11 @@ app.get('/', (req, res) => {
4843
method: 'ideal',
4944
issuer: selectedIssuer,
5045
})
51-
.then((payment) => {
46+
.then(payment => {
5247
// Redirect the consumer to complete the payment using `payment.getPaymentUrl()`.
5348
res.redirect(payment.getPaymentUrl());
5449
})
55-
.catch((error) => {
50+
.catch(error => {
5651
// Do some proper error handling.
5752
res.send(error);
5853
});

examples/with-express/05-payments-history.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,25 @@ app.get('/', (req, res) => {
2222

2323
mollieClient.payments
2424
.all(paymentParameters)
25-
.then((payments) => {
25+
.then(payments => {
2626
res.send(`
2727
<ul>
2828
${payments
29-
.map(
30-
payment => `<li>
29+
.map(
30+
payment => `<li>
3131
Payment ID: ${payment.id}<br />
3232
Method: ${payment.method}<br />
3333
Amount: ${payment.amount.value} ${payment.amount.currency}<br />
3434
Created at: ${new Date(payment.createdAt)}
3535
</li>`,
36-
)
37-
.join('')}
36+
)
37+
.join('')}
3838
</ul>
3939
${payments.previousPageCursor ? `<a href="?from=${payments.previousPageCursor}">Previous</a> | ` : ''}
4040
${payments.nextPageCursor ? `<a href="?from=${payments.nextPageCursor}">Next</a>` : ''}
4141
`);
4242
})
43-
.catch((error) => {
43+
.catch(error => {
4444
// Do some proper error handling.
4545
res.send(error);
4646
});

examples/with-express/06-refund-payment.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ mollieClient.payments_refunds
1616
currency: 'EUR',
1717
},
1818
})
19-
.then((refund) => {
19+
.then(refund => {
2020
// New refund (#`refund.id`) created with amount: `refund.amount`.
2121
})
22-
.catch((error) => {
22+
.catch(error => {
2323
// Do some proper error handling.
2424
});

examples/with-express/07-new-customer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ mollieClient.customers
1414
isJedi: true,
1515
},
1616
})
17-
.then((customer) => {
17+
.then(customer => {
1818
// New customer created with ID `customer.id` and name `customer.name`.
1919
})
20-
.catch((error) => {
20+
.catch(error => {
2121
// Do some proper error handling.
2222
});

examples/with-express/08-new-customer-payment.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const mollieClient = mollie({ apiKey: 'test_buC3bBQfSQhd4dDUeMctJjDCn3GhP4' });
1010

1111
mollieClient.customers
1212
.all()
13-
.then((customers) => {
13+
.then(customers => {
1414
const customerId = customers[0].id; // Select one of your customers.
1515
const orderId = new Date().getTime();
1616

@@ -23,13 +23,13 @@ mollieClient.customers
2323
metadata: { orderId },
2424
customerId,
2525
})
26-
.then((payment) => {
26+
.then(payment => {
2727
// Redirect customer to payment screen with `payment.getPaymentUrl()`.
2828
})
29-
.catch((error) => {
29+
.catch(error => {
3030
// Do some proper error handling.
3131
});
3232
})
33-
.catch((error) => {
33+
.catch(error => {
3434
// Do some proper error handling.
3535
});

examples/with-express/09-customer-payments-history.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ mollieClient.customers_payments
1111
count: 50,
1212
customerId: 'cst_cu5t0m3r',
1313
})
14-
.then((payments) => {
14+
.then(payments => {
1515
// List the customer's payments.
1616
})
17-
.catch((error) => {
17+
.catch(error => {
1818
// Do some proper error handling.
1919
});

examples/with-express/10-recurring-first-payment.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ mollieClient.customers_payments
1717
sequenceType: 'first',
1818
customerId: 'cst_2mVdVmuVq2',
1919
})
20-
.then((payment) => {
20+
.then(payment => {
2121
// Redirect the customer to complete the payment using `payment.getPaymentUrl()`.
2222
})
23-
.catch((error) => {
23+
.catch(error => {
2424
// Do some proper error handling.
2525
});

examples/with-express/11-recurring-payment.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const mollieClient = mollie({ apiKey: 'test_buC3bBQfSQhd4dDUeMctJjDCn3GhP4' });
88

99
mollieClient.customers
1010
.all()
11-
.then((customers) => {
11+
.then(customers => {
1212
const customerId = customers[0].id; // Select one of your customers.
1313
const orderId = new Date().getTime();
1414

@@ -22,13 +22,13 @@ mollieClient.customers
2222
customerId,
2323
sequenceType: 'recurring',
2424
})
25-
.then((payment) => {
25+
.then(payment => {
2626
// Redirect customer to payment screen with `payment.getPaymentUrl()`.
2727
})
28-
.catch((error) => {
28+
.catch(error => {
2929
// Do some proper error handling.
3030
});
3131
})
32-
.catch((error) => {
32+
.catch(error => {
3333
// Do some proper error handling.
3434
});

examples/with-express/16-recurring-subscription.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const mollie = require('@mollie/api-client');
66

77
const mollieClient = mollie({ apiKey: 'test_buC3bBQfSQhd4dDUeMctJjDCn3GhP4' });
88

9-
mollieClient.customers.all().then((customers) => {
9+
mollieClient.customers.all().then(customers => {
1010
mollieClient.customers_subscriptions
1111
.create({
1212
customerId: customers[0].id,
@@ -19,7 +19,7 @@ mollieClient.customers.all().then((customers) => {
1919
.then(({ id }) => {
2020
// i.e. send confirmation email
2121
})
22-
.catch((error) => {
22+
.catch(error => {
2323
// Do some proper error handling
2424
});
2525
});

package.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@
3333
"test:cov": "jest --coverage",
3434
"test:unit:cov": "jest ./tests/unit --coverage",
3535
"build": "rollup -c",
36+
"lint:prettier": "prettier --write \"{src,tests,examples}/**/*.{js,ts}\"",
3637
"lint:eslint": "eslint --ext .ts,.js src/ tests/ examples/",
3738
"lint:eslint:fix": "eslint --ext .ts,.js --fix src/ tests/ examples/",
38-
"lint": "yarn lint:eslint:fix"
39+
"lint": "yarn lint:eslint:fix && yarn lint:prettier"
3940
},
4041
"dependencies": {
4142
"axios": "^0.18.0",
@@ -58,9 +59,12 @@
5859
"cz-conventional-changelog": "^2.1.0",
5960
"dotenv": "^6.2.0",
6061
"eslint": "^5.13.0",
62+
"eslint-config-prettier": "^4.0.0",
63+
"eslint-plugin-prettier": "^3.0.1",
6164
"husky": "^1.3.1",
6265
"jest": "^24.1.0",
6366
"lint-staged": "^8.1.0",
67+
"prettier": "^1.16.4",
6468
"rollup": "^1.1.2",
6569
"rollup-plugin-copy-glob": "^0.3.0",
6670
"rollup-plugin-includepaths": "^0.2.3",
@@ -79,14 +83,17 @@
7983
},
8084
"lint-staged": {
8185
"src/**/*.ts": [
86+
"prettier --write \"src/**/*.{js,ts}\"",
8287
"eslint --ext .js,.ts --fix src/",
8388
"git add src/"
8489
],
8590
"tests/**/*.ts": [
91+
"prettier --write \"tests/**/*.(js|ts)\"",
8692
"eslint --ext .js,.ts --fix tests/",
8793
"git add tests/"
8894
],
8995
"examples/**/*.js": [
96+
"prettier --write \"examples/**/*.(js|ts)\"",
9097
"eslint --ext .js,.ts --fix examples/",
9198
"git add examples/"
9299
]

src/models/List.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { IListLinks } from '../types/global';
33
import Model from '../model';
44
import { ResourceCallback } from '../resource';
55

6-
interface IInstantiable<T = any> { new (...args: Array<any>): T }
6+
interface IInstantiable<T = any> {
7+
new (...args: Array<any>): T;
8+
}
79

810
interface IResourceListParams {
911
response: {
@@ -47,14 +49,7 @@ export default class List<T> extends Array {
4749
return {};
4850
}
4951

50-
public static buildResourceList({
51-
response,
52-
resourceName,
53-
params,
54-
callback,
55-
getResources,
56-
Model,
57-
}: IResourceListParams): List<Model> {
52+
public static buildResourceList({ response, resourceName, params, callback, getResources, Model }: IResourceListParams): List<Model> {
5853
const { _embedded, count, _links } = response;
5954
const resources = _embedded[resourceName];
6055
const list = new List();

src/resource.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,7 @@ export default class Resource {
108108
}
109109

110110
try {
111-
const response: AxiosResponse = await this.getClient().post(
112-
`${this.getResourceUrl()}${qs.stringify(query, { addQueryPrefix: true })}`,
113-
params,
114-
);
111+
const response: AxiosResponse = await this.getClient().post(`${this.getResourceUrl()}${qs.stringify(query, { addQueryPrefix: true })}`, params);
115112

116113
// noinspection JSPotentiallyInvalidConstructorUsage
117114
const model = new (this.constructor as any).model(response.data);
@@ -152,9 +149,7 @@ export default class Resource {
152149
}
153150

154151
try {
155-
const response: AxiosResponse = await this.getClient().get(
156-
`${this.getResourceUrl()}/${id}${qs.stringify(query, { addQueryPrefix: true })}`,
157-
);
152+
const response: AxiosResponse = await this.getClient().get(`${this.getResourceUrl()}/${id}${qs.stringify(query, { addQueryPrefix: true })}`);
158153

159154
// noinspection JSPotentiallyInvalidConstructorUsage
160155
const model = new (this.constructor as any).model(response.data);
@@ -202,9 +197,7 @@ export default class Resource {
202197
}
203198
}
204199

205-
const response: AxiosResponse = await this.getClient().get(
206-
`${this.getResourceUrl()}${qs.stringify(query, { addQueryPrefix: true })}`,
207-
);
200+
const response: AxiosResponse = await this.getClient().get(`${this.getResourceUrl()}${qs.stringify(query, { addQueryPrefix: true })}`);
208201
const resourceName = this.getResourceName();
209202
const list = List.buildResourceList({
210203
response: response.data,

src/resources/chargebacks.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ export default class ChargebacksResource extends Resource {
5555
public async list(params?: IListParams | ListCallback, cb?: ListCallback): Promise<List<Chargeback>> {
5656
// Using callbacks (DEPRECATED SINCE 2.2.0)
5757
if (typeof params === 'function' || typeof cb === 'function') {
58-
return super.list(
59-
typeof params === 'function' ? null : params,
60-
typeof params === 'function' ? params : cb,
61-
) as Promise<List<Chargeback>>;
58+
return super.list(typeof params === 'function' ? null : params, typeof params === 'function' ? params : cb) as Promise<List<Chargeback>>;
6259
}
6360

6461
return super.list(params, cb) as Promise<List<Chargeback>>;

0 commit comments

Comments
 (0)