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

Enforce EditorConfig settings for newly created files #12

Closed
dpashkevich opened this issue May 7, 2013 · 12 comments
Closed

Enforce EditorConfig settings for newly created files #12

dpashkevich opened this issue May 7, 2013 · 12 comments

Comments

@dpashkevich
Copy link

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
Copy link
Contributor

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
Copy link
Owner

It already does that but only on when loading files.

@dpashkevich
Copy link
Author

@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
Copy link
Owner

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
Copy link
Author

@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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

@dpashkevich it already does it on pre-save

@gingermusketeer
Copy link

Any progress on this?

@kevinSuttle
Copy link

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

@sindresorhus
Copy link
Owner

This should be fixed in 2e68c0c

@dpashkevich
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants