From 6a2c7681765b0a36eaa039040c889bacacd82247 Mon Sep 17 00:00:00 2001 From: Amy Boyd Date: Thu, 22 Dec 2016 14:20:41 +0000 Subject: [PATCH] Add support for non-standard rule 'ignore'. --- docs/to-do.md | 2 -- editorconfig/apply.go | 4 ++++ editorconfig/apply_test.go | 13 +++++++++++++ editorconfig/tests/.editorconfig | 3 +++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/docs/to-do.md b/docs/to-do.md index 5e26d49..a2fe200 100644 --- a/docs/to-do.md +++ b/docs/to-do.md @@ -2,8 +2,6 @@ * Add a fixer for the 'indent_style' rule. -* Add a non-standard rule to ignore directories. - * Optimize speed and memory usage. * Document how to install. diff --git a/editorconfig/apply.go b/editorconfig/apply.go index 463482e..f7af454 100644 --- a/editorconfig/apply.go +++ b/editorconfig/apply.go @@ -26,6 +26,10 @@ func GetRulesToApplyToSourcePath(sourcePath string, cfs []ConfigFile) map[string } } + if isIgnored, _ := rules["ignore"]; isIgnored == "true" { + return make(map[string]string) + } + delete(rules, "root") if indentStyleValue, _ := rules["indent_style"]; indentStyleValue == "tab" { diff --git a/editorconfig/apply_test.go b/editorconfig/apply_test.go index 593e7cd..bf2edff 100644 --- a/editorconfig/apply_test.go +++ b/editorconfig/apply_test.go @@ -32,3 +32,16 @@ func TestGetRulesToApplyToSourcePathWhenNoRulesShouldApply(t *testing.T) { t.Error("No rules should be applied for the file") } } + +func TestGetRulesToApplyToSourcePathWhenPathShouldBeIgnored(t *testing.T) { + result := GetRulesToApplyToSourcePath( + "some-file-to-ignore.ignored", + []ConfigFile{ + CreateConfigFileStruct("tests/.editorconfig"), + }, + ) + + if len(result) != 0 { + t.Error("No rules should be applied for the file") + } +} diff --git a/editorconfig/tests/.editorconfig b/editorconfig/tests/.editorconfig index 7c753d2..a8f4f94 100644 --- a/editorconfig/tests/.editorconfig +++ b/editorconfig/tests/.editorconfig @@ -13,3 +13,6 @@ trim_trailing_whitespace = false [**.go] indent_style = tabs + +[**.ignored] +ignore = true