Require Camelcase (camelcase)

When it comes to naming variables, styleguides generally fall into one of two camps: camelcase (variableName) and underscores (variable_name). This rule focuses on using the camelcase approach. If your styleguide calls for camelcasing your variable names, then this rule is for you!

Rule Details

This rule looks for any underscores (_) located within the source code. It ignores leading and trailing underscores and only checks those in the middle of a variable name. If ESLint decides that the variable is a constant (all uppercase), then no warning will be thrown. Otherwise, a warning will be thrown. This rule only flags definitions and assignments but not function calls.

Options

This rule accepts a single options argument with the following defaults:

{"rules":{"camelcase":[2,{"properties":"always"}]}}

Properties can have the following values:

always is the default and checks all property names

never does not check property names at all

The following patterns are considered problems:

/*eslint camelcase: 2*/varmy_favorite_color="#112C85";/*error Identifier 'my_favorite_color' is not in camel case.*/functiondo_something(){/*error Identifier 'do_something' is not in camel case.*/// ...}obj.do_something=function(){/*error Identifier 'do_something' is not in camel case.*/// ...};varobj={my_pref:1/*error Identifier 'my_pref' is not in camel case.*/};