neoformat icon indicating copy to clipboard operation
neoformat copied to clipboard

Use editorconfig presets

Open ChrisBFusion opened this issue 8 years ago • 6 comments

It would be very useful if neoformat took into consideration any EditorConfig settings and applied them when executing.

For example, jsbeautify defaults to spaces for indent and an indent width of 2, yet my .editorconfig file defines the indent style as tabs and indent width of 4 spaces. When executing :Neoformat in a JavaScript file, it preserves the desired tab style and width of the document defined in the .editorconfig file rather than overwrite them with the jsbeautify defaults.

ChrisBFusion avatar Aug 09 '17 17:08 ChrisBFusion

Neoformat currently uses shiftwidth() for js-beautify, and checking whether or not to use tabs should be similar.

https://github.com/sbdchd/neoformat/blob/255239e217ae124b1438c35967597b63db328820/autoload/neoformat/formatters/javascript.vim#L8

sbdchd avatar Aug 09 '17 17:08 sbdchd

That's good to know. However, as a contractor I may switch from client project to another client project with different coding style guidelines (thus EditorConfig). Not having to go to my Vim config file between switches would be nice. Just a thought. Great plugin!

ChrisBFusion avatar Aug 09 '17 19:08 ChrisBFusion

I think if you install editorconfig-vim, it will read the .editorconfig and change your shiftwidth and other options, and then Neoformat will take them into account. Give it a try 🙂

max-baz avatar Jan 17 '18 15:01 max-baz

I think this comes down to a per-tool config, though writing a basic API to make configuring this easier would be nice.

e.g. let g:neoformat_editorconfig = {'yapf', 'autoflake8', etc}

alok avatar Mar 15 '18 07:03 alok

I was wrong when I suggested that editorconfig-vim plugin is always needed, in some cases the external tools (like prettier) are themselves responsible for discovering and honoring .editorconfig.

However, in case of prettier it is not doing so when using --stdin flag, it's a bug that needs to be fixed on their side. Reported as https://github.com/prettier/prettier/issues/4351.

max-baz avatar Apr 20 '18 23:04 max-baz

If I understand the state of the current issue: with the way neoformat plugin works, it doesn't account for shiftwidth config for vim except for some formater like prettier for JavaScript. So the issue is not with editorconfig because if you have the plugin to load .editorconfig installed it set the shiftwidth accordingly. The issue is with neoformat not taking in account the vim settings?

lefuturiste avatar Jul 19 '22 17:07 lefuturiste