Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(require-tothrow-message): rename rule to require-to-throw-message #306

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -145,7 +145,7 @@ installations requiring long-term consistency.
| [prefer-to-have-length][] | Suggest using `toHaveLength()` | ![style][] | ![fixable-green][] |
| [prefer-todo][] | Suggest using `test.todo()` | | ![fixable-green][] |
| [require-top-level-describe][] | Require a top-level `describe` block | | |
| [require-tothrow-message][] | Require that `toThrow()` and `toThrowError` includes a message | | |
| [require-to-throw-message][] | Require that `toThrow()` and `toThrowError` includes a message | | |
| [valid-describe][] | Enforce valid `describe()` callback | ![recommended][] | |
| [valid-expect-in-promise][] | Enforce having return statement when testing with promises | ![recommended][] | |
| [valid-expect][] | Enforce valid `expect()` usage | ![recommended][] | |
Expand Down Expand Up @@ -200,7 +200,7 @@ https://github.com/dangreenisrael/eslint-plugin-jest-formatting
[prefer-to-have-length]: docs/rules/prefer-to-have-length.md
[prefer-todo]: docs/rules/prefer-todo.md
[require-top-level-describe]: docs/rules/require-top-level-describe.md
[require-tothrow-message]: docs/rules/require-tothrow-message.md
SimenB marked this conversation as resolved.
Show resolved Hide resolved
[require-to-throw-message]: docs/rules/require-to-throw-message.md
[valid-describe]: docs/rules/valid-describe.md
[valid-expect-in-promise]: docs/rules/valid-expect-in-promise.md
[valid-expect]: docs/rules/valid-expect.md
Expand Down
@@ -1,6 +1,6 @@
import { TSESLint } from '@typescript-eslint/experimental-utils';
import resolveFrom from 'resolve-from';
import rule from '../require-tothrow-message';
import rule from '../require-to-throw-message';

const ruleTester = new TSESLint.RuleTester({
parser: resolveFrom(require.resolve('eslint'), 'espree'),
Expand All @@ -9,7 +9,7 @@ const ruleTester = new TSESLint.RuleTester({
},
});

ruleTester.run('require-tothrow-message', rule, {
ruleTester.run('require-to-throw-message', rule, {
valid: [
// String
"expect(() => { throw new Error('a'); }).toThrow('a');",
Expand Down Expand Up @@ -68,8 +68,8 @@ ruleTester.run('require-tothrow-message', rule, {
code: "expect(() => { throw new Error('a'); }).toThrow();",
errors: [
{
messageId: 'requireRethrow',
data: { propertyName: 'toThrow' },
messageId: 'addErrorMessage',
data: { matcherName: 'toThrow' },
column: 41,
line: 1,
},
Expand All @@ -80,8 +80,8 @@ ruleTester.run('require-tothrow-message', rule, {
code: "expect(() => { throw new Error('a'); }).toThrowError();",
errors: [
{
messageId: 'requireRethrow',
data: { propertyName: 'toThrowError' },
messageId: 'addErrorMessage',
data: { matcherName: 'toThrowError' },
column: 41,
line: 1,
},
Expand All @@ -97,14 +97,14 @@ ruleTester.run('require-tothrow-message', rule, {
})`,
errors: [
{
messageId: 'requireRethrow',
data: { propertyName: 'toThrow' },
messageId: 'addErrorMessage',
data: { matcherName: 'toThrow' },
column: 49,
line: 3,
},
{
messageId: 'requireRethrow',
data: { propertyName: 'toThrowError' },
messageId: 'addErrorMessage',
data: { matcherName: 'toThrowError' },
column: 49,
line: 4,
},
Expand Down
Expand Up @@ -14,7 +14,7 @@ export default createRule({
recommended: false,
},
messages: {
requireRethrow: 'Add an error message to {{ propertyName }}()',
addErrorMessage: 'Add an error message to {{ propertyName }}()',
},
type: 'suggestion',
schema: [],
Expand All @@ -39,8 +39,8 @@ export default createRule({
) {
// Look for `toThrow` calls with no arguments.
context.report({
messageId: 'requireRethrow', // todo: rename to 'addErrorMessage'
data: { propertyName: matcher.name }, // todo: rename to 'matcherName'
messageId: 'addErrorMessage',
data: { matcherName: matcher.name },
node: matcher.node.property,
});
}
Expand Down