-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(require-tothrow-message): rename rule to require-to-throw-message
- Loading branch information
1 parent
3ee3874
commit e48fade
Showing
5 changed files
with
51 additions
and
42 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
File renamed without changes.
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 @@ | ||
import { argument, expectCase, getDocsUrl, method } from './util'; | ||
|
||
export default { | ||
meta: { | ||
docs: { | ||
url: getDocsUrl(__filename), | ||
}, | ||
messages: { | ||
requireRethrow: 'Add an error message to {{ propertyName }}()', | ||
}, | ||
schema: [], | ||
}, | ||
create(context) { | ||
return { | ||
CallExpression(node) { | ||
if (!expectCase(node)) { | ||
return; | ||
} | ||
|
||
let targetNode = method(node); | ||
if (targetNode.name === 'rejects') { | ||
targetNode = method(node.parent); | ||
} | ||
|
||
const propertyName = method(targetNode) && method(targetNode).name; | ||
|
||
// Look for `toThrow` calls with no arguments. | ||
if ( | ||
['toThrow', 'toThrowError'].includes(propertyName) && | ||
!argument(targetNode) | ||
) { | ||
context.report({ | ||
messageId: 'requireRethrow', | ||
data: { propertyName }, | ||
node: targetNode, | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}; |
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,41 +1,9 @@ | ||
import { argument, expectCase, getDocsUrl, method } from './util'; | ||
import requireToThrowMessage from './require-to-throw-message'; | ||
|
||
export default { | ||
meta: { | ||
docs: { | ||
url: getDocsUrl(__filename), | ||
}, | ||
messages: { | ||
requireRethrow: 'Add an error message to {{ propertyName }}()', | ||
}, | ||
schema: [], | ||
}, | ||
create(context) { | ||
return { | ||
CallExpression(node) { | ||
if (!expectCase(node)) { | ||
return; | ||
} | ||
const requireTothrowMessage = Object.assign({}, requireToThrowMessage); | ||
|
||
let targetNode = method(node); | ||
if (targetNode.name === 'rejects') { | ||
targetNode = method(node.parent); | ||
} | ||
requireTothrowMessage.meta.deprecated = true; | ||
requireTothrowMessage.meta.replacedBy = ['require-to-throw-message']; | ||
requireTothrowMessage.meta.docs.replacedBy = ['require-to-throw-message']; | ||
|
||
const propertyName = method(targetNode) && method(targetNode).name; | ||
|
||
// Look for `toThrow` calls with no arguments. | ||
if ( | ||
['toThrow', 'toThrowError'].includes(propertyName) && | ||
!argument(targetNode) | ||
) { | ||
context.report({ | ||
messageId: 'requireRethrow', | ||
data: { propertyName }, | ||
node: targetNode, | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}; | ||
export default requireTothrowMessage; |