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

Allow linting of filenames without extension, e.g. Makefile #132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions gitlint/linters.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,11 @@ def lint(filename, lines, config):
then a field 'skipped' will be set with the reasons. Otherwise, the field
'comments' will have the messages.
"""
_, ext = os.path.splitext(filename)
if ext in config:
root, ext = os.path.splitext(filename)
config_key = ext if ext else os.path.split(root)[1]
if config_key in config:
output = collections.defaultdict(list)
for linter in config[ext]:
for linter in config[config_key]:
linter_output = linter(filename, lines)
for category, values in linter_output[filename].items():
output[category].extend(values)
Expand All @@ -186,12 +187,12 @@ def lint(filename, lines, config):
key=lambda x: (x.get('line', -1), x.get('column', -1)))

return {filename: dict(output)}
else:
return {
filename: {
'skipped': [
'no linter is defined or enabled for files'
' with extension "%s"' % ext
]
}

return {
filename: {
'skipped': [
'no linter is defined or enabled for files'
' with extension or name "%s"' % config_key
]
}
}