Skip to content

Commit

Permalink
Merge pull request #148 from roaldnefs/release-v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
roaldnefs authored Jun 26, 2020
2 parents 6dacbb3 + 2b118e0 commit bea78c3
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 73 deletions.
2 changes: 1 addition & 1 deletion saltlint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""

NAME = 'salt-lint'
VERSION = '0.2.2'
VERSION = '0.3.0'
DESCRIPTION = __doc__

__author__ = 'Warpnet B.V.'
Expand Down
6 changes: 3 additions & 3 deletions saltlint/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ def run(args=None):
if config.json:
formatter = formatters.JsonFormatter()
elif config.severity:
formatter = formatters.SeverityFormatter()
formatter = formatters.SeverityFormatter(config.colored)
else:
formatter = formatters.Formatter()
formatter = formatters.Formatter(config.colored)

for state in states:
runner = Runner(rules, state, config, checked_files)
Expand All @@ -126,7 +126,7 @@ def run(args=None):
matches.sort(key=lambda x: (x.filename, x.linenumber, x.rule.id))

# Show the matches on the screen
formatter.process(matches, config.colored)
formatter.process(matches)

# Delete stdin temporary file
if stdin_state:
Expand Down
4 changes: 1 addition & 3 deletions saltlint/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import os
import sys
import pathspec

# Import Salt libs
from salt.ext import six
import six

import saltlint.utils

Expand Down
139 changes: 77 additions & 62 deletions saltlint/formatters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,77 +5,92 @@

import json

# Import salt libs
try:
import salt.utils.color as saltcolor
except ImportError:
import salt.utils as saltcolor

def get_colors(use=True):
"""
Return the colors as a dict, pass False to return the colors as empty
strings.
"""
colors = {
"BLACK": "\033[0;30m",
"DARK_GRAY": "\033[1;30m",
"RED": "\033[0;31m",
"LIGHT_RED": "\033[1;31m",
"GREEN": "\033[0;32m",
"LIGHT_GREEN": "\033[1;32m",
"BLUE": "\033[0;34m",
"LIGHT_BLUE": "\033[1;34m",
"MAGENTA": "\033[0;35m",
"LIGHT_MAGENTA": "\033[1;35m",
"CYAN": "\033[0;36m",
"LIGHT_CYAN": "\033[1;36m",
"LIGHT_GRAY": "\033[0;37m",
"WHITE": "\033[1;37m",
"DEFAULT_COLOR": "\033[00m",
"ENDC": "\033[0m",
}

class Formatter(object):
if not use:
for color in colors:
colors[color] = ''

def process(self, matches, colored=False):
return colors


class BaseFormatter(object):

def __init__(self, colored=False):
self.colored = colored

def process(self, matches):
for match in matches:
print(self.format(match, colored))
print(self.format(match))

def format(self, match):
raise NotImplementedError()


class Formatter(BaseFormatter):

def format(self, match, colored=False):
def format(self, match):
formatstr = u"{0} {1}\n{2}:{3}\n{4}\n"
if colored:
color = saltcolor.get_colors()
return formatstr.format(
u'{0}[{1}]{2}'.format(color['RED'], match.rule.id,
color['ENDC']),
u'{0}{1}{2}'.format(color['LIGHT_RED'], match.message,
color['ENDC']),
u'{0}{1}{2}'.format(color['BLUE'], match.filename,
color['ENDC']),
u'{0}{1}{2}'.format(color['CYAN'], str(match.linenumber),
color['ENDC']),
u'{0}{1}{2}'.format(color['MAGENTA'], match.line, color['ENDC'])
)
else:
return formatstr.format(
u'[{0}]'.format(match.rule.id),
match.message,
match.filename,
match.linenumber,
match.line)


class SeverityFormatter(object):
def process(self, matches, colored=False):
for match in matches:
print(self.format(match, colored))

def format(self, match, colored=False):
color = get_colors(self.colored)
return formatstr.format(
u'{0}[{1}]{2}'.format(color['RED'], match.rule.id,
color['ENDC']),
u'{0}{1}{2}'.format(color['LIGHT_RED'], match.message,
color['ENDC']),
u'{0}{1}{2}'.format(color['BLUE'], match.filename,
color['ENDC']),
u'{0}{1}{2}'.format(color['CYAN'], str(match.linenumber),
color['ENDC']),
u'{0}{1}{2}'.format(color['MAGENTA'], match.line, color['ENDC'])
)


class SeverityFormatter(BaseFormatter):

def format(self, match):
formatstr = u"{0} {sev} {1}\n{2}:{3}\n{4}\n"

if colored:
color = saltcolor.get_colors()
return formatstr.format(
u'{0}[{1}]{2}'.format(color['RED'], match.rule.id,
color['ENDC']),
u'{0}{1}{2}'.format(color['LIGHT_RED'], match.message,
color['ENDC']),
u'{0}{1}{2}'.format(color['BLUE'], match.filename,
color['ENDC']),
u'{0}{1}{2}'.format(color['CYAN'], str(match.linenumber),
color['ENDC']),
u'{0}{1}{2}'.format(color['MAGENTA'], match.line, color['ENDC']),
sev=u'{0}[{1}]{2}'.format(color['RED'], match.rule.severity,
color['ENDC'])
)
else:
return formatstr.format(
u'[{0}]'.format(match.rule.id),
match.message,
match.filename,
match.linenumber,
match.line,
sev=u'[{0}]'.format(match.rule.severity))


class JsonFormatter(object):
color = get_colors(self.colored)
return formatstr.format(
u'{0}[{1}]{2}'.format(color['RED'], match.rule.id,
color['ENDC']),
u'{0}{1}{2}'.format(color['LIGHT_RED'], match.message,
color['ENDC']),
u'{0}{1}{2}'.format(color['BLUE'], match.filename,
color['ENDC']),
u'{0}{1}{2}'.format(color['CYAN'], str(match.linenumber),
color['ENDC']),
u'{0}{1}{2}'.format(color['MAGENTA'], match.line, color['ENDC']),
sev=u'{0}[{1}]{2}'.format(color['RED'], match.rule.severity,
color['ENDC'])
)


class JsonFormatter(BaseFormatter):

def process(self, matches, *args, **kwargs):
items = []
Expand Down
4 changes: 1 addition & 3 deletions saltlint/linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
import re
import sys
import codecs

# import Salt libs
from salt.ext import six
import six

import saltlint.utils
from saltlint.config import SaltLintConfig
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
include_package_data=True,
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
install_requires=['salt', 'pathspec>=0.6.0'],
install_requires=['six', 'pyyaml', 'pathspec>=0.6.0'],
license=__license__,
zip_safe=False,
classifiers=[
Expand Down

0 comments on commit bea78c3

Please sign in to comment.