-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
93 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const ASSERT_DOM_SELECTOR = | ||
'CallExpression' + | ||
'[callee.type="MemberExpression"]' + | ||
'[callee.object.type="Identifier"]' + | ||
'[callee.object.name="assert"]' + | ||
'[callee.property.type="Identifier"]' + | ||
'[callee.property.name="dom"]'; | ||
|
||
module.exports = { | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
description: 'require at least one assertion on `assert.dom()`', | ||
recommended: true, | ||
url: 'https://github.com/Mainmatter/eslint-plugin-qunit-dom/blob/main/rules/require-assertion.md', | ||
}, | ||
fixable: 'code', | ||
schema: [], | ||
messages: { | ||
default: 'use at least one assertion on assert.dom(...)', | ||
}, | ||
}, | ||
|
||
create(context) { | ||
return { | ||
[ASSERT_DOM_SELECTOR](node) { | ||
if (node.parent.type === 'ExpressionStatement') { | ||
context.report({ | ||
node: node, | ||
messageId: 'default', | ||
fix(fixer) { | ||
return fixer.insertTextAfter(node, '.exists()'); | ||
}, | ||
}); | ||
} else { | ||
return; | ||
} | ||
}, | ||
}; | ||
}, | ||
}; |
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,23 @@ | ||
# require-assertion | ||
|
||
💼 This rule is enabled in the ✅ `recommended` config. | ||
|
||
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). | ||
|
||
<!-- end auto-generated rule header --> | ||
|
||
At least one assertion should be made after calling `assert.dom()`. | ||
|
||
## Examples | ||
|
||
This rule **forbids** the following: | ||
|
||
```js | ||
assert.dom('.foo'); | ||
``` | ||
|
||
This rule **allows** the following: | ||
|
||
```js | ||
assert.dom('.foo').exists(); | ||
``` |
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,27 @@ | ||
const { RuleTester } = require('eslint'); | ||
|
||
const rule = require('./require-assertion'); | ||
|
||
let ruleTester = new RuleTester({ | ||
parserOptions: { | ||
ecmaVersion: 2018, | ||
sourceType: 'module', | ||
}, | ||
}); | ||
|
||
ruleTester.run('require-assertion', rule, { | ||
valid: ['assert.dom().exists()', 'assert.dom(node).exists()'], | ||
|
||
invalid: [ | ||
{ | ||
code: 'assert.dom()', | ||
output: 'assert.dom().exists()', | ||
errors: [{ messageId: 'default' }], | ||
}, | ||
{ | ||
code: 'assert.dom(node)', | ||
output: 'assert.dom(node).exists()', | ||
errors: [{ messageId: 'default' }], | ||
}, | ||
], | ||
}); |