From 55e5f708b431bd839b63b1910967bb90fe959c6a Mon Sep 17 00:00:00 2001 From: Kevin Gibbons Date: Tue, 18 Aug 2020 15:08:09 -0700 Subject: [PATCH] lint: forbid leading/trailing whitespace within tags --- src/lint/collect-spelling-diagnostics.ts | 8 +++++++ test/lint-spelling.js | 29 ++++++++++++++++++++++++ test/lint.js | 4 ++-- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/lint/collect-spelling-diagnostics.ts b/src/lint/collect-spelling-diagnostics.ts index da212124..f79dd30a 100644 --- a/src/lint/collect-spelling-diagnostics.ts +++ b/src/lint/collect-spelling-diagnostics.ts @@ -65,6 +65,14 @@ let matchers = [ pattern: /(?<=\S) +(?! |<\/(td|th|dd|dt)>)/gu, message: 'multiple consecutive spaces are not allowed', }, + { + pattern: /(?<=<[a-z]+( [a-z]+(="[^"\n]+")?)*>)(?) /gu, + message: 'tags should not contain leading whitespace', + }, + { + pattern: /(?<=[^ \n]) +<\/(?!td|th|dd|dt)/gu, + message: 'tags should not contain trailing whitespace', + }, ]; export function collectSpellingDiagnostics( diff --git a/test/lint-spelling.js b/test/lint-spelling.js index f647a76e..fcdf8ca7 100644 --- a/test/lint-spelling.js +++ b/test/lint-spelling.js @@ -211,6 +211,32 @@ windows:${M}\r ); }); + it('leading whitespace within tags', async function () { + await assertLint( + positioned` +

${M} This is an example.

+ `, + { + ruleId: 'spelling', + nodeType: 'html', + message: 'tags should not contain leading whitespace', + } + ); + }); + + it('trailing whitespace within tags', async function () { + await assertLint( + positioned` +

This is an example:${M}

+ `, + { + ruleId: 'spelling', + nodeType: 'html', + message: 'tags should not contain trailing whitespace', + } + ); + }); + it('negative', async function () { await assertLintFree(`

@@ -241,6 +267,9 @@ windows:${M}\r Also to pad them a bit, in some cases. +

+ Paragraphs with the open/close tags on their own line are OK. +

`); }); }); diff --git a/test/lint.js b/test/lint.js index fe33dbf4..b3a542bd 100644 --- a/test/lint.js +++ b/test/lint.js @@ -58,7 +58,7 @@ describe('linting whole program', function () { it('error in inline grammar', async function () { await assertLint( positioned` - Statement[${M}a]: \`;\` + Statement[${M}a]: \`;\` `, { ruleId: 'grammarkdown:2008', @@ -91,7 +91,7 @@ describe('linting whole program', function () { it('error in inline grammar', async function () { await assertLint( positioned` - ${M}Statement: EmptyStatement + ${M}Statement: EmptyStatement 1. Return Foo.