sindresorhus / editorconfig-sublime

Sublime Text plugin for EditorConfig - Helps developers maintain consistent coding styles between different editors
MIT License
1.77k stars 108 forks source link

Enforce EditorConfig settings for newly created files #12

Closed dpashkevich closed 10 years ago

dpashkevich commented 11 years ago

Not sure if this is under plugin's control but here's the issue anyway.

I have a project (saved as a .sublime-project) with an .editorconfig file in its root directory with the following contents:

# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org
root = true

[*]
indent_style = tab
tab_width = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

However, I also have "translate_tabs_to_spaces": true (my default preference) which always forces spaces in the new files that I create, even if I have a project with indent_style = tab currently open in ST2 window. Is there a way editorconfig-sublime can override whitespace settings for new files that get saved in project directory so that .editorconfig is always respected?

treyhunner commented 11 years ago

If possible, it seems like that should be the default setting (if not the only option). Project-specific settings seem like they should always override global settings.

sindresorhus commented 11 years ago

It already does that but only on when loading files.

dpashkevich commented 11 years ago

@sindresorhus Yeah this appears to work. So to make sure indent style is respected I have to create a new file, save it somewhere within project and then close it and reopen it. Can this be somehow improved? E.g. set indent style for the file view on first saving so I don't have to reopen it?

sindresorhus commented 11 years ago

Doing it on pre_save is a bad idea since we're then changing stuff around right before persisting the file. Can consider doing it on file load too. Though I know there was a reason I didn't do it, but can't remember why.

dpashkevich commented 11 years ago

@sindresorhus I'm not familiar with ST2 API but can a plugin detect if a project has been opened in current window? If so, a plugin could set editor settings right when a new view is opened. Of course that's not an ideal solution since I might create a new file but save it outside of my project directory (in this case .editorconfig rules should not apply) but it's a tradeoff that I would happily accept.

Currently it's a bit of a pain to work on a project with whitespace settings (stored in .editorconfig) that are different from my default preferences: every new file I create ends up having the wrong settings and most of the time I only realize this when reviewing changes before comitting... Obviously I don't create a new file every minute but that still happens relatively often. Would love to hear about any alternative solutions/workarounds.

sindresorhus commented 11 years ago

I think on post-save and load is a good solution. It will then load the settings after you've saved your new file, since it can then pick up the right editorconfig settings or when you load a file. Wdyt?

dpashkevich commented 11 years ago

But then it would happen everytime I save a file? If there would be no side effects from this, then I'm happy to have that feature :)

sindresorhus commented 11 years ago

@dpashkevich it already does it on pre-save

gingermusketeer commented 10 years ago

Any progress on this?

kevinSuttle commented 10 years ago

Wondering about manual invocation also, specifically in bulk across a project.

sindresorhus commented 10 years ago

This should be fixed in https://github.com/sindresorhus/editorconfig-sublime/commit/2e68c0ca036e29e148771518ee00c3288b251799

dpashkevich commented 10 years ago

Thanks!