Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def simple_nok_check(code, check_name, line=2, **kwargs):
extra_disable = [] if "disable" not in kwargs else kwargs["disable"]
config_w_disable = DEFAULT_CONFIG.copy()
config_w_disable.update({"disable": [check_name] + extra_disable})
assert len(lint_code(code, config_w_disable)) == 0
config = DEFAULT_CONFIG.copy()
config.update({"disable": extra_disable})
outcome = lint_code(code, config)
assert len(outcome) == 1
assert outcome[0].name == check_name
assert outcome[0].line == line
def simple_ok_check(code, **kwargs):
extra_disable = [] if "disable" not in kwargs else kwargs["disable"]
config = DEFAULT_CONFIG.copy()
config.update({"disable": extra_disable})
outcome = lint_code(code, config)
assert len(outcome) == 0, outcome
def simple_nok_check(code, check_name, line=2, **kwargs):
extra_disable = [] if "disable" not in kwargs else kwargs["disable"]
config_w_disable = DEFAULT_CONFIG.copy()
config_w_disable.update({"disable": [check_name] + extra_disable})
assert len(lint_code(code, config_w_disable)) == 0
config = DEFAULT_CONFIG.copy()
config.update({"disable": extra_disable})
outcome = lint_code(code, config)
assert len(outcome) == 1
assert outcome[0].name == check_name
assert outcome[0].line == line
logging.info("Loaded config:")
for entry in config.items():
logging.info(entry)
for key in DEFAULT_CONFIG:
if key not in config:
logging.info(
"Adding missing entry from defaults: %s", (key, DEFAULT_CONFIG[key])
)
config[key] = DEFAULT_CONFIG[key]
problems_total = 0
for file_path in arguments[""]:
with open(file_path, "r") as fh: # TODO: handle exception
content = fh.read()
problems = lint_code(content, config)
problems_total += len(problems)
if len(problems) > 0: # TODO: friendly frontend like in halint
for problem in problems:
print_problem(problem, file_path)
if problems_total > 0:
print(
"Failure: {} problem{} found".format(
problems_total, "" if problems_total == 1 else "s"
),
file=sys.stderr,
)
sys.exit(1)
print("Success: no problems found")