From e7092eacc4dac176d90aaf0c81a2b960e9a7d6cf Mon Sep 17 00:00:00 2001 From: Leo Balter Date: Mon, 25 Feb 2019 15:11:17 -0500 Subject: [PATCH] set lint rules to avoid leading or trailing empty lines in frontmatter string values Fix #2034 Ref #1997 --- tools/lint/lib/checks/nopadding.py | 21 +++++++++++++++++++++ tools/lint/lint.py | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tools/lint/lib/checks/nopadding.py diff --git a/tools/lint/lib/checks/nopadding.py b/tools/lint/lib/checks/nopadding.py new file mode 100644 index 0000000000..1f3878357c --- /dev/null +++ b/tools/lint/lib/checks/nopadding.py @@ -0,0 +1,21 @@ +from ..check import Check +import re + +class CheckNoPadding(Check): + '''Ensure frontmatter string tags doesn't contain leading empty lines''' + ID = 'NOPADDING' + + def __init__(self): + self.noPadding = re.compile(r"^(?![\r\n])[\s\S]*") + + def run(self, name, meta, source): + if not meta: + return + + if 'description' in meta: + if self.noPadding.match(meta['description']) == None: + return 'The `description` tag should not have leading empty lines' + + if 'info' in meta: + if self.noPadding.match(meta['info']) == None: + return 'The `info` tag should not have leading empty lines' diff --git a/tools/lint/lint.py b/tools/lint/lint.py index a9c8d5aecd..07d99e90eb 100755 --- a/tools/lint/lint.py +++ b/tools/lint/lint.py @@ -37,6 +37,7 @@ from lib.checks.harness import CheckHarness from lib.checks.license import CheckLicense from lib.checks.negative import CheckNegative from lib.checks.filename import CheckFileName +from lib.checks.nopadding import CheckNoPadding from lib.eprint import eprint import lib.frontmatter import lib.exceptions @@ -57,7 +58,8 @@ checks = [ CheckHarnessFeatures(), CheckHarness(), CheckLicense(), - CheckNegative() + CheckNegative(), + CheckNoPadding() ] def lint(file_names):