no-extra-spacing-text

This rule disallows multiple consecutive spaces or tabs in text and comments.

How to use

.eslintrc.js
module.exports = {
  rules: {
    "@html-eslint/no-extra-spacing-text": "error",
  },
};

Rule Details

Whitespace in HTML is largely ignored, so the purpose of this rule is to prevent unnecessary whitespace in text, such as:

  1. Tab characters
  2. Sequences of more than 1 whitespace character
  3. Whitespace at the end of a line

When used with --fix, the rule will replace invalid whitespace with a single space.

Note:

  1. This rule ignores whitespace at the start of lines in order to not conflict with indentation rules. See @html-eslint/indent.
  2. This rule strips whitespace from the end of lines, as does @html-eslint/no-trailing-spaces.
  3. This rule does not affect whitespace around attributes. See @html-eslint/no-extra-spacing-attrs.

Examples of incorrect code for this rule:

<div foo   =   "   bar   "   >
  foo     bar
</div>

Examples of correct code for this rule:

<div foo="bar">
  foo bar
</div>

Options

This rule has an object option:

  1. "skip": skips whitespace-checking within the specified elements.
//...
"@html-eslint/element-newline": ["error", {
  "skip": Array<string>
}]

skip

You can specify a list of tag names in the skip option. Whitespace-checking is not performed on children of the specified tags.

Examples of correct code for the { "skip": ["pre"] } option:

<div>
  Only short whitespace here.

  <pre>    Any    kind    of   whitespace    here!    </pre>
</div>