kubosho/kotori

View on GitHub
src/config.js

Summary

Maintainability
A
1 hr
Test Coverage

Line 42 exceeds the maximum line length of 100.
Open

      const paths = `${PERSONAL_CONFIG_PATH} and ${path.resolve(process.cwd(), LOCAL_CONFIG_FILENAME)}`;
Severity: Minor
Found in src/config.js by eslint

enforce a maximum line length (max-len)

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:

/*eslint max-len: ["error", { "ignoreComments": true }]*/

/**
 * This is a really really really really really really really really really long comment
**/

ignoreTrailingComments

Examples of correct code for this rule with the { "ignoreTrailingComments": true } option:

/*eslint max-len: ["error", { "ignoreTrailingComments": true }]*/

var foo = 'bar'; // This is a really really really really really really really long comment

ignoreUrls

Examples of correct code for this rule with the { "ignoreUrls": true } option:

/*eslint max-len: ["error", { "ignoreUrls": true }]*/

var url = 'https://www.example.com/really/really/really/really/really/really/really/long';

ignoreStrings

Examples of correct code for this rule with the { "ignoreStrings": true } option:

/*eslint max-len: ["error", { "ignoreStrings": true }]*/

var longString = 'this is a really really really really really long string!';

ignoreTemplateLiterals

Examples of correct code for this rule with the { "ignoreTemplateLiterals": true } option:

/*eslint max-len: ["error", { "ignoreTemplateLiterals": true }]*/

var longTemplateLiteral = `this is a really really really really really long template literal!`;

ignoreRegExpLiterals

Examples of correct code for this rule with the { "ignoreRegExpLiterals": true } option:

/*eslint max-len: ["error", { "ignoreRegExpLiterals": true }]*/

var longRegExpLiteral = /this is a really really really really really long regular expression!/;

ignorePattern

Examples of correct code for this rule with the { "ignorePattern": true } option:

/*eslint max-len: ["error", { "ignorePattern": "^\\s*var\\s.+=\\s*require\\s*\\(/" }]*/

var dep = require('really/really/really/really/really/really/really/really/long/module');

Related Rules

  • [complexity](complexity.md)
  • [max-depth](max-depth.md)
  • [max-nested-callbacks](max-nested-callbacks.md)
  • [max-params](max-params.md)
  • [max-statements](max-statements.md) Source: http://eslint.org/docs/rules/

Function parseConfigCore has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

function parseConfigCore(configItem) {
  if (isObject(configItem) || isJSON(configItem)) {
    try {
      configItem = JSON.parse(configItem);
    } catch (err) {
Severity: Minor
Found in src/config.js - About 35 mins to fix

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 load has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  load() {
    let configLoadErrors = [];

    try {
      this.config = loadConfigCore(this.filePath);
Severity: Minor
Found in src/config.js - About 25 mins to fix

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

Expected line before comment.
Open

    // do nothing
Severity: Minor
Found in src/config.js by eslint

require empty lines around comments (lines-around-comment)

Many style guides require empty lines before or after comments. The primary goal of these rules is to make the comments easier to read and improve readability of the code.

Rule Details

This rule requires empty lines before and/or after comments. It can be enabled separately for both block (/*) and line (//) comments. This rule does not apply to comments that appear on the same line as code and does not require empty lines at the beginning or end of a file.

Options

This rule has an object option:

  • "beforeBlockComment": true (default) requires an empty line before block comments
  • "afterBlockComment": true requires an empty line after block comments
  • "beforeLineComment": true requires an empty line before line comments
  • "afterLineComment": true requires an empty line after line comments
  • "allowBlockStart": true allows comments to appear at the start of block statements
  • "allowBlockEnd": true allows comments to appear at the end of block statements
  • "allowObjectStart": true allows comments to appear at the start of object literals
  • "allowObjectEnd": true allows comments to appear at the end of object literals
  • "allowArrayStart": true allows comments to appear at the start of array literals
  • "allowArrayEnd": true allows comments to appear at the end of array literals
  • "applyDefaultIgnorePatterns" enables or disables the default comment patterns to be ignored by the rule
  • "ignorePattern" custom patterns to be ignored by the rule

beforeBlockComment

Examples of incorrect code for this rule with the default { "beforeBlockComment": true } option:

/*eslint lines-around-comment: ["error", { "beforeBlockComment": true }]*/

var night = "long";
/* what a great and wonderful day */
var day = "great"

Examples of correct code for this rule with the default { "beforeBlockComment": true } option:

/*eslint lines-around-comment: ["error", { "beforeBlockComment": true }]*/

var night = "long";

/* what a great and wonderful day */
var day = "great"

afterBlockComment

Examples of incorrect code for this rule with the { "afterBlockComment": true } option:

/*eslint lines-around-comment: ["error", { "afterBlockComment": true }]*/

var night = "long";

/* what a great and wonderful day */
var day = "great"

Examples of correct code for this rule with the { "afterBlockComment": true } option:

/*eslint lines-around-comment: ["error", { "afterBlockComment": true }]*/

var night = "long";

/* what a great and wonderful day */

var day = "great"

beforeLineComment

Examples of incorrect code for this rule with the { "beforeLineComment": true } option:

/*eslint lines-around-comment: ["error", { "beforeLineComment": true }]*/

var night = "long";
// what a great and wonderful day
var day = "great"

Examples of correct code for this rule with the { "beforeLineComment": true } option:

/*eslint lines-around-comment: ["error", { "beforeLineComment": true }]*/

var night = "long";

// what a great and wonderful day
var day = "great"

afterLineComment

Examples of incorrect code for this rule with the { "afterLineComment": true } option:

/*eslint lines-around-comment: ["error", { "afterLineComment": true }]*/

var night = "long";
// what a great and wonderful day
var day = "great"

Examples of correct code for this rule with the { "afterLineComment": true } option:

/*eslint lines-around-comment: ["error", { "afterLineComment": true }]*/

var night = "long";
// what a great and wonderful day

var day = "great"

allowBlockStart

Examples of correct code for this rule with the { "beforeLineComment": true, "allowBlockStart": true } options:

/*eslint lines-around-comment: ["error", { "beforeLineComment": true, "allowBlockStart": true }]*/

function foo(){
    // what a great and wonderful day
    var day = "great"
    return day;
}

Examples of correct code for this rule with the { "beforeBlockComment": true, "allowBlockStart": true } options:

/*eslint lines-around-comment: ["error", { "beforeBlockComment": true, "allowBlockStart": true }]*/

function foo(){
    /* what a great and wonderful day */
    var day = "great"
    return day;
}

allowBlockEnd

Examples of correct code for this rule with the { "afterLineComment": true, "allowBlockEnd": true } option:

/*eslint lines-around-comment: ["error", { "afterLineComment": true, "allowBlockEnd": true }]*/

function foo(){
    var day = "great"
    return day;
    // what a great and wonderful day
}

Examples of correct code for this rule with the { "afterBlockComment": true, "allowBlockEnd": true } option:

/*eslint lines-around-comment: ["error", { "afterBlockComment": true, "allowBlockEnd": true }]*/

function foo(){
    var day = "great"
    return day;

    /* what a great and wonderful day */
}

allowObjectStart

Examples of correct code for this rule with the { "beforeLineComment": true, "allowObjectStart": true } option:

/*eslint lines-around-comment: ["error", { "beforeLineComment": true, "allowObjectStart": true }]*/

var foo = {
    // what a great and wonderful day
    day: "great"
};

const {
    // what a great and wonderful day
    foo: someDay
} = {foo: "great"};

const {
    // what a great and wonderful day
    day
} = {day: "great"};

Examples of correct code for this rule with the { "beforeBlockComment": true, "allowObjectStart": true } option:

/*eslint lines-around-comment: ["error", { "beforeBlockComment": true, "allowObjectStart": true }]*/

var foo = {
    /* what a great and wonderful day */
    day: "great"
};

const {
    /* what a great and wonderful day */
    foo: someDay
} = {foo: "great"};

const {
    /* what a great and wonderful day */
    day
} = {day: "great"};

allowObjectEnd

Examples of correct code for this rule with the { "afterLineComment": true, "allowObjectEnd": true } option:

/*eslint lines-around-comment: ["error", { "afterLineComment": true, "allowObjectEnd": true }]*/

var foo = {
    day: "great"
    // what a great and wonderful day
};

const {
    foo: someDay
    // what a great and wonderful day
} = {foo: "great"};

const {
    day
    // what a great and wonderful day
} = {day: "great"};

Examples of correct code for this rule with the { "afterBlockComment": true, "allowObjectEnd": true } option:

/*eslint lines-around-comment: ["error", { "afterBlockComment": true, "allowObjectEnd": true }]*/

var foo = {
    day: "great"

    /* what a great and wonderful day */
};

const {
    foo: someDay

    /* what a great and wonderful day */
} = {foo: "great"};

const {
    day

    /* what a great and wonderful day */
} = {day: "great"};

allowArrayStart

Examples of correct code for this rule with the { "beforeLineComment": true, "allowArrayStart": true } option:

/*eslint lines-around-comment: ["error", { "beforeLineComment": true, "allowArrayStart": true }]*/

var day = [
    // what a great and wonderful day
    "great",
    "wonderful"
];

const [
    // what a great and wonderful day
    someDay
] = ["great", "not great"];

Examples of correct code for this rule with the { "beforeBlockComment": true, "allowArrayStart": true } option:

/*eslint lines-around-comment: ["error", { "beforeBlockComment": true, "allowArrayStart": true }]*/

var day = [
    /* what a great and wonderful day */
    "great",
    "wonderful"
];

const [
    /* what a great and wonderful day */
    someDay
] = ["great", "not great"];

allowArrayEnd

Examples of correct code for this rule with the { "afterLineComment": true, "allowArrayEnd": true } option:

/*eslint lines-around-comment: ["error", { "afterLineComment": true, "allowArrayEnd": true }]*/

var day = [
    "great",
    "wonderful"
    // what a great and wonderful day
];

const [
    someDay
    // what a great and wonderful day
] = ["great", "not great"];

Examples of correct code for this rule with the { "afterBlockComment": true, "allowArrayEnd": true } option:

/*eslint lines-around-comment: ["error", { "afterBlockComment": true, "allowArrayEnd": true }]*/

var day = [
    "great",
    "wonderful"

    /* what a great and wonderful day */
];

const [
    someDay

    /* what a great and wonderful day */
] = ["great", "not great"];

ignorePattern

By default this rule ignores comments starting with the following words: eslint, jshint, jslint, istanbul, global, exported, jscs. An alternative regular expression can be provided.

Examples of correct code for the ignorePattern option:

/*eslint lines-around-comment: ["error"]*/

foo();
/* eslint mentioned in this comment */,
bar();


/*eslint lines-around-comment: ["error", { "ignorePattern": "pragma" }] */

foo();
/* a valid comment using pragma in it */

Examples of incorrect code for the ignorePattern option:

/*eslint lines-around-comment: ["error", { "ignorePattern": "pragma" }] */

1 + 1;
/* something else */

applyDefaultIgnorePatterns

Default ignore patterns are applied even when ignorePattern is provided. If you want to omit default patterns, set this option to false.

Examples of correct code for the { "applyDefaultIgnorePatterns": false } option:

/*eslint lines-around-comment: ["error", { "ignorePattern": "pragma", applyDefaultIgnorePatterns: false }] */

foo();
/* a valid comment using pragma in it */

Examples of incorrect code for the { "applyDefaultIgnorePatterns": false } option:

/*eslint lines-around-comment: ["error", { "applyDefaultIgnorePatterns": false }] */

foo();
/* eslint mentioned in comment */

When Not To Use It

Many people enjoy a terser code style and don't mind comments bumping up against code. If you fall into that category this rule is not for you.

Related Rules

Identifier name 'LOCAL_CONFIG_FILENAME' is too long (> 16).
Open

const LOCAL_CONFIG_FILENAME = ".kotorirc";
Severity: Minor
Found in src/config.js by eslint

enforce minimum and maximum identifier lengths (id-length)

Very short identifier names like e, x, _t or very long ones like hashGeneratorResultOutputContainerObject can make code harder to read and potentially less maintainable. To prevent this, one may enforce a minimum and/or maximum identifier length.

var x = 5; // too short; difficult to understand its purpose without context

Rule Details

This rule enforces a minimum and/or maximum identifier length convention.

Options

Examples of incorrect code for this rule with the default options:

/*eslint id-length: "error"*/     // default is minimum 2-chars ({ "min": 2 })
/*eslint-env es6*/

var x = 5;
obj.e = document.body;
var foo = function (e) { };
try {
    dangerousStuff();
} catch (e) {
    // ignore as many do
}
var myObj = { a: 1 };
(a) => { a * a };
class x { }
class Foo { x() {} }
function foo(...x) { }
var { x } = {};
var { x: a} = {};
var { a: [x]} = {};
({ prop: obj.x }) = {};

Examples of correct code for this rule with the default options:

/*eslint id-length: "error"*/     // default is minimum 2-chars ({ "min": 2 })
/*eslint-env es6*/

var num = 5;
function _f() { return 42; }
function _func() { return 42; }
obj.el = document.body;
var foo = function (evt) { /* do stuff */ };
try {
    dangerousStuff();
} catch (error) {
    // ignore as many do
}
var myObj = { apple: 1 };
(num) => { num * num };
function foo(num = 0) { }
class MyClass { }
class Foo { method() {} }
function foo(...args) { }
var { prop } = {};
var { prop: a } = {};
var { prop: [x] } = {};
({ prop: obj.longName }) = {};
var data = { "x": 1 };  // excused because of quotes
data["y"] = 3;  // excused because of calculated property access

This rule has a shorthand integer option for the "min" object property.

Examples of incorrect code for this rule with a minimum of 4:

/*eslint id-length: ["error", 4]*/
/*eslint-env es6*/

var val = 5;
obj.e = document.body;
function (e) { };
try {
    dangerousStuff();
} catch (e) {
    // ignore as many do
}
var myObj = { a: 1 };
(val) => { val * val };
class x { }
class Foo { x() {} }
function foo(...x) { }
var { x } = {};
var { x: a} = {};
var { a: [x]} = {};
({ prop: obj.x }) = {};

Examples of correct code for this rule with a minimum of 4:

/*eslint id-length: ["error", 4]*/
/*eslint-env es6*/

var value = 5;
function func() { return 42; }
obj.element = document.body;
var foo = function (event) { /* do stuff */ };
try {
    dangerousStuff();
} catch (error) {
    // ignore as many do
}
var myObj = { apple: 1 };
(value) => { value * value };
function foobar(value = 0) { }
class MyClass { }
class Foobar { method() {} }
function foobar(...args) { }
var { prop } = {};
var { prop: a } = {};
var { prop: [x] } = {};
({ prop: obj.name }) = {};
var data = { "x": 1 };  // excused because of quotes
data["y"] = 3;  // excused because of calculated property access

This rule has an object option:

  • "min" (default: 2) enforces a minimum identifier length
  • "max" (default: Infinity) enforces a maximum identifier length
  • "properties": always (default) enforces identifier length convention for property names
  • "properties": never ignores identifier length convention for property names
  • "exceptions" allows an array of specified identifier names

min

Examples of incorrect code for this rule with the { "min": 4 } option:

/*eslint id-length: ["error", { "min": 4 }]*/
/*eslint-env es6*/

var val = 5;
obj.e = document.body;
function (e) { };
try {
    dangerousStuff();
} catch (e) {
    // ignore as many do
}
var myObj = { a: 1 };
(val) => { val * val };
class x { }
class Foo { x() {} }
function foo(...x) { }
var { x } = {};
var { x: a} = {};
var { a: [x]} = {};
({ prop: obj.x }) = {};

Examples of correct code for this rule with the { "min": 4 } option:

/*eslint id-length: ["error", { "min": 4 }]*/
/*eslint-env es6*/

var value = 5;
function func() { return 42; }
obj.element = document.body;
var foo = function (event) { /* do stuff */ };
try {
    dangerousStuff();
} catch (error) {
    // ignore as many do
}
var myObj = { apple: 1 };
(value) => { value * value };
function foobar(value = 0) { }
class MyClass { }
class Foobar { method() {} }
function foobar(...args) { }
var { prop } = {};
var { prop: a } = {};
var { prop: [x] } = {};
({ prop: obj.name }) = {};
var data = { "x": 1 };  // excused because of quotes
data["y"] = 3;  // excused because of calculated property access

max

Examples of incorrect code for this rule with the { "max": 10 } option:

/*eslint id-length: ["error", { "max": "10" }]*/
/*eslint-env es6*/

var reallyLongVarName = 5;
function reallyLongFuncName() { return 42; }
obj.reallyLongPropName = document.body;
var foo = function (reallyLongArgName) { /* do stuff */ };
try {
    dangerousStuff();
} catch (reallyLongErrorName) {
    // ignore as many do
}
(reallyLongArgName) => { return !reallyLongArgName; };

Examples of correct code for this rule with the { "max": 10 } option:

/*eslint id-length: ["error", { "max": "10" }]*/
/*eslint-env es6*/

var varName = 5;
function funcName() { return 42; }
obj.propName = document.body;
var foo = function (arg) { /* do stuff */ };
try {
    dangerousStuff();
} catch (error) {
    // ignore as many do
}
(arg) => { return !arg; };

properties

Examples of correct code for this rule with the { "properties": "never" } option:

/*eslint id-length: ["error", { "properties": "never" }]*/
/*eslint-env es6*/

var myObj = { a: 1 };
({ a: obj.x.y.z }) = {};
({ prop: obj.i }) = {};

exceptions

Examples of additional correct code for this rule with the { "exceptions": ["x"] } option:

/*eslint id-length: ["error", { "exceptions": ["x"] }]*/
/*eslint-env es6*/

var x = 5;
function x() { return 42; }
obj.x = document.body;
var foo = function (x) { /* do stuff */ };
try {
    dangerousStuff();
} catch (x) {
    // ignore as many do
}
(x) => { return x * x; };

Related Rules

Identifier name 'KOTORI_CONFIG_DIR' is too long (> 16).
Open

const KOTORI_CONFIG_DIR = path.resolve(__dirname, "../conf/");
Severity: Minor
Found in src/config.js by eslint

enforce minimum and maximum identifier lengths (id-length)

Very short identifier names like e, x, _t or very long ones like hashGeneratorResultOutputContainerObject can make code harder to read and potentially less maintainable. To prevent this, one may enforce a minimum and/or maximum identifier length.

var x = 5; // too short; difficult to understand its purpose without context

Rule Details

This rule enforces a minimum and/or maximum identifier length convention.

Options

Examples of incorrect code for this rule with the default options:

/*eslint id-length: "error"*/     // default is minimum 2-chars ({ "min": 2 })
/*eslint-env es6*/

var x = 5;
obj.e = document.body;
var foo = function (e) { };
try {
    dangerousStuff();
} catch (e) {
    // ignore as many do
}
var myObj = { a: 1 };
(a) => { a * a };
class x { }
class Foo { x() {} }
function foo(...x) { }
var { x } = {};
var { x: a} = {};
var { a: [x]} = {};
({ prop: obj.x }) = {};

Examples of correct code for this rule with the default options:

/*eslint id-length: "error"*/     // default is minimum 2-chars ({ "min": 2 })
/*eslint-env es6*/

var num = 5;
function _f() { return 42; }
function _func() { return 42; }
obj.el = document.body;
var foo = function (evt) { /* do stuff */ };
try {
    dangerousStuff();
} catch (error) {
    // ignore as many do
}
var myObj = { apple: 1 };
(num) => { num * num };
function foo(num = 0) { }
class MyClass { }
class Foo { method() {} }
function foo(...args) { }
var { prop } = {};
var { prop: a } = {};
var { prop: [x] } = {};
({ prop: obj.longName }) = {};
var data = { "x": 1 };  // excused because of quotes
data["y"] = 3;  // excused because of calculated property access

This rule has a shorthand integer option for the "min" object property.

Examples of incorrect code for this rule with a minimum of 4:

/*eslint id-length: ["error", 4]*/
/*eslint-env es6*/

var val = 5;
obj.e = document.body;
function (e) { };
try {
    dangerousStuff();
} catch (e) {
    // ignore as many do
}
var myObj = { a: 1 };
(val) => { val * val };
class x { }
class Foo { x() {} }
function foo(...x) { }
var { x } = {};
var { x: a} = {};
var { a: [x]} = {};
({ prop: obj.x }) = {};

Examples of correct code for this rule with a minimum of 4:

/*eslint id-length: ["error", 4]*/
/*eslint-env es6*/

var value = 5;
function func() { return 42; }
obj.element = document.body;
var foo = function (event) { /* do stuff */ };
try {
    dangerousStuff();
} catch (error) {
    // ignore as many do
}
var myObj = { apple: 1 };
(value) => { value * value };
function foobar(value = 0) { }
class MyClass { }
class Foobar { method() {} }
function foobar(...args) { }
var { prop } = {};
var { prop: a } = {};
var { prop: [x] } = {};
({ prop: obj.name }) = {};
var data = { "x": 1 };  // excused because of quotes
data["y"] = 3;  // excused because of calculated property access

This rule has an object option:

  • "min" (default: 2) enforces a minimum identifier length
  • "max" (default: Infinity) enforces a maximum identifier length
  • "properties": always (default) enforces identifier length convention for property names
  • "properties": never ignores identifier length convention for property names
  • "exceptions" allows an array of specified identifier names

min

Examples of incorrect code for this rule with the { "min": 4 } option:

/*eslint id-length: ["error", { "min": 4 }]*/
/*eslint-env es6*/

var val = 5;
obj.e = document.body;
function (e) { };
try {
    dangerousStuff();
} catch (e) {
    // ignore as many do
}
var myObj = { a: 1 };
(val) => { val * val };
class x { }
class Foo { x() {} }
function foo(...x) { }
var { x } = {};
var { x: a} = {};
var { a: [x]} = {};
({ prop: obj.x }) = {};

Examples of correct code for this rule with the { "min": 4 } option:

/*eslint id-length: ["error", { "min": 4 }]*/
/*eslint-env es6*/

var value = 5;
function func() { return 42; }
obj.element = document.body;
var foo = function (event) { /* do stuff */ };
try {
    dangerousStuff();
} catch (error) {
    // ignore as many do
}
var myObj = { apple: 1 };
(value) => { value * value };
function foobar(value = 0) { }
class MyClass { }
class Foobar { method() {} }
function foobar(...args) { }
var { prop } = {};
var { prop: a } = {};
var { prop: [x] } = {};
({ prop: obj.name }) = {};
var data = { "x": 1 };  // excused because of quotes
data["y"] = 3;  // excused because of calculated property access

max

Examples of incorrect code for this rule with the { "max": 10 } option:

/*eslint id-length: ["error", { "max": "10" }]*/
/*eslint-env es6*/

var reallyLongVarName = 5;
function reallyLongFuncName() { return 42; }
obj.reallyLongPropName = document.body;
var foo = function (reallyLongArgName) { /* do stuff */ };
try {
    dangerousStuff();
} catch (reallyLongErrorName) {
    // ignore as many do
}
(reallyLongArgName) => { return !reallyLongArgName; };

Examples of correct code for this rule with the { "max": 10 } option:

/*eslint id-length: ["error", { "max": "10" }]*/
/*eslint-env es6*/

var varName = 5;
function funcName() { return 42; }
obj.propName = document.body;
var foo = function (arg) { /* do stuff */ };
try {
    dangerousStuff();
} catch (error) {
    // ignore as many do
}
(arg) => { return !arg; };

properties

Examples of correct code for this rule with the { "properties": "never" } option:

/*eslint id-length: ["error", { "properties": "never" }]*/
/*eslint-env es6*/

var myObj = { a: 1 };
({ a: obj.x.y.z }) = {};
({ prop: obj.i }) = {};

exceptions

Examples of additional correct code for this rule with the { "exceptions": ["x"] } option:

/*eslint id-length: ["error", { "exceptions": ["x"] }]*/
/*eslint-env es6*/

var x = 5;
function x() { return 42; }
obj.x = document.body;
var foo = function (x) { /* do stuff */ };
try {
    dangerousStuff();
} catch (x) {
    // ignore as many do
}
(x) => { return x * x; };

Related Rules

Identifier name 'PERSONAL_CONFIG_PATH' is too long (> 16).
Open

const PERSONAL_CONFIG_PATH = userHome ? `${userHome}/${LOCAL_CONFIG_FILENAME}` : null;
Severity: Minor
Found in src/config.js by eslint

enforce minimum and maximum identifier lengths (id-length)

Very short identifier names like e, x, _t or very long ones like hashGeneratorResultOutputContainerObject can make code harder to read and potentially less maintainable. To prevent this, one may enforce a minimum and/or maximum identifier length.

var x = 5; // too short; difficult to understand its purpose without context

Rule Details

This rule enforces a minimum and/or maximum identifier length convention.

Options

Examples of incorrect code for this rule with the default options:

/*eslint id-length: "error"*/     // default is minimum 2-chars ({ "min": 2 })
/*eslint-env es6*/

var x = 5;
obj.e = document.body;
var foo = function (e) { };
try {
    dangerousStuff();
} catch (e) {
    // ignore as many do
}
var myObj = { a: 1 };
(a) => { a * a };
class x { }
class Foo { x() {} }
function foo(...x) { }
var { x } = {};
var { x: a} = {};
var { a: [x]} = {};
({ prop: obj.x }) = {};

Examples of correct code for this rule with the default options:

/*eslint id-length: "error"*/     // default is minimum 2-chars ({ "min": 2 })
/*eslint-env es6*/

var num = 5;
function _f() { return 42; }
function _func() { return 42; }
obj.el = document.body;
var foo = function (evt) { /* do stuff */ };
try {
    dangerousStuff();
} catch (error) {
    // ignore as many do
}
var myObj = { apple: 1 };
(num) => { num * num };
function foo(num = 0) { }
class MyClass { }
class Foo { method() {} }
function foo(...args) { }
var { prop } = {};
var { prop: a } = {};
var { prop: [x] } = {};
({ prop: obj.longName }) = {};
var data = { "x": 1 };  // excused because of quotes
data["y"] = 3;  // excused because of calculated property access

This rule has a shorthand integer option for the "min" object property.

Examples of incorrect code for this rule with a minimum of 4:

/*eslint id-length: ["error", 4]*/
/*eslint-env es6*/

var val = 5;
obj.e = document.body;
function (e) { };
try {
    dangerousStuff();
} catch (e) {
    // ignore as many do
}
var myObj = { a: 1 };
(val) => { val * val };
class x { }
class Foo { x() {} }
function foo(...x) { }
var { x } = {};
var { x: a} = {};
var { a: [x]} = {};
({ prop: obj.x }) = {};

Examples of correct code for this rule with a minimum of 4:

/*eslint id-length: ["error", 4]*/
/*eslint-env es6*/

var value = 5;
function func() { return 42; }
obj.element = document.body;
var foo = function (event) { /* do stuff */ };
try {
    dangerousStuff();
} catch (error) {
    // ignore as many do
}
var myObj = { apple: 1 };
(value) => { value * value };
function foobar(value = 0) { }
class MyClass { }
class Foobar { method() {} }
function foobar(...args) { }
var { prop } = {};
var { prop: a } = {};
var { prop: [x] } = {};
({ prop: obj.name }) = {};
var data = { "x": 1 };  // excused because of quotes
data["y"] = 3;  // excused because of calculated property access

This rule has an object option:

  • "min" (default: 2) enforces a minimum identifier length
  • "max" (default: Infinity) enforces a maximum identifier length
  • "properties": always (default) enforces identifier length convention for property names
  • "properties": never ignores identifier length convention for property names
  • "exceptions" allows an array of specified identifier names

min

Examples of incorrect code for this rule with the { "min": 4 } option:

/*eslint id-length: ["error", { "min": 4 }]*/
/*eslint-env es6*/

var val = 5;
obj.e = document.body;
function (e) { };
try {
    dangerousStuff();
} catch (e) {
    // ignore as many do
}
var myObj = { a: 1 };
(val) => { val * val };
class x { }
class Foo { x() {} }
function foo(...x) { }
var { x } = {};
var { x: a} = {};
var { a: [x]} = {};
({ prop: obj.x }) = {};

Examples of correct code for this rule with the { "min": 4 } option:

/*eslint id-length: ["error", { "min": 4 }]*/
/*eslint-env es6*/

var value = 5;
function func() { return 42; }
obj.element = document.body;
var foo = function (event) { /* do stuff */ };
try {
    dangerousStuff();
} catch (error) {
    // ignore as many do
}
var myObj = { apple: 1 };
(value) => { value * value };
function foobar(value = 0) { }
class MyClass { }
class Foobar { method() {} }
function foobar(...args) { }
var { prop } = {};
var { prop: a } = {};
var { prop: [x] } = {};
({ prop: obj.name }) = {};
var data = { "x": 1 };  // excused because of quotes
data["y"] = 3;  // excused because of calculated property access

max

Examples of incorrect code for this rule with the { "max": 10 } option:

/*eslint id-length: ["error", { "max": "10" }]*/
/*eslint-env es6*/

var reallyLongVarName = 5;
function reallyLongFuncName() { return 42; }
obj.reallyLongPropName = document.body;
var foo = function (reallyLongArgName) { /* do stuff */ };
try {
    dangerousStuff();
} catch (reallyLongErrorName) {
    // ignore as many do
}
(reallyLongArgName) => { return !reallyLongArgName; };

Examples of correct code for this rule with the { "max": 10 } option:

/*eslint id-length: ["error", { "max": "10" }]*/
/*eslint-env es6*/

var varName = 5;
function funcName() { return 42; }
obj.propName = document.body;
var foo = function (arg) { /* do stuff */ };
try {
    dangerousStuff();
} catch (error) {
    // ignore as many do
}
(arg) => { return !arg; };

properties

Examples of correct code for this rule with the { "properties": "never" } option:

/*eslint id-length: ["error", { "properties": "never" }]*/
/*eslint-env es6*/

var myObj = { a: 1 };
({ a: obj.x.y.z }) = {};
({ prop: obj.i }) = {};

exceptions

Examples of additional correct code for this rule with the { "exceptions": ["x"] } option:

/*eslint id-length: ["error", { "exceptions": ["x"] }]*/
/*eslint-env es6*/

var x = 5;
function x() { return 42; }
obj.x = document.body;
var foo = function (x) { /* do stuff */ };
try {
    dangerousStuff();
} catch (x) {
    // ignore as many do
}
(x) => { return x * x; };

Related Rules

Identifier 'KOTORI_CONFIG_DIR' does not match the pattern '^[a-z|A-Z]+([A-Z][a-z]+)*$'.
Open

      this.config = loadConfigCore(`${KOTORI_CONFIG_DIR}/${LOCAL_CONFIG_FILENAME}`);
Severity: Minor
Found in src/config.js by eslint

require identifiers to match a specified regular expression (id-match)

"There are only two hard things in Computer Science: cache invalidation and naming things." — Phil Karlton

Naming things consistently in a project is an often underestimated aspect of code creation. When done correctly, it can save your team hours of unnecessary head scratching and misdirections. This rule allows you to precisely define and enforce the variables and function names on your team should use. No more limiting yourself to camelCase, snake_case, PascalCase or oHungarianNotation. Id-match has all your needs covered!

Rule Details

This rule requires identifiers in assignments and function definitions to match a specified regular expression.

Options

This rule has a string option for the specified regular expression.

For example, to enforce a camelcase naming convention:

{
    "id-match": ["error", "^[a-z]+([A-Z][a-z]+)*$"]
}

Examples of correct code for this rule with the "^[a-z]+([A-Z][a-z]+)*$" option:

/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$"]*/

var myFavoriteColor   = "#112C85";
var foo = bar.baz_boom;
var foo = { qux: bar.baz_boom };
do_something();
var obj = {
    my_pref: 1
};

Examples of incorrect code for this rule with the "^[a-z]+([A-Z][a-z]+)*$" option:

/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$"]*/

var my_favorite_color = "#112C85";
var _myFavoriteColor  = "#112C85";
var myFavoriteColor_  = "#112C85";
var MY_FAVORITE_COLOR = "#112C85";
function do_something() {
    // ...
}
obj.do_something = function() {
    // ...
};

This rule has an object option:

  • "properties": true requires object properties to match the specified regular expression
  • "onlyDeclarations": true requires only var, function, and class declarations to match the specified regular expression

properties

Examples of incorrect code for this rule with the "^[a-z]+([A-Z][a-z]+)*$", { "properties": true } options:

/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$", { "properties": true }]*/

var obj = {
    my_pref: 1
};

onlyDeclarations

Examples of correct code for this rule with the "^[a-z]+([A-Z][a-z]+)*$", { "onlyDeclarations": true } options:

/*eslint id-match: [2, "^[a-z]+([A-Z][a-z]+)*$", { "onlyDeclarations": true }]*/

do_something(__dirname);

When Not To Use It

If your rules are too complex, it is possible that you encounter performance issues due to the nature of the job. Source: http://eslint.org/docs/rules/

Expected line before comment.
Open

      // configItem is Object.
Severity: Minor
Found in src/config.js by eslint

require empty lines around comments (lines-around-comment)

Many style guides require empty lines before or after comments. The primary goal of these rules is to make the comments easier to read and improve readability of the code.

Rule Details

This rule requires empty lines before and/or after comments. It can be enabled separately for both block (/*) and line (//) comments. This rule does not apply to comments that appear on the same line as code and does not require empty lines at the beginning or end of a file.

Options

This rule has an object option:

  • "beforeBlockComment": true (default) requires an empty line before block comments
  • "afterBlockComment": true requires an empty line after block comments
  • "beforeLineComment": true requires an empty line before line comments
  • "afterLineComment": true requires an empty line after line comments
  • "allowBlockStart": true allows comments to appear at the start of block statements
  • "allowBlockEnd": true allows comments to appear at the end of block statements
  • "allowObjectStart": true allows comments to appear at the start of object literals
  • "allowObjectEnd": true allows comments to appear at the end of object literals
  • "allowArrayStart": true allows comments to appear at the start of array literals
  • "allowArrayEnd": true allows comments to appear at the end of array literals
  • "applyDefaultIgnorePatterns" enables or disables the default comment patterns to be ignored by the rule
  • "ignorePattern" custom patterns to be ignored by the rule

beforeBlockComment

Examples of incorrect code for this rule with the default { "beforeBlockComment": true } option:

/*eslint lines-around-comment: ["error", { "beforeBlockComment": true }]*/

var night = "long";
/* what a great and wonderful day */
var day = "great"

Examples of correct code for this rule with the default { "beforeBlockComment": true } option:

/*eslint lines-around-comment: ["error", { "beforeBlockComment": true }]*/

var night = "long";

/* what a great and wonderful day */
var day = "great"

afterBlockComment

Examples of incorrect code for this rule with the { "afterBlockComment": true } option:

/*eslint lines-around-comment: ["error", { "afterBlockComment": true }]*/

var night = "long";

/* what a great and wonderful day */
var day = "great"

Examples of correct code for this rule with the { "afterBlockComment": true } option:

/*eslint lines-around-comment: ["error", { "afterBlockComment": true }]*/

var night = "long";

/* what a great and wonderful day */

var day = "great"

beforeLineComment

Examples of incorrect code for this rule with the { "beforeLineComment": true } option:

/*eslint lines-around-comment: ["error", { "beforeLineComment": true }]*/

var night = "long";
// what a great and wonderful day
var day = "great"

Examples of correct code for this rule with the { "beforeLineComment": true } option:

/*eslint lines-around-comment: ["error", { "beforeLineComment": true }]*/

var night = "long";

// what a great and wonderful day
var day = "great"

afterLineComment

Examples of incorrect code for this rule with the { "afterLineComment": true } option:

/*eslint lines-around-comment: ["error", { "afterLineComment": true }]*/

var night = "long";
// what a great and wonderful day
var day = "great"

Examples of correct code for this rule with the { "afterLineComment": true } option:

/*eslint lines-around-comment: ["error", { "afterLineComment": true }]*/

var night = "long";
// what a great and wonderful day

var day = "great"

allowBlockStart

Examples of correct code for this rule with the { "beforeLineComment": true, "allowBlockStart": true } options:

/*eslint lines-around-comment: ["error", { "beforeLineComment": true, "allowBlockStart": true }]*/

function foo(){
    // what a great and wonderful day
    var day = "great"
    return day;
}

Examples of correct code for this rule with the { "beforeBlockComment": true, "allowBlockStart": true } options:

/*eslint lines-around-comment: ["error", { "beforeBlockComment": true, "allowBlockStart": true }]*/

function foo(){
    /* what a great and wonderful day */
    var day = "great"
    return day;
}

allowBlockEnd

Examples of correct code for this rule with the { "afterLineComment": true, "allowBlockEnd": true } option:

/*eslint lines-around-comment: ["error", { "afterLineComment": true, "allowBlockEnd": true }]*/

function foo(){
    var day = "great"
    return day;
    // what a great and wonderful day
}

Examples of correct code for this rule with the { "afterBlockComment": true, "allowBlockEnd": true } option:

/*eslint lines-around-comment: ["error", { "afterBlockComment": true, "allowBlockEnd": true }]*/

function foo(){
    var day = "great"
    return day;

    /* what a great and wonderful day */
}

allowObjectStart

Examples of correct code for this rule with the { "beforeLineComment": true, "allowObjectStart": true } option:

/*eslint lines-around-comment: ["error", { "beforeLineComment": true, "allowObjectStart": true }]*/

var foo = {
    // what a great and wonderful day
    day: "great"
};

const {
    // what a great and wonderful day
    foo: someDay
} = {foo: "great"};

const {
    // what a great and wonderful day
    day
} = {day: "great"};

Examples of correct code for this rule with the { "beforeBlockComment": true, "allowObjectStart": true } option:

/*eslint lines-around-comment: ["error", { "beforeBlockComment": true, "allowObjectStart": true }]*/

var foo = {
    /* what a great and wonderful day */
    day: "great"
};

const {
    /* what a great and wonderful day */
    foo: someDay
} = {foo: "great"};

const {
    /* what a great and wonderful day */
    day
} = {day: "great"};

allowObjectEnd

Examples of correct code for this rule with the { "afterLineComment": true, "allowObjectEnd": true } option:

/*eslint lines-around-comment: ["error", { "afterLineComment": true, "allowObjectEnd": true }]*/

var foo = {
    day: "great"
    // what a great and wonderful day
};

const {
    foo: someDay
    // what a great and wonderful day
} = {foo: "great"};

const {
    day
    // what a great and wonderful day
} = {day: "great"};

Examples of correct code for this rule with the { "afterBlockComment": true, "allowObjectEnd": true } option:

/*eslint lines-around-comment: ["error", { "afterBlockComment": true, "allowObjectEnd": true }]*/

var foo = {
    day: "great"

    /* what a great and wonderful day */
};

const {
    foo: someDay

    /* what a great and wonderful day */
} = {foo: "great"};

const {
    day

    /* what a great and wonderful day */
} = {day: "great"};

allowArrayStart

Examples of correct code for this rule with the { "beforeLineComment": true, "allowArrayStart": true } option:

/*eslint lines-around-comment: ["error", { "beforeLineComment": true, "allowArrayStart": true }]*/

var day = [
    // what a great and wonderful day
    "great",
    "wonderful"
];

const [
    // what a great and wonderful day
    someDay
] = ["great", "not great"];

Examples of correct code for this rule with the { "beforeBlockComment": true, "allowArrayStart": true } option:

/*eslint lines-around-comment: ["error", { "beforeBlockComment": true, "allowArrayStart": true }]*/

var day = [
    /* what a great and wonderful day */
    "great",
    "wonderful"
];

const [
    /* what a great and wonderful day */
    someDay
] = ["great", "not great"];

allowArrayEnd

Examples of correct code for this rule with the { "afterLineComment": true, "allowArrayEnd": true } option:

/*eslint lines-around-comment: ["error", { "afterLineComment": true, "allowArrayEnd": true }]*/

var day = [
    "great",
    "wonderful"
    // what a great and wonderful day
];

const [
    someDay
    // what a great and wonderful day
] = ["great", "not great"];

Examples of correct code for this rule with the { "afterBlockComment": true, "allowArrayEnd": true } option:

/*eslint lines-around-comment: ["error", { "afterBlockComment": true, "allowArrayEnd": true }]*/

var day = [
    "great",
    "wonderful"

    /* what a great and wonderful day */
];

const [
    someDay

    /* what a great and wonderful day */
] = ["great", "not great"];

ignorePattern

By default this rule ignores comments starting with the following words: eslint, jshint, jslint, istanbul, global, exported, jscs. An alternative regular expression can be provided.

Examples of correct code for the ignorePattern option:

/*eslint lines-around-comment: ["error"]*/

foo();
/* eslint mentioned in this comment */,
bar();


/*eslint lines-around-comment: ["error", { "ignorePattern": "pragma" }] */

foo();
/* a valid comment using pragma in it */

Examples of incorrect code for the ignorePattern option:

/*eslint lines-around-comment: ["error", { "ignorePattern": "pragma" }] */

1 + 1;
/* something else */

applyDefaultIgnorePatterns

Default ignore patterns are applied even when ignorePattern is provided. If you want to omit default patterns, set this option to false.

Examples of correct code for the { "applyDefaultIgnorePatterns": false } option:

/*eslint lines-around-comment: ["error", { "ignorePattern": "pragma", applyDefaultIgnorePatterns: false }] */

foo();
/* a valid comment using pragma in it */

Examples of incorrect code for the { "applyDefaultIgnorePatterns": false } option:

/*eslint lines-around-comment: ["error", { "applyDefaultIgnorePatterns": false }] */

foo();
/* eslint mentioned in comment */

When Not To Use It

Many people enjoy a terser code style and don't mind comments bumping up against code. If you fall into that category this rule is not for you.

Related Rules

Identifier 'LOCAL_CONFIG_FILENAME' does not match the pattern '^[a-z|A-Z]+([A-Z][a-z]+)*$'.
Open

const LOCAL_CONFIG_FILENAME = ".kotorirc";
Severity: Minor
Found in src/config.js by eslint

require identifiers to match a specified regular expression (id-match)

"There are only two hard things in Computer Science: cache invalidation and naming things." — Phil Karlton

Naming things consistently in a project is an often underestimated aspect of code creation. When done correctly, it can save your team hours of unnecessary head scratching and misdirections. This rule allows you to precisely define and enforce the variables and function names on your team should use. No more limiting yourself to camelCase, snake_case, PascalCase or oHungarianNotation. Id-match has all your needs covered!

Rule Details

This rule requires identifiers in assignments and function definitions to match a specified regular expression.

Options

This rule has a string option for the specified regular expression.

For example, to enforce a camelcase naming convention:

{
    "id-match": ["error", "^[a-z]+([A-Z][a-z]+)*$"]
}

Examples of correct code for this rule with the "^[a-z]+([A-Z][a-z]+)*$" option:

/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$"]*/

var myFavoriteColor   = "#112C85";
var foo = bar.baz_boom;
var foo = { qux: bar.baz_boom };
do_something();
var obj = {
    my_pref: 1
};

Examples of incorrect code for this rule with the "^[a-z]+([A-Z][a-z]+)*$" option:

/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$"]*/

var my_favorite_color = "#112C85";
var _myFavoriteColor  = "#112C85";
var myFavoriteColor_  = "#112C85";
var MY_FAVORITE_COLOR = "#112C85";
function do_something() {
    // ...
}
obj.do_something = function() {
    // ...
};

This rule has an object option:

  • "properties": true requires object properties to match the specified regular expression
  • "onlyDeclarations": true requires only var, function, and class declarations to match the specified regular expression

properties

Examples of incorrect code for this rule with the "^[a-z]+([A-Z][a-z]+)*$", { "properties": true } options:

/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$", { "properties": true }]*/

var obj = {
    my_pref: 1
};

onlyDeclarations

Examples of correct code for this rule with the "^[a-z]+([A-Z][a-z]+)*$", { "onlyDeclarations": true } options:

/*eslint id-match: [2, "^[a-z]+([A-Z][a-z]+)*$", { "onlyDeclarations": true }]*/

do_something(__dirname);

When Not To Use It

If your rules are too complex, it is possible that you encounter performance issues due to the nature of the job. Source: http://eslint.org/docs/rules/

Identifier 'LOCAL_CONFIG_FILENAME' does not match the pattern '^[a-z|A-Z]+([A-Z][a-z]+)*$'.
Open

      this.config = loadConfigCore(`${KOTORI_CONFIG_DIR}/${LOCAL_CONFIG_FILENAME}`);
Severity: Minor
Found in src/config.js by eslint

require identifiers to match a specified regular expression (id-match)

"There are only two hard things in Computer Science: cache invalidation and naming things." — Phil Karlton

Naming things consistently in a project is an often underestimated aspect of code creation. When done correctly, it can save your team hours of unnecessary head scratching and misdirections. This rule allows you to precisely define and enforce the variables and function names on your team should use. No more limiting yourself to camelCase, snake_case, PascalCase or oHungarianNotation. Id-match has all your needs covered!

Rule Details

This rule requires identifiers in assignments and function definitions to match a specified regular expression.

Options

This rule has a string option for the specified regular expression.

For example, to enforce a camelcase naming convention:

{
    "id-match": ["error", "^[a-z]+([A-Z][a-z]+)*$"]
}

Examples of correct code for this rule with the "^[a-z]+([A-Z][a-z]+)*$" option:

/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$"]*/

var myFavoriteColor   = "#112C85";
var foo = bar.baz_boom;
var foo = { qux: bar.baz_boom };
do_something();
var obj = {
    my_pref: 1
};

Examples of incorrect code for this rule with the "^[a-z]+([A-Z][a-z]+)*$" option:

/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$"]*/

var my_favorite_color = "#112C85";
var _myFavoriteColor  = "#112C85";
var myFavoriteColor_  = "#112C85";
var MY_FAVORITE_COLOR = "#112C85";
function do_something() {
    // ...
}
obj.do_something = function() {
    // ...
};

This rule has an object option:

  • "properties": true requires object properties to match the specified regular expression
  • "onlyDeclarations": true requires only var, function, and class declarations to match the specified regular expression

properties

Examples of incorrect code for this rule with the "^[a-z]+([A-Z][a-z]+)*$", { "properties": true } options:

/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$", { "properties": true }]*/

var obj = {
    my_pref: 1
};

onlyDeclarations

Examples of correct code for this rule with the "^[a-z]+([A-Z][a-z]+)*$", { "onlyDeclarations": true } options:

/*eslint id-match: [2, "^[a-z]+([A-Z][a-z]+)*$", { "onlyDeclarations": true }]*/

do_something(__dirname);

When Not To Use It

If your rules are too complex, it is possible that you encounter performance issues due to the nature of the job. Source: http://eslint.org/docs/rules/

Identifier 'LOCAL_CONFIG_FILENAME' does not match the pattern '^[a-z|A-Z]+([A-Z][a-z]+)*$'.
Open

      this.filePath = `${process.cwd()}/${LOCAL_CONFIG_FILENAME}`;
Severity: Minor
Found in src/config.js by eslint

require identifiers to match a specified regular expression (id-match)

"There are only two hard things in Computer Science: cache invalidation and naming things." — Phil Karlton

Naming things consistently in a project is an often underestimated aspect of code creation. When done correctly, it can save your team hours of unnecessary head scratching and misdirections. This rule allows you to precisely define and enforce the variables and function names on your team should use. No more limiting yourself to camelCase, snake_case, PascalCase or oHungarianNotation. Id-match has all your needs covered!

Rule Details

This rule requires identifiers in assignments and function definitions to match a specified regular expression.

Options

This rule has a string option for the specified regular expression.

For example, to enforce a camelcase naming convention:

{
    "id-match": ["error", "^[a-z]+([A-Z][a-z]+)*$"]
}

Examples of correct code for this rule with the "^[a-z]+([A-Z][a-z]+)*$" option:

/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$"]*/

var myFavoriteColor   = "#112C85";
var foo = bar.baz_boom;
var foo = { qux: bar.baz_boom };
do_something();
var obj = {
    my_pref: 1
};

Examples of incorrect code for this rule with the "^[a-z]+([A-Z][a-z]+)*$" option:

/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$"]*/

var my_favorite_color = "#112C85";
var _myFavoriteColor  = "#112C85";
var myFavoriteColor_  = "#112C85";
var MY_FAVORITE_COLOR = "#112C85";
function do_something() {
    // ...
}
obj.do_something = function() {
    // ...
};

This rule has an object option:

  • "properties": true requires object properties to match the specified regular expression
  • "onlyDeclarations": true requires only var, function, and class declarations to match the specified regular expression

properties

Examples of incorrect code for this rule with the "^[a-z]+([A-Z][a-z]+)*$", { "properties": true } options:

/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$", { "properties": true }]*/

var obj = {
    my_pref: 1
};

onlyDeclarations

Examples of correct code for this rule with the "^[a-z]+([A-Z][a-z]+)*$", { "onlyDeclarations": true } options:

/*eslint id-match: [2, "^[a-z]+([A-Z][a-z]+)*$", { "onlyDeclarations": true }]*/

do_something(__dirname);

When Not To Use It

If your rules are too complex, it is possible that you encounter performance issues due to the nature of the job. Source: http://eslint.org/docs/rules/

'configLoadErrors' is never reassigned. Use 'const' instead.
Open

    let configLoadErrors = [];
Severity: Minor
Found in src/config.js by eslint

Suggest using const (prefer-const)

If a variable is never reassigned, using the const declaration is better.

const declaration tells readers, "this variable is never reassigned," reducing cognitive load and improving maintainability.

Rule Details

This rule is aimed at flagging variables that are declared using let keyword, but never reassigned after the initial assignment.

Examples of incorrect code for this rule:

/*eslint prefer-const: "error"*/
/*eslint-env es6*/

// it's initialized and never reassigned.
let a = 3;
console.log(a);

let a;
a = 0;
console.log(a);

// `i` is redefined (not reassigned) on each loop step.
for (let i in [1, 2, 3]) {
    console.log(i);
}

// `a` is redefined (not reassigned) on each loop step.
for (let a of [1, 2, 3]) {
    console.log(a);
}

Examples of correct code for this rule:

/*eslint prefer-const: "error"*/
/*eslint-env es6*/

// using const.
const a = 0;

// it's never initialized.
let a;
console.log(a);

// it's reassigned after initialized.
let a;
a = 0;
a = 1;
console.log(a);

// it's initialized in a different block from the declaration.
let a;
if (true) {
    a = 0;
}
console.log(a);

// it's initialized at a place that we cannot write a variable declaration.
let a;
if (true) a = 0;
console.log(a);

// `i` gets a new binding each iteration
for (const i in [1, 2, 3]) {
  console.log(i);
}

// `a` gets a new binding each iteration
for (const a of [1, 2, 3]) {
  console.log(a);
}

// `end` is never reassigned, but we cannot separate the declarations without modifying the scope.
for (let i = 0, end = 10; i < end; ++i) {
    console.log(a);
}

// suggest to use `no-var` rule.
var b = 3;
console.log(b);

Options

{
    "prefer-const": ["error", {
        "destructuring": "any",
        "ignoreReadBeforeAssign": false
    }]
}

destructuring

The kind of the way to address variables in destructuring. There are 2 values:

  • "any" (default) - If any variables in destructuring should be const, this rule warns for those variables.
  • "all" - If all variables in destructuring should be const, this rule warns the variables. Otherwise, ignores them.

Examples of incorrect code for the default {"destructuring": "any"} option:

/*eslint prefer-const: "error"*/
/*eslint-env es6*/

let {a, b} = obj;    /*error 'b' is never reassigned, use 'const' instead.*/
a = a + 1;

Examples of correct code for the default {"destructuring": "any"} option:

/*eslint prefer-const: "error"*/
/*eslint-env es6*/

// using const.
const {a: a0, b} = obj;
const a = a0 + 1;

// all variables are reassigned.
let {a, b} = obj;
a = a + 1;
b = b + 1;

Examples of incorrect code for the {"destructuring": "all"} option:

/*eslint prefer-const: ["error", {"destructuring": "all"}]*/
/*eslint-env es6*/

// all of `a` and `b` should be const, so those are warned.
let {a, b} = obj;    /*error 'a' is never reassigned, use 'const' instead.
                             'b' is never reassigned, use 'const' instead.*/

Examples of correct code for the {"destructuring": "all"} option:

/*eslint prefer-const: ["error", {"destructuring": "all"}]*/
/*eslint-env es6*/

// 'b' is never reassigned, but all of `a` and `b` should not be const, so those are ignored.
let {a, b} = obj;
a = a + 1;

ignoreReadBeforeAssign

This is an option to avoid conflicting with no-use-before-define rule (without "nofunc" option). If true is specified, this rule will ignore variables that are read between the declaration and the first assignment. Default is false.

Examples of correct code for the {"ignoreReadBeforeAssign": true} option:

/*eslint prefer-const: ["error", {"ignoreReadBeforeAssign": true}]*/
/*eslint-env es6*/

let timer;
function initialize() {
    if (foo()) {
        clearInterval(timer);
    }
}
timer = setInterval(initialize, 100);

Examples of correct code for the default {"ignoreReadBeforeAssign": false} option:

/*eslint prefer-const: ["error", {"ignoreReadBeforeAssign": false}]*/
/*eslint-env es6*/

const timer = setInterval(initialize, 100);
function initialize() {
    if (foo()) {
        clearInterval(timer);
    }
}

When Not To Use It

If you don't want to be notified about variables that are never reassigned after initial assignment, you can safely disable this rule.

Related Rules

Identifier 'PERSONAL_CONFIG_PATH' does not match the pattern '^[a-z|A-Z]+([A-Z][a-z]+)*$'.
Open

      const paths = `${PERSONAL_CONFIG_PATH} and ${path.resolve(process.cwd(), LOCAL_CONFIG_FILENAME)}`;
Severity: Minor
Found in src/config.js by eslint

require identifiers to match a specified regular expression (id-match)

"There are only two hard things in Computer Science: cache invalidation and naming things." — Phil Karlton

Naming things consistently in a project is an often underestimated aspect of code creation. When done correctly, it can save your team hours of unnecessary head scratching and misdirections. This rule allows you to precisely define and enforce the variables and function names on your team should use. No more limiting yourself to camelCase, snake_case, PascalCase or oHungarianNotation. Id-match has all your needs covered!

Rule Details

This rule requires identifiers in assignments and function definitions to match a specified regular expression.

Options

This rule has a string option for the specified regular expression.

For example, to enforce a camelcase naming convention:

{
    "id-match": ["error", "^[a-z]+([A-Z][a-z]+)*$"]
}

Examples of correct code for this rule with the "^[a-z]+([A-Z][a-z]+)*$" option:

/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$"]*/

var myFavoriteColor   = "#112C85";
var foo = bar.baz_boom;
var foo = { qux: bar.baz_boom };
do_something();
var obj = {
    my_pref: 1
};

Examples of incorrect code for this rule with the "^[a-z]+([A-Z][a-z]+)*$" option:

/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$"]*/

var my_favorite_color = "#112C85";
var _myFavoriteColor  = "#112C85";
var myFavoriteColor_  = "#112C85";
var MY_FAVORITE_COLOR = "#112C85";
function do_something() {
    // ...
}
obj.do_something = function() {
    // ...
};

This rule has an object option:

  • "properties": true requires object properties to match the specified regular expression
  • "onlyDeclarations": true requires only var, function, and class declarations to match the specified regular expression

properties

Examples of incorrect code for this rule with the "^[a-z]+([A-Z][a-z]+)*$", { "properties": true } options:

/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$", { "properties": true }]*/

var obj = {
    my_pref: 1
};

onlyDeclarations

Examples of correct code for this rule with the "^[a-z]+([A-Z][a-z]+)*$", { "onlyDeclarations": true } options:

/*eslint id-match: [2, "^[a-z]+([A-Z][a-z]+)*$", { "onlyDeclarations": true }]*/

do_something(__dirname);

When Not To Use It

If your rules are too complex, it is possible that you encounter performance issues due to the nature of the job. Source: http://eslint.org/docs/rules/

Identifier 'KOTORI_CONFIG_DIR' does not match the pattern '^[a-z|A-Z]+([A-Z][a-z]+)*$'.
Open

const KOTORI_CONFIG_DIR = path.resolve(__dirname, "../conf/");
Severity: Minor
Found in src/config.js by eslint

require identifiers to match a specified regular expression (id-match)

"There are only two hard things in Computer Science: cache invalidation and naming things." — Phil Karlton

Naming things consistently in a project is an often underestimated aspect of code creation. When done correctly, it can save your team hours of unnecessary head scratching and misdirections. This rule allows you to precisely define and enforce the variables and function names on your team should use. No more limiting yourself to camelCase, snake_case, PascalCase or oHungarianNotation. Id-match has all your needs covered!

Rule Details

This rule requires identifiers in assignments and function definitions to match a specified regular expression.

Options

This rule has a string option for the specified regular expression.

For example, to enforce a camelcase naming convention:

{
    "id-match": ["error", "^[a-z]+([A-Z][a-z]+)*$"]
}

Examples of correct code for this rule with the "^[a-z]+([A-Z][a-z]+)*$" option:

/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$"]*/

var myFavoriteColor   = "#112C85";
var foo = bar.baz_boom;
var foo = { qux: bar.baz_boom };
do_something();
var obj = {
    my_pref: 1
};

Examples of incorrect code for this rule with the "^[a-z]+([A-Z][a-z]+)*$" option:

/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$"]*/

var my_favorite_color = "#112C85";
var _myFavoriteColor  = "#112C85";
var myFavoriteColor_  = "#112C85";
var MY_FAVORITE_COLOR = "#112C85";
function do_something() {
    // ...
}
obj.do_something = function() {
    // ...
};

This rule has an object option:

  • "properties": true requires object properties to match the specified regular expression
  • "onlyDeclarations": true requires only var, function, and class declarations to match the specified regular expression

properties

Examples of incorrect code for this rule with the "^[a-z]+([A-Z][a-z]+)*$", { "properties": true } options:

/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$", { "properties": true }]*/

var obj = {
    my_pref: 1
};

onlyDeclarations

Examples of correct code for this rule with the "^[a-z]+([A-Z][a-z]+)*$", { "onlyDeclarations": true } options:

/*eslint id-match: [2, "^[a-z]+([A-Z][a-z]+)*$", { "onlyDeclarations": true }]*/

do_something(__dirname);

When Not To Use It

If your rules are too complex, it is possible that you encounter performance issues due to the nature of the job. Source: http://eslint.org/docs/rules/

Identifier 'LOCAL_CONFIG_FILENAME' does not match the pattern '^[a-z|A-Z]+([A-Z][a-z]+)*$'.
Open

const PERSONAL_CONFIG_PATH = userHome ? `${userHome}/${LOCAL_CONFIG_FILENAME}` : null;
Severity: Minor
Found in src/config.js by eslint

require identifiers to match a specified regular expression (id-match)

"There are only two hard things in Computer Science: cache invalidation and naming things." — Phil Karlton

Naming things consistently in a project is an often underestimated aspect of code creation. When done correctly, it can save your team hours of unnecessary head scratching and misdirections. This rule allows you to precisely define and enforce the variables and function names on your team should use. No more limiting yourself to camelCase, snake_case, PascalCase or oHungarianNotation. Id-match has all your needs covered!

Rule Details

This rule requires identifiers in assignments and function definitions to match a specified regular expression.

Options

This rule has a string option for the specified regular expression.

For example, to enforce a camelcase naming convention:

{
    "id-match": ["error", "^[a-z]+([A-Z][a-z]+)*$"]
}

Examples of correct code for this rule with the "^[a-z]+([A-Z][a-z]+)*$" option:

/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$"]*/

var myFavoriteColor   = "#112C85";
var foo = bar.baz_boom;
var foo = { qux: bar.baz_boom };
do_something();
var obj = {
    my_pref: 1
};

Examples of incorrect code for this rule with the "^[a-z]+([A-Z][a-z]+)*$" option:

/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$"]*/

var my_favorite_color = "#112C85";
var _myFavoriteColor  = "#112C85";
var myFavoriteColor_  = "#112C85";
var MY_FAVORITE_COLOR = "#112C85";
function do_something() {
    // ...
}
obj.do_something = function() {
    // ...
};

This rule has an object option:

  • "properties": true requires object properties to match the specified regular expression
  • "onlyDeclarations": true requires only var, function, and class declarations to match the specified regular expression

properties

Examples of incorrect code for this rule with the "^[a-z]+([A-Z][a-z]+)*$", { "properties": true } options:

/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$", { "properties": true }]*/

var obj = {
    my_pref: 1
};

onlyDeclarations

Examples of correct code for this rule with the "^[a-z]+([A-Z][a-z]+)*$", { "onlyDeclarations": true } options:

/*eslint id-match: [2, "^[a-z]+([A-Z][a-z]+)*$", { "onlyDeclarations": true }]*/

do_something(__dirname);

When Not To Use It

If your rules are too complex, it is possible that you encounter performance issues due to the nature of the job. Source: http://eslint.org/docs/rules/

Identifier 'PERSONAL_CONFIG_PATH' does not match the pattern '^[a-z|A-Z]+([A-Z][a-z]+)*$'.
Open

const PERSONAL_CONFIG_PATH = userHome ? `${userHome}/${LOCAL_CONFIG_FILENAME}` : null;
Severity: Minor
Found in src/config.js by eslint

require identifiers to match a specified regular expression (id-match)

"There are only two hard things in Computer Science: cache invalidation and naming things." — Phil Karlton

Naming things consistently in a project is an often underestimated aspect of code creation. When done correctly, it can save your team hours of unnecessary head scratching and misdirections. This rule allows you to precisely define and enforce the variables and function names on your team should use. No more limiting yourself to camelCase, snake_case, PascalCase or oHungarianNotation. Id-match has all your needs covered!

Rule Details

This rule requires identifiers in assignments and function definitions to match a specified regular expression.

Options

This rule has a string option for the specified regular expression.

For example, to enforce a camelcase naming convention:

{
    "id-match": ["error", "^[a-z]+([A-Z][a-z]+)*$"]
}

Examples of correct code for this rule with the "^[a-z]+([A-Z][a-z]+)*$" option:

/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$"]*/

var myFavoriteColor   = "#112C85";
var foo = bar.baz_boom;
var foo = { qux: bar.baz_boom };
do_something();
var obj = {
    my_pref: 1
};

Examples of incorrect code for this rule with the "^[a-z]+([A-Z][a-z]+)*$" option:

/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$"]*/

var my_favorite_color = "#112C85";
var _myFavoriteColor  = "#112C85";
var myFavoriteColor_  = "#112C85";
var MY_FAVORITE_COLOR = "#112C85";
function do_something() {
    // ...
}
obj.do_something = function() {
    // ...
};

This rule has an object option:

  • "properties": true requires object properties to match the specified regular expression
  • "onlyDeclarations": true requires only var, function, and class declarations to match the specified regular expression

properties

Examples of incorrect code for this rule with the "^[a-z]+([A-Z][a-z]+)*$", { "properties": true } options:

/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$", { "properties": true }]*/

var obj = {
    my_pref: 1
};

onlyDeclarations

Examples of correct code for this rule with the "^[a-z]+([A-Z][a-z]+)*$", { "onlyDeclarations": true } options:

/*eslint id-match: [2, "^[a-z]+([A-Z][a-z]+)*$", { "onlyDeclarations": true }]*/

do_something(__dirname);

When Not To Use It

If your rules are too complex, it is possible that you encounter performance issues due to the nature of the job. Source: http://eslint.org/docs/rules/

Expected 'undefined' and instead saw 'void'.
Open

    if (this.filePath === void 0) {
Severity: Minor
Found in src/config.js by eslint

Disallow use of the void operator. (no-void)

The void operator takes an operand and returns undefined: void expression will evaluate expression and return undefined. It can be used to ignore any side effects expression may produce:

The common case of using void operator is to get a "pure" undefined value as prior to ES5 the undefined variable was mutable:

// will always return undefined
(function(){
    return void 0;
})();

// will return 1 in ES3 and undefined in ES5+
(function(){
    undefined = 1;
    return undefined;
})();

// will throw TypeError in ES5+
(function(){
    'use strict';
    undefined = 1;
})();

Another common case is to minify code as void 0 is shorter than undefined:

foo = void 0;
foo = undefined;

When used with IIFE (immediately-invoked function expression), void can be used to force the function keyword to be treated as an expression instead of a declaration:

var foo = 1;
void function(){ foo = 1; }() // will assign foo a value of 1
+function(){ foo = 1; }() // same as above
function(){ foo = 1; }() // will throw SyntaxError

Some code styles prohibit void operator, marking it as non-obvious and hard to read.

Rule Details

This rule aims to eliminate use of void operator.

Examples of incorrect code for this rule:

/*eslint no-void: "error"*/

void foo

var foo = void bar();

When Not To Use It

If you intentionally use the void operator then you can disable this rule.

Further Reading

Related Rules

There are no issues that match your filters.

Category
Status