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

methodName: ensure method(node) returns truthy before trying to use return #358

Merged
merged 4 commits into from Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions src/rules/__tests__/prefer-to-be-null.test.js
Expand Up @@ -17,6 +17,7 @@ ruleTester.run('prefer-to-be-null', rule, {
'expect("a string").not.toMatchSnapshot();',
"expect(something).toEqual('a string');",
'expect(null).toBe',
'expect("something");',
],

invalid: [
Expand Down
1 change: 1 addition & 0 deletions src/rules/__tests__/prefer-to-be-undefined.test.js
Expand Up @@ -14,6 +14,7 @@ ruleTester.run('prefer-to-be-undefined', rule, {
'expect(something).not.toBe(somethingElse)',
'expect(something).not.toEqual(somethingElse)',
'expect(undefined).toBe',
'expect("something");',
],

invalid: [
Expand Down
2 changes: 1 addition & 1 deletion src/rules/util.js
Expand Up @@ -87,7 +87,7 @@ export const method = node => node.parent.property;

export const method2 = node => node.parent.parent.property;

const methodName = node => method(node).name;
const methodName = node => method(node) && method(node).name;

const methodName2 = node => method2(node).name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here? expect(something).not; or something like that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could do - I don't think it's needed per say b/c all the rules that use it check using method first, but I'll add it in anyway :)


Expand Down