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

Unexpected Weird Ternary warning. #2

Open
microwheels opened this issue Jul 23, 2012 · 2 comments
Open

Unexpected Weird Ternary warning. #2

microwheels opened this issue Jul 23, 2012 · 2 comments

Comments

@microwheels
Copy link

I have the following lines at the end of a javascript function. When I ran JSLint on it I get a 'weird ternary' warning on the last line.

        return node === null
            ? {'node': this.storeContentsNode, 'placement': undefined}
            : {'node': node.domNode, 'placement': 'after'};

If I'm doing something wrong I'd like to know but the warning message isn't particularly helpful.

@JamesSwift
Copy link

After a little investigation it appears this may be a bug with JSLint itself misinterpreting the colon in the object literal. Can't get a straight answer from google though.

@JamesSwift
Copy link

Actually, after looking through the JSLint source, it would appear that its flagging the "weird ternary" error because the two alternate objects you return as so similar:

[https://github.com/douglascrockford/JSLint/blob/256cf8decf04e7dc9012176d81c90b7128fcd30d/jslint.js#L2552]

if (are_similar(that.second, that.third)) {
      colon.warn('weird_ternary');
} else if (are_similar(that.first, that.second)) {
     that.warn('use_or');
}

Just one of the many undocumented strange things that JSLint does. Is this a bug? Not in the traditional sense of the word I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants