Skip to content

Commit

Permalink
[MegaLinter] Apply linters fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bdovaz committed Jan 28, 2023
1 parent acaca07 commit fa90fd8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
4 changes: 3 additions & 1 deletion megalinter/linter_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
25 changes: 16 additions & 9 deletions megalinter/tests/test_megalinter/LinterTestRoot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
Unit tests for Linter class (and sub-classes)
"""
import os

from typing import Optional

from megalinter import config, linter_factory
Expand All @@ -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": [],
Expand All @@ -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()
Expand Down Expand Up @@ -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)
5 changes: 3 additions & 2 deletions megalinter/tests/test_megalinter/helpers/utilstest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import contextlib
import difflib
import git
import io
import json
import logging
Expand All @@ -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 (
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down

0 comments on commit fa90fd8

Please sign in to comment.