collapse-preserve-inline
kswope opened this issue · 20 comments
will vim-jsbeautify be supporting this option?
brace_style = collapse_preserve_inline
This was a very popular request over at js-beautify.
I've tried to run vim-jsbeautify with
path=/usr/local/bin/js-beautify
but all I get is ugly errors
/Users/kevin/.home/.vim/bundle/vim-jsbeautify/plugin/beautify.min.js:1
(function (exports, require, module, __filename, __dirname) { (function(contentPath,options,path){"use strict";var global=function(){return this||eval.call(null,"this")}(),load=global.load,read=global.read,hop=Object.prototype.hasOwnProperty,print=null,hasCache=null,objectPrototypeToString=Object.prototype.toString,isFunction=function(it){return objectPrototypeToString.call(it)==="[object Function]"},isUndefined=function(it){return typeof it==="undefined"},has=function(name){hasCache[name]=isFunction(hasCache[name])?hasCache[name](global):hasCache[name];return hasCache[name]};hasCache=has.cache={};has.add=function(name,test,now,force){if(isUndefined(hasCache[name])||force){hasCache[name]=test}return now&&has(name)};has.add("host-node",global.process&&/node(\.exe||js)?$/.test(global.process.execPath));has.add("host-v8",isFunction(global.load)&&isFunction(global.read));has.add("host-iojs",global.process&&/iojs(\.exe)?$/.test(global.process
TypeError: global.beautify is not a function
at /Users/kevin/.home/.vim/bundle/vim-jsbeautify/plugin/beautify.min.js:1:1954
at Object.<anonymous> (/Users/kevin/.home/.vim/bundle/vim-jsbeautify/plugin/beautify.min.js:1:1982)
at Object.<anonymous> (/Users/kevin/.home/.vim/bundle/vim-jsbeautify/plugin/beautify.min.js:1:2011)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.runMain (module.js:590:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
; .editorconfig
root = true
[**.js]
path=/usr/local/bin/js-beautify
indent_size = 2
indent_style = space
preserve_newlines = true
space_in_paren = true
keep_array_indentation = true
brace_style = collapse_preserve_inline
[**.html]
indent_style = space
indent_size = 2
[**.css]
indent_style = space
indent_size = 2
kevin@walnut frontend $ node --version
v6.4.0
kevin@walnut frontend $ which js-beautify
/usr/local/bin/js-beautify
kevin@walnut frontend $ js-beautify --version
1.6.4
@kswope thanks!
Try use lib/beautify.js instead bin/js-beautify
.editorconfig
path=/<node_modules>/js-beautify/lib/beautify.js
This works
path=/usr/local/lib/node_modules/js-beautify/js/lib/beautify.js
But unfortunately the reason I did this was for this config, which is being ignored
brace_style = collapse_preserve_inline
Just to make sure it could work I ran this with success
js-beautify --brace-style collapse-preserve-inline file.js
@kswope you should write collapse-preserve-inline instead collapse_preserver_inline
.editorconfig
brace_style=collapse-preserve-inline
Thanks!
I probably would have tried that, after trying everything else first :)
Thanks.
I have some problem with the collapse-preserve-inline
. From the http://jsbeautifier.org/, when I type
import {a,b,c} from 'test'
it will be changed to
import { a, b, c } from 'test';
However, when using your settings, it will be changed to
import {
a, b, c
}
from 'test';
My setting is exactly like yours
[**.js]
indent_size = 2
indent_style = space
preserve_newlines = true
space_in_paren = true
keep_array_indentation = true
brace_style = collapse-preserve-inline
Do you have any solution for this ? I stuck with this for a while now
@bubuzzz could you post result of :echo g:config_Beautifier
and :echo b:config_Beautifier
@maksimr This is my configuration
:echo g:config_Beautifier
{'jsx': {'e4x': 'true', 'indent_style': 'space', 'indent_size': '2'}, 'js': {'keep_array_indentation': 'true', 'space_in_paren': 'true', 'preserve_newlines': 'true', 'brace_style':
'collapse-preserve-inline', 'indent_style': 'space', 'indent_size': '2'}, 'json': {'indent_style': 'space', 'indent_size': '2'}, 'html': {'indent_style': 'space', 'indent_size': '4'
, 'max_char': '78'}, 'css': {'indent_style': 'space', 'indent_size': '2'}}
:echo b:config_Beautifier
{'jsx': {'indent_char': ' ', 'e4x': 'true', 'indent_style': 'space', 'indent_size': '2'}, 'js': {'keep_array_indentation': 'true', 'preserve_newlines': 'true', 'brace_style': 'colla
pse-preserve-inline', 'indent_char': ' ', 'indent_style': 'space', 'indent_size': '2', 'space_in_paren': 'true'}, 'json': {'indent_char': ' ', 'indent_style': 'space', 'indent_size'
: '2'}, 'html': {'indent_char': ' ', 'indent_style': 'space', 'indent_size': '4', 'max_char': '78'}, 'css': {'indent_char': ' ', 'indent_style': 'space', 'indent_size': '2'}}
@bubuzzz thanks, first of all if you want use custom js-beautify you should specify path
[**.js]
path=~/.vim/bundle/js-beautify/js/lib/beautify.js
indent_style = space
indent_size = 2
Now plugin use own version js-beautify. Could you print result of
cat .vim/bundle/vim-jsbeautify/plugin/lib/package.json | grep version
@bubuzzz Thanks, I think problem that plugin use old version of js-beautify.
I could suggest two ways:
-
You could update vim-jsbeautify plugin, now it use js-beautify@1.6.3
-
or you could set path to your global js-beautify, you can use command which -
which js-beautify
to get full path
@i tested with the global js-beautify
Look like the global one indeed make it as that way. I will try to update your plugin to see if it helps
@bubuzzz you should pass brace-style to js-beautify
js-beautify --brace-style collapse-preserve-inline a.js
@maksimr wow, then i think the .vim/.editorconfig does not affect the beautifier. It is weird. I will update the version of vim-beautify
@bubuzzz after update vim-jsbeuatify check version of bundled js-beautify
cat .vim/bundle/vim-jsbeautify/plugin/lib/package.json | grep version
it should be 1.6.3
@maksimr Horray, it worked now. The main problem is because of the version of jsbeautify. In my current vim-jsbeautify, i checked the plugin/lib/package and it still use 1.5.x; however, after I removed the whole vim-jsbeautify and install it again, i check that file and see that the package.json has been updated to 1.6.3. Now i trigger the command and it format code code correctly. Thank a lot for your support
@bubuzzz no problem!
Example how use js-beautify from npm:
[**.js]
path=/Users/maksimrv/.nvm/versions/node/v5.12.0/lib/node_modules/js-beautify/js/lib/beautify.js
indent_size = 2
indent_style = space
preserve_newlines = true
space_in_paren = true
keep_array_indentation = true
brace_style = collapse-preserve-inline