ember-template-lint
Version:
Linter for Ember or Handlebars templates.
34 lines (28 loc) • 828 B
JavaScript
import Rule from './_base.js';
const ERROR_MESSAGE = 'Excess whitespace detected.';
export default class NoWhitespaceForLayout extends Rule {
/**
* @returns {import('./types.js').VisitorReturnType<NoWhitespaceForLayout>}
*/
visitor() {
return {
TextNode(node) {
let source = this.sourceForNode(node);
let lines = source.split('\n');
for (let line of lines) {
// ignore whitespace at the start and end of the line
let trimmed = line.trim();
// check for two ` ` or ` ` in a row
let matches = trimmed.match(/(( )|( ))(( )|( ))/g);
if (matches !== null) {
this.log({
message: ERROR_MESSAGE,
node,
});
return;
}
}
},
};
}
}