add lint check for newline at end of file

This commit is contained in:
Gus Caplan 2019-11-10 20:11:10 -08:00
parent 1bc193528b
commit 833825849d
No known key found for this signature in database
GPG Key ID: F00BD11880E82F0E
3 changed files with 14 additions and 2 deletions

View File

@ -0,0 +1,10 @@
from ..check import Check
import re
class CheckPosix(Check):
'''Ensure tests are valid POSIX files'''
ID = 'POSIX'
def run(self, name, meta, source):
if not source.endswith('\n'):
return 'File must end with a newline'

View File

@ -43,6 +43,7 @@ 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.checks.nopadding import CheckNoPadding
from lib.checks.flags import CheckFlags from lib.checks.flags import CheckFlags
from lib.checks.posix import CheckPosix
from lib.eprint import eprint from lib.eprint import eprint
import lib.frontmatter import lib.frontmatter
import lib.exceptions import lib.exceptions
@ -67,6 +68,7 @@ checks = [
CheckNegative(), CheckNegative(),
CheckNoPadding(), CheckNoPadding(),
CheckFlags(), CheckFlags(),
CheckPosix(),
] ]
def lint(file_names): def lint(file_names):

View File

@ -39,7 +39,7 @@ class TestLinter(unittest.TestCase):
def test_exceptions_single(self): def test_exceptions_single(self):
test_content = ('// Copyright (C) 2017 Mike Pennisi. All rights reserved.\n' + test_content = ('// Copyright (C) 2017 Mike Pennisi. All rights reserved.\n' +
'// This code is governed by the BSD license found in the LICENSE file.') '// This code is governed by the BSD license found in the LICENSE file.\n')
test_file = self.fixture('input.js', test_content) test_file = self.fixture('input.js', test_content)
exceptions_content = test_file + ' FRONTMATTER' exceptions_content = test_file + ' FRONTMATTER'
exceptions_file = self.fixture('lint.exceptions', exceptions_content) exceptions_file = self.fixture('lint.exceptions', exceptions_content)
@ -54,7 +54,7 @@ class TestLinter(unittest.TestCase):
def test_exceptions_comment(self): def test_exceptions_comment(self):
test_content = ('// Copyright (C) 2017 Mike Pennisi. All rights reserved.\n' + test_content = ('// Copyright (C) 2017 Mike Pennisi. All rights reserved.\n' +
'// This code is governed by the BSD license found in the LICENSE file.') '// This code is governed by the BSD license found in the LICENSE file.\n')
test_file = self.fixture('input.js', test_content) test_file = self.fixture('input.js', test_content)
exceptions_content = ('# One comment\n' + exceptions_content = ('# One comment\n' +
'# Another comment\n' + '# Another comment\n' +