Encountered an ESLint error (no-mixed-spaces-and-tabs
), which serves as a reminder to avoid mixing spaces and tabs when indenting code. Maintaining consistency in using either spaces or tabs is a crucial code convention, especially when collaborating on a codebase within a team (1) (2). If you are working solo and prefer a different approach, feel free to enable/disable any rules.
Turning off the rule for a project
You have the option to configure ESLint to ignore this error across your entire project. Typically, the configuration is stored in .eslintrc.js
in a Vue CLI generated project. Simply edit the rules
object within that file to include:
// .eslintrc.js
module.exports = {
"rules": {
"no-mixed-spaces-and-tabs": 0, // disable rule
}
}
Turning off the rule for a specific line
If you wish to ignore this error for a single line only, use an inline comment (eslint-disable-line no-mixed-spaces-and-tabs
or eslint-disable-next-line no-mixed-spaces-and-tabs
) on that line:
⋅⋅const x = 1
⇥⋅⋅const y = 2 // eslint-disable-line no-mixed-spaces-and-tabs
// eslint-disable-next-line no-mixed-spaces-and-tabs
⇥⋅⋅const z = 3
Turning off the rule for a block of code
To disregard this error for multiple lines of code, encapsulate the code with
eslint-disable no-mixed-spaces-and-tabs
and
eslint-enable no-mixed-spaces-and-tabs
within
multi-line comments:
⋅⋅const x = 1
/* eslint-disable no-mixed-spaces-and-tabs */
⇥⋅⋅const y = 2 // 🙈
⇥⋅⋅const z = 3 // 🙈
/* eslint-enable no-mixed-spaces-and-tabs */
⇥⋅⋅const q = 4 // ❌ error: mixed spaces and tabs!