-
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.
Introduce
no-visibility
, deprecate no-show
, no-hide
, no-toggle
(
#166) * Introduce `no-visibility`, deprecate `no-show`, `no-hide`, `no-toggle` See #163 * Update test-all/methods.js
- Loading branch information
1 parent
102bbd0
commit 8ee107e
Showing
13 changed files
with
170 additions
and
9 deletions.
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
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,40 @@ | ||
# no-visibility | ||
|
||
Disallows the .show/hide/toggle methods. | ||
|
||
## Rule details | ||
|
||
❌ The following patterns are considered errors: | ||
```js | ||
$( 'div' ).show(); | ||
$div.show(); | ||
$( 'div' ).first().show(); | ||
$( 'div' ).append( $( 'input' ).show() ); | ||
$( 'div' ).hide(); | ||
$div.hide(); | ||
$( 'div' ).first().hide(); | ||
$( 'div' ).append( $( 'input' ).hide() ); | ||
$( 'div' ).toggle(); | ||
$div.toggle(); | ||
$( 'div' ).first().toggle(); | ||
$( 'div' ).append( $( 'input' ).toggle() ); | ||
``` | ||
|
||
✔️ The following patterns are not considered errors: | ||
```js | ||
show(); | ||
[].show(); | ||
div.show(); | ||
div.show; | ||
hide(); | ||
[].hide(); | ||
div.hide(); | ||
div.hide; | ||
toggle(); | ||
[].toggle(); | ||
div.toggle(); | ||
div.toggle; | ||
``` | ||
## Rule source | ||
|
||
* [rules/no-visibility.js](../rules/no-visibility.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
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
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,8 @@ | ||
'use strict'; | ||
|
||
const utils = require( './utils.js' ); | ||
|
||
module.exports = utils.createCollectionMethodRule( | ||
[ 'show', 'hide', 'toggle' ], | ||
( node ) => `$.${node.callee.property.name} is not allowed` | ||
); |
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,78 @@ | ||
'use strict'; | ||
|
||
const rule = require( '../rules/no-visibility' ); | ||
const RuleTesterAndDocs = require( '../rule-tester-and-docs' ); | ||
|
||
const errorShow = '$.show is not allowed'; | ||
const errorHide = '$.hide is not allowed'; | ||
const errorToggle = '$.toggle is not allowed'; | ||
|
||
const ruleTester = new RuleTesterAndDocs(); | ||
ruleTester.run( 'no-visibility', rule, { | ||
valid: [ | ||
'show()', | ||
'[].show()', | ||
'div.show()', | ||
'div.show', | ||
|
||
'hide()', | ||
'[].hide()', | ||
'div.hide()', | ||
'div.hide', | ||
|
||
'toggle()', | ||
'[].toggle()', | ||
'div.toggle()', | ||
'div.toggle' | ||
], | ||
invalid: [ | ||
{ | ||
code: '$("div").show()', | ||
errors: [ { message: errorShow, type: 'CallExpression' } ] | ||
}, | ||
{ | ||
code: '$div.show()', | ||
errors: [ { message: errorShow, type: 'CallExpression' } ] | ||
}, | ||
{ | ||
code: '$("div").first().show()', | ||
errors: [ { message: errorShow, type: 'CallExpression' } ] | ||
}, | ||
{ | ||
code: '$("div").append($("input").show())', | ||
errors: [ { message: errorShow, type: 'CallExpression' } ] | ||
}, | ||
{ | ||
code: '$("div").hide()', | ||
errors: [ { message: errorHide, type: 'CallExpression' } ] | ||
}, | ||
{ | ||
code: '$div.hide()', | ||
errors: [ { message: errorHide, type: 'CallExpression' } ] | ||
}, | ||
{ | ||
code: '$("div").first().hide()', | ||
errors: [ { message: errorHide, type: 'CallExpression' } ] | ||
}, | ||
{ | ||
code: '$("div").append($("input").hide())', | ||
errors: [ { message: errorHide, type: 'CallExpression' } ] | ||
}, | ||
{ | ||
code: '$("div").toggle()', | ||
errors: [ { message: errorToggle, type: 'CallExpression' } ] | ||
}, | ||
{ | ||
code: '$div.toggle()', | ||
errors: [ { message: errorToggle, type: 'CallExpression' } ] | ||
}, | ||
{ | ||
code: '$("div").first().toggle()', | ||
errors: [ { message: errorToggle, type: 'CallExpression' } ] | ||
}, | ||
{ | ||
code: '$("div").append($("input").toggle())', | ||
errors: [ { message: errorToggle, type: 'CallExpression' } ] | ||
} | ||
] | ||
} ); |