<commit_before>" Author: <NAME> -- @zperrault
" Description: FlowType checking for JavaScript files

let g:ale_javascript_flow_executable =
\   get(g:, 'ale_javascript_flow_executable', 'flow')

let g:ale_javascript_flow_use_global =
\   get(g:, 'ale_javascript_flow_use_global', 0)

function! ale_linters#javascript#flow#GetExecutable(buffer) abort
  if g:ale_javascript_flow_use_global
    return g:ale_javascript_flow_executable
  endif

  return ale#util#ResolveLocalPath(
  \   a:buffer,
  \   'node_modules/.bin/flow',
  \   g:ale_javascript_flow_executable
  \)
endfunction

function! ale_linters#javascript#flow#GetCommand(buffer) abort
  return ale_linters#javascript#flow#GetExecutable(a:buffer)
  \   . ' check-contents --respect-pragma --json --from ale'
endfunction

function! ale_linters#javascript#flow#Handle(buffer, lines)
  let l:flow_output = json_decode(join(a:lines, ''))

  if has_key(l:flow_output, 'errors')
    let l:output = []

    for l:error in l:flow_output.errors
      " Each error is broken up into parts
      let l:text = ''
      let l:line = 0
      for l:message in l:error.message
        " Comments have no line of column information
        if l:message.line + 0
          let l:line = l:message.line + 0
        endif
        let l:text = l:text . ' ' . l:message.descr
      endfor

      call add(l:output, {
      \   'bufnr': a:buffer,
      \   'lnum': l:line,
      \   'vcol': 0,
      \   'col': 0,
      \   'text': l:text,
      \   'type': l:error.level ==# 'error' ? 'E' : 'W',
      \})
    endfor

    return l:output
  else
    return []
  endif
endfunction

call ale#linter#Define('javascript', {
\   'name': 'flow',
\   'executable_callback': 'ale_linters#javascript#flow#GetExecutable',
\   'command_callback': 'ale_linters#javascript#flow#GetCommand',
\   'callback': 'ale_linters#javascript#flow#Handle',<commit_msg>Flow linter improvements (#176)<commit_after>" Author: <NAME> -- @zperrault
" Description: FlowType checking for JavaScript files

let g:ale_javascript_flow_executable =
\   get(g:, 'ale_javascript_flow_executable', 'flow')

let g:ale_javascript_flow_use_global =
\   get(g:, 'ale_javascript_flow_use_global', 0)

function! ale_linters#javascript#flow#GetExecutable(buffer) abort
  if g:ale_javascript_flow_use_global
    return g:ale_javascript_flow_executable
  endif

  return ale#util#ResolveLocalPath(
  \   a:buffer,
  \   'node_modules/.bin/flow',
  \   g:ale_javascript_flow_executable
  \)
endfunction

function! ale_linters#javascript#flow#GetCommand(buffer) abort
  return ale_linters#javascript#flow#GetExecutable(a:buffer)
  \   . ' check-contents --respect-pragma --json --from ale %s'
endfunction

function! ale_linters#javascript#flow#Handle(buffer, lines)
  let l:str = join(a:lines, '')
  if l:str ==# ''
    return []
  endif
  let l:flow_output = json_decode(l:str)

  if has_key(l:flow_output, 'errors')
    let l:output = []

    for l:error in l:flow_output.errors
      " Each error is broken up into parts
      let l:text = ''
      let l:line = 0
      let l:col = 0
      for l:message in l:error.message
        " Comments have no line of column information
        if has_key(l:message, 'loc') && l:line ==# 0
          let l:line = l:message.loc.start.line + 0
          let l:col = l:message.loc.start.column + 0
        endif
        if l:text ==# ''
          let l:text = l:message.descr . ':'
        else
          let l:text = l:text . ' ' . l:message.descr
        endif
      endfor

      if has_key(l:error, 'operation')
        let l:text = l:text . ' See also: ' . l:error.operation.descr
      endif

      call add(l:output, {
      \   'bufnr': a:buffer,
      \   'lnum': l:line,
      \   'vcol': 0,
      \   'col': l:col,
      \   'text': l:text,
      \   'type': l:error.level ==# 'error' ? 'E' : 'W',
      \})
    endfor

    return l:output
  else
    return []
  endif
endfunction

call ale#linter#Define('javascript', {
\   'name': 'flow',
\   'executable_callback': 'ale_linters#javascript#flow#GetExecutable',
\   'command_callback': 'ale_linters#javascript#flow#GetCommand',
\   'callback': 'ale_linters#javascript#flow#Handle',
{'fraction_non_alphanumeric': 0.13171785028790786, 'fraction_numerical': 0.003838771593090211, 'mean_word_length': 3.1400198609731875, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4987620', 'n_tokens_mistral': 1471, 'n_tokens_neox': 1431, 'n_words': 296}