requireDotNotation

Requires member expressions to use dot notation when possible

Types: Boolean or Object

Values:

  • true
  • "except_snake_case" (deprecated use "allExcept": ["snake_case"]) allow quoted snake cased identifiers
  • Object:
    • 'allExcept' array of exceptions:
      • 'keywords' allow quoted identifiers made of reserved words
      • 'snake_case' allow quoted snake cased identifiers

N.B.: keywords are always allowed with es3 enabled (http://jscs.info/overview.html#es3)

JSHint: sub

Example

"requireDotNotation": true
Valid
var a = b[c];
var a = b.c;
var a = b[c.d];
var a = b[1];
var a = b.while; // reserved words can be property names in ES5
Invalid
var a = b['c'];
var a = b['snake_cased'];
var a = b['_camelCased'];
var a = b['camelCased_'];

Example for allExcept snake_case

"requireDotNotation": { "allExcept": [ "snake_case" ] }
Valid
var a = b[c];
var a = b.c;
var a = b['snake_cased'];
var a = b['camelCased_butWithSnakes'];

Example for allExcept keywords

"requireDotNotation": { "allExcept": [ "keywords" ] }
Valid
var a = b['await']; // reserved word in ES6
var a = b['yield']; // reserved word in ES5
var a = b['let'];
Invalid
var a = b['c'];

Example for "es3": true

"requireDotNotation": true,
"es3": true
Valid
var a = b[c];
var a = b.c;
var a = b[c.d];
var a = b[1];
var a = b['while']; // reserved word in ES3
Invalid
var a = b['c'];
Rule source
Test source