Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New rule: no-fx #340

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ Where rules are included in the configs `recommended`, `slim`, `all` or `depreca
* [`no-jquery/no-find`](docs/rules/no-find.md)
* [`no-jquery/no-find-collection`](docs/rules/no-find-collection.md) `all`
* [`no-jquery/no-find-util`](docs/rules/no-find-util.md) `all`
* [`no-jquery/no-fx`](docs/rules/no-fx.md) `slim`
* [`no-jquery/no-fx-interval`](docs/rules/no-fx-interval.md) `3.0`
* [`no-jquery/no-global-eval`](docs/rules/no-global-eval.md) `all`
* [`no-jquery/no-global-selector`](docs/rules/no-global-selector.md) ⚙️
Expand Down
30 changes: 30 additions & 0 deletions docs/rules/no-fx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[//]: # (This file is generated by eslint-docgen. Do not edit it directly.)

# no-fx

Disallows `$.fx`.

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

## Rule details

❌ Examples of **incorrect** code:
```js
$.fx;
$.fx.interval;
$.fx.off;
$.fx.speeds.slow;
$.fx.start();
```

✔️ Examples of **correct** code:
```js
fx;
fx.interval;
a.fx;
```

## Resources

* [Rule source](/src/rules/no-fx.js)
* [Test source](/tests/rules/no-fx.js)
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module.exports = {
'no-find': require( './rules/no-find' ),
'no-find-collection': require( './rules/no-find-collection' ),
'no-find-util': require( './rules/no-find-util' ),
'no-fx': require( './rules/no-fx' ),
'no-fx-interval': require( './rules/no-fx-interval' ),
'no-global-eval': require( './rules/no-global-eval' ),
'no-global-selector': require( './rules/no-global-selector' ),
Expand Down Expand Up @@ -118,6 +119,7 @@ module.exports = {
'no-jquery/no-animate-toggle': 'error',
'no-jquery/no-fade': 'error',
'no-jquery/no-slide': 'error',
'no-jquery/no-fx': 'error',
// Ajax
'no-jquery/no-ajax': 'error',
'no-jquery/no-ajax-events': 'error',
Expand Down
29 changes: 29 additions & 0 deletions src/rules/no-fx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

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

module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'Disallows `$.fx`.'
},
schema: []
},

create: ( context ) => ( {
MemberExpression: ( node ) => {
if (
!utils.isjQueryConstructor( context, node.object.name ) ||
node.property.name !== 'fx'
) {
return;
}

context.report( {
node,
message: '$.fx is not allowed'
} );
}
} )
};
33 changes: 33 additions & 0 deletions tests/rules/no-fx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

const rule = require( '../../src/rules/no-fx' );
const RuleTester = require( '../../tools/rule-tester' );

const error = '$.fx is not allowed';

const ruleTester = new RuleTester();
ruleTester.run( 'no-fx', rule, {
valid: [ 'fx', 'fx.interval', 'a.fx' ],
invalid: [
{
code: '$.fx',
errors: [ error ]
},
{
code: '$.fx.interval',
errors: [ error ]
},
{
code: '$.fx.off',
errors: [ error ]
},
{
code: '$.fx.speeds.slow',
errors: [ error ]
},
{
code: '$.fx.start()',
errors: [ error ]
}
]
} );
Loading