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

Issue:
`indent_style = space` is ignored if `indent_size = unset`
If the `indent_size` is not set for a file, the check for `indent_style = space` is silently skipped.

Example:
```ini
# .editorconfig
root = true
[*]
indent_style = space
# indent_size = 3
```
```
# example.txt (whitespace made visible)
this line is unindented -- should PASS
····this line is indented with 4 spaces -- should PASS
￫       this line is indented with 1 tab -- should FAIL
￫       ····this line is indented with 1 tab and 4 spaces -- should FAIL
```
```console
$ ec example.txt  # Should fail on the latter 2 lines
$ echo $?
0
```

Note that if the `indent_size = 3` is uncommented from the `.editorconfig` but we disable the indentation size check, the expected errors are reported:
```console
$ ec -disable-indent-size example.txt
example.txt:
	3: Wrong indent style found (tabs instead of spaces)
	4: Wrong indent style found (tabs instead of spaces)

2 errors found
```

Pull request:
fix: indent_style = space is ignored if indent_size = unset (#277)
Looking to fix #277 to support indent in spaces.  I added a test case as well to verify it's fixed.

Patch:
diff --git a/pkg/validation/validators/validators.go b/pkg/validation/validators/validators.go
index 272e5e2..61af677 100644
--- a/pkg/validation/validators/validators.go
+++ b/pkg/validation/validators/validators.go
@@ -26,8 +26,16 @@ func Indentation(line string, indentStyle string, indentSize int, config config.
 
 // Space validates if a line is indented correctly respecting the indentSize
 func Space(line string, indentSize int, config config.Config) error {
-	if len(line) > 0 && indentSize > 0 {
-		if !config.Disable.IndentSize {
+	if len(line) > 0 {
+		// match recurring spaces and everything except tab characters
+		regexpPattern := `^( )*([^ \t]|$)`
+		matched, _ := regexp.MatchString(regexpPattern, line)
+
+		if !matched {
+			return fmt.Errorf("Wrong indent style found (tabs instead of spaces)")
+		}
+
+		if !config.Disable.IndentSize && indentSize > 0 {
 			// match recurring spaces indentSize times - this can be recurring or never
 			// match either a space followed by a * and maybe a space (block-comments)
 			// or match everything despite a space or tab-character
@@ -37,14 +45,6 @@ func Space(line string, indentSize int, config config.Config) error {
 			if !matched {
 				return fmt.Errorf("Wrong amount of left-padding spaces(want multiple of %d)", indentSize)
 			}
-		} else {
-			// match recurring spaces and everything except tab characters
-			regexpPattern := `^( )*([^ \t]|$)`
-			matched, _ := regexp.MatchString(regexpPattern, line)
-
-			if !matched {
-				return fmt.Errorf("Wrong indent style found (tabs instead of spaces)")
-			}
 		}
 	}
 


Test patch:
diff --git a/pkg/validation/validation_test.go b/pkg/validation/validation_test.go
index 1471832..7b12e57 100644
--- a/pkg/validation/validation_test.go
+++ b/pkg/validation/validation_test.go
@@ -127,7 +127,7 @@ func TestValidateFile(t *testing.T) {
 	configuration = config.Config{Verbose: true}
 	result = ValidateFile("./../../testfiles/line-to-long.txt", configuration)
 	if len(result) != 1 {
-		t.Error("Should have no error, got", result)
+		t.Error("Should have one error, got", result)
 	}
 
 	configuration = config.Config{Verbose: true}
@@ -136,4 +136,10 @@ func TestValidateFile(t *testing.T) {
 	if len(result) != 0 {
 		t.Error("Should have no error, got", result)
 	}
+
+	configuration = config.Config{Verbose: true}
+	result = ValidateFile("./../../testfiles/spaces-with-tab.c", configuration)
+	if len(result) != 1 {
+		t.Error("Should have one error, got", result)
+	}
 }
diff --git a/testfiles/.editorconfig b/testfiles/.editorconfig
index 7e7c604..d77c839 100644
--- a/testfiles/.editorconfig
+++ b/testfiles/.editorconfig
@@ -17,3 +17,7 @@ end_of_line = lf
 
 [line-to-long.txt]
 max_line_length = 2
+
+[spaces-with-tab.c]
+indent_style = space
+indent_size = unset
diff --git a/testfiles/spaces-with-tab.c b/testfiles/spaces-with-tab.c
new file mode 100644
index 0000000..a015fa7
--- /dev/null
+++ b/testfiles/spaces-with-tab.c
@@ -0,0 +1,14 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+
+int main(int argc, char *argv[])
+{
+    if (argc > 1) {
+	for (int i=0; i < argc; i++) {       // This line is indented with tab
+            printf("%d: %s\n", i, argv[i]);
+        }
+    }
+    return 0;
+}
+