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

Update: requireStringLiterals option for valid-typeof (fixes #6698) #6923

Merged
merged 1 commit into from Aug 21, 2016

Conversation

not-an-aardvark
Copy link
Member

What issue does this pull request address?
#6698

What changes did you make? (Give an overview)

This PR adds a requireStringLiterals option to valid-typeof, to enforce comparisons to string literals.

Is there anything you'd like reviewers to focus on? Not really

I noticed that #6698 hasn't been marked as "accepted" yet, but it seemed like there was enough support that it was worth making this PR. I realize that I'll probably have to wait for that issue to get accepted before this PR gets merged, though.

@mention-bot
Copy link

@not-an-aardvark, thanks for your PR! By analyzing the annotation information on this pull request, we identified @vitorbal, @pmcelhaney and @iancmyers to be potential reviewers

@eslintbot
Copy link

LGTM

```js
typeof foo === "undefined"
typeof bar == "object"
typeof baz === "string"
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if we want to mention something like typeof thing = "foo"? To clarify that we're not checking if it's a valid string literal.

Copy link
Member

Choose a reason for hiding this comment

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

Never mind, I guess we are checking that. In that case I would love the docs to mention this and the example I proposed should be listed in incorrect code.

Copy link
Contributor

Choose a reason for hiding this comment

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

There's typeof baz === "strnig", which certainly signifies the intent (to catch typos), but it's easy to overlook. I'm +1 for adding typeof baz = "foo" or typeof baz = "someInvalidType"as another example.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a couple more "invalid" examples.

@eslintbot
Copy link

LGTM

@pmcelhaney
Copy link
Contributor

Left some comments on a previous commit. I'm not sure why they're not showing up in the conversation view.

a01a003#commitcomment-18670186

@not-an-aardvark
Copy link
Member Author

@pmcelhaney I think it's because you left the comments on the commit itself rather than this PR.

@eslintbot
Copy link

LGTM

context.report(sibling, "Invalid typeof comparison value.");
}
} else if (context.options[0] && context.options[0].requireStringLiterals) {
context.report(sibling, "Invalid typeof comparison to a non-string literal.");
Copy link
Member

Choose a reason for hiding this comment

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

To avoid the double negative, what about saying "Typeof comparisons should be to string literals."? (I'm not thrilled with the wording of that either, so I'd be open to better phrasings.)

Copy link
Member Author

Choose a reason for hiding this comment

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

I couldn't think of anything better, so I went with "Typeof comparisons should be to string literals."

@btmills
Copy link
Member

btmills commented Aug 19, 2016

Nice work on this, @not-an-aardvark! I'd like to tweak the message a bit to avoid a double negative, but everything else looks good!

@eslintbot
Copy link

LGTM

@btmills
Copy link
Member

btmills commented Aug 19, 2016

LGTM, leaving open for another day since the issue wasn't accepted until yesterday.

@platinumazure
Copy link
Member

LGTM as well.

@btmills
Copy link
Member

btmills commented Aug 21, 2016

Thanks @not-an-aardvark!

@btmills btmills merged commit cf2242c into eslint:master Aug 21, 2016
@not-an-aardvark not-an-aardvark deleted the issue6698 branch August 27, 2016 03:51
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants