Skip to content

Commit 387002b

Browse files
authored
New rule: no-fx (#340)
In slim mode, $.fx is completely missing, so create a rule for this (more generic that no-fx-interval, which exists as that property is deprecated).
1 parent 5fc1937 commit 387002b

File tree

5 files changed

+95
-0
lines changed

5 files changed

+95
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ Where rules are included in the configs `recommended`, `slim`, `all` or `depreca
121121
* [`no-jquery/no-find`](docs/rules/no-find.md)
122122
* [`no-jquery/no-find-collection`](docs/rules/no-find-collection.md) `all`
123123
* [`no-jquery/no-find-util`](docs/rules/no-find-util.md) `all`
124+
* [`no-jquery/no-fx`](docs/rules/no-fx.md) `slim`
124125
* [`no-jquery/no-fx-interval`](docs/rules/no-fx-interval.md) `3.0`
125126
* [`no-jquery/no-global-eval`](docs/rules/no-global-eval.md) `all`
126127
* [`no-jquery/no-global-selector`](docs/rules/no-global-selector.md) ⚙️

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ module.exports = {
3939
'no-find': require( './rules/no-find' ),
4040
'no-find-collection': require( './rules/no-find-collection' ),
4141
'no-find-util': require( './rules/no-find-util' ),
42+
'no-fx': require( './rules/no-fx' ),
4243
'no-fx-interval': require( './rules/no-fx-interval' ),
4344
'no-global-eval': require( './rules/no-global-eval' ),
4445
'no-global-selector': require( './rules/no-global-selector' ),
@@ -118,6 +119,7 @@ module.exports = {
118119
'no-jquery/no-animate-toggle': 'error',
119120
'no-jquery/no-fade': 'error',
120121
'no-jquery/no-slide': 'error',
122+
'no-jquery/no-fx': 'error',
121123
// Ajax
122124
'no-jquery/no-ajax': 'error',
123125
'no-jquery/no-ajax-events': 'error',

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+
};

tests/rules/no-fx.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
const rule = require( '../../src/rules/no-fx' );
4+
const RuleTester = require( '../../tools/rule-tester' );
5+
6+
const error = '$.fx is not allowed';
7+
8+
const ruleTester = new RuleTester();
9+
ruleTester.run( 'no-fx', rule, {
10+
valid: [ 'fx', 'fx.interval', 'a.fx' ],
11+
invalid: [
12+
{
13+
code: '$.fx',
14+
errors: [ error ]
15+
},
16+
{
17+
code: '$.fx.interval',
18+
errors: [ error ]
19+
},
20+
{
21+
code: '$.fx.off',
22+
errors: [ error ]
23+
},
24+
{
25+
code: '$.fx.speeds.slow',
26+
errors: [ error ]
27+
},
28+
{
29+
code: '$.fx.start()',
30+
errors: [ error ]
31+
}
32+
]
33+
} );

0 commit comments

Comments
 (0)