forked from ember-cli/eslint-plugin-ember
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate-no-whitespace-for-layout.js
More file actions
52 lines (47 loc) · 1.41 KB
/
template-no-whitespace-for-layout.js
File metadata and controls
52 lines (47 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/** @type {import('eslint').Rule.RuleModule} */
const ERROR_MESSAGE = 'Excess whitespace detected.';
module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'disallow using whitespace for layout purposes',
category: 'Best Practices',
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-no-whitespace-for-layout.md',
templateMode: 'both',
},
schema: [],
messages: {
noWhitespaceForLayout: ERROR_MESSAGE,
},
originallyFrom: {
name: 'ember-template-lint',
rule: 'lib/rules/no-whitespace-for-layout.js',
docs: 'docs/rule/no-whitespace-for-layout.md',
tests: 'test/unit/rules/no-whitespace-for-layout-test.js',
},
},
create(context) {
const sourceCode = context.sourceCode;
return {
GlimmerTextNode(node) {
const text = sourceCode.getText(node);
if (!text) {
return;
}
const lines = text.split('\n');
for (const line of lines) {
// Ignore whitespace at the start and end of the line
const trimmed = line.trim();
// Check for two consecutive ` ` or ` ` in a row
if (/(( )|( ))(( )|( ))/.test(trimmed)) {
context.report({
node,
messageId: 'noWhitespaceForLayout',
});
return;
}
}
},
};
},
};