代码之家  ›  专栏  ›  技术社区  ›  Rohit

在Vim中使用ALE和Prettier格式化Jinja html模板

  •  1
  • Rohit  · 技术社区  · 6 年前

    我在Ubuntu 16.04 LTS上使用NVIM v0.3.2-208-g2841e89,并使用ALE作为我的Linting引擎插件。我对jinja模板html文件的格式有问题 prettier

    以开头的html文件 <html> ALEFix 在这些文件上什么都没有发生。

    以开头的html文件 {% extends %} 阿莱菲克斯

    {% extends "home.html" %}
    {% block body %}
    <div class="jumbotron">
    <p>Thank you {{ session['username'] }} for signing up !!</p>
    </div>
    
    {% endblock %}
    

    格式化文件

    {% extends "home.html" %} {% block body %}
    <div class="jumbotron">
      <p>Thank you {{ session['username'] }} for signing up !!</p>
    </div>
    
    {% endblock %}
    

    原始文件

     {% extends "home.html" %}
    {% block body %}
    <form method="POST">
        {{ form.hidden_tag() }}
        {{ form.username.label }} {{ form.username }}
        {{ form.password.label }} {{ form.password }}
        {{ form.submit }}
    </form>
    {% endblock %}
    

    {% extends "home.html" %} {% block body %}
    <form method="POST">
      {{ form.hidden_tag() }} {{ form.username.label }} {{ form.username }} {{
      form.password.label }} {{ form.password }} {{ form.submit }}
    </form>
    {% endblock %}
    

    我不确定这是否是jinja文件的正确格式,但它看起来不太可读。

    这就是我的配置

    let g:ale_fixers = {
                        \ '*': ['remove_trailing_lines', 'trim_whitespace'],
                        \ 'html': ['prettier'],
                        \ 'javascript': ['eslint', 'prettier'],
                        \ 'css' : ['stylelint', 'prettier'],
                        \ 'python' : ['yapf', 'isort', 'autopep8']
                        \ }
    

    下面是ALEInfo为jinja模板文件报告的内容。

     Current Filetype: jinja.html                                                                                                                                                                                      
    Available Linters: ['alex', 'htmlhint', 'proselint', 'stylelint', 'tidy', 'writegood']                                                                                                                             
       Linter Aliases:                                                                                                                                                                                                 
    'writegood' -> ['write-good']                                                                                                                                                                                      
      Enabled Linters: ['alex', 'htmlhint', 'proselint', 'stylelint', 'tidy', 'writegood']                                                                                                                             
     Suggested Fixers:                                                                                                                                                                                                 
      'prettier' - Apply prettier to a file.                                                                                                                                                                           
      'remove_trailing_lines' - Remove all blank lines at the end of a file.                                                                                                                                           
      'tidy' - Fix HTML files with tidy.                                                                                                                                                                               
      'trim_whitespace' - Remove all trailing whitespace characters at the end of every line.                                                                                                                          
     Linter Variables:                                                                                                                                                                                                 
    let g:ale_html_htmlhint_executable = 'htmlhint'                                                                                                                                                                    
    let g:ale_html_htmlhint_options = ''                                                                                                                                                                               
    let g:ale_html_htmlhint_use_global = 0                                                                                                                                                                             
    let g:ale_html_stylelint_executable = 'stylelint'                                                                                                                                                                  
    let g:ale_html_stylelint_options = ''                                                                                                                                                                              
    let g:ale_html_stylelint_use_global = 0                                                                                                                                                                            
    let g:ale_html_tidy_executable = 'tidy'                                                                                                                                                                            
    let g:ale_html_tidy_options = '-q -e -language en'                                                                                                                                                                 
     Global Variables:                                                                                                                                                                                                 
    let g:ale_cache_executable_check_failures = v:null                                                                                                                                                                 
    let g:ale_change_sign_column_color = 0                                                                                                                                                                             
    let g:ale_command_wrapper = ''                                                                                                                                                                                     
    let g:ale_completion_delay = v:null                                                                                                                                                                                
    let g:ale_completion_enabled = 0                                                                                                                                                                                   
    let g:ale_completion_max_suggestions = v:null                                                                                                                                                                      
    let g:ale_echo_cursor = 1                                                                                                                                                                                          
    let g:ale_echo_msg_error_str = 'E'                                                                                                                                                                                 
    let g:ale_echo_msg_format = '[%linter%] %s [%severity%]'                                                                                                                                                           
    let g:ale_echo_msg_info_str = 'Info'                                                                                                                                                                               
    let g:ale_echo_msg_warning_str = 'W'                                                                                                                                                                               
    let g:ale_enabled = 1                                                                                                                                                                                              
    let g:ale_fix_on_save = 1                                                                                                                                                                                          
    let g:ale_fixers = {'html': ['prettier'], '*': ['remove_trailing_lines', 'trim_whitespace'], 'javascript': ['eslint', 'prettier'], 'css': ['stylelint', 'prettier'], 'python': ['yapf', 'isort', 'autopep8']}      
    let g:ale_history_enabled = 1                                                                                                                                                                                      
    let g:ale_history_log_output = 1                                                                                                                                                                                   
    let g:ale_keep_list_window_open = 0                                                                                                                                                                                
    let g:ale_lint_delay = 200                                                                                                                                                                                         
    let g:ale_lint_on_enter = 1                                                                                                                                                                                        
    let g:ale_lint_on_filetype_changed = 1                                                                                                                                                                             
    let g:ale_lint_on_insert_leave = 0                                                                                                                                                                                 
    let g:ale_lint_on_save = 1                                                                                                                                                                                         
    let g:ale_lint_on_text_changed = 'always'                                                                                                                                                                          
    let g:ale_linter_aliases = {}                                                                                                                                                                                      
    let g:ale_linters = {'css': ['stylelint'], 'python': ['flake8']}                                                                                                                                                   
    let g:ale_linters_explicit = 0                     
    
    0 回复  |  直到 6 年前
        1
  •  3
  •   WhyNotHugo    4 年前

    这不受prettier支持。需要有人站出来为它写一个插件。

    更漂亮的问题: https://github.com/prettier/prettier/issues/5581