<commit_before>
" Global Options
"
" Enable/Disable highlighting of errors in source.
" Default is Enable
" To disable the highlighting put the line
" let g:JSLintHighlightErrorLine = 0
" in your .vimrc
"
if exists("b:did_jslint_plugin")
    finish
else
    let b:did_jslint_plugin = 1
endif

au BufLeave <buffer> call s:JSLintClear()

au BufEnter <buffer> call s:JSLint()
au InsertLeave <buffer> call s:JSLint()
au InsertEnter <buffer> call s:JSLint()
au BufWritePost <buffer> call s:JSLint()

au CursorHold <buffer> call s:JSLint()
au CursorHoldI <buffer> call s:JSLint()

au CursorHold <buffer> call s:GetJSLintMessage()
au CursorMoved <buffer> call s:GetJSLintMessage()

if !exists("g:JSLintHighlightErrorLine")
  let g:JSLintHighlightErrorLine = 1
endif

if !exists("*s:JSLintUpdate")
    function s:JSLintUpdate()
        silent call s:JSLint()
        call s:GetJSLintMessage()
    endfunction
endif

if !exists(":JSLintUpdate")
    command JSLintUpdate :call s:JSLintUpdate()
endif

noremap <buffer><silent> dd dd:JSLintUpdate<CR>
noremap <buffer><silent> dw dw:JSLintUpdate<CR>
noremap <buffer><silent> u u:JSLintUpdate<CR>
noremap <buffer><silent> <C-R> <C-R>:JSLintUpdate<CR>


" WideMsg() prints [long] message up to (&columns-1) length
" guaranteed without "Press Enter" prompt.
if !exists("*s:WideMsg")
    function s:WideMsg(msg)
        let x=&ruler | let y=&showcmd
        set noruler noshowcmd
        redraw
        echo a:msg
        let &ruler=x | let &showcmd=y
    endfun
endif


function! s:JSLintClear()
  " Delete previous matches
  let s:matches = getmatches()
  for s:matchId in s:matches
    if s:matchId['group'] == 'JSLintError'
        call matchdelete(s:matchId['id'])
    endif
  endfor
  let b:matched = []
  let b:matchedlines = {}
  let b:cleared = 1
endfunction

function! s:JSLint()
  highlight link JSLintError SpellBad

  if exists("b:cleared")
      if b:cleared == 0
          call s:JSLintClear()
      endif
      let b:cleared = 1
  endif

  let b:matched = []
  let b:matchedlines = {}

  " Detect range
  if a:firstline == a:lastline
    let b:firstline = 1
    let b:lastline = '$'
  else 
    let b:firstline = a:firstline
    let b:lastline = a:lastline
  endif


  " Set up command and parameters
  let s:plugin_path = '"' . expand("~/") . '"'
  if has("win32")
    let s:cmd = 'cscript /NoLogo '
    let s:plugin_path = s:plugin_path . "vimfiles"
    let s:runjslint_ext = 'wsf'
  else
    if has("gui_macvim") && filereadable('/System/Library/Frameworks/JavaScriptCore.framework/Resources/jsc')
      let s:cmd = '/System/Library/Frameworks/JavaScriptCore.framework/Resources/jsc'
    else
      let s:cmd = 'js'
    endif
    let s:plugin_path = s:plugin_path . ".vim"
    let s:runjslint_ext = 'js'
  endif
  let s:plugin_path = s:plugin_path . "/ftplugin/javascript/jslint/"
  let s:cmd = "cd " . s:plugin_path . " && " . s:cmd . " " . s:plugin_path 
               \ . "runjslint." . s:runjslint_ext
  let s:jslintrc_file = expand('~/.jslintrc')
  if filereadable(s:jslintrc_file)
    let s:jslintrc = readfile(s:jslintrc_file)
  else
    let s:jslintrc = []
  end
  let b:jslint_output = system(s:cmd, join(s:jslintrc + getline(b:firstline, b:lastline),
              \ "\n") . "\n")

  for error in split(b:jslint_output, "\n")
      
    " Match {line}:{char}:{message}
    let b:parts = matchlist(error, "\\(\\d\\+\\):\\(\\d\\+\\):\\(.*\\)")
    if !empty(b:parts)
      let l:line = b:parts[1] + (b:firstline - 1 - len(s:jslintrc)) " Get line relative to selection

        " Store the error for an error under the cursor
      let s:matchDict = {}
      let s:matchDict['lineNum'] = l:line
      let s:matchDict['message'] = b:parts[3]
      let b:matchedlines[l:line] = s:matchDict
      if g:JSLintHighlightErrorLine == 1
          let s:mID = matchadd('JSLintError', '\%' . l:line . 'l\n\@!')
      endif
      " Add line to match list
      call add(b:matched, s:matchDict)
    endif
  endfor
  let b:cleared = 0
endfunction

let b:showing_message = 0

if !exists("*s:GetJSLintMessage")
    function s:GetJSLintMessage()
        let s:cursorPos = getpos(".")

        " Bail if RunJSLint hasn't been called yet
        if !exists('b:matchedlines')
            return
        endif

        if has_key(b:matchedlines, s:cursorPos[1])
            let s:jslintMatch = get(b:matchedlines, s:cursorPos[1])
            call s:WideMsg(s:jslintMatch['message'])
            let b:showing_message = 1
            return
        endif

        if b:showing_message == 1
            echo
            let b:showing_message = 0
        endif
    endfunction
endif

<commit_msg>Make jslint location independent and echo warning if invoking JSLint fails<commit_after>
" Global Options
"
" Enable/Disable highlighting of errors in source.
" Default is Enable
" To disable the highlighting put the line
" let g:JSLintHighlightErrorLine = 0
" in your .vimrc
"
if exists("b:did_jslint_plugin")
    finish
else
    let b:did_jslint_plugin = 1
endif

let s:install_dir = expand("<sfile>:p:h")

au BufLeave <buffer> call s:JSLintClear()

au BufEnter <buffer> call s:JSLint()
au InsertLeave <buffer> call s:JSLint()
au InsertEnter <buffer> call s:JSLint()
au BufWritePost <buffer> call s:JSLint()

au CursorHold <buffer> call s:JSLint()
au CursorHoldI <buffer> call s:JSLint()

au CursorHold <buffer> call s:GetJSLintMessage()
au CursorMoved <buffer> call s:GetJSLintMessage()

if !exists("g:JSLintHighlightErrorLine")
  let g:JSLintHighlightErrorLine = 1
endif

if !exists("*s:JSLintUpdate")
    function s:JSLintUpdate()
        silent call s:JSLint()
        call s:GetJSLintMessage()
    endfunction
endif

if !exists(":JSLintUpdate")
    command JSLintUpdate :call s:JSLintUpdate()
endif

noremap <buffer><silent> dd dd:JSLintUpdate<CR>
noremap <buffer><silent> dw dw:JSLintUpdate<CR>
noremap <buffer><silent> u u:JSLintUpdate<CR>
noremap <buffer><silent> <C-R> <C-R>:JSLintUpdate<CR>


" WideMsg() prints [long] message up to (&columns-1) length
" guaranteed without "Press Enter" prompt.
if !exists("*s:WideMsg")
    function s:WideMsg(msg)
        let x=&ruler | let y=&showcmd
        set noruler noshowcmd
        redraw
        echo a:msg
        let &ruler=x | let &showcmd=y
    endfun
endif


function! s:JSLintClear()
  " Delete previous matches
  let s:matches = getmatches()
  for s:matchId in s:matches
    if s:matchId['group'] == 'JSLintError'
        call matchdelete(s:matchId['id'])
    endif
  endfor
  let b:matched = []
  let b:matchedlines = {}
  let b:cleared = 1
endfunction

function! s:JSLint()
  highlight link JSLintError SpellBad

  if exists("b:cleared")
      if b:cleared == 0
          call s:JSLintClear()
      endif
      let b:cleared = 1
  endif

  let b:matched = []
  let b:matchedlines = {}

  " Detect range
  if a:firstline == a:lastline
    let b:firstline = 1
    let b:lastline = '$'
  else 
    let b:firstline = a:firstline
    let b:lastline = a:lastline
  endif


  " Set up command and parameters
  if has("win32")
    let s:cmd = 'cscript /NoLogo '
    let s:plugin_path = s:plugin_path . "vimfiles"
    let s:runjslint_ext = 'wsf'
  else
    if has("gui_macvim") && filereadable('/System/Library/Frameworks/JavaScriptCore.framework/Resources/jsc')
      let s:cmd = '/System/Library/Frameworks/JavaScriptCore.framework/Resources/jsc'
    else
      let s:cmd = 'js'
    endif
    let s:runjslint_ext = 'js'
  endif
  let s:plugin_path = s:install_dir . "/jslint/"
  let s:cmd = "cd " . s:plugin_path . " && " . s:cmd . " " . s:plugin_path 
               \ . "runjslint." . s:runjslint_ext
  let s:jslintrc_file = expand('~/.jslintrc')
  if filereadable(s:jslintrc_file)
    let s:jslintrc = readfile(s:jslintrc_file)
  else
    let s:jslintrc = []
  end
  let b:jslint_output = system(s:cmd, join(s:jslintrc + getline(b:firstline, b:lastline),
              \ "\n") . "\n")
  if v:shell_error
     echo 'could not invoke JSLint!'
  end

  for error in split(b:jslint_output, "\n")
    " Match {line}:{char}:{message}
    let b:parts = matchlist(error, "\\(\\d\\+\\):\\(\\d\\+\\):\\(.*\\)")
    if !empty(b:parts)
      let l:line = b:parts[1] + (b:firstline - 1 - len(s:jslintrc)) " Get line relative to selection

        " Store the error for an error under the cursor
      let s:matchDict = {}
      let s:matchDict['lineNum'] = l:line
      let s:matchDict['message'] = b:parts[3]
      let b:matchedlines[l:line] = s:matchDict
      if g:JSLintHighlightErrorLine == 1
          let s:mID = matchadd('JSLintError', '\%' . l:line . 'l\n\@!')
      endif
      " Add line to match list
      call add(b:matched, s:matchDict)
    endif
  endfor
  let b:cleared = 0
endfunction

let b:showing_message = 0

if !exists("*s:GetJSLintMessage")
    function s:GetJSLintMessage()
        let s:cursorPos = getpos(".")

        " Bail if RunJSLint hasn't been called yet
        if !exists('b:matchedlines')
            return
        endif

        if has_key(b:matchedlines, s:cursorPos[1])
            let s:jslintMatch = get(b:matchedlines, s:cursorPos[1])
            call s:WideMsg(s:jslintMatch['message'])
            let b:showing_message = 1
            return
        endif

        if b:showing_message == 1
            echo
            let b:showing_message = 0
        endif
    endfunction
endif


{'fraction_non_alphanumeric': 0.12748362152292986, 'fraction_numerical': 0.004510793684888841, 'mean_word_length': 3.036410923276983, 'pattern_counts': {'":': 2, '<': 50, '<?xml version=': 0, '>': 50, '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': '1338352', 'n_tokens_mistral': 3466, 'n_tokens_neox': 3317, 'n_words': 820}