Skip to content

Commit 405d9bd

Browse files
authored
remove level restriction for extendsConfigPath (#408)
* remove level restriction for extendsConfigPath
1 parent e259fef commit 405d9bd

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## dev branch / next version (2.x.x)
2-
- Added `extendsConfigPath` field to config files, to allow one level of extension, fixes [#401](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/401) ([#407](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/407))
2+
- Added `extendsConfigPath` field to config files fixes [#401](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/401) ([#407](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/407) + [#408](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/408))
33

44
## version 2.2.2
55

src/checkstyle/Main.hx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ class Main {
4545
var numberOfCheckerThreads:Int;
4646
var overrideCheckerThreads:Int;
4747
var disableThreads:Bool;
48+
var seenConfigPaths:Array<String>;
4849

4950
function new() {
5051
info = new ChecksInfo();
5152
checker = new Checker();
5253
paths = [];
5354
allExcludes = [];
55+
seenConfigPaths = [];
5456
excludesMap = new Map();
5557
exitCode = 0;
5658
configPath = null;
@@ -123,18 +125,21 @@ class Main {
123125

124126
public function loadConfig(path:String) {
125127
if (path != null && FileSystem.exists(path) && !FileSystem.isDirectory(path)) {
128+
seenConfigPaths.push(path);
126129
parseAndValidateConfig(Json.parse(File.getContent(path)));
127130
}
128131
else addAllChecks();
129132
}
130133

131-
public function parseAndValidateConfig(config:Config, allowExtend:Bool = true) {
134+
public function parseAndValidateConfig(config:Config) {
132135

133136
validateAllowedFields(config, Reflect.fields(getEmptyConfig()), "Config");
134137

135-
if (allowExtend && !config.extendsConfigPath.isEmpty()) {
138+
if (!config.extendsConfigPath.isEmpty()) {
139+
if (seenConfigPaths.contains(config.extendsConfigPath)) failWith("extendsConfig: config file loop detected!");
140+
seenConfigPaths.push(config.extendsConfigPath);
136141
if (FileSystem.exists(config.extendsConfigPath) && !FileSystem.isDirectory(config.extendsConfigPath)) {
137-
parseAndValidateConfig(Json.parse(File.getContent(config.extendsConfigPath)), false);
142+
parseAndValidateConfig(Json.parse(File.getContent(config.extendsConfigPath)));
138143
}
139144
else failWith('extendsConfig: Failed to load parent configuration file [${config.extendsConfigPath}]');
140145
}

0 commit comments

Comments
 (0)