Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path separator not handled correctly on Windows #27

Closed
schalch-net opened this issue Aug 28, 2023 · 7 comments · Fixed by editorconfig-checker/editorconfig-checker#292
Closed
Labels
help wanted Extra attention is needed

Comments

@schalch-net
Copy link

My .editorconfig file looks as following:

root = true

[*]
trim_trailing_whitespace = true

[lib/**]
trim_trailing_whitespace = unset

I use the editorconfig-checker 2.7.2 from pip. On a Linux system, everything works as expected. Namely, the trailing whitespace rule is applied everywhere expect in all files and subfolders of the folder lib.

However, on Windows, this exception is ignored. Namely, I get some errors for the trailing whitespace rule inside the folder lib.

I found out that the tool works as expected on Windows if I change the line [lib/**] to [lib\\**]. But this is not an acceptable workaround for me, because I need the editorconfig-checker to behave exactly the same on Linux and on Windows. And it clearly violates the editorconfig file format rules, saying that "Backslashes (\) are not allowed as path separators (even on Windows)."

@mstruebing
Copy link
Member

@schalch-net
Copy link
Author

Yes, the effect is the same! I cannot assess whether it is the same bug in the editorconfig-core-go that propagates to the python package, but it really seems so.

@mstruebing
Copy link
Member

editorconfig-checker.python uses editorconfig-checker which uses editorconfig-core-go so if the issue is the same, it should be fixed when the issue in editorconfig-core-go is fixed.

@greut
Copy link

greut commented Aug 29, 2023

@mstruebing it seems that editorconfig-core-go works fine with forward slashed files. You could change filepath.Walk^1^2 to use fs.WalkDir^3 instead or call filepath.ToSlash^4 on them, your call.

WalkDir calls fn with paths that use the separator character appropriate for the operating system. This is unlike io/fs.WalkDir, which always uses slash separated paths.

https://pkg.go.dev/path/filepath#WalkDir

  1. https://github.com/editorconfig-checker/editorconfig-checker/blob/main/pkg/files/files.go#L83
  2. https://pkg.go.dev/path/filepath#Walk
  3. https://pkg.go.dev/io/fs#WalkDir
  4. https://pkg.go.dev/path/filepath#ToSlash

@mstruebing
Copy link
Member

Thank you @greut

If anyone is willing to provide a PR I will make sure to get a new release out quickly.

@mstruebing mstruebing added the help wanted Extra attention is needed label Aug 30, 2023
@greut
Copy link

greut commented Sep 27, 2023

One last error was present in the library, editorconfig/editorconfig-core-go@7354273 - So make sure you're sending slash separated paths to it.

@schalch-net
Copy link
Author

schalch-net commented Oct 16, 2023

I just tried out the new release 2.7.3 from pip, and things even get worse with the new release...

The initial example from above does still not work on Windows. Also the workarounds with [lib\\**] or with [lib**] both do not work anymore. It seems that any rule involving a path separator or ** is not considered anymore!

EDIT: Also on Linux, the syntax [lib/**] does not work anymore with version 2.7.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants