Skip to content

Commit

Permalink
[Fix] no-typos: Compilation error when method name is string instea…
Browse files Browse the repository at this point in the history
…d of identifier
  • Loading branch information
李凤宝 authored and ljharb committed Dec 5, 2019
1 parent d52002a commit 4fedc5f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/rules/no-typos.js
Expand Up @@ -144,7 +144,11 @@ module.exports = {

function reportErrorIfLifecycleMethodCasingTypo(node) {
LIFECYCLE_METHODS.forEach((method) => {
if (method.toLowerCase() === node.key.name.toLowerCase() && method !== node.key.name) {
let nodeKeyName = node.key.name;
if (node.key.type === 'Literal') {
nodeKeyName = node.key.value;
}
if (method.toLowerCase() === nodeKeyName.toLowerCase() && method !== nodeKeyName) {
context.report({
node,
message: 'Typo in component lifecycle method declaration'
Expand Down
8 changes: 8 additions & 0 deletions tests/lib/rules/no-typos.js
Expand Up @@ -203,6 +203,14 @@ ruleTester.run('no-typos', rule, {
}
`,
parserOptions
}, {
code: `
class Hello extends React.Component {
"componentDidMount"() { }
"my-method"() { }
}
`,
parserOptions
}, {
code: `
class MyClass {
Expand Down

0 comments on commit 4fedc5f

Please sign in to comment.