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
This change makes consistent with other rule naming format and removes spelling error message from editors
- Loading branch information
1 parent
28bd1dc
commit 672917b
Showing
5 changed files
with
47 additions
and
38 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
2 changes: 1 addition & 1 deletion
2
docs/rules/require-tothrow-message.md → docs/rules/require-to-throw-message.md
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
4 changes: 2 additions & 2 deletions
4
...__tests__/require-tothrow-message.test.js → ..._tests__/require-to-throw-message.test.js
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,36 @@ | ||
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; | ||
} | ||
|
||
const propertyName = method(node) && method(node).name; | ||
|
||
// Look for `toThrow` calls with no arguments. | ||
if ( | ||
['toThrow', 'toThrowError'].includes(propertyName) && | ||
!argument(node) | ||
) { | ||
context.report({ | ||
messageId: 'requireRethrow', | ||
data: { propertyName }, | ||
node: method(node), | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}; |
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,36 +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 merged = Object.assign({}, requireToThrowMessage); | ||
|
||
const propertyName = method(node) && method(node).name; | ||
merged.meta.deprecated = true; | ||
merged.meta.replacedBy = ['require-to-throw-message']; | ||
merged.meta.docs.replacedBy = ['require-to-throw-message']; | ||
|
||
// Look for `toThrow` calls with no arguments. | ||
if ( | ||
['toThrow', 'toThrowError'].includes(propertyName) && | ||
!argument(node) | ||
) { | ||
context.report({ | ||
messageId: 'requireRethrow', | ||
data: { propertyName }, | ||
node: method(node), | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}; | ||
export default merged; |