Skip to content

Commit d387c50

Browse files
authored
Merge branch 'master' into doc
2 parents 1497668 + 387002b commit d387c50

25 files changed

+294
-49
lines changed

.github/workflows/nodejs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ jobs:
1212
node-version: [18.x, 20.x, 22.x]
1313

1414
steps:
15-
- uses: actions/checkout@v1
15+
- uses: actions/checkout@v4
1616
- name: Use Node.js ${{ matrix.node-version }}
17-
uses: actions/setup-node@v1
17+
uses: actions/setup-node@v4
1818
with:
1919
node-version: ${{ matrix.node-version }}
2020
- name: npm install, build, and test
@@ -28,7 +28,7 @@ jobs:
2828
env:
2929
CI: true
3030
- name: Upload coverage to Codecov
31-
uses: codecov/codecov-action@v1
31+
uses: codecov/codecov-action@v4
3232
with:
3333
token: ${{ secrets.CODECOV_TOKEN }}
3434
file: ./coverage.lcov

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ Where rules are included in the configs `recommended`, `slim`, `all` or `depreca
107107
* [`no-jquery/no-data`](docs/rules/no-data.md) `all`
108108
* [`no-jquery/no-deferred`](docs/rules/no-deferred.md) `all`
109109
* [`no-jquery/no-delegate`](docs/rules/no-delegate.md) `3.0`, `all`
110+
* [`no-jquery/no-done-fail`](docs/rules/no-done-fail.md) `all`
110111
* [`no-jquery/no-each`](docs/rules/no-each.md)
111112
* [`no-jquery/no-each-collection`](docs/rules/no-each-collection.md) `all`
112113
* [`no-jquery/no-each-util`](docs/rules/no-each-util.md) `all`
@@ -120,6 +121,7 @@ Where rules are included in the configs `recommended`, `slim`, `all` or `depreca
120121
* [`no-jquery/no-find`](docs/rules/no-find.md)
121122
* [`no-jquery/no-find-collection`](docs/rules/no-find-collection.md) `all`
122123
* [`no-jquery/no-find-util`](docs/rules/no-find-util.md) `all`
124+
* [`no-jquery/no-fx`](docs/rules/no-fx.md) `slim`
123125
* [`no-jquery/no-fx-interval`](docs/rules/no-fx-interval.md) `3.0`
124126
* [`no-jquery/no-global-eval`](docs/rules/no-global-eval.md) `all`
125127
* [`no-jquery/no-global-selector`](docs/rules/no-global-selector.md) ⚙️

docs/rules/no-animate.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# no-animate
44

5-
Disallows the [`.animate`](https://api.jquery.com/animate/) method. Use the `allowScroll` option to allow animations which are just used for scrolling. Prefer CSS transitions.
5+
Disallows the [`.animate`](https://api.jquery.com/animate/)/[`.stop`](https://api.jquery.com/stop/)/[`.finish`](https://api.jquery.com/finish/) methods. Use the `allowScroll` option to allow animations which are just used for scrolling. Prefer CSS transitions.
66

77
📋 This rule is enabled in `plugin:no-jquery/slim`.
88

@@ -13,6 +13,8 @@ Disallows the [`.animate`](https://api.jquery.com/animate/) method. Use the `all
1313
❌ Examples of **incorrect** code:
1414
```js
1515
$( 'div' ).animate();
16+
$( 'div' ).stop();
17+
$( 'div' ).finish();
1618
$div.animate();
1719
$( 'div' ).first().animate();
1820
$( 'div' ).append( $( 'input' ).animate() );
@@ -28,6 +30,14 @@ animate();
2830
[].animate();
2931
div.animate();
3032
div.animate;
33+
stop();
34+
[].stop();
35+
div.stop();
36+
div.stop;
37+
finish();
38+
[].finish();
39+
div.finish();
40+
div.finish;
3141
```
3242

3343
❌ Examples of **incorrect** code with `[{"allowScroll":false}]` options:
@@ -39,6 +49,8 @@ $div.animate( { scrollTop: 100 } );
3949
```js
4050
$div.animate();
4151
$div.animate( { scrollTop: 100, width: 300 } );
52+
$( 'div' ).stop( { scrollTop: 100, scrollLeft: 200 } );
53+
$( 'div' ).finish( { scrollTop: 100, scrollLeft: 200 } );
4254
```
4355

4456
✔️ Examples of **correct** code with `[{"allowScroll":true}]` options:

docs/rules/no-done-fail.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[//]: # (This file is generated by eslint-docgen. Do not edit it directly.)
2+
3+
# no-done-fail
4+
5+
Disallows the [`.done`](https://api.jquery.com/deferred.done/)/[`.fail`](https://api.jquery.com/deferred.fail/) methods. Prefer `.then`.
6+
7+
📋 This rule is enabled in `plugin:no-jquery/all`.
8+
9+
## Rule details
10+
11+
❌ Examples of **incorrect** code:
12+
```js
13+
promise.done( callback );
14+
promise.fail( callback );
15+
```
16+
17+
✔️ Examples of **correct** code:
18+
```js
19+
promise.then( doneCallback, failCallback );
20+
done();
21+
fail();
22+
```
23+
24+
## Resources
25+
26+
* [Rule source](/src/rules/no-done-fail.js)
27+
* [Test source](/tests/rules/no-done-fail.js)

docs/rules/no-fx.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[//]: # (This file is generated by eslint-docgen. Do not edit it directly.)
2+
3+
# no-fx
4+
5+
Disallows `$.fx`.
6+
7+
📋 This rule is enabled in `plugin:no-jquery/slim`.
8+
9+
## Rule details
10+
11+
❌ Examples of **incorrect** code:
12+
```js
13+
$.fx;
14+
$.fx.interval;
15+
$.fx.off;
16+
$.fx.speeds.slow;
17+
$.fx.start();
18+
```
19+
20+
✔️ Examples of **correct** code:
21+
```js
22+
fx;
23+
fx.interval;
24+
a.fx;
25+
```
26+
27+
## Resources
28+
29+
* [Rule source](/src/rules/no-fx.js)
30+
* [Test source](/tests/rules/no-fx.js)

src/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module.exports = {
2525
'no-deferred': require( './rules/no-deferred' ),
2626
'no-delegate': require( './rules/no-delegate' ),
2727
'no-die': require( './rules/no-die' ),
28+
'no-done-fail': require( './rules/no-done-fail' ),
2829
'no-each': require( './rules/no-each' ),
2930
'no-each-collection': require( './rules/no-each-collection' ),
3031
'no-each-util': require( './rules/no-each-util' ),
@@ -38,6 +39,7 @@ module.exports = {
3839
'no-find': require( './rules/no-find' ),
3940
'no-find-collection': require( './rules/no-find-collection' ),
4041
'no-find-util': require( './rules/no-find-util' ),
42+
'no-fx': require( './rules/no-fx' ),
4143
'no-fx-interval': require( './rules/no-fx-interval' ),
4244
'no-global-eval': require( './rules/no-global-eval' ),
4345
'no-global-selector': require( './rules/no-global-selector' ),
@@ -117,6 +119,7 @@ module.exports = {
117119
'no-jquery/no-animate-toggle': 'error',
118120
'no-jquery/no-fade': 'error',
119121
'no-jquery/no-slide': 'error',
122+
'no-jquery/no-fx': 'error',
120123
// Ajax
121124
'no-jquery/no-ajax': 'error',
122125
'no-jquery/no-ajax-events': 'error',
@@ -333,8 +336,10 @@ module.exports = {
333336
'no-jquery/no-filter': 'warn',
334337
'no-jquery/no-prop': 'warn',
335338
'no-jquery/no-sub': 'warn',
336-
'no-jquery/no-text': 'warn'
339+
'no-jquery/no-text': 'warn',
337340

341+
// Other methods
342+
'no-jquery/no-done-fail': 'warn'
338343
}
339344
}
340345
}

src/rules/no-animate.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
const utils = require( '../utils.js' );
44

5+
const methods = [ 'animate', 'stop', 'finish' ];
6+
57
module.exports = {
68
meta: {
79
type: 'suggestion',
810
docs: {
911
description:
10-
'Disallows the ' + utils.jQueryCollectionLink( 'animate' ) +
11-
' method. Use the `allowScroll` option to allow animations which are just used for scrolling. Prefer CSS transitions.'
12+
'Disallows the ' + methods.map( utils.jQueryCollectionLink ).join( '/' ) +
13+
' methods. Use the `allowScroll` option to allow animations which are just used for scrolling. Prefer CSS transitions.'
1214
},
1315
schema: [
1416
{
@@ -27,12 +29,12 @@ module.exports = {
2729
'CallExpression:exit': ( node ) => {
2830
if (
2931
node.callee.type !== 'MemberExpression' ||
30-
node.callee.property.name !== 'animate'
32+
!methods.includes( node.callee.property.name )
3133
) {
3234
return;
3335
}
3436
const allowScroll = context.options[ 0 ] && context.options[ 0 ].allowScroll;
35-
if ( allowScroll ) {
37+
if ( node.callee.property.name === 'animate' && allowScroll ) {
3638
const arg = node.arguments[ 0 ];
3739
// Check properties list has more than just scrollTop/scrollLeft
3840
if ( arg && arg.type === 'ObjectExpression' ) {

src/rules/no-done-fail.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
const utils = require( '../utils.js' );
4+
5+
module.exports = utils.createUniversalMethodRule(
6+
[ 'done', 'fail' ],
7+
( node ) => node === true ?
8+
'Prefer `.then`' :
9+
`Prefer .then to .${ node.callee.property.name }`,
10+
( method ) => `[\`.${ method }\`](https://api.jquery.com/deferred.${ method }/)`
11+
);

src/rules/no-event-shorthand.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ const rule = utils.createCollectionMethodRule(
4444
'mousemove',
4545
'mouseout',
4646
'mouseover',
47-
'mouseup'
48-
].concat( ajaxEvents ),
47+
'mouseup',
48+
...ajaxEvents
49+
],
4950
( node ) => node === true ?
5051
'Use the `allowAjaxEvents` option to allow `ajax*` methods. Prefer `.on` or `.trigger`' :
5152
`Prefer .on or .trigger to .${ node.callee.property.name }`,

src/rules/no-fx.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
const utils = require( '../utils.js' );
4+
5+
module.exports = {
6+
meta: {
7+
type: 'suggestion',
8+
docs: {
9+
description: 'Disallows `$.fx`.'
10+
},
11+
schema: []
12+
},
13+
14+
create: ( context ) => ( {
15+
MemberExpression: ( node ) => {
16+
if (
17+
!utils.isjQueryConstructor( context, node.object.name ) ||
18+
node.property.name !== 'fx'
19+
) {
20+
return;
21+
}
22+
23+
context.report( {
24+
node,
25+
message: '$.fx is not allowed'
26+
} );
27+
}
28+
} )
29+
};

0 commit comments

Comments
 (0)