diff --git a/megalinter/linter_factory.py b/megalinter/linter_factory.py index 88ea8e69b76..57b4321448f 100644 --- a/megalinter/linter_factory.py +++ b/megalinter/linter_factory.py @@ -131,7 +131,9 @@ def build_linter(language, linter_name, linter_init_params=None): assert os.path.isfile( language_descriptor_file ), f"Unable to find {language_descriptor_file}" - linters = build_descriptor_linters(language_descriptor_file, linter_init_params, [linter_name]) + linters = build_descriptor_linters( + language_descriptor_file, linter_init_params, [linter_name] + ) assert ( len(linters) == 1 ), f"Unable to find linter {linter_name} in {language_descriptor_file}" diff --git a/megalinter/tests/test_megalinter/LinterTestRoot.py b/megalinter/tests/test_megalinter/LinterTestRoot.py index 6361b7d3f02..fcb2d63775f 100644 --- a/megalinter/tests/test_megalinter/LinterTestRoot.py +++ b/megalinter/tests/test_megalinter/LinterTestRoot.py @@ -3,7 +3,6 @@ Unit tests for Linter class (and sub-classes) """ import os - from typing import Optional from megalinter import config, linter_factory @@ -15,7 +14,10 @@ class LinterTestRoot: linter_name: Optional[str] = None def get_linter_instance(self): - return linter_factory.build_linter(self.descriptor_id, self.linter_name, { + return linter_factory.build_linter( + self.descriptor_id, + self.linter_name, + { "default_linter_activation": True, "enable_descriptors": [], "enable_linters": [], @@ -24,7 +26,8 @@ def get_linter_instance(self): "disable_errors_linters": [], "github_workspace": os.getcwd(), "post_linter_status": True, - }) + }, + ) def test_success(self): utilstest.linter_test_setup() @@ -53,15 +56,19 @@ def test_report_sarif(self): def test_format_fix(self): utilstest.linter_test_setup() - if self.linter_name == 'prettier': + if self.linter_name == "prettier": config.set_value("JAVASCRIPT_DEFAULT_STYLE", "prettier") - - if self.linter_name == 'standard': + + if self.linter_name == "standard": config.set_value("JAVASCRIPT_DEFAULT_STYLE", "standard") - linter=self.get_linter_instance() + linter = self.get_linter_instance() - if self.linter_name == 'standard': - config.set_value("JAVASCRIPT_STANDARD_ARGUMENTS", config.get("DEFAULT_WORKSPACE").replace("\\", "/") + f"/{linter.test_folder}/*_fix_*.js") + if self.linter_name == "standard": + config.set_value( + "JAVASCRIPT_STANDARD_ARGUMENTS", + config.get("DEFAULT_WORKSPACE").replace("\\", "/") + + f"/{linter.test_folder}/*_fix_*.js", + ) utilstest.test_linter_format_fix(linter, self) diff --git a/megalinter/tests/test_megalinter/helpers/utilstest.py b/megalinter/tests/test_megalinter/helpers/utilstest.py index d002f895a90..9baca15c12f 100644 --- a/megalinter/tests/test_megalinter/helpers/utilstest.py +++ b/megalinter/tests/test_megalinter/helpers/utilstest.py @@ -1,6 +1,5 @@ import contextlib import difflib -import git import io import json import logging @@ -13,6 +12,7 @@ from datetime import datetime from distutils.dir_util import copy_tree +import git from git import Repo from megalinter import Megalinter, config, utils from megalinter.constants import ( @@ -606,6 +606,7 @@ def assert_file_has_been_updated(file_name, bool_val, test_self): else: test_self.assertFalse(updated, f"{file_name} has not been updated") + def test_linter_format_fix(linter, test_self): if ( linter.disabled is True @@ -620,7 +621,7 @@ def test_linter_format_fix(linter, test_self): workspace = workspace + os.path.sep + "fix" tmp_report_folder = tempfile.gettempdir() + os.path.sep + str(uuid.uuid4()) assert os.path.isdir(workspace), f"Test folder {workspace} is not existing" - + file_map = {} for file_name in os.listdir(workspace):