'ESLint: Rule to disallow and fix line breaks in template literal placeholder expressions

If I have this Javascript code which uses string concatenation spread across multiple lines:

const htmlString = '<span style="' +
    STYLE +
    '">Test</span>";

And I run ESLint with the prefer-template rule to fix with this config:

.eslintrc.json:

{
    "parserOptions": {
        "ecmaVersion": 2020
    },
    "rules": {
        "prefer-template": "error",
        "template-curly-spacing": ["error", "never"]
    }
}

The code is corrected to:

const htmlString = `<span style="${ 
    STYLE 
    }">Test</span>`;

The template-curly-spacing rule disallows spaces but not line breaks.

Is there an ESLint rule that could be used to disallow and remove the line breaks in the placeholder expression so that it could be automatically fixed to be this?

const htmlString = `<span style="${STYLE}">Test</span>`;

I understand that newline characters are preserved in template literal multi-line strings, but in this case it would be cleaner in my code for there to not be line breaks inside my placeholder expressions.

If this can't be done with an existing ESLint rule, I suppose I could do a global find/replace in VS Code, but it would be ideal to be able to enforce this with ESLint.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source