#193 Fix a parsing error for parsing errors with eslint
This commit is contained in:
		
							parent
							
								
									bda6df61a0
								
							
						
					
					
						commit
						771bfe3b18
					
				@ -30,17 +30,32 @@ function! ale_linters#javascript#eslint#Handle(buffer, lines)
 | 
				
			|||||||
    " /path/to/some-filename.js:47:14: Missing trailing comma. [Warning/comma-dangle]
 | 
					    " /path/to/some-filename.js:47:14: Missing trailing comma. [Warning/comma-dangle]
 | 
				
			||||||
    " /path/to/some-filename.js:56:41: Missing semicolon. [Error/semi]
 | 
					    " /path/to/some-filename.js:56:41: Missing semicolon. [Error/semi]
 | 
				
			||||||
    let l:pattern = '^.*:\(\d\+\):\(\d\+\): \(.\+\) \[\(.\+\)\]$'
 | 
					    let l:pattern = '^.*:\(\d\+\):\(\d\+\): \(.\+\) \[\(.\+\)\]$'
 | 
				
			||||||
 | 
					    " This second pattern matches lines like the following:
 | 
				
			||||||
 | 
					    "
 | 
				
			||||||
 | 
					    " /path/to/some-filename.js:13:3: Parsing error: Unexpected token
 | 
				
			||||||
 | 
					    let l:parsing_pattern = '^.*:\(\d\+\):\(\d\+\): \(.\+\)$'
 | 
				
			||||||
    let l:output = []
 | 
					    let l:output = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for l:line in a:lines
 | 
					    for l:line in a:lines
 | 
				
			||||||
        let l:match = matchlist(l:line, l:pattern)
 | 
					        let l:match = matchlist(l:line, l:pattern)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if len(l:match) == 0
 | 
				
			||||||
 | 
					            " Try the parsing pattern for parsing errors.
 | 
				
			||||||
 | 
					            let l:match = matchlist(l:line, l:parsing_pattern)
 | 
				
			||||||
 | 
					        endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if len(l:match) == 0
 | 
					        if len(l:match) == 0
 | 
				
			||||||
            continue
 | 
					            continue
 | 
				
			||||||
        endif
 | 
					        endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let l:type = split(l:match[4], '/')[0]
 | 
					        let l:type = 'Error'
 | 
				
			||||||
        let l:text = l:match[3] . ' [' . l:match[4] . ']'
 | 
					        let l:text = l:match[3]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        " Take the error type from the output if available.
 | 
				
			||||||
 | 
					        if !empty(l:match[4])
 | 
				
			||||||
 | 
					            let l:type = split(l:match[4], '/')[0]
 | 
				
			||||||
 | 
					            let l:text .= ' [' . l:match[4] . ']'
 | 
				
			||||||
 | 
					        endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        " vcol is Needed to indicate that the column is a character.
 | 
					        " vcol is Needed to indicate that the column is a character.
 | 
				
			||||||
        call add(l:output, {
 | 
					        call add(l:output, {
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										43
									
								
								test/test_eslint_handler.vader
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								test/test_eslint_handler.vader
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,43 @@
 | 
				
			|||||||
 | 
					Execute(The eslint handler should parse lines correctly):
 | 
				
			||||||
 | 
					  runtime ale_linters/javascript/eslint.vim
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  AssertEqual
 | 
				
			||||||
 | 
					  \ [
 | 
				
			||||||
 | 
					  \   {
 | 
				
			||||||
 | 
					  \     'bufnr': 347,
 | 
				
			||||||
 | 
					  \     'lnum': 47,
 | 
				
			||||||
 | 
					  \     'vcol': 0,
 | 
				
			||||||
 | 
					  \     'col': 14,
 | 
				
			||||||
 | 
					  \     'text': 'Missing trailing comma. [Warning/comma-dangle]',
 | 
				
			||||||
 | 
					  \     'type': 'W',
 | 
				
			||||||
 | 
					  \     'nr': -1,
 | 
				
			||||||
 | 
					  \   },
 | 
				
			||||||
 | 
					  \   {
 | 
				
			||||||
 | 
					  \     'bufnr': 347,
 | 
				
			||||||
 | 
					  \     'lnum': 56,
 | 
				
			||||||
 | 
					  \     'vcol': 0,
 | 
				
			||||||
 | 
					  \     'col': 41,
 | 
				
			||||||
 | 
					  \     'text': 'Missing semicolon. [Error/semi]',
 | 
				
			||||||
 | 
					  \     'type': 'E',
 | 
				
			||||||
 | 
					  \     'nr': -1,
 | 
				
			||||||
 | 
					  \   },
 | 
				
			||||||
 | 
					  \   {
 | 
				
			||||||
 | 
					  \     'bufnr': 347,
 | 
				
			||||||
 | 
					  \     'lnum': 13,
 | 
				
			||||||
 | 
					  \     'vcol': 0,
 | 
				
			||||||
 | 
					  \     'col': 3,
 | 
				
			||||||
 | 
					  \     'text': 'Parsing error: Unexpected token',
 | 
				
			||||||
 | 
					  \     'type': 'E',
 | 
				
			||||||
 | 
					  \     'nr': -1,
 | 
				
			||||||
 | 
					  \   },
 | 
				
			||||||
 | 
					  \ ],
 | 
				
			||||||
 | 
					  \ ale_linters#javascript#eslint#Handle(347, [
 | 
				
			||||||
 | 
					  \   'This line should be ignored completely',
 | 
				
			||||||
 | 
					  \   '/path/to/some-filename.js:47:14: Missing trailing comma. [Warning/comma-dangle]',
 | 
				
			||||||
 | 
					  \   '/path/to/some-filename.js:56:41: Missing semicolon. [Error/semi]',
 | 
				
			||||||
 | 
					  \   'This line should be ignored completely',
 | 
				
			||||||
 | 
					  \   '/path/to/some-filename.js:13:3: Parsing error: Unexpected token',
 | 
				
			||||||
 | 
					  \ ])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					After:
 | 
				
			||||||
 | 
					  call ale#linter#Reset()
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user