Skip to content

Commit

Permalink
Introduce no-error rule
Browse files Browse the repository at this point in the history
See #112
  • Loading branch information
edg2s committed Sep 30, 2019
1 parent 188b910 commit d82d39f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docs/no-contains.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ $.contains();
✓ The following patterns are not considered errors:
```js
contains();
div.contains();
div.contains;
myClass.contains();
$div.contains();
```
17 changes: 17 additions & 0 deletions docs/no-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# no-error

Disallows the $.error utility. Prefer throw to $.error.

## Rule details

✗ The following patterns are considered errors:
```js
$.error();
```

✓ The following patterns are not considered errors:
```js
nodeName();
myClass.nodeName();
$div.nodeName();
```
8 changes: 8 additions & 0 deletions rules/no-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

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

module.exports = utils.createUtilMethodRule(
'error',
'Prefer throw to $.error'
);
6 changes: 1 addition & 5 deletions tests/no-contains.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ const error = 'Prefer Node#contains to $.contains';

const ruleTester = new RuleTesterAndDocs();
ruleTester.run( 'no-contains', rule, {
valid: [
'contains()',
'div.contains()',
'div.contains'
],
valid: [ 'contains()', 'myClass.contains()', '$div.contains()' ],
invalid: [
{
code: '$.contains()',
Expand Down
17 changes: 17 additions & 0 deletions tests/no-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

const rule = require( '../rules/no-error' );
const RuleTesterAndDocs = require( '../rule-tester-and-docs' );

const error = 'Prefer throw to $.error';

const ruleTester = new RuleTesterAndDocs();
ruleTester.run( 'no-error', rule, {
valid: [ 'nodeName()', 'myClass.nodeName()', '$div.nodeName()' ],
invalid: [
{
code: '$.error()',
errors: [ { message: error, type: 'CallExpression' } ]
}
]
} );

0 comments on commit d82d39f

Please sign in to comment.