-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from tlvince/remcohaszing-no-assign-spyon
feat(no-assign-spyon): add no-assign-spyon rule
- Loading branch information
Showing
6 changed files
with
81 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
let $PATH = './node_modules/.bin:' . $PATH | ||
let g:syntastic_javascript_checkers = ['eslint'] | ||
let g:neomake_javascript_enabled_makers = ['standard'] |
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,20 @@ | ||
# Disallow the assignment of a `spyOn` return value | ||
|
||
It is often more obvious to pass the spy as a property of the object spied upon | ||
instead of from a referencing variable. | ||
|
||
The following are considered warnings: | ||
|
||
```js | ||
var someSpy = spyOn(someObj, 'someMethod'); | ||
// Handle someSpy, for example | ||
// expect(someSpy).toHaveBeenCalled(); | ||
``` | ||
|
||
The following are not warnings: | ||
|
||
```js | ||
spyOn(someObj, 'someMethod'); | ||
// Handle someObj.someMethod, for example | ||
// expect(someObj.someMethod).toHaveBeenCalled(); | ||
``` |
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,16 @@ | ||
'use strict' | ||
|
||
/** | ||
* @fileoverview Disallow the assignment of a spyOn call result. | ||
* @author Remco Haszing | ||
*/ | ||
|
||
module.exports = function (context) { | ||
return { | ||
CallExpression: function (node) { | ||
if (node.callee.name === 'spyOn' && (node.parent.type === 'AssignmentExpression' || node.parent.type === 'VariableDeclarator')) { | ||
context.report(node, 'The result of spyOn() should not be assigned') | ||
} | ||
} | ||
} | ||
} |
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,31 @@ | ||
'use strict' | ||
|
||
var rule = require('../../lib/rules/no-assign-spyon') | ||
var RuleTester = require('eslint').RuleTester | ||
|
||
var eslintTester = new RuleTester() | ||
|
||
eslintTester.run('no-assign-spyon', rule, { | ||
valid: [ | ||
'var result = someFunc()', | ||
'result = someFunc()' | ||
], | ||
invalid: [ | ||
{ | ||
code: 'var spy = spyOn(object, "property");', | ||
errors: [ | ||
{ | ||
message: 'The result of spyOn() should not be assigned' | ||
} | ||
] | ||
}, | ||
{ | ||
code: 'spy = spyOn(object, "property");', | ||
errors: [ | ||
{ | ||
message: 'The result of spyOn() should not be assigned' | ||
} | ||
] | ||
} | ||
] | ||
}) |