<commit_before>call ale#Set('javascript_xo_executable', 'xo')
call ale#Set('javascript_xo_use_global', get(g:, 'ale_use_global_executables', 0))
call ale#Set('javascript_xo_options', '')

call ale#Set('typescript_xo_executable', 'xo')
call ale#Set('typescript_xo_use_global', get(g:, 'ale_use_global_executables', 0))
call ale#Set('typescript_xo_options', '')

function! ale#handlers#xo#GetExecutable(buffer) abort
    let l:filetype = getbufvar(a:buffer, '&filetype')
    let l:type = ''

    if l:filetype =~# 'javascript'
        let l:type = 'javascript'
    elseif l:filetype =~# 'typescript'
        let l:type = 'typescript'
    endif

    return ale#node#FindExecutable(a:buffer, l:type . '_xo', [
    \   'node_modules/xo/cli.js',
    \   'node_modules/.bin/xo',
    \])
endfunction

function! ale#handlers#xo#GetLintCommand(buffer) abort
    return ale#Escape(ale#handlers#xo#GetExecutable(a:buffer))
    \   . ale#Pad(ale#handlers#xo#GetOptions(a:buffer))
    \   . ' --reporter json --stdin --stdin-filename %s'
endfunction

function! ale#handlers#xo#GetOptions(buffer) abort
    let l:filetype = getbufvar(a:buffer, '&filetype')
    let l:type = ''

    if l:filetype =~# 'javascript'
        let l:type = 'javascript'
    elseif l:filetype =~# 'typescript'
        let l:type = 'typescript'
    endif

    return ale#Var(a:buffer, l:type . '_xo_options')
endfunction

" xo uses eslint and the output format is the same
function! ale#handlers#xo#HandleJSON(buffer, lines) abort
    return ale#handlers#eslint#HandleJSON(a:buffer, a:lines)
endfunction<commit_msg>xo: refactor to function<commit_after>call ale#Set('javascript_xo_executable', 'xo')
call ale#Set('javascript_xo_use_global', get(g:, 'ale_use_global_executables', 0))
call ale#Set('javascript_xo_options', '')

call ale#Set('typescript_xo_executable', 'xo')
call ale#Set('typescript_xo_use_global', get(g:, 'ale_use_global_executables', 0))
call ale#Set('typescript_xo_options', '')

function! ale#handlers#xo#GetExecutable(buffer) abort
    let l:type = ale#handlers#xo#GetType(a:buffer)

    return ale#node#FindExecutable(a:buffer, l:type . '_xo', [
    \   'node_modules/xo/cli.js',
    \   'node_modules/.bin/xo',
    \])
endfunction

function! ale#handlers#xo#GetLintCommand(buffer) abort
    return ale#Escape(ale#handlers#xo#GetExecutable(a:buffer))
    \   . ale#Pad(ale#handlers#xo#GetOptions(a:buffer))
    \   . ' --reporter json --stdin --stdin-filename %s'
endfunction

function! ale#handlers#xo#GetOptions(buffer) abort
    let l:type = ale#handlers#xo#GetType(a:buffer)

    return ale#Var(a:buffer, l:type . '_xo_options')
endfunction

" xo uses eslint and the output format is the same
function! ale#handlers#xo#HandleJSON(buffer, lines) abort
    return ale#handlers#eslint#HandleJSON(a:buffer, a:lines)
endfunction

function! ale#handlers#xo#GetType(buffer) abort
    let l:filetype = getbufvar(a:buffer, '&filetype')
    let l:type = 'javascript'

    if l:filetype =~# 'typescript'
        let l:type = 'typescript'
    endif

    return l:type
endfunction
{'fraction_non_alphanumeric': 0.1444480838519489, 'fraction_numerical': 0.0013101867016049786, 'mean_word_length': 5.0, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4864353', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1124, 'n_words': 202}