Skip to content

Add JSON fixer using 'python -m json.tool' #4314

Closed
@Konstantin-Glukhov

Description

Implement something similar to the following code:

ftplugin/json.vim:

let b:ale_fixers = ['json_python_fixer] let b:ale_json_python_fixer_options = '--indent 2'

autoload/ale/fixers/json_python_fixer.vim:

" Description: Fix JSON files with "python -m json.tool"
call ale#Set('json_python_fixer_options', '')

function! ale#fixers#json_python_fixer#Fix(buffer) abort
  let l:command = 'python'

  if !executable(l:command)
    echo 'ALEFix: ' . l:command . ' executable not found'
    return {'command': 'REM'}
  endif

  let l:command .= ' -m json.tool'

  let l:options = ale#Var(a:buffer, 'json_python_fixer_options')
  if len(l:options)
    let l:command .= ' ' . l:options
  endif

  return { 'command': l:command . ' -'}
endfunction

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    new toolSupport for new linters, fixers, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions