Permalink
Browse files

feat: support insert_final_newline options resolve #81

  • Loading branch information...
1 parent c33bff7 commit 6b6b023e6b804640da52f5a8567324907e0c9c0e @maksimr committed Feb 27, 2015
View
@@ -179,6 +179,10 @@ function s:treatConfig(config)
endif
endif
+ if has_key(config, 'insert_final_newline')
+ let config["end_with_newline"] = config["insert_final_newline"]
+ endif
+
return config
endfunction
@@ -415,6 +419,15 @@ func! Beautifier(...)
return result
endif
+ " TODO(maksimrv): Find better solution for splitting result on lines
+ " NOTE(maksimrv): This is need because if result contain newline in the end of file
+ " then split simple remove last line
+ if has_key(opts, 'end_with_newline')
+ if opts["end_with_newline"] == 'true'
+ let lines_Beautify = lines_Beautify + ['']
+ endif
+ endif
+
silent exec line1.",".line2."j"
call setline(line1, lines_Beautify[0])
call append(line1, lines_Beautify[1:])
@@ -0,0 +1,10 @@
+root = true
+
+[**.js]
+
+indent_style = space
+indent_size = 2
+jslint_happy = 1
+keep_array_indentation = 1
+space_before_conditional = 1
+insert_final_newline = true
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+# issue_81
+# insert_final_newline doesn't work
+
+TMP_FILE="$(tempfile)"
+
+echo $(cat file) > $TMP_FILE
+
+vim -u vimrc -c "execute 'silent call JsBeautify()' | w | q | q" $TMP_FILE
+
+RESULT=$(cat $TMP_FILE)
+
+test ! "$(diff $TMP_FILE expected)"
@@ -0,0 +1,8 @@
+(function (global) {
+ var $ = global.jQuery;
+ if (!$) {
+ return ['some', 'content'];
+ }
+ $('.class').addClass('myclass').removeClass('deleted');
+}(this));
+
@@ -0,0 +1 @@
+(function (global) { var $ = global.jQuery; if(!$){ return [ 'some', 'content']; } $('.class') .addClass('myclass') .removeClass('deleted'); }(this));
@@ -0,0 +1,14 @@
+" vim -u vimrc
+set nocompatible
+
+set nowrap
+
+let root = '~/.vim/bundle'
+
+filetype off
+syntax on
+
+let g:editorconfig_Beautifier = expand("<sfile>:p:h").'/.editorconfig'
+
+runtime macros/matchit.vim
+exec 'set rtp+=../../../'

0 comments on commit 6b6b023

Please sign in to comment.