Skip to content

Commit 841b135

Browse files
authored
Fix local files with extends (#2236)
* Append workspace to filename * Add tests * Remove unnecessary fields
1 parent e337103 commit 841b135

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FILTER_REGEX_INCLUDE: "(base-local)"
2+
SHOW_ELAPSED_TIME: true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
EXTENDS: base-error.local.mega-linter.yml
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
EXTENDS: base.local.mega-linter.yml
2+
FILTER_REGEX_INCLUDE: "(local)"
3+
SHOW_ELAPSED_TIME: false

megalinter/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def init_config(workspace=None):
8383
), f"Unable to retrieve EXTENDS config file {config_file_name}"
8484
extends_config_data = yaml.safe_load(r.content)
8585
else:
86-
with open(extends_item, "r", encoding="utf-8") as f:
86+
with open(workspace + os.path.sep + extends_item, "r", encoding="utf-8") as f:
8787
extends_config_data = yaml.safe_load(f)
8888
combined_config.update(extends_config_data)
8989
CONFIG_SOURCE += f"\n[config] - extends from: {extends_item}"

megalinter/tests/test_megalinter/config_test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from megalinter import config
1010
from megalinter.constants import ML_REPO
11+
from megalinter.utils import REPO_HOME_DEFAULT
1112

1213

1314
class config_test(unittest.TestCase):
@@ -45,6 +46,21 @@ def test_remote_config_error(self):
4546
except Exception as e:
4647
self.assertIn("http", str(e))
4748

49+
def test_local_config_extends_success(self):
50+
local_config = "local.mega-linter.yml"
51+
os.environ["MEGALINTER_CONFIG"] = local_config
52+
config.init_config(REPO_HOME_DEFAULT + os.path.sep + ".automation" + os.path.sep + "test" + os.path.sep + "mega-linter-config-test")
53+
self.assertEqual("(local)", config.get("FILTER_REGEX_INCLUDE"))
54+
self.assertEqual("false", config.get("SHOW_ELAPSED_TIME"))
55+
56+
def test_local_config_extends_error(self):
57+
local_config = "local-error.mega-linter.yml"
58+
os.environ["MEGALINTER_CONFIG"] = local_config
59+
try:
60+
config.init_config(REPO_HOME_DEFAULT + os.path.sep + ".automation" + os.path.sep + "test" + os.path.sep + "mega-linter-config-test")
61+
except Exception as e:
62+
self.assertIn("No such file or directory", str(e))
63+
4864
def test_remote_config_extends_success(self):
4965
remote_config = self.test_folder + "base.mega-linter.yml"
5066
os.environ["MEGALINTER_CONFIG"] = remote_config

0 commit comments

Comments
 (0)