Repository: editorconfig-checker/editorconfig-checker (go)

Issue:
Add flags to disable checks
- [x] Indentation
- [x] Final newline
- [x] Line ending
- [x] Trailing whitespace

Pull request description:
feat(disableChecks): disable trailing whitespace check
closes #69

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 85c34bb..27d64a1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
 
 ## Unreleased
 ### Added
+* (disable specific checks)[https://github.com/editorconfig-checker/editorconfig-checker/pull/71]
 ### Changed
 ### Deprecated
 ### Removed
diff --git a/README.md b/README.md
index 6081c45..b916380 100644
--- a/README.md
+++ b/README.md
@@ -53,7 +53,14 @@ This will place a binary called `ec` into the `bin` directory.
 
 ```
 USAGE:
-  -d    show which files would be checked
+  -disable-final-newline
+        disables the final newline check
+  -disable-indentation
+        disables the indentation check
+  -disable-line-ending
+        disables the trailing whitespace check
+  -disable-trailing-whitespace
+        disables the trailing whitespace check
   -dry-run
         show which files would be checked
   -e string
diff --git a/cmd/editorconfig-checker/main.go b/cmd/editorconfig-checker/main.go
index ce094d1..97c79d6 100644
--- a/cmd/editorconfig-checker/main.go
+++ b/cmd/editorconfig-checker/main.go
@@ -32,7 +32,6 @@ func init() {
 	flag.BoolVar(&params.IgnoreDefaults, "i", false, "ignore default excludes")
 
 	flag.BoolVar(&params.DryRun, "dry-run", false, "show which files would be checked")
-	flag.BoolVar(&params.DryRun, "d", false, "show which files would be checked")
 
 	flag.BoolVar(&params.Version, "version", false, "print the version number")
 
@@ -44,6 +43,11 @@ func init() {
 
 	flag.BoolVar(&params.SpacesAfterTabs, "spaces-after-tabs", false, "allow spaces to be used as alignment after tabs")
 
+	flag.BoolVar(&params.Disabled.TrailingWhitspace, "disable-trailing-whitespace", false, "disables the trailing whitespace check")
+	flag.BoolVar(&params.Disabled.LineEnding, "disable-line-ending", false, "disables the trailing whitespace check")
+	flag.BoolVar(&params.Disabled.FinalNewline, "disable-final-newline", false, "disables the final newline check")
+	flag.BoolVar(&params.Disabled.Indentation, "disable-indentation", false, "disables the indentation check")
+
 	// parse flags
 	flag.Parse()
 
diff --git a/pkg/types/types.go b/pkg/types/types.go
index e3f247f..0ae69ca 100644
--- a/pkg/types/types.go
+++ b/pkg/types/types.go
@@ -11,6 +11,14 @@ type Params struct {
 	DryRun          bool
 	Excludes        string
 	RawFiles        []string
+	Disabled        DisabledChecks
+}
+
+type DisabledChecks struct {
+	TrailingWhitspace bool
+	LineEnding        bool
+	FinalNewline      bool
+	Indentation       bool
 }
 
 // ValidationError represents one validation error
diff --git a/pkg/validation/validation.go b/pkg/validation/validation.go
index ea16afd..9690be0 100644
--- a/pkg/validation/validation.go
+++ b/pkg/validation/validation.go
@@ -38,7 +38,7 @@ func ValidateFile(filePath string, params types.Params) []types.ValidationError
 	if currentError := validators.FinalNewline(
 		fileContent,
 		editorconfig.Raw["insert_final_newline"],
-		editorconfig.Raw["end_of_line"]); currentError != nil {
+		editorconfig.Raw["end_of_line"]); !params.Disabled.FinalNewline && currentError != nil {
 		if params.Verbose {
 			logger.Output(fmt.Sprintf("Final newline error found in %s", filePath))
 		}
@@ -47,7 +47,7 @@ func ValidateFile(filePath string, params types.Params) []types.ValidationError
 
 	if currentError := validators.LineEnding(
 		fileContent,
-		editorconfig.Raw["end_of_line"]); currentError != nil {
+		editorconfig.Raw["end_of_line"]); !params.Disabled.LineEnding && currentError != nil {
 		if params.Verbose {
 			logger.Output(fmt.Sprintf("Line ending error found in %s", filePath))
 		}
@@ -61,7 +61,7 @@ func ValidateFile(filePath string, params types.Params) []types.ValidationError
 
 		if currentError := validators.TrailingWhitespace(
 			line,
-			editorconfig.Raw["trim_trailing_whitespace"] == "true"); currentError != nil {
+			editorconfig.Raw["trim_trailing_whitespace"] == "true"); !params.Disabled.TrailingWhitspace && currentError != nil {
 			if params.Verbose {
 				logger.Output(fmt.Sprintf("Trailing whitespace error found in %s on line %d", filePath, lineNumber))
 			}
@@ -79,7 +79,7 @@ func ValidateFile(filePath string, params types.Params) []types.ValidationError
 		if currentError := validators.Indentation(
 			line,
 			editorconfig.Raw["indent_style"],
-			indentSize, params); currentError != nil {
+			indentSize, params); !params.Disabled.Indentation && currentError != nil {
 			if params.Verbose {
 				logger.Output(fmt.Sprintf("Indentation error found in %s on line %d", filePath, lineNumber))
 			}


Test patch:
diff --git a/pkg/validation/validation_test.go b/pkg/validation/validation_test.go
index f9d30e3..814aa4f 100644
--- a/pkg/validation/validation_test.go
+++ b/pkg/validation/validation_test.go
@@ -43,6 +43,12 @@ func TestValidateFile(t *testing.T) {
 		t.Error("Should have errors when validating file with one error, got", result)
 	}
 
+	params.Disabled.Indentation = true
+	result = ValidateFile("./../../testfiles/wrong-file.txt", params)
+	if len(result) != 0 {
+		t.Error("Should have no errors, got", result)
+	}
+
 	params = types.Params{SpacesAfterTabs: true}
 	result = ValidateFile("./../../testfiles/spaces-after-tabs.txt", params)
 	if len(result) != 0 {
@@ -72,15 +78,36 @@ func TestValidateFile(t *testing.T) {
 		t.Error("Should have one error, got", result)
 	}
 
+	params = types.Params{Verbose: true}
+	params.Disabled.TrailingWhitspace = true
+	result = ValidateFile("./../../testfiles/trailing-whitespace.txt", params)
+	if len(result) != 0 {
+		t.Error("Should have no error, got", result)
+	}
+
 	params = types.Params{Verbose: true}
 	result = ValidateFile("./../../testfiles/final-newline-missing.txt", params)
 	if len(result) != 1 {
+		t.Error("Should have one error, got", result)
+	}
+
+	params = types.Params{Verbose: true}
+	params.Disabled.FinalNewline = true
+	result = ValidateFile("./../../testfiles/final-newline-missing.txt", params)
+	if len(result) != 0 {
 		t.Error("Should have no error, got", result)
 	}
 
 	params = types.Params{Verbose: true}
 	result = ValidateFile("./../../testfiles/wrong-line-ending.txt", params)
 	if len(result) == 0 {
+		t.Error("Should have one error, got", result)
+	}
+
+	params = types.Params{Verbose: true}
+	params.Disabled.LineEnding = true
+	result = ValidateFile("./../../testfiles/wrong-line-ending.txt", params)
+	if len(result) != 0 {
 		t.Error("Should have no error, got", result)
 	}
 }