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
a29f993
commit b2a7f7d
Showing
6 changed files
with
92 additions
and
52 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
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,50 @@ | ||
import { | ||
ModifierName, | ||
createRule, | ||
isExpectCall, | ||
parseExpectCall, | ||
} from './utils'; | ||
|
||
export default createRule({ | ||
name: __filename, | ||
meta: { | ||
docs: { | ||
category: 'Best Practices', | ||
description: 'Require a message for `toThrow()`', | ||
recommended: false, | ||
}, | ||
messages: { | ||
requireRethrow: 'Add an error message to {{ propertyName }}()', | ||
}, | ||
type: 'suggestion', | ||
schema: [], | ||
}, | ||
defaultOptions: [], | ||
create(context) { | ||
return { | ||
CallExpression(node) { | ||
if (!isExpectCall(node)) { | ||
return; | ||
} | ||
|
||
const { matcher, modifier } = parseExpectCall(node); | ||
|
||
if ( | ||
matcher && | ||
matcher.arguments && | ||
matcher.arguments.length === 0 && | ||
['toThrow', 'toThrowError'].includes(matcher.name) && | ||
(!modifier || | ||
!(modifier.name === ModifierName.not || modifier.negation)) | ||
) { | ||
// Look for `toThrow` calls with no arguments. | ||
context.report({ | ||
messageId: 'requireRethrow', // todo: rename to 'addErrorMessage' | ||
data: { propertyName: matcher.name }, // todo: rename to 'matcherName' | ||
node: matcher.node.property, | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}); |
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,50 +1,12 @@ | ||
import { | ||
ModifierName, | ||
createRule, | ||
isExpectCall, | ||
parseExpectCall, | ||
} from './utils'; | ||
import requireToThrowMessage from './require-to-throw-message'; | ||
|
||
export default createRule({ | ||
name: __filename, | ||
meta: { | ||
docs: { | ||
category: 'Best Practices', | ||
description: 'Require a message for `toThrow()`', | ||
recommended: false, | ||
}, | ||
messages: { | ||
requireRethrow: 'Add an error message to {{ propertyName }}()', | ||
}, | ||
type: 'suggestion', | ||
schema: [], | ||
}, | ||
defaultOptions: [], | ||
create(context) { | ||
return { | ||
CallExpression(node) { | ||
if (!isExpectCall(node)) { | ||
return; | ||
} | ||
// remove this file in major version bump | ||
|
||
const { matcher, modifier } = parseExpectCall(node); | ||
|
||
if ( | ||
matcher && | ||
matcher.arguments && | ||
matcher.arguments.length === 0 && | ||
['toThrow', 'toThrowError'].includes(matcher.name) && | ||
(!modifier || | ||
!(modifier.name === ModifierName.not || modifier.negation)) | ||
) { | ||
// Look for `toThrow` calls with no arguments. | ||
context.report({ | ||
messageId: 'requireRethrow', // todo: rename to 'addErrorMessage' | ||
data: { propertyName: matcher.name }, // todo: rename to 'matcherName' | ||
node: matcher.node.property, | ||
}); | ||
} | ||
}, | ||
}; | ||
export default { | ||
...requireToThrowMessage, | ||
meta: { | ||
...requireToThrowMessage.meta, | ||
deprecated: true, | ||
replacedBy: ['require-to-throw-message'], | ||
}, | ||
}); | ||
}; |