Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
help='Rules to always warn (rather than error)')
parser.add_argument('-e', '--error',
help='Rules to always error (rather than warn)')
parser.add_argument('-v', '--verbose', action='store_true', default=False)
parser.add_argument('--version', action='store_true',
help='show bashate version number and exit',
default=False)
parser.add_argument('-s', '--show', action='store_true', default=False)
opts = parser.parse_args(args)
if opts.version:
print("bashate: %s" % bashate.__version__)
sys.exit(0)
if opts.show:
messages.print_messages()
sys.exit(0)
files = opts.files
if not files:
parser.print_usage()
return 1
run = BashateRun()
run.register_ignores(opts.ignore)
run.register_warnings(opts.warn)
run.register_errors(opts.error)
try:
run.check_files(files, opts.verbose)
except IOError as e:
print("bashate: %s" % e)
opts = parser.parse_args(args)
if opts.version:
print("bashate: %s" % bashate.__version__)
sys.exit(0)
if opts.show:
messages.print_messages()
sys.exit(0)
files = opts.files
if not files:
parser.print_usage()
return 1
run = BashateRun()
run.register_ignores(opts.ignore)
run.register_warnings(opts.warn)
run.register_errors(opts.error)
try:
run.check_files(files, opts.verbose)
except IOError as e:
print("bashate: %s" % e)
return 1
if run.warning_count > 0:
print("%d bashate warning(s) found" % run.warning_count)
if run.error_count > 0:
print("%d bashate error(s) found" % run.error_count)
return 1
parser.add_argument('files', metavar='file', nargs='*',
help='files to scan for errors')
parser.add_argument('-i', '--ignore', help='Rules to ignore')
parser.add_argument('-w', '--warn',
help='Rules to always warn (rather than error)')
parser.add_argument('-e', '--error',
help='Rules to always error (rather than warn)')
parser.add_argument('-v', '--verbose', action='store_true', default=False)
parser.add_argument('--version', action='store_true',
help='show bashate version number and exit',
default=False)
parser.add_argument('-s', '--show', action='store_true', default=False)
opts = parser.parse_args(args)
if opts.version:
print("bashate: %s" % bashate.__version__)
sys.exit(0)
if opts.show:
messages.print_messages()
sys.exit(0)
files = opts.files
if not files:
parser.print_usage()
return 1
run = BashateRun()
run.register_ignores(opts.ignore)
run.register_warnings(opts.warn)
run.register_errors(opts.error)
def should_warn(self, error):
# if in the errors list, overrides warning level
if self.error_list and re.search(self.error_list, error):
return False
if messages.is_default_warning(error):
return True
return self.warning_list and re.search(self.warning_list, error)
# under the License.
from __future__ import absolute_import
import argparse
import fileinput
import os
import re
import shlex
import subprocess
import sys
import bashate
from bashate import messages
MESSAGES = messages.MESSAGES
def is_continuation(line):
return re.search('\\\\\s*$', line)
def check_for_do(line, report):
if not is_continuation(line):
match = re.match('^\s*(for|while|until)\s', line)
if match:
operator = match.group(1).strip()
if operator == "for":
# "for i in ..." and "for ((" is bash, but
# "for (" is likely from an embedded awk script,
# so skip it
if re.search('for \([^\(]', line):
"""
[ is the POSIX test operator, while [[ is the bash keyword
comparision operator. Comparisons such as =~, < and > require
the use of [[.
""",
'default': 'E',
},
}
MESSAGES = {}
_default_errors = []
_default_warnings = []
for k, v in _messages.items():
MESSAGES[k] = _Message(k, v['msg'], v['long_msg'], v['default'])
if v['default'] == 'E':
_default_errors.append(k)
if v['default'] == 'W':
_default_warnings.append(k)
# convert this to the regex strings. This looks a bit weird
# but it fits the current model of error/warning/ignore checking
# easily.
_default_errors = '^(' + '|'.join(_default_errors) + ')'
_default_warnings = '^(' + '|'.join(_default_warnings) + ')'
def is_default_error(error):
return re.search(_default_errors, error)