Skip to content
This repository has been archived by the owner on Apr 10, 2021. It is now read-only.

Commit

Permalink
Merge pull request #60 from welovecoding/issue-59-editorconfig-with-n…
Browse files Browse the repository at this point in the history
…ame-fix

Closes #59 editorconfig with name are not working
  • Loading branch information
Yserz committed Mar 24, 2015
2 parents 05017fc + e1651cf commit e2e4100
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main/java/org/editorconfig/core/EditorConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ public List<OutPair> getProperties(String filePath) throws EditorConfigException
String dir = new File(filePath).getParent();
while (dir != null && !root) {
String configPath = dir + "/" + configFilename;

/**
* allows .../*.editorconfig files
*/
for (File file : new File(dir).listFiles()) {
if (getFileExtension(file).equals(configFilename)) {
configPath = file.getAbsolutePath();
}
}

if (new File(configPath).exists()) {
FileInputStream stream = new FileInputStream(configPath);
InputStreamReader reader = new InputStreamReader(stream, "UTF-8");
Expand Down Expand Up @@ -115,6 +125,16 @@ public List<OutPair> getProperties(String filePath) throws EditorConfigException
return result;
}

private String getFileExtension(File file) {
String name = file.getName();
int lastIndexOf = name.lastIndexOf(".");
if (lastIndexOf > -1) {
return name.substring(lastIndexOf);
} else {
return ""; // empty extension
}
}

private void checkAssertions() throws VersionException {
if (compareVersions(version, VERSION) > 0) {
throw new VersionException("Required version is greater than the current version.");
Expand Down

0 comments on commit e2e4100

Please sign in to comment.