Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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

like image 547
TomFuertes Avatar asked Nov 02 '12 09:11

TomFuertes


People also ask

Is better to write in dot notation?

However, the dot notation is often preferred because it is easier to read, less verbose, and works better with aggressive JavaScript minimizers.

How do you use dot notation?

Dot notation is one way to access a property of an object. To use dot notation, write the name of the object, followed by a dot (.), followed by the name of the property. Example: var cat = { name: 'Moo', age: 5, }; console.


2 Answers

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 */ 
like image 41
SavoryBytes Avatar answered Oct 16 '22 03:10

SavoryBytes


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

like image 150
TomFuertes Avatar answered Oct 16 '22 01:10

TomFuertes