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] Compilation error when method name is string instead of identifier #2514

Merged
merged 1 commit into from Dec 9, 2019
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
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