Showing 41 of 41 total issues
Function addRequest
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
RequestApi.prototype.addRequest = function (originalOptions, callback) {
var options;
LOG.debug('RequestApi#addRequest called');
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function auth
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
CommunicationApi.prototype.auth = function (originalOptions, callback) {
var options;
LOG.debug('CommunicationApi#auth called');
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
A function with a name starting with an uppercase letter should only be used as a constructor. Open
callback(communicationErrors.NoToken());
- Read upRead up
- Exclude checks
require constructor names to begin with a capital letter (new-cap)
The new
operator in JavaScript creates a new instance of a particular type of object. That type of object is represented by a constructor function. Since constructor functions are just regular functions, the only defining characteristic is that new
is being used as part of the call. Native JavaScript functions begin with an uppercase letter to distinguish those functions that are to be used as constructors from functions that are not. Many style guides recommend following this pattern to more easily determine which functions are to be used as constructors.
var friend = new Person();
Rule Details
This rule requires constructor names to begin with a capital letter. Certain built-in identifiers are exempt from this rule. These identifiers are:
Array
Boolean
Date
Error
Function
Number
Object
RegExp
String
Symbol
Examples of correct code for this rule:
/*eslint new-cap: "error"*/
function foo(arg) {
return Boolean(arg);
}
Options
This rule has an object option:
-
"newIsCap": true
(default) requires allnew
operators to be called with uppercase-started functions. -
"newIsCap": false
allowsnew
operators to be called with lowercase-started or uppercase-started functions. -
"capIsNew": true
(default) requires all uppercase-started functions to be called withnew
operators. -
"capIsNew": false
allows uppercase-started functions to be called withoutnew
operators. -
"newIsCapExceptions"
allows specified lowercase-started function names to be called with thenew
operator. -
"newIsCapExceptionPattern"
allows any lowercase-started function names that match the specified regex pattern to be called with thenew
operator. -
"capIsNewExceptions"
allows specified uppercase-started function names to be called without thenew
operator. -
"capIsNewExceptionPattern"
allows any uppercase-started function names that match the specified regex pattern to be called without thenew
operator. -
"properties": true
(default) enables checks on object properties -
"properties": false
disables checks on object properties
newIsCap
Examples of incorrect code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new person();
Examples of correct code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new Person();
Examples of correct code for this rule with the { "newIsCap": false }
option:
/*eslint new-cap: ["error", { "newIsCap": false }]*/
var friend = new person();
capIsNew
Examples of incorrect code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = Person();
Examples of correct code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = new Person();
Examples of correct code for this rule with the { "capIsNew": false }
option:
/*eslint new-cap: ["error", { "capIsNew": false }]*/
var colleague = Person();
newIsCapExceptions
Examples of additional correct code for this rule with the { "newIsCapExceptions": ["events"] }
option:
/*eslint new-cap: ["error", { "newIsCapExceptions": ["events"] }]*/
var events = require('events');
var emitter = new events();
newIsCapExceptionPattern
Examples of additional correct code for this rule with the { "newIsCapExceptionPattern": "^person\.." }
option:
/*eslint new-cap: ["error", { "newIsCapExceptionPattern": "^person\.." }]*/
var friend = new person.acquaintance();
var bestFriend = new person.friend();
capIsNewExceptions
Examples of additional correct code for this rule with the { "capIsNewExceptions": ["Person"] }
option:
/*eslint new-cap: ["error", { "capIsNewExceptions": ["Person"] }]*/
function foo(arg) {
return Person(arg);
}
capIsNewExceptionPattern
Examples of additional correct code for this rule with the { "capIsNewExceptionPattern": "^Person\.." }
option:
/*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^Person\.." }]*/
var friend = person.Acquaintance();
var bestFriend = person.Friend();
properties
Examples of incorrect code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.acquaintance();
Examples of correct code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.Acquaintance();
Examples of correct code for this rule with the { "properties": false }
option:
/*eslint new-cap: ["error", { "properties": false }]*/
var friend = new person.acquaintance();
When Not To Use It
If you have conventions that don't require an uppercase letter for constructors, or don't require capitalized functions be only used as constructors, turn this rule off. Source: http://eslint.org/docs/rules/
A function with a name starting with an uppercase letter should only be used as a constructor. Open
callback(commonErrors.SystemError(
- Read upRead up
- Exclude checks
require constructor names to begin with a capital letter (new-cap)
The new
operator in JavaScript creates a new instance of a particular type of object. That type of object is represented by a constructor function. Since constructor functions are just regular functions, the only defining characteristic is that new
is being used as part of the call. Native JavaScript functions begin with an uppercase letter to distinguish those functions that are to be used as constructors from functions that are not. Many style guides recommend following this pattern to more easily determine which functions are to be used as constructors.
var friend = new Person();
Rule Details
This rule requires constructor names to begin with a capital letter. Certain built-in identifiers are exempt from this rule. These identifiers are:
Array
Boolean
Date
Error
Function
Number
Object
RegExp
String
Symbol
Examples of correct code for this rule:
/*eslint new-cap: "error"*/
function foo(arg) {
return Boolean(arg);
}
Options
This rule has an object option:
-
"newIsCap": true
(default) requires allnew
operators to be called with uppercase-started functions. -
"newIsCap": false
allowsnew
operators to be called with lowercase-started or uppercase-started functions. -
"capIsNew": true
(default) requires all uppercase-started functions to be called withnew
operators. -
"capIsNew": false
allows uppercase-started functions to be called withoutnew
operators. -
"newIsCapExceptions"
allows specified lowercase-started function names to be called with thenew
operator. -
"newIsCapExceptionPattern"
allows any lowercase-started function names that match the specified regex pattern to be called with thenew
operator. -
"capIsNewExceptions"
allows specified uppercase-started function names to be called without thenew
operator. -
"capIsNewExceptionPattern"
allows any uppercase-started function names that match the specified regex pattern to be called without thenew
operator. -
"properties": true
(default) enables checks on object properties -
"properties": false
disables checks on object properties
newIsCap
Examples of incorrect code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new person();
Examples of correct code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new Person();
Examples of correct code for this rule with the { "newIsCap": false }
option:
/*eslint new-cap: ["error", { "newIsCap": false }]*/
var friend = new person();
capIsNew
Examples of incorrect code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = Person();
Examples of correct code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = new Person();
Examples of correct code for this rule with the { "capIsNew": false }
option:
/*eslint new-cap: ["error", { "capIsNew": false }]*/
var colleague = Person();
newIsCapExceptions
Examples of additional correct code for this rule with the { "newIsCapExceptions": ["events"] }
option:
/*eslint new-cap: ["error", { "newIsCapExceptions": ["events"] }]*/
var events = require('events');
var emitter = new events();
newIsCapExceptionPattern
Examples of additional correct code for this rule with the { "newIsCapExceptionPattern": "^person\.." }
option:
/*eslint new-cap: ["error", { "newIsCapExceptionPattern": "^person\.." }]*/
var friend = new person.acquaintance();
var bestFriend = new person.friend();
capIsNewExceptions
Examples of additional correct code for this rule with the { "capIsNewExceptions": ["Person"] }
option:
/*eslint new-cap: ["error", { "capIsNewExceptions": ["Person"] }]*/
function foo(arg) {
return Person(arg);
}
capIsNewExceptionPattern
Examples of additional correct code for this rule with the { "capIsNewExceptionPattern": "^Person\.." }
option:
/*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^Person\.." }]*/
var friend = person.Acquaintance();
var bestFriend = person.Friend();
properties
Examples of incorrect code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.acquaintance();
Examples of correct code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.Acquaintance();
Examples of correct code for this rule with the { "properties": false }
option:
/*eslint new-cap: ["error", { "properties": false }]*/
var friend = new person.acquaintance();
When Not To Use It
If you have conventions that don't require an uppercase letter for constructors, or don't require capitalized functions be only used as constructors, turn this rule off. Source: http://eslint.org/docs/rules/
A function with a name starting with an uppercase letter should only be used as a constructor. Open
communicationErrors.ZimbraError(
- Read upRead up
- Exclude checks
require constructor names to begin with a capital letter (new-cap)
The new
operator in JavaScript creates a new instance of a particular type of object. That type of object is represented by a constructor function. Since constructor functions are just regular functions, the only defining characteristic is that new
is being used as part of the call. Native JavaScript functions begin with an uppercase letter to distinguish those functions that are to be used as constructors from functions that are not. Many style guides recommend following this pattern to more easily determine which functions are to be used as constructors.
var friend = new Person();
Rule Details
This rule requires constructor names to begin with a capital letter. Certain built-in identifiers are exempt from this rule. These identifiers are:
Array
Boolean
Date
Error
Function
Number
Object
RegExp
String
Symbol
Examples of correct code for this rule:
/*eslint new-cap: "error"*/
function foo(arg) {
return Boolean(arg);
}
Options
This rule has an object option:
-
"newIsCap": true
(default) requires allnew
operators to be called with uppercase-started functions. -
"newIsCap": false
allowsnew
operators to be called with lowercase-started or uppercase-started functions. -
"capIsNew": true
(default) requires all uppercase-started functions to be called withnew
operators. -
"capIsNew": false
allows uppercase-started functions to be called withoutnew
operators. -
"newIsCapExceptions"
allows specified lowercase-started function names to be called with thenew
operator. -
"newIsCapExceptionPattern"
allows any lowercase-started function names that match the specified regex pattern to be called with thenew
operator. -
"capIsNewExceptions"
allows specified uppercase-started function names to be called without thenew
operator. -
"capIsNewExceptionPattern"
allows any uppercase-started function names that match the specified regex pattern to be called without thenew
operator. -
"properties": true
(default) enables checks on object properties -
"properties": false
disables checks on object properties
newIsCap
Examples of incorrect code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new person();
Examples of correct code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new Person();
Examples of correct code for this rule with the { "newIsCap": false }
option:
/*eslint new-cap: ["error", { "newIsCap": false }]*/
var friend = new person();
capIsNew
Examples of incorrect code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = Person();
Examples of correct code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = new Person();
Examples of correct code for this rule with the { "capIsNew": false }
option:
/*eslint new-cap: ["error", { "capIsNew": false }]*/
var colleague = Person();
newIsCapExceptions
Examples of additional correct code for this rule with the { "newIsCapExceptions": ["events"] }
option:
/*eslint new-cap: ["error", { "newIsCapExceptions": ["events"] }]*/
var events = require('events');
var emitter = new events();
newIsCapExceptionPattern
Examples of additional correct code for this rule with the { "newIsCapExceptionPattern": "^person\.." }
option:
/*eslint new-cap: ["error", { "newIsCapExceptionPattern": "^person\.." }]*/
var friend = new person.acquaintance();
var bestFriend = new person.friend();
capIsNewExceptions
Examples of additional correct code for this rule with the { "capIsNewExceptions": ["Person"] }
option:
/*eslint new-cap: ["error", { "capIsNewExceptions": ["Person"] }]*/
function foo(arg) {
return Person(arg);
}
capIsNewExceptionPattern
Examples of additional correct code for this rule with the { "capIsNewExceptionPattern": "^Person\.." }
option:
/*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^Person\.." }]*/
var friend = person.Acquaintance();
var bestFriend = person.Friend();
properties
Examples of incorrect code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.acquaintance();
Examples of correct code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.Acquaintance();
Examples of correct code for this rule with the { "properties": false }
option:
/*eslint new-cap: ["error", { "properties": false }]*/
var friend = new person.acquaintance();
When Not To Use It
If you have conventions that don't require an uppercase letter for constructors, or don't require capitalized functions be only used as constructors, turn this rule off. Source: http://eslint.org/docs/rules/
A function with a name starting with an uppercase letter should only be used as a constructor. Open
commonErrors.SystemError(
- Read upRead up
- Exclude checks
require constructor names to begin with a capital letter (new-cap)
The new
operator in JavaScript creates a new instance of a particular type of object. That type of object is represented by a constructor function. Since constructor functions are just regular functions, the only defining characteristic is that new
is being used as part of the call. Native JavaScript functions begin with an uppercase letter to distinguish those functions that are to be used as constructors from functions that are not. Many style guides recommend following this pattern to more easily determine which functions are to be used as constructors.
var friend = new Person();
Rule Details
This rule requires constructor names to begin with a capital letter. Certain built-in identifiers are exempt from this rule. These identifiers are:
Array
Boolean
Date
Error
Function
Number
Object
RegExp
String
Symbol
Examples of correct code for this rule:
/*eslint new-cap: "error"*/
function foo(arg) {
return Boolean(arg);
}
Options
This rule has an object option:
-
"newIsCap": true
(default) requires allnew
operators to be called with uppercase-started functions. -
"newIsCap": false
allowsnew
operators to be called with lowercase-started or uppercase-started functions. -
"capIsNew": true
(default) requires all uppercase-started functions to be called withnew
operators. -
"capIsNew": false
allows uppercase-started functions to be called withoutnew
operators. -
"newIsCapExceptions"
allows specified lowercase-started function names to be called with thenew
operator. -
"newIsCapExceptionPattern"
allows any lowercase-started function names that match the specified regex pattern to be called with thenew
operator. -
"capIsNewExceptions"
allows specified uppercase-started function names to be called without thenew
operator. -
"capIsNewExceptionPattern"
allows any uppercase-started function names that match the specified regex pattern to be called without thenew
operator. -
"properties": true
(default) enables checks on object properties -
"properties": false
disables checks on object properties
newIsCap
Examples of incorrect code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new person();
Examples of correct code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new Person();
Examples of correct code for this rule with the { "newIsCap": false }
option:
/*eslint new-cap: ["error", { "newIsCap": false }]*/
var friend = new person();
capIsNew
Examples of incorrect code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = Person();
Examples of correct code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = new Person();
Examples of correct code for this rule with the { "capIsNew": false }
option:
/*eslint new-cap: ["error", { "capIsNew": false }]*/
var colleague = Person();
newIsCapExceptions
Examples of additional correct code for this rule with the { "newIsCapExceptions": ["events"] }
option:
/*eslint new-cap: ["error", { "newIsCapExceptions": ["events"] }]*/
var events = require('events');
var emitter = new events();
newIsCapExceptionPattern
Examples of additional correct code for this rule with the { "newIsCapExceptionPattern": "^person\.." }
option:
/*eslint new-cap: ["error", { "newIsCapExceptionPattern": "^person\.." }]*/
var friend = new person.acquaintance();
var bestFriend = new person.friend();
capIsNewExceptions
Examples of additional correct code for this rule with the { "capIsNewExceptions": ["Person"] }
option:
/*eslint new-cap: ["error", { "capIsNewExceptions": ["Person"] }]*/
function foo(arg) {
return Person(arg);
}
capIsNewExceptionPattern
Examples of additional correct code for this rule with the { "capIsNewExceptionPattern": "^Person\.." }
option:
/*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^Person\.." }]*/
var friend = person.Acquaintance();
var bestFriend = person.Friend();
properties
Examples of incorrect code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.acquaintance();
Examples of correct code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.Acquaintance();
Examples of correct code for this rule with the { "properties": false }
option:
/*eslint new-cap: ["error", { "properties": false }]*/
var friend = new person.acquaintance();
When Not To Use It
If you have conventions that don't require an uppercase letter for constructors, or don't require capitalized functions be only used as constructors, turn this rule off. Source: http://eslint.org/docs/rules/
A function with a name starting with an uppercase letter should only be used as a constructor. Open
callback(commonErrors.InvalidOption(undefined, {
- Read upRead up
- Exclude checks
require constructor names to begin with a capital letter (new-cap)
The new
operator in JavaScript creates a new instance of a particular type of object. That type of object is represented by a constructor function. Since constructor functions are just regular functions, the only defining characteristic is that new
is being used as part of the call. Native JavaScript functions begin with an uppercase letter to distinguish those functions that are to be used as constructors from functions that are not. Many style guides recommend following this pattern to more easily determine which functions are to be used as constructors.
var friend = new Person();
Rule Details
This rule requires constructor names to begin with a capital letter. Certain built-in identifiers are exempt from this rule. These identifiers are:
Array
Boolean
Date
Error
Function
Number
Object
RegExp
String
Symbol
Examples of correct code for this rule:
/*eslint new-cap: "error"*/
function foo(arg) {
return Boolean(arg);
}
Options
This rule has an object option:
-
"newIsCap": true
(default) requires allnew
operators to be called with uppercase-started functions. -
"newIsCap": false
allowsnew
operators to be called with lowercase-started or uppercase-started functions. -
"capIsNew": true
(default) requires all uppercase-started functions to be called withnew
operators. -
"capIsNew": false
allows uppercase-started functions to be called withoutnew
operators. -
"newIsCapExceptions"
allows specified lowercase-started function names to be called with thenew
operator. -
"newIsCapExceptionPattern"
allows any lowercase-started function names that match the specified regex pattern to be called with thenew
operator. -
"capIsNewExceptions"
allows specified uppercase-started function names to be called without thenew
operator. -
"capIsNewExceptionPattern"
allows any uppercase-started function names that match the specified regex pattern to be called without thenew
operator. -
"properties": true
(default) enables checks on object properties -
"properties": false
disables checks on object properties
newIsCap
Examples of incorrect code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new person();
Examples of correct code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new Person();
Examples of correct code for this rule with the { "newIsCap": false }
option:
/*eslint new-cap: ["error", { "newIsCap": false }]*/
var friend = new person();
capIsNew
Examples of incorrect code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = Person();
Examples of correct code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = new Person();
Examples of correct code for this rule with the { "capIsNew": false }
option:
/*eslint new-cap: ["error", { "capIsNew": false }]*/
var colleague = Person();
newIsCapExceptions
Examples of additional correct code for this rule with the { "newIsCapExceptions": ["events"] }
option:
/*eslint new-cap: ["error", { "newIsCapExceptions": ["events"] }]*/
var events = require('events');
var emitter = new events();
newIsCapExceptionPattern
Examples of additional correct code for this rule with the { "newIsCapExceptionPattern": "^person\.." }
option:
/*eslint new-cap: ["error", { "newIsCapExceptionPattern": "^person\.." }]*/
var friend = new person.acquaintance();
var bestFriend = new person.friend();
capIsNewExceptions
Examples of additional correct code for this rule with the { "capIsNewExceptions": ["Person"] }
option:
/*eslint new-cap: ["error", { "capIsNewExceptions": ["Person"] }]*/
function foo(arg) {
return Person(arg);
}
capIsNewExceptionPattern
Examples of additional correct code for this rule with the { "capIsNewExceptionPattern": "^Person\.." }
option:
/*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^Person\.." }]*/
var friend = person.Acquaintance();
var bestFriend = person.Friend();
properties
Examples of incorrect code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.acquaintance();
Examples of correct code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.Acquaintance();
Examples of correct code for this rule with the { "properties": false }
option:
/*eslint new-cap: ["error", { "properties": false }]*/
var friend = new person.acquaintance();
When Not To Use It
If you have conventions that don't require an uppercase letter for constructors, or don't require capitalized functions be only used as constructors, turn this rule off. Source: http://eslint.org/docs/rules/
A function with a name starting with an uppercase letter should only be used as a constructor. Open
commonErrors.SystemError(
- Read upRead up
- Exclude checks
require constructor names to begin with a capital letter (new-cap)
The new
operator in JavaScript creates a new instance of a particular type of object. That type of object is represented by a constructor function. Since constructor functions are just regular functions, the only defining characteristic is that new
is being used as part of the call. Native JavaScript functions begin with an uppercase letter to distinguish those functions that are to be used as constructors from functions that are not. Many style guides recommend following this pattern to more easily determine which functions are to be used as constructors.
var friend = new Person();
Rule Details
This rule requires constructor names to begin with a capital letter. Certain built-in identifiers are exempt from this rule. These identifiers are:
Array
Boolean
Date
Error
Function
Number
Object
RegExp
String
Symbol
Examples of correct code for this rule:
/*eslint new-cap: "error"*/
function foo(arg) {
return Boolean(arg);
}
Options
This rule has an object option:
-
"newIsCap": true
(default) requires allnew
operators to be called with uppercase-started functions. -
"newIsCap": false
allowsnew
operators to be called with lowercase-started or uppercase-started functions. -
"capIsNew": true
(default) requires all uppercase-started functions to be called withnew
operators. -
"capIsNew": false
allows uppercase-started functions to be called withoutnew
operators. -
"newIsCapExceptions"
allows specified lowercase-started function names to be called with thenew
operator. -
"newIsCapExceptionPattern"
allows any lowercase-started function names that match the specified regex pattern to be called with thenew
operator. -
"capIsNewExceptions"
allows specified uppercase-started function names to be called without thenew
operator. -
"capIsNewExceptionPattern"
allows any uppercase-started function names that match the specified regex pattern to be called without thenew
operator. -
"properties": true
(default) enables checks on object properties -
"properties": false
disables checks on object properties
newIsCap
Examples of incorrect code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new person();
Examples of correct code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new Person();
Examples of correct code for this rule with the { "newIsCap": false }
option:
/*eslint new-cap: ["error", { "newIsCap": false }]*/
var friend = new person();
capIsNew
Examples of incorrect code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = Person();
Examples of correct code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = new Person();
Examples of correct code for this rule with the { "capIsNew": false }
option:
/*eslint new-cap: ["error", { "capIsNew": false }]*/
var colleague = Person();
newIsCapExceptions
Examples of additional correct code for this rule with the { "newIsCapExceptions": ["events"] }
option:
/*eslint new-cap: ["error", { "newIsCapExceptions": ["events"] }]*/
var events = require('events');
var emitter = new events();
newIsCapExceptionPattern
Examples of additional correct code for this rule with the { "newIsCapExceptionPattern": "^person\.." }
option:
/*eslint new-cap: ["error", { "newIsCapExceptionPattern": "^person\.." }]*/
var friend = new person.acquaintance();
var bestFriend = new person.friend();
capIsNewExceptions
Examples of additional correct code for this rule with the { "capIsNewExceptions": ["Person"] }
option:
/*eslint new-cap: ["error", { "capIsNewExceptions": ["Person"] }]*/
function foo(arg) {
return Person(arg);
}
capIsNewExceptionPattern
Examples of additional correct code for this rule with the { "capIsNewExceptionPattern": "^Person\.." }
option:
/*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^Person\.." }]*/
var friend = person.Acquaintance();
var bestFriend = person.Friend();
properties
Examples of incorrect code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.acquaintance();
Examples of correct code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.Acquaintance();
Examples of correct code for this rule with the { "properties": false }
option:
/*eslint new-cap: ["error", { "properties": false }]*/
var friend = new person.acquaintance();
When Not To Use It
If you have conventions that don't require an uppercase letter for constructors, or don't require capitalized functions be only used as constructors, turn this rule off. Source: http://eslint.org/docs/rules/
A function with a name starting with an uppercase letter should only be used as a constructor. Open
callback(commonErrors.SystemError(undefined, {
- Read upRead up
- Exclude checks
require constructor names to begin with a capital letter (new-cap)
The new
operator in JavaScript creates a new instance of a particular type of object. That type of object is represented by a constructor function. Since constructor functions are just regular functions, the only defining characteristic is that new
is being used as part of the call. Native JavaScript functions begin with an uppercase letter to distinguish those functions that are to be used as constructors from functions that are not. Many style guides recommend following this pattern to more easily determine which functions are to be used as constructors.
var friend = new Person();
Rule Details
This rule requires constructor names to begin with a capital letter. Certain built-in identifiers are exempt from this rule. These identifiers are:
Array
Boolean
Date
Error
Function
Number
Object
RegExp
String
Symbol
Examples of correct code for this rule:
/*eslint new-cap: "error"*/
function foo(arg) {
return Boolean(arg);
}
Options
This rule has an object option:
-
"newIsCap": true
(default) requires allnew
operators to be called with uppercase-started functions. -
"newIsCap": false
allowsnew
operators to be called with lowercase-started or uppercase-started functions. -
"capIsNew": true
(default) requires all uppercase-started functions to be called withnew
operators. -
"capIsNew": false
allows uppercase-started functions to be called withoutnew
operators. -
"newIsCapExceptions"
allows specified lowercase-started function names to be called with thenew
operator. -
"newIsCapExceptionPattern"
allows any lowercase-started function names that match the specified regex pattern to be called with thenew
operator. -
"capIsNewExceptions"
allows specified uppercase-started function names to be called without thenew
operator. -
"capIsNewExceptionPattern"
allows any uppercase-started function names that match the specified regex pattern to be called without thenew
operator. -
"properties": true
(default) enables checks on object properties -
"properties": false
disables checks on object properties
newIsCap
Examples of incorrect code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new person();
Examples of correct code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new Person();
Examples of correct code for this rule with the { "newIsCap": false }
option:
/*eslint new-cap: ["error", { "newIsCap": false }]*/
var friend = new person();
capIsNew
Examples of incorrect code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = Person();
Examples of correct code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = new Person();
Examples of correct code for this rule with the { "capIsNew": false }
option:
/*eslint new-cap: ["error", { "capIsNew": false }]*/
var colleague = Person();
newIsCapExceptions
Examples of additional correct code for this rule with the { "newIsCapExceptions": ["events"] }
option:
/*eslint new-cap: ["error", { "newIsCapExceptions": ["events"] }]*/
var events = require('events');
var emitter = new events();
newIsCapExceptionPattern
Examples of additional correct code for this rule with the { "newIsCapExceptionPattern": "^person\.." }
option:
/*eslint new-cap: ["error", { "newIsCapExceptionPattern": "^person\.." }]*/
var friend = new person.acquaintance();
var bestFriend = new person.friend();
capIsNewExceptions
Examples of additional correct code for this rule with the { "capIsNewExceptions": ["Person"] }
option:
/*eslint new-cap: ["error", { "capIsNewExceptions": ["Person"] }]*/
function foo(arg) {
return Person(arg);
}
capIsNewExceptionPattern
Examples of additional correct code for this rule with the { "capIsNewExceptionPattern": "^Person\.." }
option:
/*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^Person\.." }]*/
var friend = person.Acquaintance();
var bestFriend = person.Friend();
properties
Examples of incorrect code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.acquaintance();
Examples of correct code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.Acquaintance();
Examples of correct code for this rule with the { "properties": false }
option:
/*eslint new-cap: ["error", { "properties": false }]*/
var friend = new person.acquaintance();
When Not To Use It
If you have conventions that don't require an uppercase letter for constructors, or don't require capitalized functions be only used as constructors, turn this rule off. Source: http://eslint.org/docs/rules/
A function with a name starting with an uppercase letter should only be used as a constructor. Open
callback(requestErrors.NoRequests());
- Read upRead up
- Exclude checks
require constructor names to begin with a capital letter (new-cap)
The new
operator in JavaScript creates a new instance of a particular type of object. That type of object is represented by a constructor function. Since constructor functions are just regular functions, the only defining characteristic is that new
is being used as part of the call. Native JavaScript functions begin with an uppercase letter to distinguish those functions that are to be used as constructors from functions that are not. Many style guides recommend following this pattern to more easily determine which functions are to be used as constructors.
var friend = new Person();
Rule Details
This rule requires constructor names to begin with a capital letter. Certain built-in identifiers are exempt from this rule. These identifiers are:
Array
Boolean
Date
Error
Function
Number
Object
RegExp
String
Symbol
Examples of correct code for this rule:
/*eslint new-cap: "error"*/
function foo(arg) {
return Boolean(arg);
}
Options
This rule has an object option:
-
"newIsCap": true
(default) requires allnew
operators to be called with uppercase-started functions. -
"newIsCap": false
allowsnew
operators to be called with lowercase-started or uppercase-started functions. -
"capIsNew": true
(default) requires all uppercase-started functions to be called withnew
operators. -
"capIsNew": false
allows uppercase-started functions to be called withoutnew
operators. -
"newIsCapExceptions"
allows specified lowercase-started function names to be called with thenew
operator. -
"newIsCapExceptionPattern"
allows any lowercase-started function names that match the specified regex pattern to be called with thenew
operator. -
"capIsNewExceptions"
allows specified uppercase-started function names to be called without thenew
operator. -
"capIsNewExceptionPattern"
allows any uppercase-started function names that match the specified regex pattern to be called without thenew
operator. -
"properties": true
(default) enables checks on object properties -
"properties": false
disables checks on object properties
newIsCap
Examples of incorrect code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new person();
Examples of correct code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new Person();
Examples of correct code for this rule with the { "newIsCap": false }
option:
/*eslint new-cap: ["error", { "newIsCap": false }]*/
var friend = new person();
capIsNew
Examples of incorrect code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = Person();
Examples of correct code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = new Person();
Examples of correct code for this rule with the { "capIsNew": false }
option:
/*eslint new-cap: ["error", { "capIsNew": false }]*/
var colleague = Person();
newIsCapExceptions
Examples of additional correct code for this rule with the { "newIsCapExceptions": ["events"] }
option:
/*eslint new-cap: ["error", { "newIsCapExceptions": ["events"] }]*/
var events = require('events');
var emitter = new events();
newIsCapExceptionPattern
Examples of additional correct code for this rule with the { "newIsCapExceptionPattern": "^person\.." }
option:
/*eslint new-cap: ["error", { "newIsCapExceptionPattern": "^person\.." }]*/
var friend = new person.acquaintance();
var bestFriend = new person.friend();
capIsNewExceptions
Examples of additional correct code for this rule with the { "capIsNewExceptions": ["Person"] }
option:
/*eslint new-cap: ["error", { "capIsNewExceptions": ["Person"] }]*/
function foo(arg) {
return Person(arg);
}
capIsNewExceptionPattern
Examples of additional correct code for this rule with the { "capIsNewExceptionPattern": "^Person\.." }
option:
/*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^Person\.." }]*/
var friend = person.Acquaintance();
var bestFriend = person.Friend();
properties
Examples of incorrect code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.acquaintance();
Examples of correct code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.Acquaintance();
Examples of correct code for this rule with the { "properties": false }
option:
/*eslint new-cap: ["error", { "properties": false }]*/
var friend = new person.acquaintance();
When Not To Use It
If you have conventions that don't require an uppercase letter for constructors, or don't require capitalized functions be only used as constructors, turn this rule off. Source: http://eslint.org/docs/rules/
Expected space(s) after "throw". Open
throw(err);
- Read upRead up
- Exclude checks
enforce consistent spacing before and after keywords (keyword-spacing)
Keywords are syntax elements of JavaScript, such as function
and if
.
These identifiers have special meaning to the language and so often appear in a different color in code editors.
As an important part of the language, style guides often refer to the spacing that should be used around keywords.
For example, you might have a style guide that says keywords should be always surrounded by spaces, which would mean if-else
statements must look like this:
if (foo) {
// ...
} else {
// ...
}
Of course, you could also have a style guide that disallows spaces around keywords.
Rule Details
This rule enforces consistent spacing around keywords and keyword-like tokens: as
(in module declarations), async
(of async functions), await
(of await expressions), break
, case
, catch
, class
, const
, continue
, debugger
, default
, delete
, do
, else
, export
, extends
, finally
, for
, from
(in module declarations), function
, get
(of getters), if
, import
, in
, instanceof
, let
, new
, of
(in for-of statements), return
, set
(of setters), static
, super
, switch
, this
, throw
, try
, typeof
, var
, void
, while
, with
, and yield
. This rule is designed carefully not to conflict with other spacing rules: it does not apply to spacing where other rules report problems.
Options
This rule has an object option:
-
"before": true
(default) requires at least one space before keywords -
"before": false
disallows spaces before keywords -
"after": true
(default) requires at least one space after keywords -
"after": false
disallows spaces after keywords -
"overrides"
allows overriding spacing style for specified keywords
before
Examples of incorrect code for this rule with the default { "before": true }
option:
/*eslint keyword-spacing: ["error", { "before": true }]*/
if (foo) {
//...
}else if (bar) {
//...
}else {
//...
}
Examples of correct code for this rule with the default { "before": true }
option:
/*eslint keyword-spacing: ["error", { "before": true }]*/
/*eslint-env es6*/
if (foo) {
//...
} else if (bar) {
//...
} else {
//...
}
// no conflict with `array-bracket-spacing`
let a = [this];
let b = [function() {}];
// no conflict with `arrow-spacing`
let a = ()=> this.foo;
// no conflict with `block-spacing`
{function foo() {}}
// no conflict with `comma-spacing`
let a = [100,this.foo, this.bar];
// not conflict with `computed-property-spacing`
obj[this.foo] = 0;
// no conflict with `generator-star-spacing`
function *foo() {}
// no conflict with `key-spacing`
let obj = {
foo:function() {}
};
// no conflict with `object-curly-spacing`
let obj = {foo: this};
// no conflict with `semi-spacing`
let a = this;function foo() {}
// no conflict with `space-in-parens`
(function () {})();
// no conflict with `space-infix-ops`
if ("foo"in {foo: 0}) {}
if (10+this.foo<= this.bar) {}
// no conflict with `jsx-curly-spacing`
let a =
Examples of incorrect code for this rule with the { "before": false }
option:
/*eslint keyword-spacing: ["error", { "before": false }]*/
if (foo) {
//...
} else if (bar) {
//...
} else {
//...
}
Examples of correct code for this rule with the { "before": false }
option:
/*eslint keyword-spacing: ["error", { "before": false }]*/
if (foo) {
//...
}else if (bar) {
//...
}else {
//...
}
after
Examples of incorrect code for this rule with the default { "after": true }
option:
/*eslint keyword-spacing: ["error", { "after": true }]*/
if(foo) {
//...
} else if(bar) {
//...
} else{
//...
}
Examples of correct code for this rule with the default { "after": true }
option:
/*eslint keyword-spacing: ["error", { "after": true }]*/
if (foo) {
//...
} else if (bar) {
//...
} else {
//...
}
// not conflict with `array-bracket-spacing`
let a = [this];
// not conflict with `arrow-spacing`
let a = ()=> this.foo;
// not conflict with `comma-spacing`
let a = [100, this.foo, this.bar];
// not conflict with `computed-property-spacing`
obj[this.foo] = 0;
// not conflict with `generator-star-spacing`
function* foo() {}
// not conflict with `key-spacing`
let obj = {
foo:function() {}
};
// not conflict with `func-call-spacing`
class A {
constructor() {
super();
}
}
// not conflict with `object-curly-spacing`
let obj = {foo: this};
// not conflict with `semi-spacing`
let a = this;function foo() {}
// not conflict with `space-before-function-paren`
function() {}
// no conflict with `space-infix-ops`
if ("foo"in{foo: 0}) {}
if (10+this.foo<= this.bar) {}
// no conflict with `space-unary-ops`
function* foo(a) {
return yield+a;
}
// no conflict with `yield-star-spacing`
function* foo(a) {
return yield* a;
}
// no conflict with `jsx-curly-spacing`
let a =
Examples of incorrect code for this rule with the { "after": false }
option:
/*eslint keyword-spacing: ["error", { "after": false }]*/
if (foo) {
//...
} else if (bar) {
//...
} else {
//...
}
Examples of correct code for this rule with the { "after": false }
option:
/*eslint keyword-spacing: ["error", { "after": false }]*/
if(foo) {
//...
} else if(bar) {
//...
} else{
//...
}
overrides
Examples of correct code for this rule with the { "overrides": { "if": { "after": false }, "for": { "after": false }, "while": { "after": false } } }
option:
/*eslint keyword-spacing: ["error", { "overrides": {
"if": { "after": false },
"for": { "after": false },
"while": { "after": false }
} }]*/
if(foo) {
//...
} else if(bar) {
//...
} else {
//...
}
for(;;);
while(true) {
//...
}
When Not To Use It
If you don't want to enforce consistency on keyword spacing, then it's safe to disable this rule. Source: http://eslint.org/docs/rules/
A function with a name starting with an uppercase letter should only be used as a constructor. Open
throw commonErrors.InvalidOption(
- Read upRead up
- Exclude checks
require constructor names to begin with a capital letter (new-cap)
The new
operator in JavaScript creates a new instance of a particular type of object. That type of object is represented by a constructor function. Since constructor functions are just regular functions, the only defining characteristic is that new
is being used as part of the call. Native JavaScript functions begin with an uppercase letter to distinguish those functions that are to be used as constructors from functions that are not. Many style guides recommend following this pattern to more easily determine which functions are to be used as constructors.
var friend = new Person();
Rule Details
This rule requires constructor names to begin with a capital letter. Certain built-in identifiers are exempt from this rule. These identifiers are:
Array
Boolean
Date
Error
Function
Number
Object
RegExp
String
Symbol
Examples of correct code for this rule:
/*eslint new-cap: "error"*/
function foo(arg) {
return Boolean(arg);
}
Options
This rule has an object option:
-
"newIsCap": true
(default) requires allnew
operators to be called with uppercase-started functions. -
"newIsCap": false
allowsnew
operators to be called with lowercase-started or uppercase-started functions. -
"capIsNew": true
(default) requires all uppercase-started functions to be called withnew
operators. -
"capIsNew": false
allows uppercase-started functions to be called withoutnew
operators. -
"newIsCapExceptions"
allows specified lowercase-started function names to be called with thenew
operator. -
"newIsCapExceptionPattern"
allows any lowercase-started function names that match the specified regex pattern to be called with thenew
operator. -
"capIsNewExceptions"
allows specified uppercase-started function names to be called without thenew
operator. -
"capIsNewExceptionPattern"
allows any uppercase-started function names that match the specified regex pattern to be called without thenew
operator. -
"properties": true
(default) enables checks on object properties -
"properties": false
disables checks on object properties
newIsCap
Examples of incorrect code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new person();
Examples of correct code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new Person();
Examples of correct code for this rule with the { "newIsCap": false }
option:
/*eslint new-cap: ["error", { "newIsCap": false }]*/
var friend = new person();
capIsNew
Examples of incorrect code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = Person();
Examples of correct code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = new Person();
Examples of correct code for this rule with the { "capIsNew": false }
option:
/*eslint new-cap: ["error", { "capIsNew": false }]*/
var colleague = Person();
newIsCapExceptions
Examples of additional correct code for this rule with the { "newIsCapExceptions": ["events"] }
option:
/*eslint new-cap: ["error", { "newIsCapExceptions": ["events"] }]*/
var events = require('events');
var emitter = new events();
newIsCapExceptionPattern
Examples of additional correct code for this rule with the { "newIsCapExceptionPattern": "^person\.." }
option:
/*eslint new-cap: ["error", { "newIsCapExceptionPattern": "^person\.." }]*/
var friend = new person.acquaintance();
var bestFriend = new person.friend();
capIsNewExceptions
Examples of additional correct code for this rule with the { "capIsNewExceptions": ["Person"] }
option:
/*eslint new-cap: ["error", { "capIsNewExceptions": ["Person"] }]*/
function foo(arg) {
return Person(arg);
}
capIsNewExceptionPattern
Examples of additional correct code for this rule with the { "capIsNewExceptionPattern": "^Person\.." }
option:
/*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^Person\.." }]*/
var friend = person.Acquaintance();
var bestFriend = person.Friend();
properties
Examples of incorrect code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.acquaintance();
Examples of correct code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.Acquaintance();
Examples of correct code for this rule with the { "properties": false }
option:
/*eslint new-cap: ["error", { "properties": false }]*/
var friend = new person.acquaintance();
When Not To Use It
If you have conventions that don't require an uppercase letter for constructors, or don't require capitalized functions be only used as constructors, turn this rule off. Source: http://eslint.org/docs/rules/
Expected space(s) after "throw". Open
throw(
- Read upRead up
- Exclude checks
enforce consistent spacing before and after keywords (keyword-spacing)
Keywords are syntax elements of JavaScript, such as function
and if
.
These identifiers have special meaning to the language and so often appear in a different color in code editors.
As an important part of the language, style guides often refer to the spacing that should be used around keywords.
For example, you might have a style guide that says keywords should be always surrounded by spaces, which would mean if-else
statements must look like this:
if (foo) {
// ...
} else {
// ...
}
Of course, you could also have a style guide that disallows spaces around keywords.
Rule Details
This rule enforces consistent spacing around keywords and keyword-like tokens: as
(in module declarations), async
(of async functions), await
(of await expressions), break
, case
, catch
, class
, const
, continue
, debugger
, default
, delete
, do
, else
, export
, extends
, finally
, for
, from
(in module declarations), function
, get
(of getters), if
, import
, in
, instanceof
, let
, new
, of
(in for-of statements), return
, set
(of setters), static
, super
, switch
, this
, throw
, try
, typeof
, var
, void
, while
, with
, and yield
. This rule is designed carefully not to conflict with other spacing rules: it does not apply to spacing where other rules report problems.
Options
This rule has an object option:
-
"before": true
(default) requires at least one space before keywords -
"before": false
disallows spaces before keywords -
"after": true
(default) requires at least one space after keywords -
"after": false
disallows spaces after keywords -
"overrides"
allows overriding spacing style for specified keywords
before
Examples of incorrect code for this rule with the default { "before": true }
option:
/*eslint keyword-spacing: ["error", { "before": true }]*/
if (foo) {
//...
}else if (bar) {
//...
}else {
//...
}
Examples of correct code for this rule with the default { "before": true }
option:
/*eslint keyword-spacing: ["error", { "before": true }]*/
/*eslint-env es6*/
if (foo) {
//...
} else if (bar) {
//...
} else {
//...
}
// no conflict with `array-bracket-spacing`
let a = [this];
let b = [function() {}];
// no conflict with `arrow-spacing`
let a = ()=> this.foo;
// no conflict with `block-spacing`
{function foo() {}}
// no conflict with `comma-spacing`
let a = [100,this.foo, this.bar];
// not conflict with `computed-property-spacing`
obj[this.foo] = 0;
// no conflict with `generator-star-spacing`
function *foo() {}
// no conflict with `key-spacing`
let obj = {
foo:function() {}
};
// no conflict with `object-curly-spacing`
let obj = {foo: this};
// no conflict with `semi-spacing`
let a = this;function foo() {}
// no conflict with `space-in-parens`
(function () {})();
// no conflict with `space-infix-ops`
if ("foo"in {foo: 0}) {}
if (10+this.foo<= this.bar) {}
// no conflict with `jsx-curly-spacing`
let a =
Examples of incorrect code for this rule with the { "before": false }
option:
/*eslint keyword-spacing: ["error", { "before": false }]*/
if (foo) {
//...
} else if (bar) {
//...
} else {
//...
}
Examples of correct code for this rule with the { "before": false }
option:
/*eslint keyword-spacing: ["error", { "before": false }]*/
if (foo) {
//...
}else if (bar) {
//...
}else {
//...
}
after
Examples of incorrect code for this rule with the default { "after": true }
option:
/*eslint keyword-spacing: ["error", { "after": true }]*/
if(foo) {
//...
} else if(bar) {
//...
} else{
//...
}
Examples of correct code for this rule with the default { "after": true }
option:
/*eslint keyword-spacing: ["error", { "after": true }]*/
if (foo) {
//...
} else if (bar) {
//...
} else {
//...
}
// not conflict with `array-bracket-spacing`
let a = [this];
// not conflict with `arrow-spacing`
let a = ()=> this.foo;
// not conflict with `comma-spacing`
let a = [100, this.foo, this.bar];
// not conflict with `computed-property-spacing`
obj[this.foo] = 0;
// not conflict with `generator-star-spacing`
function* foo() {}
// not conflict with `key-spacing`
let obj = {
foo:function() {}
};
// not conflict with `func-call-spacing`
class A {
constructor() {
super();
}
}
// not conflict with `object-curly-spacing`
let obj = {foo: this};
// not conflict with `semi-spacing`
let a = this;function foo() {}
// not conflict with `space-before-function-paren`
function() {}
// no conflict with `space-infix-ops`
if ("foo"in{foo: 0}) {}
if (10+this.foo<= this.bar) {}
// no conflict with `space-unary-ops`
function* foo(a) {
return yield+a;
}
// no conflict with `yield-star-spacing`
function* foo(a) {
return yield* a;
}
// no conflict with `jsx-curly-spacing`
let a =
Examples of incorrect code for this rule with the { "after": false }
option:
/*eslint keyword-spacing: ["error", { "after": false }]*/
if (foo) {
//...
} else if (bar) {
//...
} else {
//...
}
Examples of correct code for this rule with the { "after": false }
option:
/*eslint keyword-spacing: ["error", { "after": false }]*/
if(foo) {
//...
} else if(bar) {
//...
} else{
//...
}
overrides
Examples of correct code for this rule with the { "overrides": { "if": { "after": false }, "for": { "after": false }, "while": { "after": false } } }
option:
/*eslint keyword-spacing: ["error", { "overrides": {
"if": { "after": false },
"for": { "after": false },
"while": { "after": false }
} }]*/
if(foo) {
//...
} else if(bar) {
//...
} else {
//...
}
for(;;);
while(true) {
//...
}
When Not To Use It
If you don't want to enforce consistency on keyword spacing, then it's safe to disable this rule. Source: http://eslint.org/docs/rules/
A function with a name starting with an uppercase letter should only be used as a constructor. Open
commonErrors.InvalidOption(
- Read upRead up
- Exclude checks
require constructor names to begin with a capital letter (new-cap)
The new
operator in JavaScript creates a new instance of a particular type of object. That type of object is represented by a constructor function. Since constructor functions are just regular functions, the only defining characteristic is that new
is being used as part of the call. Native JavaScript functions begin with an uppercase letter to distinguish those functions that are to be used as constructors from functions that are not. Many style guides recommend following this pattern to more easily determine which functions are to be used as constructors.
var friend = new Person();
Rule Details
This rule requires constructor names to begin with a capital letter. Certain built-in identifiers are exempt from this rule. These identifiers are:
Array
Boolean
Date
Error
Function
Number
Object
RegExp
String
Symbol
Examples of correct code for this rule:
/*eslint new-cap: "error"*/
function foo(arg) {
return Boolean(arg);
}
Options
This rule has an object option:
-
"newIsCap": true
(default) requires allnew
operators to be called with uppercase-started functions. -
"newIsCap": false
allowsnew
operators to be called with lowercase-started or uppercase-started functions. -
"capIsNew": true
(default) requires all uppercase-started functions to be called withnew
operators. -
"capIsNew": false
allows uppercase-started functions to be called withoutnew
operators. -
"newIsCapExceptions"
allows specified lowercase-started function names to be called with thenew
operator. -
"newIsCapExceptionPattern"
allows any lowercase-started function names that match the specified regex pattern to be called with thenew
operator. -
"capIsNewExceptions"
allows specified uppercase-started function names to be called without thenew
operator. -
"capIsNewExceptionPattern"
allows any uppercase-started function names that match the specified regex pattern to be called without thenew
operator. -
"properties": true
(default) enables checks on object properties -
"properties": false
disables checks on object properties
newIsCap
Examples of incorrect code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new person();
Examples of correct code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new Person();
Examples of correct code for this rule with the { "newIsCap": false }
option:
/*eslint new-cap: ["error", { "newIsCap": false }]*/
var friend = new person();
capIsNew
Examples of incorrect code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = Person();
Examples of correct code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = new Person();
Examples of correct code for this rule with the { "capIsNew": false }
option:
/*eslint new-cap: ["error", { "capIsNew": false }]*/
var colleague = Person();
newIsCapExceptions
Examples of additional correct code for this rule with the { "newIsCapExceptions": ["events"] }
option:
/*eslint new-cap: ["error", { "newIsCapExceptions": ["events"] }]*/
var events = require('events');
var emitter = new events();
newIsCapExceptionPattern
Examples of additional correct code for this rule with the { "newIsCapExceptionPattern": "^person\.." }
option:
/*eslint new-cap: ["error", { "newIsCapExceptionPattern": "^person\.." }]*/
var friend = new person.acquaintance();
var bestFriend = new person.friend();
capIsNewExceptions
Examples of additional correct code for this rule with the { "capIsNewExceptions": ["Person"] }
option:
/*eslint new-cap: ["error", { "capIsNewExceptions": ["Person"] }]*/
function foo(arg) {
return Person(arg);
}
capIsNewExceptionPattern
Examples of additional correct code for this rule with the { "capIsNewExceptionPattern": "^Person\.." }
option:
/*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^Person\.." }]*/
var friend = person.Acquaintance();
var bestFriend = person.Friend();
properties
Examples of incorrect code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.acquaintance();
Examples of correct code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.Acquaintance();
Examples of correct code for this rule with the { "properties": false }
option:
/*eslint new-cap: ["error", { "properties": false }]*/
var friend = new person.acquaintance();
When Not To Use It
If you have conventions that don't require an uppercase letter for constructors, or don't require capitalized functions be only used as constructors, turn this rule off. Source: http://eslint.org/docs/rules/
A function with a name starting with an uppercase letter should only be used as a constructor. Open
commonErrors.InvalidOption(
- Read upRead up
- Exclude checks
require constructor names to begin with a capital letter (new-cap)
The new
operator in JavaScript creates a new instance of a particular type of object. That type of object is represented by a constructor function. Since constructor functions are just regular functions, the only defining characteristic is that new
is being used as part of the call. Native JavaScript functions begin with an uppercase letter to distinguish those functions that are to be used as constructors from functions that are not. Many style guides recommend following this pattern to more easily determine which functions are to be used as constructors.
var friend = new Person();
Rule Details
This rule requires constructor names to begin with a capital letter. Certain built-in identifiers are exempt from this rule. These identifiers are:
Array
Boolean
Date
Error
Function
Number
Object
RegExp
String
Symbol
Examples of correct code for this rule:
/*eslint new-cap: "error"*/
function foo(arg) {
return Boolean(arg);
}
Options
This rule has an object option:
-
"newIsCap": true
(default) requires allnew
operators to be called with uppercase-started functions. -
"newIsCap": false
allowsnew
operators to be called with lowercase-started or uppercase-started functions. -
"capIsNew": true
(default) requires all uppercase-started functions to be called withnew
operators. -
"capIsNew": false
allows uppercase-started functions to be called withoutnew
operators. -
"newIsCapExceptions"
allows specified lowercase-started function names to be called with thenew
operator. -
"newIsCapExceptionPattern"
allows any lowercase-started function names that match the specified regex pattern to be called with thenew
operator. -
"capIsNewExceptions"
allows specified uppercase-started function names to be called without thenew
operator. -
"capIsNewExceptionPattern"
allows any uppercase-started function names that match the specified regex pattern to be called without thenew
operator. -
"properties": true
(default) enables checks on object properties -
"properties": false
disables checks on object properties
newIsCap
Examples of incorrect code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new person();
Examples of correct code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new Person();
Examples of correct code for this rule with the { "newIsCap": false }
option:
/*eslint new-cap: ["error", { "newIsCap": false }]*/
var friend = new person();
capIsNew
Examples of incorrect code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = Person();
Examples of correct code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = new Person();
Examples of correct code for this rule with the { "capIsNew": false }
option:
/*eslint new-cap: ["error", { "capIsNew": false }]*/
var colleague = Person();
newIsCapExceptions
Examples of additional correct code for this rule with the { "newIsCapExceptions": ["events"] }
option:
/*eslint new-cap: ["error", { "newIsCapExceptions": ["events"] }]*/
var events = require('events');
var emitter = new events();
newIsCapExceptionPattern
Examples of additional correct code for this rule with the { "newIsCapExceptionPattern": "^person\.." }
option:
/*eslint new-cap: ["error", { "newIsCapExceptionPattern": "^person\.." }]*/
var friend = new person.acquaintance();
var bestFriend = new person.friend();
capIsNewExceptions
Examples of additional correct code for this rule with the { "capIsNewExceptions": ["Person"] }
option:
/*eslint new-cap: ["error", { "capIsNewExceptions": ["Person"] }]*/
function foo(arg) {
return Person(arg);
}
capIsNewExceptionPattern
Examples of additional correct code for this rule with the { "capIsNewExceptionPattern": "^Person\.." }
option:
/*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^Person\.." }]*/
var friend = person.Acquaintance();
var bestFriend = person.Friend();
properties
Examples of incorrect code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.acquaintance();
Examples of correct code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.Acquaintance();
Examples of correct code for this rule with the { "properties": false }
option:
/*eslint new-cap: ["error", { "properties": false }]*/
var friend = new person.acquaintance();
When Not To Use It
If you have conventions that don't require an uppercase letter for constructors, or don't require capitalized functions be only used as constructors, turn this rule off. Source: http://eslint.org/docs/rules/
A function with a name starting with an uppercase letter should only be used as a constructor. Open
commonErrors.InvalidOption(
- Read upRead up
- Exclude checks
require constructor names to begin with a capital letter (new-cap)
The new
operator in JavaScript creates a new instance of a particular type of object. That type of object is represented by a constructor function. Since constructor functions are just regular functions, the only defining characteristic is that new
is being used as part of the call. Native JavaScript functions begin with an uppercase letter to distinguish those functions that are to be used as constructors from functions that are not. Many style guides recommend following this pattern to more easily determine which functions are to be used as constructors.
var friend = new Person();
Rule Details
This rule requires constructor names to begin with a capital letter. Certain built-in identifiers are exempt from this rule. These identifiers are:
Array
Boolean
Date
Error
Function
Number
Object
RegExp
String
Symbol
Examples of correct code for this rule:
/*eslint new-cap: "error"*/
function foo(arg) {
return Boolean(arg);
}
Options
This rule has an object option:
-
"newIsCap": true
(default) requires allnew
operators to be called with uppercase-started functions. -
"newIsCap": false
allowsnew
operators to be called with lowercase-started or uppercase-started functions. -
"capIsNew": true
(default) requires all uppercase-started functions to be called withnew
operators. -
"capIsNew": false
allows uppercase-started functions to be called withoutnew
operators. -
"newIsCapExceptions"
allows specified lowercase-started function names to be called with thenew
operator. -
"newIsCapExceptionPattern"
allows any lowercase-started function names that match the specified regex pattern to be called with thenew
operator. -
"capIsNewExceptions"
allows specified uppercase-started function names to be called without thenew
operator. -
"capIsNewExceptionPattern"
allows any uppercase-started function names that match the specified regex pattern to be called without thenew
operator. -
"properties": true
(default) enables checks on object properties -
"properties": false
disables checks on object properties
newIsCap
Examples of incorrect code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new person();
Examples of correct code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new Person();
Examples of correct code for this rule with the { "newIsCap": false }
option:
/*eslint new-cap: ["error", { "newIsCap": false }]*/
var friend = new person();
capIsNew
Examples of incorrect code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = Person();
Examples of correct code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = new Person();
Examples of correct code for this rule with the { "capIsNew": false }
option:
/*eslint new-cap: ["error", { "capIsNew": false }]*/
var colleague = Person();
newIsCapExceptions
Examples of additional correct code for this rule with the { "newIsCapExceptions": ["events"] }
option:
/*eslint new-cap: ["error", { "newIsCapExceptions": ["events"] }]*/
var events = require('events');
var emitter = new events();
newIsCapExceptionPattern
Examples of additional correct code for this rule with the { "newIsCapExceptionPattern": "^person\.." }
option:
/*eslint new-cap: ["error", { "newIsCapExceptionPattern": "^person\.." }]*/
var friend = new person.acquaintance();
var bestFriend = new person.friend();
capIsNewExceptions
Examples of additional correct code for this rule with the { "capIsNewExceptions": ["Person"] }
option:
/*eslint new-cap: ["error", { "capIsNewExceptions": ["Person"] }]*/
function foo(arg) {
return Person(arg);
}
capIsNewExceptionPattern
Examples of additional correct code for this rule with the { "capIsNewExceptionPattern": "^Person\.." }
option:
/*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^Person\.." }]*/
var friend = person.Acquaintance();
var bestFriend = person.Friend();
properties
Examples of incorrect code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.acquaintance();
Examples of correct code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.Acquaintance();
Examples of correct code for this rule with the { "properties": false }
option:
/*eslint new-cap: ["error", { "properties": false }]*/
var friend = new person.acquaintance();
When Not To Use It
If you have conventions that don't require an uppercase letter for constructors, or don't require capitalized functions be only used as constructors, turn this rule off. Source: http://eslint.org/docs/rules/
A function with a name starting with an uppercase letter should only be used as a constructor. Open
commonErrors.SystemError(
- Read upRead up
- Exclude checks
require constructor names to begin with a capital letter (new-cap)
The new
operator in JavaScript creates a new instance of a particular type of object. That type of object is represented by a constructor function. Since constructor functions are just regular functions, the only defining characteristic is that new
is being used as part of the call. Native JavaScript functions begin with an uppercase letter to distinguish those functions that are to be used as constructors from functions that are not. Many style guides recommend following this pattern to more easily determine which functions are to be used as constructors.
var friend = new Person();
Rule Details
This rule requires constructor names to begin with a capital letter. Certain built-in identifiers are exempt from this rule. These identifiers are:
Array
Boolean
Date
Error
Function
Number
Object
RegExp
String
Symbol
Examples of correct code for this rule:
/*eslint new-cap: "error"*/
function foo(arg) {
return Boolean(arg);
}
Options
This rule has an object option:
-
"newIsCap": true
(default) requires allnew
operators to be called with uppercase-started functions. -
"newIsCap": false
allowsnew
operators to be called with lowercase-started or uppercase-started functions. -
"capIsNew": true
(default) requires all uppercase-started functions to be called withnew
operators. -
"capIsNew": false
allows uppercase-started functions to be called withoutnew
operators. -
"newIsCapExceptions"
allows specified lowercase-started function names to be called with thenew
operator. -
"newIsCapExceptionPattern"
allows any lowercase-started function names that match the specified regex pattern to be called with thenew
operator. -
"capIsNewExceptions"
allows specified uppercase-started function names to be called without thenew
operator. -
"capIsNewExceptionPattern"
allows any uppercase-started function names that match the specified regex pattern to be called without thenew
operator. -
"properties": true
(default) enables checks on object properties -
"properties": false
disables checks on object properties
newIsCap
Examples of incorrect code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new person();
Examples of correct code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new Person();
Examples of correct code for this rule with the { "newIsCap": false }
option:
/*eslint new-cap: ["error", { "newIsCap": false }]*/
var friend = new person();
capIsNew
Examples of incorrect code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = Person();
Examples of correct code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = new Person();
Examples of correct code for this rule with the { "capIsNew": false }
option:
/*eslint new-cap: ["error", { "capIsNew": false }]*/
var colleague = Person();
newIsCapExceptions
Examples of additional correct code for this rule with the { "newIsCapExceptions": ["events"] }
option:
/*eslint new-cap: ["error", { "newIsCapExceptions": ["events"] }]*/
var events = require('events');
var emitter = new events();
newIsCapExceptionPattern
Examples of additional correct code for this rule with the { "newIsCapExceptionPattern": "^person\.." }
option:
/*eslint new-cap: ["error", { "newIsCapExceptionPattern": "^person\.." }]*/
var friend = new person.acquaintance();
var bestFriend = new person.friend();
capIsNewExceptions
Examples of additional correct code for this rule with the { "capIsNewExceptions": ["Person"] }
option:
/*eslint new-cap: ["error", { "capIsNewExceptions": ["Person"] }]*/
function foo(arg) {
return Person(arg);
}
capIsNewExceptionPattern
Examples of additional correct code for this rule with the { "capIsNewExceptionPattern": "^Person\.." }
option:
/*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^Person\.." }]*/
var friend = person.Acquaintance();
var bestFriend = person.Friend();
properties
Examples of incorrect code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.acquaintance();
Examples of correct code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.Acquaintance();
Examples of correct code for this rule with the { "properties": false }
option:
/*eslint new-cap: ["error", { "properties": false }]*/
var friend = new person.acquaintance();
When Not To Use It
If you have conventions that don't require an uppercase letter for constructors, or don't require capitalized functions be only used as constructors, turn this rule off. Source: http://eslint.org/docs/rules/
A function with a name starting with an uppercase letter should only be used as a constructor. Open
commonErrors.InvalidOption(
- Read upRead up
- Exclude checks
require constructor names to begin with a capital letter (new-cap)
The new
operator in JavaScript creates a new instance of a particular type of object. That type of object is represented by a constructor function. Since constructor functions are just regular functions, the only defining characteristic is that new
is being used as part of the call. Native JavaScript functions begin with an uppercase letter to distinguish those functions that are to be used as constructors from functions that are not. Many style guides recommend following this pattern to more easily determine which functions are to be used as constructors.
var friend = new Person();
Rule Details
This rule requires constructor names to begin with a capital letter. Certain built-in identifiers are exempt from this rule. These identifiers are:
Array
Boolean
Date
Error
Function
Number
Object
RegExp
String
Symbol
Examples of correct code for this rule:
/*eslint new-cap: "error"*/
function foo(arg) {
return Boolean(arg);
}
Options
This rule has an object option:
-
"newIsCap": true
(default) requires allnew
operators to be called with uppercase-started functions. -
"newIsCap": false
allowsnew
operators to be called with lowercase-started or uppercase-started functions. -
"capIsNew": true
(default) requires all uppercase-started functions to be called withnew
operators. -
"capIsNew": false
allows uppercase-started functions to be called withoutnew
operators. -
"newIsCapExceptions"
allows specified lowercase-started function names to be called with thenew
operator. -
"newIsCapExceptionPattern"
allows any lowercase-started function names that match the specified regex pattern to be called with thenew
operator. -
"capIsNewExceptions"
allows specified uppercase-started function names to be called without thenew
operator. -
"capIsNewExceptionPattern"
allows any uppercase-started function names that match the specified regex pattern to be called without thenew
operator. -
"properties": true
(default) enables checks on object properties -
"properties": false
disables checks on object properties
newIsCap
Examples of incorrect code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new person();
Examples of correct code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new Person();
Examples of correct code for this rule with the { "newIsCap": false }
option:
/*eslint new-cap: ["error", { "newIsCap": false }]*/
var friend = new person();
capIsNew
Examples of incorrect code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = Person();
Examples of correct code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = new Person();
Examples of correct code for this rule with the { "capIsNew": false }
option:
/*eslint new-cap: ["error", { "capIsNew": false }]*/
var colleague = Person();
newIsCapExceptions
Examples of additional correct code for this rule with the { "newIsCapExceptions": ["events"] }
option:
/*eslint new-cap: ["error", { "newIsCapExceptions": ["events"] }]*/
var events = require('events');
var emitter = new events();
newIsCapExceptionPattern
Examples of additional correct code for this rule with the { "newIsCapExceptionPattern": "^person\.." }
option:
/*eslint new-cap: ["error", { "newIsCapExceptionPattern": "^person\.." }]*/
var friend = new person.acquaintance();
var bestFriend = new person.friend();
capIsNewExceptions
Examples of additional correct code for this rule with the { "capIsNewExceptions": ["Person"] }
option:
/*eslint new-cap: ["error", { "capIsNewExceptions": ["Person"] }]*/
function foo(arg) {
return Person(arg);
}
capIsNewExceptionPattern
Examples of additional correct code for this rule with the { "capIsNewExceptionPattern": "^Person\.." }
option:
/*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^Person\.." }]*/
var friend = person.Acquaintance();
var bestFriend = person.Friend();
properties
Examples of incorrect code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.acquaintance();
Examples of correct code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.Acquaintance();
Examples of correct code for this rule with the { "properties": false }
option:
/*eslint new-cap: ["error", { "properties": false }]*/
var friend = new person.acquaintance();
When Not To Use It
If you have conventions that don't require an uppercase letter for constructors, or don't require capitalized functions be only used as constructors, turn this rule off. Source: http://eslint.org/docs/rules/
A function with a name starting with an uppercase letter should only be used as a constructor. Open
commonErrors.SystemError(
- Read upRead up
- Exclude checks
require constructor names to begin with a capital letter (new-cap)
The new
operator in JavaScript creates a new instance of a particular type of object. That type of object is represented by a constructor function. Since constructor functions are just regular functions, the only defining characteristic is that new
is being used as part of the call. Native JavaScript functions begin with an uppercase letter to distinguish those functions that are to be used as constructors from functions that are not. Many style guides recommend following this pattern to more easily determine which functions are to be used as constructors.
var friend = new Person();
Rule Details
This rule requires constructor names to begin with a capital letter. Certain built-in identifiers are exempt from this rule. These identifiers are:
Array
Boolean
Date
Error
Function
Number
Object
RegExp
String
Symbol
Examples of correct code for this rule:
/*eslint new-cap: "error"*/
function foo(arg) {
return Boolean(arg);
}
Options
This rule has an object option:
-
"newIsCap": true
(default) requires allnew
operators to be called with uppercase-started functions. -
"newIsCap": false
allowsnew
operators to be called with lowercase-started or uppercase-started functions. -
"capIsNew": true
(default) requires all uppercase-started functions to be called withnew
operators. -
"capIsNew": false
allows uppercase-started functions to be called withoutnew
operators. -
"newIsCapExceptions"
allows specified lowercase-started function names to be called with thenew
operator. -
"newIsCapExceptionPattern"
allows any lowercase-started function names that match the specified regex pattern to be called with thenew
operator. -
"capIsNewExceptions"
allows specified uppercase-started function names to be called without thenew
operator. -
"capIsNewExceptionPattern"
allows any uppercase-started function names that match the specified regex pattern to be called without thenew
operator. -
"properties": true
(default) enables checks on object properties -
"properties": false
disables checks on object properties
newIsCap
Examples of incorrect code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new person();
Examples of correct code for this rule with the default { "newIsCap": true }
option:
/*eslint new-cap: ["error", { "newIsCap": true }]*/
var friend = new Person();
Examples of correct code for this rule with the { "newIsCap": false }
option:
/*eslint new-cap: ["error", { "newIsCap": false }]*/
var friend = new person();
capIsNew
Examples of incorrect code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = Person();
Examples of correct code for this rule with the default { "capIsNew": true }
option:
/*eslint new-cap: ["error", { "capIsNew": true }]*/
var colleague = new Person();
Examples of correct code for this rule with the { "capIsNew": false }
option:
/*eslint new-cap: ["error", { "capIsNew": false }]*/
var colleague = Person();
newIsCapExceptions
Examples of additional correct code for this rule with the { "newIsCapExceptions": ["events"] }
option:
/*eslint new-cap: ["error", { "newIsCapExceptions": ["events"] }]*/
var events = require('events');
var emitter = new events();
newIsCapExceptionPattern
Examples of additional correct code for this rule with the { "newIsCapExceptionPattern": "^person\.." }
option:
/*eslint new-cap: ["error", { "newIsCapExceptionPattern": "^person\.." }]*/
var friend = new person.acquaintance();
var bestFriend = new person.friend();
capIsNewExceptions
Examples of additional correct code for this rule with the { "capIsNewExceptions": ["Person"] }
option:
/*eslint new-cap: ["error", { "capIsNewExceptions": ["Person"] }]*/
function foo(arg) {
return Person(arg);
}
capIsNewExceptionPattern
Examples of additional correct code for this rule with the { "capIsNewExceptionPattern": "^Person\.." }
option:
/*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^Person\.." }]*/
var friend = person.Acquaintance();
var bestFriend = person.Friend();
properties
Examples of incorrect code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.acquaintance();
Examples of correct code for this rule with the default { "properties": true }
option:
/*eslint new-cap: ["error", { "properties": true }]*/
var friend = new person.Acquaintance();
Examples of correct code for this rule with the { "properties": false }
option:
/*eslint new-cap: ["error", { "properties": false }]*/
var friend = new person.acquaintance();
When Not To Use It
If you have conventions that don't require an uppercase letter for constructors, or don't require capitalized functions be only used as constructors, turn this rule off. Source: http://eslint.org/docs/rules/
Expected space(s) after "throw". Open
throw(
- Read upRead up
- Exclude checks
enforce consistent spacing before and after keywords (keyword-spacing)
Keywords are syntax elements of JavaScript, such as function
and if
.
These identifiers have special meaning to the language and so often appear in a different color in code editors.
As an important part of the language, style guides often refer to the spacing that should be used around keywords.
For example, you might have a style guide that says keywords should be always surrounded by spaces, which would mean if-else
statements must look like this:
if (foo) {
// ...
} else {
// ...
}
Of course, you could also have a style guide that disallows spaces around keywords.
Rule Details
This rule enforces consistent spacing around keywords and keyword-like tokens: as
(in module declarations), async
(of async functions), await
(of await expressions), break
, case
, catch
, class
, const
, continue
, debugger
, default
, delete
, do
, else
, export
, extends
, finally
, for
, from
(in module declarations), function
, get
(of getters), if
, import
, in
, instanceof
, let
, new
, of
(in for-of statements), return
, set
(of setters), static
, super
, switch
, this
, throw
, try
, typeof
, var
, void
, while
, with
, and yield
. This rule is designed carefully not to conflict with other spacing rules: it does not apply to spacing where other rules report problems.
Options
This rule has an object option:
-
"before": true
(default) requires at least one space before keywords -
"before": false
disallows spaces before keywords -
"after": true
(default) requires at least one space after keywords -
"after": false
disallows spaces after keywords -
"overrides"
allows overriding spacing style for specified keywords
before
Examples of incorrect code for this rule with the default { "before": true }
option:
/*eslint keyword-spacing: ["error", { "before": true }]*/
if (foo) {
//...
}else if (bar) {
//...
}else {
//...
}
Examples of correct code for this rule with the default { "before": true }
option:
/*eslint keyword-spacing: ["error", { "before": true }]*/
/*eslint-env es6*/
if (foo) {
//...
} else if (bar) {
//...
} else {
//...
}
// no conflict with `array-bracket-spacing`
let a = [this];
let b = [function() {}];
// no conflict with `arrow-spacing`
let a = ()=> this.foo;
// no conflict with `block-spacing`
{function foo() {}}
// no conflict with `comma-spacing`
let a = [100,this.foo, this.bar];
// not conflict with `computed-property-spacing`
obj[this.foo] = 0;
// no conflict with `generator-star-spacing`
function *foo() {}
// no conflict with `key-spacing`
let obj = {
foo:function() {}
};
// no conflict with `object-curly-spacing`
let obj = {foo: this};
// no conflict with `semi-spacing`
let a = this;function foo() {}
// no conflict with `space-in-parens`
(function () {})();
// no conflict with `space-infix-ops`
if ("foo"in {foo: 0}) {}
if (10+this.foo<= this.bar) {}
// no conflict with `jsx-curly-spacing`
let a =
Examples of incorrect code for this rule with the { "before": false }
option:
/*eslint keyword-spacing: ["error", { "before": false }]*/
if (foo) {
//...
} else if (bar) {
//...
} else {
//...
}
Examples of correct code for this rule with the { "before": false }
option:
/*eslint keyword-spacing: ["error", { "before": false }]*/
if (foo) {
//...
}else if (bar) {
//...
}else {
//...
}
after
Examples of incorrect code for this rule with the default { "after": true }
option:
/*eslint keyword-spacing: ["error", { "after": true }]*/
if(foo) {
//...
} else if(bar) {
//...
} else{
//...
}
Examples of correct code for this rule with the default { "after": true }
option:
/*eslint keyword-spacing: ["error", { "after": true }]*/
if (foo) {
//...
} else if (bar) {
//...
} else {
//...
}
// not conflict with `array-bracket-spacing`
let a = [this];
// not conflict with `arrow-spacing`
let a = ()=> this.foo;
// not conflict with `comma-spacing`
let a = [100, this.foo, this.bar];
// not conflict with `computed-property-spacing`
obj[this.foo] = 0;
// not conflict with `generator-star-spacing`
function* foo() {}
// not conflict with `key-spacing`
let obj = {
foo:function() {}
};
// not conflict with `func-call-spacing`
class A {
constructor() {
super();
}
}
// not conflict with `object-curly-spacing`
let obj = {foo: this};
// not conflict with `semi-spacing`
let a = this;function foo() {}
// not conflict with `space-before-function-paren`
function() {}
// no conflict with `space-infix-ops`
if ("foo"in{foo: 0}) {}
if (10+this.foo<= this.bar) {}
// no conflict with `space-unary-ops`
function* foo(a) {
return yield+a;
}
// no conflict with `yield-star-spacing`
function* foo(a) {
return yield* a;
}
// no conflict with `jsx-curly-spacing`
let a =
Examples of incorrect code for this rule with the { "after": false }
option:
/*eslint keyword-spacing: ["error", { "after": false }]*/
if (foo) {
//...
} else if (bar) {
//...
} else {
//...
}
Examples of correct code for this rule with the { "after": false }
option:
/*eslint keyword-spacing: ["error", { "after": false }]*/
if(foo) {
//...
} else if(bar) {
//...
} else{
//...
}
overrides
Examples of correct code for this rule with the { "overrides": { "if": { "after": false }, "for": { "after": false }, "while": { "after": false } } }
option:
/*eslint keyword-spacing: ["error", { "overrides": {
"if": { "after": false },
"for": { "after": false },
"while": { "after": false }
} }]*/
if(foo) {
//...
} else if(bar) {
//...
} else {
//...
}
for(;;);
while(true) {
//...
}
When Not To Use It
If you don't want to enforce consistency on keyword spacing, then it's safe to disable this rule. Source: http://eslint.org/docs/rules/