def linter_test_setup(params=None): config.init_config(None) if params is None: params = {} # Root to lint sub_lint_root = (params["sub_lint_root"] if "sub_lint_root" in params else f"{os.path.sep}.automation{os.path.sep}test") # Ignore report folder config.set_value("FILTER_REGEX_EXCLUDE", "\\/(report)\\/") # TAP Output deactivated by default config.set_value("OUTPUT_FORMAT", "text") config.set_value("OUTPUT_DETAIL", "detailed") # Root path of default rules root_dir = ("/tmp/lint" if os.path.isdir("/tmp/lint") else os.path.relpath( os.path.relpath(os.path.dirname(os.path.abspath(__file__))) + "/../../../..")) config.set_value("VALIDATE_ALL_CODEBASE", "true") # Root path of files to lint config.set_value( "DEFAULT_WORKSPACE", (config.get("DEFAULT_WORKSPACE") + sub_lint_root if config.exists("DEFAULT_WORKSPACE") and os.path.isdir(config.get("DEFAULT_WORKSPACE") + sub_lint_root) else root_dir + sub_lint_root), ) assert os.path.isdir( config.get("DEFAULT_WORKSPACE")), ("DEFAULT_WORKSPACE " + config.get("DEFAULT_WORKSPACE") + " is not a valid folder")
def call_mega_linter(env_vars): prev_environ = config.copy() usage_stdout = io.StringIO() with contextlib.redirect_stdout(usage_stdout): # Set env variables for env_var_key, env_var_value in env_vars.items(): config.set_value(env_var_key, env_var_value) # Call linter mega_linter = Megalinter() mega_linter.run() # Set back env variable previous values for env_var_key, env_var_value in env_vars.items(): if env_var_key in prev_environ: config.set_value(env_var_key, prev_environ[env_var_key]) else: config.delete(env_var_key) output = usage_stdout.getvalue().strip() print_output(output) return mega_linter, output
def linter_test_setup(params=None): for key in [ "MEGALINTER_CONFIG", "EXTENDS", "FILTER_REGEX_INCLUDE", "FILTER_REGEX_EXCLUDE", "SHOW_ELAPSED_TIME", ]: if key in os.environ: del os.environ[key] config.delete() if params is None: params = {} # Root to lint sub_lint_root = (params["sub_lint_root"] if "sub_lint_root" in params else f"{os.path.sep}.automation{os.path.sep}test") # Root path of default rules root_dir = ("/tmp/lint" if os.path.isdir("/tmp/lint") else os.path.relpath( os.path.relpath(os.path.dirname(os.path.abspath(__file__))) + "/../../../..")) workspace = None config_file_path = root_dir + sub_lint_root + os.path.sep + ".mega-linter.yml" if os.path.isfile(config_file_path): workspace = root_dir + sub_lint_root elif params.get("required_config_file", False) is True: raise Exception( f"[test] There should be a .mega-linter.yml file in test folder {config_file_path}" ) config.init_config(workspace) # Ignore report folder config.set_value("FILTER_REGEX_EXCLUDE", r"\/report\/") # TAP Output deactivated by default config.set_value("OUTPUT_FORMAT", "text") config.set_value("OUTPUT_DETAIL", "detailed") config.set_value("PLUGINS", "") config.set_value("VALIDATE_ALL_CODEBASE", "true") # Root path of files to lint config.set_value( "DEFAULT_WORKSPACE", (config.get("DEFAULT_WORKSPACE") + sub_lint_root if config.exists("DEFAULT_WORKSPACE") and os.path.isdir(config.get("DEFAULT_WORKSPACE") + sub_lint_root) else root_dir + sub_lint_root), ) assert os.path.isdir( config.get("DEFAULT_WORKSPACE")), ("DEFAULT_WORKSPACE " + config.get("DEFAULT_WORKSPACE") + " is not a valid folder")