Skip to content

Commit

Permalink
lint: forbid multiple spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkot committed Aug 18, 2020
1 parent 45a2cfb commit 0bc4039
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
4 changes: 4 additions & 0 deletions src/lint/collect-spelling-diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ let matchers = [
message:
'clauses should be referenced using <emu-xref> tags rather than hardcoding clause numbers',
},
{
pattern: /(?<=\S) +(?! |<\/(td|th|dd|dt)>)/gu,
message: 'multiple consecutive spaces are not allowed',
},
];

export function collectSpellingDiagnostics(
Expand Down
20 changes: 19 additions & 1 deletion test/lint-spelling.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('spelling', function () {
it('trailing whitespace', async function () {
await assertLint(
positioned`
<p>something</p>${M}
<p>something</p>${M}
`,
{
ruleId: 'spelling',
Expand Down Expand Up @@ -198,6 +198,19 @@ windows:${M}\r
);
});

it('multiple internal spaces', async function () {
await assertLint(
positioned`
I am writing on a typewriter.${M} In the 21st century, for some reason.
`,
{
ruleId: 'spelling',
nodeType: 'html',
message: 'multiple consecutive spaces are not allowed',
}
);
});

it('negative', async function () {
await assertLintFree(`
<p>
Expand All @@ -223,6 +236,11 @@ windows:${M}\r
<p>Something about step <emu-xref href="#step-label"></emu-xref>.</p>
<p>See clause <emu-xref href="#example"></emu-xref>.</p>
<table><tr><td>Spaces for aligning table cells are acceptable.</td>
<td> For example, it is nice for these to line up. </td>
<td> Also to pad them a bit, in some cases. </td>
</tr></table>
`);
});
});
12 changes: 0 additions & 12 deletions test/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,6 @@ describe('linting whole program', function () {
message: 'expected header to have a single space before the argument list',
}
);

await assertLint(
positioned`
<emu-clause id="foo">
<h1>Example ${M} ( )</h1>
`,
{
ruleId: 'header-format',
nodeType: 'h1',
message: 'expected header to have a single space before the argument list',
}
);
});

it('arg format', async function () {
Expand Down

0 comments on commit 0bc4039

Please sign in to comment.