language-formatters-pre-commit-hooks icon indicating copy to clipboard operation
language-formatters-pre-commit-hooks copied to clipboard

.editorconfig is not a valid INI file with root specified

Open danil51608 opened this issue 2 years ago • 6 comments
trafficstars

The hook works well if root is not present in my .editconfig file. However it breaks with the below message if I add root = true to my .editconfig:

Pretty format INI....................................................................Failed
- hook id: pretty-format-ini
- exit code: 1

Input File .editorconfig is not a valid INI file: File contains no section headers.
file: '<string>', line: 1
'root = true\n'

My .editconfig

root = true

[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
indent_style = space
indent_size = 4
max_line_length = 80

danil51608 avatar Oct 03 '23 09:10 danil51608

Hi @danil51608.

This is because INI files with global values (such as root in your case) isn't valid as per Python configparser module.

I'll try to update the config-formatter library on which language-formatters-pre-commit-hooks depends to support this feature.

References:

Delgan avatar Oct 03 '23 22:10 Delgan

@Delgan Hi!

I found out you had updated the config-formatter. Sadly it doesn't fix the issue. The error is still present.

danil51608 avatar Oct 23 '23 10:10 danil51608

Actually, I haven't updated config-formatter yet, so it's not surprising that the issue isn't fixed.

My library depends on another one, namely ConfigUpdater, and I was waiting for an answer in https://github.com/pyscaffold/configupdater/issues/123 to decide how I should implement the fix for .editorconfig files.

Delgan avatar Oct 23 '23 19:10 Delgan

oh, my bad. I thought you had updated it with this commit :)

danil51608 avatar Oct 24 '23 11:10 danil51608

Hey @danil51608.

I just published version 1.2.0 of config-formatter which now supports INI files with no section headers.

If you force re-installation of language-formatters-pre-commit-hooks by clearing the cache of pre-commit, your .editorconfig should now be formatted as expected without error. :+1:

Delgan avatar Nov 18 '23 18:11 Delgan

@Delgan Hey! Thanks a lot! Works great! 😊

danil51608 avatar Nov 20 '23 10:11 danil51608