How to suppress "{variable} is better written in dot notation."

JavascriptSyntaxPropertiesJshint

Javascript Problem Overview


Is there an option to and/or how do I suppress errors like the following?

>175,14:['tracker'] is better written in dot notation.

Javascript Solutions


Solution 1 - Javascript

If it's a feature and not a bug, place this at the top of your file.

/*jshint sub:true*/

If it's a bug, you should refactor your code

foo['tracker'] = bar // from this...
foo.tracker = bar;   // to this!

Good post on the reasons here: https://stackoverflow.com/a/2001410/94668

As suggested by: @ThorSummoner you can use below in your .jshintrc file

"sub": true

Solution 2 - Javascript

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 W069.

This means you can tell JSHint to not issue this warning with the /*jshint -W069 */ directive.

You can even wrap several lines of code and then reenable the warning as the example below (with a note to future you why it was a good idea):

/*jshint -W069 */
/*Disable Warning Justification:
    Using bracket notation so Google Closure Compiler 
    ADVANCED_OPTIMIZATIONS will keep the original property names. */
obj['prop1'] ='foo';
obj['prop2'] ='bar';
/*jshint +W069 */

Solution 3 - Javascript

I assume you are asking about Dreamweaver or another editor.

Dreamweaver

You may go to Edit -> Preferences -> Linting

Select JS in the dropdown and hit Edit & Apply changes

Find

 "sub": false,

and change that to true. Save the file and that notice will disappear.

If you have OTHER Linting things you wish to edit, you can find a helpful list of them all at https://jshint.com/docs/options/

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTomFuertesView Question on Stackoverflow
Solution 1 - JavascriptTomFuertesView Answer on Stackoverflow
Solution 2 - JavascriptSavoryBytesView Answer on Stackoverflow
Solution 3 - JavascriptCaseView Answer on Stackoverflow