Skip to content

Commit a9c0635

Browse files
committedDec 18, 2021
updated husky/prettier/etc
1 parent 4281516 commit a9c0635

16 files changed

+256
-8493
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
.idea
33
coverage/
4+
.eslintcache

‎.husky/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_

‎.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx lint-staged

‎.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
coverage

‎LICENSE.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
Copyright (c) 2020, Jamund Ferguson
22

3-
Permission to use, copy, modify, and/or distribute this software for any
4-
purpose with or without fee is hereby granted, provided that the above
5-
copyright notice and this permission notice appear in all copies.
3+
Permission to use, copy, modify, and/or distribute this software for any purpose
4+
with or without fee is hereby granted, provided that the above copyright notice
5+
and this permission notice appear in all copies.
66

77
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
88
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
99
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13-
PERFORMANCE OF THIS SOFTWARE.
10+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
11+
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
12+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
13+
THIS SOFTWARE.

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ or start with the recommended rule set:
9090
| [`no-new-statics`][no-new-statics] | Avoid calling `new` on a Promise static method | :bangbang: | :wrench: |
9191
| [`no-return-in-finally`][no-return-in-finally] | Disallow return statements in `finally()` | :warning: | |
9292
| [`valid-params`][valid-params] | Ensures the proper number of arguments are passed to Promise functions | :warning: | |
93-
| [`prefer-await-to-then`][prefer-await-to-then] | Prefer `await` to `then()`/`catch()`/`finally()` for reading Promise values | :seven: | |
93+
| [`prefer-await-to-then`][prefer-await-to-then] | Prefer `await` to `then()`/`catch()`/`finally()` for reading Promise values | :seven: | |
9494
| [`prefer-await-to-callbacks`][prefer-await-to-callbacks] | Prefer async/await to the callback pattern | :seven: | |
9595

9696
**Key**

‎docs/rules/always-return.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ myPromise.then((b) => { if (b) { return "yes" } else { return "no" } });
1919
#### Invalid
2020

2121
```js
22-
myPromise.then(function(val) {})
22+
myPromise.then(function (val) {})
2323
myPromise.then(() => {
2424
doSomething()
2525
})
26-
myPromise.then(b => {
26+
myPromise.then((b) => {
2727
if (b) {
2828
return 'yes'
2929
} else {

‎docs/rules/catch-or-return.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ as well. Exceptions are made if you are returning that promise.
77

88
```js
99
myPromise.then(doSomething).catch(errors)
10-
myPromise
11-
.then(doSomething)
12-
.then(doSomethingElse)
13-
.catch(errors)
10+
myPromise.then(doSomething).then(doSomethingElse).catch(errors)
1411
function doSomethingElse() {
1512
return myPromise.then(doSomething)
1613
}

‎docs/rules/no-callback-in-promise.md

+30-17
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
# Avoid calling `cb()` inside of a `then()` or `catch()` (no-callback-in-promise)
22

3-
As a general rule, callbacks should never be directly invoked inside a [Promise.prototype.then()] or [Promise.prototype.catch()] method. That's because your callback may be unintentionally be invoked twice. It also can be confusing to mix paradigms.
3+
As a general rule, callbacks should never be directly invoked inside a
4+
[Promise.prototype.then()] or [Promise.prototype.catch()] method. That's because
5+
your callback may be unintentionally be invoked twice. It also can be confusing
6+
to mix paradigms.
47

58
Take the following example:
69

710
```js
811
function callback(err, data) {
9-
console.log("Callback got called with:", err, data);
10-
throw new Error("My error");
12+
console.log('Callback got called with:', err, data)
13+
throw new Error('My error')
1114
}
1215

1316
// note: passing `err.message` for demo purposes, normally you would pass `err`
1417
Promise.resolve()
15-
.then(() => callback(null, "data"))
16-
.catch(err => callback(err.message, null));
18+
.then(() => callback(null, 'data'))
19+
.catch((err) => callback(err.message, null))
1720
```
1821

1922
If you run this example, your output will look like the following:
@@ -25,20 +28,22 @@ Callback got called with: My error null
2528

2629
**How to fix it?**
2730

28-
Ensure that your callback invocations are wrapped by a deferred execution function such as:
31+
Ensure that your callback invocations are wrapped by a deferred execution
32+
function such as:
33+
2934
- [setImmediate()] or [process.nextTick()]: for Node.js.
3035
- [setTimeout()]: for Browsers and Node.js.
3136

3237
```js
3338
// node.js
3439
Promise.resolve()
35-
.then(() => setImmediate(() => callback(null, "data")))
36-
.catch(err => setImmediate(() => callback(err.message, null)));
40+
.then(() => setImmediate(() => callback(null, 'data')))
41+
.catch((err) => setImmediate(() => callback(err.message, null)))
3742

3843
// node.js and browsers
3944
Promise.resolve()
40-
.then(() => setTimeout(() => callback(null, "data"), 0))
41-
.catch(err => setTimeout(() => callback(err.message, null), 0));
45+
.then(() => setTimeout(() => callback(null, 'data'), 0))
46+
.catch((err) => setTimeout(() => callback(err.message, null), 0))
4247
```
4348

4449
Your output will now look like the following:
@@ -47,11 +52,19 @@ Your output will now look like the following:
4752
Callback got called with: null data
4853
```
4954

50-
Finally, if your callbacks have a Node.js signature (i.e. `callback(err, data)`), consider using [util.promsify] for promisifying your callback code instead of combining the approaches.
55+
Finally, if your callbacks have a Node.js signature (i.e.
56+
`callback(err, data)`), consider using [util.promsify] for promisifying your
57+
callback code instead of combining the approaches.
5158

52-
[util.promisify]: https://nodejs.org/dist/latest/docs/api/util.html#utilpromisifyoriginal
53-
[Promise.prototype.then()]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then
54-
[Promise.prototype.catch()]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch
55-
[setImmediate()]: https://nodejs.org/docs/latest-v14.x/api/timers.html#timers_setimmediate_callback_args
56-
[process.nextTick()]: https://nodejs.org/docs/latest-v14.x/api/process.html#process_process_nexttick_callback_args
57-
[setTimeout()]: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout
59+
[util.promisify]:
60+
https://nodejs.org/dist/latest/docs/api/util.html#utilpromisifyoriginal
61+
[promise.prototype.then()]:
62+
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then
63+
[promise.prototype.catch()]:
64+
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch
65+
[setimmediate()]:
66+
https://nodejs.org/docs/latest-v14.x/api/timers.html#timers_setimmediate_callback_args
67+
[process.nexttick()]:
68+
https://nodejs.org/docs/latest-v14.x/api/process.html#process_process_nexttick_callback_args
69+
[settimeout()]:
70+
https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout

‎docs/rules/no-nesting.md

+5-16
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,17 @@
33
#### Valid
44

55
```js
6-
myPromise
7-
.then(doSomething)
8-
.then(doSomethingElse)
9-
.catch(errors)
6+
myPromise.then(doSomething).then(doSomethingElse).catch(errors)
107
```
118

129
#### Invalid
1310

1411
```js
15-
myPromise.then(val =>
16-
doSomething(val).then(doSomethingElse)
17-
)
12+
myPromise.then((val) => doSomething(val).then(doSomethingElse))
1813

19-
myPromise.then(val =>
20-
doSomething(val).catch(errors)
21-
)
14+
myPromise.then((val) => doSomething(val).catch(errors))
2215

23-
myPromise.catch(err =>
24-
doSomething(err).then(doSomethingElse)
25-
)
16+
myPromise.catch((err) => doSomething(err).then(doSomethingElse))
2617

27-
myPromise.catch(err =>
28-
doSomething(err).catch(errors)
29-
)
18+
myPromise.catch((err) => doSomething(err).catch(errors))
3019
```

‎docs/rules/no-return-in-finally.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ nothing would consume what's returned.
66
#### Valid
77

88
```js
9-
myPromise.finally(function(val) {
9+
myPromise.finally(function (val) {
1010
console.log('value:', val)
1111
})
1212
```
1313

1414
#### Invalid
1515

1616
```js
17-
myPromise.finally(function(val) {
17+
myPromise.finally(function (val) {
1818
return val
1919
})
2020
```

‎docs/rules/no-return-wrap.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ value instead of wrapping in `Promise.resolve` or `Promise.reject`
66
#### Valid
77

88
```js
9-
myPromise.then(function(val) {
9+
myPromise.then(function (val) {
1010
return val * 2
1111
})
12-
myPromise.then(function(val) {
12+
myPromise.then(function (val) {
1313
throw 'bad thing'
1414
})
1515
```
1616

1717
#### Invalid
1818

1919
```js
20-
myPromise.then(function(val) {
20+
myPromise.then(function (val) {
2121
return Promise.resolve(val * 2)
2222
})
23-
myPromise.then(function(val) {
23+
myPromise.then(function (val) {
2424
return Promise.reject('bad thing')
2525
})
2626
```

‎docs/rules/prefer-await-to-then.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,10 @@ function exampleTwo() {
3535
}
3636

3737
function exampleThree() {
38-
return myPromise
39-
.catch(errors)
38+
return myPromise.catch(errors)
4039
}
4140

4241
function exampleFour() {
43-
return myPromise
44-
.finally(cleanup)
42+
return myPromise.finally(cleanup)
4543
}
4644
```

‎docs/rules/valid-params.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ Promise.reject(Error())
4141
Promise.reject(referenceToError)
4242

4343
// Promise.then() requires 1 or 2 arguments
44-
somePromise().then(value => doSomething(value))
44+
somePromise().then((value) => doSomething(value))
4545
somePromise().then(successCallback, errorCallback)
4646

4747
// Promise.catch() requires 1 argument
48-
somePromise().catch(error => {
48+
somePromise().catch((error) => {
4949
handleError(error)
5050
})
5151
somePromise().catch(console.error)

‎package-lock.json

+186-8,427
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
"homepage": "https://github.com/xjamundx/eslint-plugin-promise",
1818
"bugs": "https://github.com/xjamundx/eslint-plugin-promise/issues",
1919
"scripts": {
20-
"precommit": "lint-staged --concurrent false",
21-
"test": "jest --coverage",
22-
"lint": "eslint rules __tests__ index.js",
23-
"format": "prettier --write '**/*.js'"
20+
"format": "prettier --write .",
21+
"lint": "eslint .",
22+
"prepare": "husky install",
23+
"test": "jest --coverage"
2424
},
2525
"dependencies": {},
2626
"devDependencies": {
@@ -31,11 +31,11 @@
3131
"eslint-plugin-jest": "^25.3.0",
3232
"eslint-plugin-node": "^11.1.0",
3333
"eslint-plugin-prettier": "^3.4.1",
34-
"husky": "^6.0.0",
34+
"husky": "^7.0.4",
3535
"jest": "^26.6.3",
3636
"jest-runner-eslint": "^0.11.1",
37-
"lint-staged": "^10.5.4",
38-
"prettier": "2.5.1"
37+
"lint-staged": "^12.1.2",
38+
"prettier": "^2.5.1"
3939
},
4040
"peerDependencies": {
4141
"eslint": "^7.0.0"

0 commit comments

Comments
 (0)
Please sign in to comment.