You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add EditorConfig for more consistent coding styles #3278
EditorConfig helps maintain consistent coding styles for multiple developers working on the same project across various editors and IDEs.
We already have ruff to format our Python codes, but we also have many non-Python files. For these non-Python files, it would be great if we could also remove trailing whitespace (xref #935), and end lines with \n.
For maintainers, I think most of us are aware of the style rules already, so it doesn't seem necesary. For casual contributors who might just edit files using the GitHub GUI (which is super prone to whitespace issues), I don't think an editorconfig would help?
For maintainers, I think most of us are aware of the style rules already, so it doesn't seem necesary.
Yes, but we sometimes still make mistakes. For example, currently, the repository contains two files (./examples/projections/README.txt and ./doc/changes.md) that have trailing whitespaces:
For casual contributors who might just edit files using the GitHub GUI (which is super prone to whitespace issues), I don't think an editorconfig would help?
GitHub has native support of EditorConfig since 2015 (editorconfig/editorconfig.github.com#48) but as I understand it, it can't remove trailing whitespaces. So contributors may still accidentally commit trailing whitespaces to the repository, but if .editorconfig exists, the trailing whitespace can be automatically removed when any maintainers or contributors edit the file using a local text editor (depends on if a plugin is need/installed or not).
GitHub has native support of EditorConfig since 2015 (editorconfig/editorconfig.github.com#48) but as I understand it, it can't remove trailing whitespaces. So contributors may still accidentally commit trailing whitespaces to the repository, but if .editorconfig exists, the trailing whitespace can be automatically removed when any maintainers or contributors edit the file using a local text editor (depends on if a plugin is need/installed or not).
Yes, but we sometimes still make mistakes. For example, currently, the repository contains two files (./examples/projections/README.txt and ./doc/changes.md) that have trailing whitespaces:
GitHub has native support of EditorConfig since 2015 (editorconfig/editorconfig.github.com#48) but as I understand it, it can't remove trailing whitespaces. So contributors may still accidentally commit trailing whitespaces to the repository, but if .editorconfig exists, the trailing whitespace can be automatically removed when any maintainers or contributors edit the file using a local text editor (depends on if a plugin is need/installed or not).
Hm. I am somehow unsure here. Maybe we can make a POC PR for this? And see if it works as expected and helps us / we need it?
Yes, but we sometimes still make mistakes. For example, currently, the repository contains two files (./examples/projections/README.txt and ./doc/changes.md) that have trailing whitespaces:
So, these two files should be corrected, or?
Yes, but let's keep these two files for a while so that we can test if .editorconfig or other solutions works.
Then I added a few lines to the examples/projections/README.txt file and expected to see that the extra trailing whitespace at line 5 would be trimmed automatically when saving, but nothing happened.
If we're talking about enforcing no trailing whitespaces, maybe we should revisit #1593 and add a .pre-commit-config.yaml instead? We can set autofix_prs=false to disable the autofixing of pre-commit.ci by default to address your concerns about the automatic fixes not being friendly for git-newbies.
Yes, I was re-reading that issue too. I think what we care about most are trailing whitespace and leading tabs.
I guess we have two different solutions:
Enable the pre-commit CI service
Extend the "Style Checks" workflow and "/format" slash command
For solution 2, to find files with trailing whitespace:
$ git grep -I -n -e ' \+$'
doc/changes.md:10:* 🚀 Almost all module wrappers (with a few exceptions) now use in-memory GMT *virtual files* instead of intermediate temporary files to improve performance ([#2730](https://github.com/GenericMappingTools/pygmt/issues/2730))
doc/changes.md:12:* Adopt [SPEC 0](https://scientific-python.org/specs/spec-0000/) policy for minimum supported versions of GMT, Python, and other core dependencies
examples/projections/README.txt:5:one you want to use in all plotting methods. The projection is specified by a one-letter
Activity
seisman commentedon Jun 2, 2024
Ping @GenericMappingTools/pygmt-maintainers for comments.
weiji14 commentedon Jun 2, 2024
For maintainers, I think most of us are aware of the style rules already, so it doesn't seem necesary. For casual contributors who might just edit files using the GitHub GUI (which is super prone to whitespace issues), I don't think an editorconfig would help?
seisman commentedon Jun 2, 2024
Yes, but we sometimes still make mistakes. For example, currently, the repository contains two files (
./examples/projections/README.txtand./doc/changes.md) that have trailing whitespaces:GitHub has native support of EditorConfig since 2015 (editorconfig/editorconfig.github.com#48) but as I understand it, it can't remove trailing whitespaces. So contributors may still accidentally commit trailing whitespaces to the repository, but if
.editorconfigexists, the trailing whitespace can be automatically removed when any maintainers or contributors edit the file using a local text editor (depends on if a plugin is need/installed or not).yvonnefroehlich commentedon Jun 3, 2024
Hm. I am somehow unsure here. Maybe we can make a POC PR for this? And see if it works as expected and helps us / we need it?
It looks like this tool can also check the spelling (see
speeling_languageat the end of the table at https://spec.editorconfig.org/#supported-pairs).So, these two files should be corrected, or?
seisman commentedon Jun 3, 2024
The https://github.com/editorconfig/editorconfig.github.com repository contains the
.editorconfigfile. I've forked it and tried to add some trailing whitespaces. PR https://github.com/seisman/editorconfig.github.com/pull/1 shows that the trailing whitespaces are added, so it means GitHub doesn't supporttrim_trailing_whitespace.Yes, but let's keep these two files for a while so that we can test if
.editorconfigor other solutions works.seisman commentedon Jun 4, 2024
I just tried to add a
.editorconfigfile locally. Here is the content:Then I added a few lines to the
examples/projections/README.txtfile and expected to see that the extra trailing whitespace at line 5 would be trimmed automatically when saving, but nothing happened.I'm using vim 9.1 but as per the documentation (https://github.com/editorconfig/editorconfig-vim#bundled-versions), vim has native support for editorconfig for Vim 9.0.1799 and above.
weiji14 commentedon Jun 4, 2024
If we're talking about enforcing no trailing whitespaces, maybe we should revisit #1593 and add a
.pre-commit-config.yamlinstead? We can setautofix_prs=falseto disable the autofixing of pre-commit.ci by default to address your concerns about the automatic fixes not being friendly for git-newbies.seisman commentedon Jun 4, 2024
Yes, I was re-reading that issue too. I think what we care about most are trailing whitespace and leading tabs.
I guess we have two different solutions:
For solution 2, to find files with trailing whitespace:
To find files with leading tabs:
seisman commentedon Jun 4, 2024
After thinking twice, I think pre-commmit CI service is better.
weiji14 commentedon Jun 4, 2024
Ok, I'll close this issue and re-open #1593 😆