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_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
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
arguments = docopt(
__doc__,
version="gdlint {}".format(pkg_resources.get_distribution("gdtoolkit").version),
)
if not isinstance(arguments, dict):
print(arguments) # stderr
sys.exit(0)
if arguments["--verbose"]:
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
if arguments["--dump-default-config"]: # TODO: error handling
assert not os.path.isfile(CONFIG_FILE_NAME)
with open(CONFIG_FILE_NAME, "w") as fh:
fh.write(yaml.dump(DEFAULT_CONFIG.copy()))
sys.exit(0)
# TODO: add opt-based config-file providing
# TODO: extract the algorithm
search_dir = Path(os.getcwd())
found_config_file_path = None
while search_dir != Path(os.path.abspath(os.sep)):
file_path = os.path.join(search_dir, CONFIG_FILE_NAME)
if os.path.isfile(file_path):
found_config_file_path = file_path
break
file_path = os.path.join(search_dir, ".{}".format(CONFIG_FILE_NAME))
if os.path.isfile(file_path):
found_config_file_path = file_path
break
search_dir = search_dir.parent