This repository has been archived by the owner on Apr 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in feature/hadolint (pull request #64)
Support hadolint for Dockerfile lint Approved-by: Xiaohong Zhao <mrluanma@gmail.com>
- Loading branch information
Showing
9 changed files
with
105 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# -*- coding: utf-8 -*- | ||
import os | ||
|
||
from badwolf.utils import run_command | ||
from badwolf.lint import Problem | ||
from badwolf.lint.linters import Linter | ||
from badwolf.lint.utils import in_path | ||
|
||
|
||
class HadoLinter(Linter): | ||
name = 'hadolint' | ||
default_pattern = '*Dockerfile*' | ||
|
||
def is_usable(self): | ||
return in_path('hadolint') | ||
|
||
def lint_files(self, files): | ||
for file in files: | ||
command = ['hadolint', file] | ||
_, output = run_command( | ||
command, | ||
split=True, | ||
include_errors=True, | ||
cwd=self.working_dir, | ||
env={ | ||
'HOME': os.getenv('HOME', '/'), | ||
'XDG_CONFIG_HOME': os.getenv('XDG_CONFIG_HOME', '/') | ||
} | ||
) | ||
if not output: | ||
continue | ||
|
||
for line in output: | ||
parsed = self._parse_line(line) | ||
if not parsed: | ||
continue | ||
|
||
filename, line, message = parsed | ||
yield Problem(filename, line, message, self.name) | ||
|
||
def _parse_line(self, line): | ||
parts = line.split(' ', 1) | ||
if len(parts) != 2: | ||
return | ||
|
||
location, message = parts | ||
if ':' in location: | ||
filename, line = location.split(':', 1) | ||
line = int(line) | ||
else: | ||
filename = location | ||
line = 1 | ||
return filename, line, message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM ubuntu:16.04 | ||
|
||
RUN apt-get update && apt-get install file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters