set lint rules to avoid leading or trailing empty lines in frontmatter string values

Fix #2034
Ref #1997
This commit is contained in:
Leo Balter 2019-02-25 15:11:17 -05:00
parent b4e15b3d5c
commit e7092eacc4
2 changed files with 24 additions and 1 deletions

View File

@ -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'

View File

@ -37,6 +37,7 @@ from lib.checks.harness import CheckHarness
from lib.checks.license import CheckLicense from lib.checks.license import CheckLicense
from lib.checks.negative import CheckNegative from lib.checks.negative import CheckNegative
from lib.checks.filename import CheckFileName from lib.checks.filename import CheckFileName
from lib.checks.nopadding import CheckNoPadding
from lib.eprint import eprint from lib.eprint import eprint
import lib.frontmatter import lib.frontmatter
import lib.exceptions import lib.exceptions
@ -57,7 +58,8 @@ checks = [
CheckHarnessFeatures(), CheckHarnessFeatures(),
CheckHarness(), CheckHarness(),
CheckLicense(), CheckLicense(),
CheckNegative() CheckNegative(),
CheckNoPadding()
] ]
def lint(file_names): def lint(file_names):