-
Notifications
You must be signed in to change notification settings - Fork 76
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
Add default editorconfig
feature
#645
Conversation
Codecov ReportBase: 97.27% // Head: 97.27% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #645 +/- ##
==========================================
- Coverage 97.27% 97.27% -0.01%
==========================================
Files 15 16 +1
Lines 5845 6124 +279
==========================================
+ Hits 5686 5957 +271
- Misses 159 167 +8
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for submitting this!
A few things:
-
What happens when there doesn't exist any
.editorconfig
file at all? It looks like we "apply" the default properties fromec4rs
, but are they the same as the stylua defaults? Is it possible to detect that no.editorconfig
file was found, and just useConfig::default()
? Maybe there should be a test here to ensure the final config == Config::default() -
Maybe we should search in parent directories for
.editorconfig
as well when--search-parent-directories
is enabled -
Looks like there are some unrelated changes, probably to make clippy happy. I guess its fine to leave them in this PR
The ignored test in Each file in a same directory could have a different configuration, though it is probably not a common use case. |
bbc02f1
to
4362162
Compare
EditorConfig overrides are applied in Otherwise, the configuration overrides are loaded for each file in |
Nevermind, I misunderstood. For non-stdin, you check individually for each file in Could you pull in the latest changes from main? I've resolved the clippy lints there so it can be removed from this PR |
Yeah, I think this would be better, and then
Is it necessary to loop through the properties? It might just be simpler if its something like fn load(config: Config, properties: &Properties) -> Config {
let mut new_config = config;
// Handle standard keys
if let Ok(end_of_line) = properties.get::<EndOfLine>() {
// ...
}
if let Ok(indent_size) = properties.get::<IndentSize>() {
// ...
}
// ...
// Handle custom keys Also, for the custom keys, is it worth creating a custom enum for them and impl PropertyKey + PropertyValue? If its not too necessary, feel free to leave it
Sorry - I missed this. I don't think I think we should also have a test with both an Could you also update the CHANGELOG (add something into the Added section). Sorry for the long review time, thank you once again for adding this! |
Fixes:
TODO:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Just a few more comments which are hopefully a bit more minor.
Also, could we add a CLI option --no-editorconfig
to ignore editorconfig completely like prettier does: https://prettier.io/docs/en/cli.html#--no-editorconfig
- Add support for sort_requires?
Yeah, I guess we can do
@@ -7,6 +7,8 @@ use wasm_bindgen::prelude::*; | |||
|
|||
#[macro_use] | |||
mod context; | |||
#[cfg(feature = "editorconfig")] | |||
pub mod editorconfig; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Full public visibility to editorconfig is probably not ideal, since it shouldn't be an API consumers rely on. I don't think there is much we can do about it though, pub(crate)
is probably too restrictive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, there are ways around it but it seems more involved.
I just pushed some cleanup, hopefully fixing the case where the input file would be left modified if test_stylua_toml
failed, and removing the EOL test attempt (too tricky).
My last concern would be MaxLineLen::Off => config.with_column_width(0)
since I did not test if 0 === off
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
max_line_length = off
was not working, fixed in the latest commit using usize::MAX
instead of 0
.
Reordered the functions in |
Probably best to use |
Future options could work like this and it saves a few characters, unless I am missing something:
|
Yeah you're right. Let's leave it as-is then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for tackling this longstanding issue!
I'm happy with the general implementation here. I don't know if you have anymore outstanding TODOs. If not, I'll probably merge by the end of this week and get a release out then
61ed0cb
to
93d8ec1
Compare
93d8ec1
to
3d450c4
Compare
3d450c4
to
fff4c56
Compare
fff4c56
to
8e9d5a4
Compare
8e9d5a4
to
24d4c3d
Compare
24d4c3d
to
b2a236d
Compare
The test for max line length is now updated and commits are squashed. Should be ready to go if you are okay with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thank you, and sorry for the delay!
insert_final_newline is not supported: JohnnyMorganz/StyLua#645
What is the reason why |
Stylua does not respect the option itself - it will always add a newline. Although, it should parse the option and ignore it - an error is not useful if you are using the editor config for multiple languages |
That's extremely odd - in both my neovim setup and running from command line, |
I'm getting the exact opposite: after adding a newline after |
Sorry, I would have no clue how to diagnose further as I do not have a setup such as yours. All our test cases have a final newline (+1 extra that is added by the snapshot testing library) so I would assume it is something to do with your setup. Stupid question - but could it be whatever you are using to render your file is hiding the final newline? Note that stylua does trim multiple final newlines into only one newline, that may be hidden by your editor. |
That is really weird. Sorry I don't have a better answer for you, I'm curious what is causing this |
This adds support for EditorConfig via ec4rs including domain-specific properties and should close #75 once the special cases are settled:
end_of_line
=line_endings
cr = Unix (Mac)
indent_size
/tab_width
=indent_width
indent_style
=indent_type
max_line_length
=column_width
quote_type
=quote_style
double = AutoPreferDouble
single = AutoPreferSingle
auto = StyLua default
call_parentheses
collapse_simple_statement
sort_requires
EditorConfig properties
charset
,insert_final_newline
andtrim_trailing_whitespace
are not supported.The
.editorconfig
file in the current directory is loaded if no.stylua.toml
file was found: not sure if it's the desired behavior and how it should handle different directories. I usedpub mod editorconfig
insrc/lib.rs
in order to run tests on a real directory structure.