Ignore the camelcase variable in JSHint

Having a bit of a problem with JShint and the next line of code.

$location.path('map-' + map.id + '/venue-' + map.attributes.default_venue.value); 

I get an error, Identifier 'default_venue' is not in camel case. This will not be a problem normally, but I have no control over the variable name - it was introduced through the JSON API.

Is there a way to suppress this problem for both the affected variables and the lines in which they appear?

Sorry if this was asked before, I'm sure it must have been, but I canโ€™t find a solution.

+63
javascript coding-style jshint code-cleanup
Oct 18 '13 at 11:20
source share
5 answers

JSHint obeys directives at the function level, so you can find the closing function and add the camelcase parameter to it. Here is an example:

 /*jshint camelcase: true */ var not_camel_case = 1; // Warns function example() { /*jshint camelcase: false */ var not_camel_case = 2; // Does not warn } 
+122
Oct 18 '13 at 11:52
source share

According to JSHint Docs, you can create a configuration file in the same directory as .jshintrc , or any directory in the root directory. I just found that I used this:

  { "camelcase": false } 

There are many other options here: http://jshint.com/docs/options/#camelcase

+17
Aug 27 '14 at 8:11
source share

I put the name of the property coming from the api on a separate line. For example:.

 var defaultVenueAttributeKey = 'default_venue'; $location.path('map-' + map.id + '/venue-' + map.attributes[defaultVenueAttributeKey].value); 

This is a bit more verbose, but you can group all the property names coming from your API together and then respond more easily to the API.

+3
Nov 18 '14 at 15:41
source share

The accepted answer /*jshint camelcase: true */ did not work for me. I was still getting errors.

I look at the docs and found this solution that worked for me:

 /*eslint camelcase: ["error", {properties: "never"}]*/ 
0
Jun 18 '17 at 7:26
source share

Try something like this. Although evil, it will work.

 var foo; $.each( jsonArray, function ( i, value ) { if ( i === 'array_element' ) { foo = value; } }); 
-6
Jun 30 '14 at 11:38
source share



All Articles