-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #332
- Loading branch information
Showing
7 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[//]: # (This file is generated by eslint-docgen. Do not edit it directly.) | ||
|
||
# no-done-fail | ||
|
||
Disallows the [`.done`](https://api.jquery.com/deferred.done/)/[`.fail`](https://api.jquery.com/deferred.fail/) methods. Prefer `.then`. | ||
|
||
📋 This rule is enabled in `plugin:no-jquery/all`. | ||
|
||
## Rule details | ||
|
||
❌ Examples of **incorrect** code: | ||
```js | ||
promise.done( callback ); | ||
promise.fail( callback ); | ||
``` | ||
|
||
✔️ Examples of **correct** code: | ||
```js | ||
promise.then( doneCallback, failCallback ); | ||
done(); | ||
fail(); | ||
``` | ||
|
||
## Resources | ||
|
||
* [Rule source](/src/rules/no-done-fail.js) | ||
* [Test source](/tests/rules/no-done-fail.js) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
const utils = require( '../utils.js' ); | ||
|
||
module.exports = utils.createUniversalMethodRule( | ||
[ 'done', 'fail' ], | ||
( node ) => node === true ? | ||
'Prefer `.then`' : | ||
`Prefer .then to .${ node.callee.property.name }`, | ||
( method ) => `[\`.${ method }\`](https://api.jquery.com/deferred.${ method }/)` | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
const rule = require( '../../src/rules/no-done-fail' ); | ||
const RuleTester = require( '../../tools/rule-tester' ); | ||
|
||
const error = ( method ) => `Prefer .then to .${ method }`; | ||
|
||
const ruleTester = new RuleTester(); | ||
ruleTester.run( 'no-done-fail', rule, { | ||
valid: [ 'promise.then( doneCallback, failCallback )', 'done()', 'fail()' ], | ||
invalid: [ | ||
{ | ||
code: 'promise.done( callback )', | ||
errors: [ error( 'done' ) ] | ||
}, | ||
{ | ||
code: 'promise.fail( callback )', | ||
errors: [ error( 'fail' ) ] | ||
} | ||
] | ||
} ); |