Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
Address some of the linter issues (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
sk- committed May 31, 2018
1 parent 03dae97 commit 72897ab
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion gitlint/__init__.py
Expand Up @@ -193,7 +193,7 @@ def main(argv, stdout=sys.stdout, stderr=sys.stderr):
stdout = codecs.getwriter("utf-8")(stdout)
if stderr == sys.stderr:
stderr = codecs.getwriter("utf-8")(stderr)
linesep = unicode(os.linesep)
linesep = unicode(os.linesep) # pylint: disable=undefined-variable

arguments = docopt.docopt(
__doc__, argv=argv[1:], version='git-lint v%s' % __VERSION__)
Expand Down
4 changes: 2 additions & 2 deletions gitlint/configs/pylintrc
Expand Up @@ -12,7 +12,7 @@ profile=no

# Add files or directories to the blacklist. They should be base names, not
# paths.
ignore=CVS,.git
ignore=CVS,.git,.hg,.eggs

# Pickle collected data for later comparisons.
persistent=no
Expand Down Expand Up @@ -244,7 +244,7 @@ max-args=8

# Argument names that match this expression will be ignored. Default to name
# with leading underscore
ignored-argument-names=_.*
ignored-argument-names=(unused)?_[a-z_][a-z0-9_]+

# Maximum number of locals for function / method body
max-locals=15
Expand Down
6 changes: 3 additions & 3 deletions gitlint/linters.py
Expand Up @@ -38,8 +38,8 @@ def __repr__(self):
(self.func.__name__, self.args, self.keywords)) # pragma: no cover


def missing_requirements_command(unused_name, missing_programs,
installation_string, filename, unused_lines):
def missing_requirements_command(missing_programs, installation_string,
filename, unused_lines):
"""Pseudo-command to be used when requirements are missing."""
verb = 'is'
if len(missing_programs) > 1:
Expand Down Expand Up @@ -146,7 +146,7 @@ def parse_yaml_config(yaml_config, repo_home):
not_found_programs = utils.programs_not_in_path([command] +
requirements)
if not_found_programs:
linter_command = Partial(missing_requirements_command, name,
linter_command = Partial(missing_requirements_command,
not_found_programs, data['installation'])
else:
linter_command = Partial(lint_command, name, command, arguments,
Expand Down
25 changes: 13 additions & 12 deletions test/e2etest/test_e2e.py
Expand Up @@ -23,6 +23,17 @@
# pylint: disable=too-many-public-methods


def get_linter_output(linter_name, file_path):
cache_path = os.path.expanduser('~/.git-lint/cache')
filename = os.path.join(cache_path, linter_name, file_path[1:])
if not os.path.exists(filename):
return 'No git-lint cache found for %s' % filename

with open(filename) as f:
output = f.read()
return output


class E2EMixin(object):
"""Mixin holding the actual end to end tests.
Expand Down Expand Up @@ -62,7 +73,7 @@ def tearDown(self):
if self.filename_repo is None:
return

with open(self.filename_repo, 'w') as f:
with open(self.filename_repo, 'w'):
pass
self.add(self.filename_repo)
self.commit('Commit teardown')
Expand All @@ -81,16 +92,6 @@ def test_extension_not_defined(self):
self.assertIn('SKIPPED', output)
self.assertIn(extension, output)

def get_linter_output(self, linter_name, file_path):
cache_path = os.path.expanduser('~/.git-lint/cache')
filename = os.path.join(cache_path, linter_name, file_path[1:])
if not os.path.exists(filename):
return 'No git-lint cache found for %s' % filename

with open(filename) as f:
output = f.read()
return output

# TODO(skreft): check that the first file has more than 1 error, check that
# the second file has 1 new error, check also the lines that changed.
def assert_linter_works(self, linter_name, extension):
Expand Down Expand Up @@ -135,7 +136,7 @@ def assert_linter_works(self, linter_name, extension):
0, response,
('Git lint for file %s should have failed.\n git-lint output: %s' +
'\nLinter Output:\n%s') % (filename_error, output,
self.get_linter_output(
get_linter_output(
linter_name, filename_repo)))
self.add(filename_repo)
self.commit('Commit 2')
Expand Down
4 changes: 2 additions & 2 deletions test/unittest/test_linters.py
Expand Up @@ -344,7 +344,7 @@ def test_lint_extension_not_defined(self):
self.assertEqual({'foo.txt': {'skipped': []}}, output)

def test_lint_missing_programs(self):
linter1 = functools.partial(linters.missing_requirements_command, 'l1',
linter1 = functools.partial(linters.missing_requirements_command,
['p1', 'p2'], 'Install p1 and p2')
config = {'.txt': [linter1]}
output = linters.lint('foo.txt', lines=[4, 5], config=config)
Expand All @@ -353,7 +353,7 @@ def test_lint_missing_programs(self):
self.assertEqual({'foo.txt': {'skipped': []}}, output)

def test_lint_two_missing_programs(self):
linter1 = functools.partial(linters.missing_requirements_command, 'l1',
linter1 = functools.partial(linters.missing_requirements_command,
['p1', 'p2'], 'Install p1 and p2')
config = {'.txt': [linter1, linter1]}
output = linters.lint('foo.txt', lines=[4, 5], config=config)
Expand Down

0 comments on commit 72897ab

Please sign in to comment.