
rules.jshint.W110.html Maven / Gradle / Ivy
Show all versions of sonar-web-frontend-js Show documentation
When do I get this error?
The "Mixed double and single quotes" error is thrown when JSHint encounters
string literal delimited by double or single quote characters when a string
literal delimited by the other has already been found. It will only raise this
warning if the quotmark
option is set to true
. In the following example we
attempt to assign string literals to the variables x
and y
:
x 1/*jshint quotmark: true */
2var x = "My String",
3 y = 'Another string';
4
Why do I get this error?
This error is raised to highlight a lack of consistency. Your code will run
fine if you do not fix this error, but it demonstrates a lack of care. There is
no difference in JavaScript between single and double quotes. This is made clear
by the grammar for string literals (ES5 §7.8.4):
StringLiteral ::
"
DoubleStringCharactersopt "
'
SingleStringCharactersopt '
The only difference is that DoubleStringCharacters cannot contain another
double quote, and SingleStringCharacters cannot contain a single quote (as
that would terminate the string literal). However, it would usually be frowned
upon to mix both types of quote within one program (there are obvious
exceptions, such as nested quotes). You can easily resolve this issue by
sticking to one type, and you should consider setting the quotmark
option to
either double
or single
to enforce your preference:
4 1/*jshint quotmark: double */
2var x = "My String",
3 y = "Another string";
4
In JSHint 1.0.0 and above you have the ability to ignore any warning with a
special option syntax. The identifier of this warning is W110.
This means you can tell JSHint to not issue this warning with the /*jshint
-W110 */
directive. You can also set the quotmark
option to false
.