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"
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"
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"
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"
Very long lines of code in any language can be difficult to read. In order to aid in readability and maintainability many coders have developed a convention to limit lines of code to X number of characters (traditionally 80 characters).
var foo ={"bar":"This is a bar.","baz":{"qux":"This is a qux"},"difficult":"to read"};// very long
Rule Details
This rule enforces a maximum line length to increase code readability and maintainability. The length of a line is defined as the number of Unicode characters in the line.
Options
This rule has a number or object option:
"code" (default 80) enforces a maximum line length
"tabWidth" (default 4) specifies the character width for tab characters
"comments" enforces a maximum line length for comments; defaults to value of code
"ignorePattern" ignores lines matching a regular expression; can only match a single line and need to be double escaped when written in YAML or JSON
"ignoreComments": true ignores all trailing comments and comments on their own line
"ignoreTrailingComments": true ignores only trailing comments
"ignoreUrls": true ignores lines that contain a URL
"ignoreStrings": true ignores lines that contain a double-quoted or single-quoted string
"ignoreTemplateLiterals": true ignores lines that contain a template literal
"ignoreRegExpLiterals": true ignores lines that contain a RegExp literal
code
Examples of incorrect code for this rule with the default { "code": 80 } option:
/*eslint max-len: ["error", 80]*/
var foo ={"bar":"This is a bar.","baz":{"qux":"This is a qux"},"difficult":"to read"};
Examples of correct code for this rule with the default { "code": 80 } option:
/*eslint max-len: ["error", 80]*/
var foo ={
"bar":"This is a bar.",
"baz":{"qux":"This is a qux"},
"easier":"to read"
};
tabWidth
Examples of incorrect code for this rule with the default { "tabWidth": 4 } option:
/*eslint max-len: ["error", 80, 4]*/
\t \t var foo ={"bar":"This is a bar.","baz":{"qux":"This is a qux"}};
Examples of correct code for this rule with the default { "tabWidth": 4 } option:
/*eslint max-len: ["error", 80, 4]*/
\t \t var foo ={
\t \t \t \t "bar":"This is a bar.",
\t \t \t \t "baz":{"qux":"This is a qux"}
\t \t };
comments
Examples of incorrect code for this rule with the { "comments": 65 } option:
/*eslint max-len: ["error", { "comments": 65 }]*/
/**
* This is a comment that violates the maximum line length we have specified
**/
ignoreComments
Examples of correct code for this rule with the { "ignoreComments": true } option:
Very long lines of code in any language can be difficult to read. In order to aid in readability and maintainability many coders have developed a convention to limit lines of code to X number of characters (traditionally 80 characters).
var foo ={"bar":"This is a bar.","baz":{"qux":"This is a qux"},"difficult":"to read"};// very long
Rule Details
This rule enforces a maximum line length to increase code readability and maintainability. The length of a line is defined as the number of Unicode characters in the line.
Options
This rule has a number or object option:
"code" (default 80) enforces a maximum line length
"tabWidth" (default 4) specifies the character width for tab characters
"comments" enforces a maximum line length for comments; defaults to value of code
"ignorePattern" ignores lines matching a regular expression; can only match a single line and need to be double escaped when written in YAML or JSON
"ignoreComments": true ignores all trailing comments and comments on their own line
"ignoreTrailingComments": true ignores only trailing comments
"ignoreUrls": true ignores lines that contain a URL
"ignoreStrings": true ignores lines that contain a double-quoted or single-quoted string
"ignoreTemplateLiterals": true ignores lines that contain a template literal
"ignoreRegExpLiterals": true ignores lines that contain a RegExp literal
code
Examples of incorrect code for this rule with the default { "code": 80 } option:
/*eslint max-len: ["error", 80]*/
var foo ={"bar":"This is a bar.","baz":{"qux":"This is a qux"},"difficult":"to read"};
Examples of correct code for this rule with the default { "code": 80 } option:
/*eslint max-len: ["error", 80]*/
var foo ={
"bar":"This is a bar.",
"baz":{"qux":"This is a qux"},
"easier":"to read"
};
tabWidth
Examples of incorrect code for this rule with the default { "tabWidth": 4 } option:
/*eslint max-len: ["error", 80, 4]*/
\t \t var foo ={"bar":"This is a bar.","baz":{"qux":"This is a qux"}};
Examples of correct code for this rule with the default { "tabWidth": 4 } option:
/*eslint max-len: ["error", 80, 4]*/
\t \t var foo ={
\t \t \t \t "bar":"This is a bar.",
\t \t \t \t "baz":{"qux":"This is a qux"}
\t \t };
comments
Examples of incorrect code for this rule with the { "comments": 65 } option:
/*eslint max-len: ["error", { "comments": 65 }]*/
/**
* This is a comment that violates the maximum line length we have specified
**/
ignoreComments
Examples of correct code for this rule with the { "ignoreComments": true } option:
Very long lines of code in any language can be difficult to read. In order to aid in readability and maintainability many coders have developed a convention to limit lines of code to X number of characters (traditionally 80 characters).
var foo ={"bar":"This is a bar.","baz":{"qux":"This is a qux"},"difficult":"to read"};// very long
Rule Details
This rule enforces a maximum line length to increase code readability and maintainability. The length of a line is defined as the number of Unicode characters in the line.
Options
This rule has a number or object option:
"code" (default 80) enforces a maximum line length
"tabWidth" (default 4) specifies the character width for tab characters
"comments" enforces a maximum line length for comments; defaults to value of code
"ignorePattern" ignores lines matching a regular expression; can only match a single line and need to be double escaped when written in YAML or JSON
"ignoreComments": true ignores all trailing comments and comments on their own line
"ignoreTrailingComments": true ignores only trailing comments
"ignoreUrls": true ignores lines that contain a URL
"ignoreStrings": true ignores lines that contain a double-quoted or single-quoted string
"ignoreTemplateLiterals": true ignores lines that contain a template literal
"ignoreRegExpLiterals": true ignores lines that contain a RegExp literal
code
Examples of incorrect code for this rule with the default { "code": 80 } option:
/*eslint max-len: ["error", 80]*/
var foo ={"bar":"This is a bar.","baz":{"qux":"This is a qux"},"difficult":"to read"};
Examples of correct code for this rule with the default { "code": 80 } option:
/*eslint max-len: ["error", 80]*/
var foo ={
"bar":"This is a bar.",
"baz":{"qux":"This is a qux"},
"easier":"to read"
};
tabWidth
Examples of incorrect code for this rule with the default { "tabWidth": 4 } option:
/*eslint max-len: ["error", 80, 4]*/
\t \t var foo ={"bar":"This is a bar.","baz":{"qux":"This is a qux"}};
Examples of correct code for this rule with the default { "tabWidth": 4 } option:
/*eslint max-len: ["error", 80, 4]*/
\t \t var foo ={
\t \t \t \t "bar":"This is a bar.",
\t \t \t \t "baz":{"qux":"This is a qux"}
\t \t };
comments
Examples of incorrect code for this rule with the { "comments": 65 } option:
/*eslint max-len: ["error", { "comments": 65 }]*/
/**
* This is a comment that violates the maximum line length we have specified
**/
ignoreComments
Examples of correct code for this rule with the { "ignoreComments": true } option:
Very long lines of code in any language can be difficult to read. In order to aid in readability and maintainability many coders have developed a convention to limit lines of code to X number of characters (traditionally 80 characters).
var foo ={"bar":"This is a bar.","baz":{"qux":"This is a qux"},"difficult":"to read"};// very long
Rule Details
This rule enforces a maximum line length to increase code readability and maintainability. The length of a line is defined as the number of Unicode characters in the line.
Options
This rule has a number or object option:
"code" (default 80) enforces a maximum line length
"tabWidth" (default 4) specifies the character width for tab characters
"comments" enforces a maximum line length for comments; defaults to value of code
"ignorePattern" ignores lines matching a regular expression; can only match a single line and need to be double escaped when written in YAML or JSON
"ignoreComments": true ignores all trailing comments and comments on their own line
"ignoreTrailingComments": true ignores only trailing comments
"ignoreUrls": true ignores lines that contain a URL
"ignoreStrings": true ignores lines that contain a double-quoted or single-quoted string
"ignoreTemplateLiterals": true ignores lines that contain a template literal
"ignoreRegExpLiterals": true ignores lines that contain a RegExp literal
code
Examples of incorrect code for this rule with the default { "code": 80 } option:
/*eslint max-len: ["error", 80]*/
var foo ={"bar":"This is a bar.","baz":{"qux":"This is a qux"},"difficult":"to read"};
Examples of correct code for this rule with the default { "code": 80 } option:
/*eslint max-len: ["error", 80]*/
var foo ={
"bar":"This is a bar.",
"baz":{"qux":"This is a qux"},
"easier":"to read"
};
tabWidth
Examples of incorrect code for this rule with the default { "tabWidth": 4 } option:
/*eslint max-len: ["error", 80, 4]*/
\t \t var foo ={"bar":"This is a bar.","baz":{"qux":"This is a qux"}};
Examples of correct code for this rule with the default { "tabWidth": 4 } option:
/*eslint max-len: ["error", 80, 4]*/
\t \t var foo ={
\t \t \t \t "bar":"This is a bar.",
\t \t \t \t "baz":{"qux":"This is a qux"}
\t \t };
comments
Examples of incorrect code for this rule with the { "comments": 65 } option:
/*eslint max-len: ["error", { "comments": 65 }]*/
/**
* This is a comment that violates the maximum line length we have specified
**/
ignoreComments
Examples of correct code for this rule with the { "ignoreComments": true } option: