Ale: Flow typings in JS/JSX files wrongly considered invalid Typescript typings

Created on 15 Jul 2018  Â·  11Comments  Â·  Source: dense-analysis/ale

Information

VIM version

NVIM v0.3.0
Build type: Release

Operating System:

Vanilla Archlinux

:ALEInfo

 Current Filetype: javascript.jsx                                                                                                                                                              
Available Linters: ['eslint', 'flow', 'flow-language-server', 'jscs', 'jshint', 'standard', 'tsserver', 'xo']                                                                                  
  Enabled Linters: ['eslint', 'flow', 'flow-language-server', 'jscs', 'jshint', 'standard', 'tsserver', 'xo']                                                                                  
 Suggested Fixers:                                                                                                                                                                             
  'eslint' - Apply eslint --fix to a file.                                                                                                                                                     
  'importjs' - automatic imports for javascript                                                                                                                                                
  'prettier' - Apply prettier to a file.                                                                                                                                                       
  'prettier_eslint', 'prettier-eslint' - Apply prettier-eslint to a file.                                                                                                                      
  'prettier_standard', 'prettier-standard' - Apply prettier-standard to a file.                                                                                                                
  'remove_trailing_lines' - Remove all blank lines at the end of a file.                                                                                                                       
  'standard' - Fix JavaScript files using standard --fix                                                                                                                                       
  'trim_whitespace' - Remove all trailing whitespace characters at the end of every line.                                                                                                      
  'xo' - Fix JavaScript files using xo --fix.                                                                                                                                                  
 Linter Variables:                                                                                                                                                                             
let g:ale_javascript_eslint_executable = 'eslint'                                                                                                                                              
let g:ale_javascript_eslint_options = ''                                                                                                                                                       
let g:ale_javascript_eslint_suppress_eslintignore = 0                                                                                                                                          
let g:ale_javascript_eslint_suppress_missing_config = 0                                                                                                                                        
let g:ale_javascript_eslint_use_global = 0                                                                                                                                                     
let g:ale_javascript_flow_executable = 'flow'                                                                                                                                                  
let g:ale_javascript_flow_ls_executable = 'flow'                                                                                                                                               
let g:ale_javascript_flow_ls_use_global = 0                                                                                                                                                    
let g:ale_javascript_flow_use_global = 0                                                                                                                                                       
let g:ale_javascript_flow_use_home_config = 0                                                                                                                                                  
let g:ale_javascript_flow_use_respect_pragma = 1                                                                                                                                               
let g:ale_javascript_jscs_executable = 'jscs'                                                                                                                                                  
let g:ale_javascript_jscs_use_global = 0                                                                                                                                                       
let g:ale_javascript_jshint_executable = 'jshint'                                                                                                                                              
let g:ale_javascript_jshint_use_global = 0                                                                                                                                                     
let g:ale_javascript_standard_executable = 'standard'                                                                                                                                          
let g:ale_javascript_standard_options = ''                                                                                                                                                     
let g:ale_javascript_standard_use_global = 0                                                                                                                                                   
let g:ale_javascript_tsserver_config_path = ''                                                                                                                                                 
let g:ale_javascript_tsserver_executable = 'tsserver'                                                                                                                                          
let g:ale_javascript_tsserver_use_global = 0                                                                                                                                                   
let g:ale_javascript_xo_executable = 'xo'                                                                                                                                                      
let g:ale_javascript_xo_options = ''                                                                                                                                                           
let g:ale_javascript_xo_use_global = 0                                                                                                                                                         
 Global Variables:                                                                                                                                                                             
let g:ale_cache_executable_check_failures = v:null                                                                                                                                             
let g:ale_change_sign_column_color = 0                                                                                                                                                         
let g:ale_command_wrapper = ''                                                                                                                                                                 
let g:ale_completion_delay = v:null                                                                                                                                                            
let g:ale_completion_enabled = 0                                                                                                                                                               
let g:ale_completion_max_suggestions = v:null                                                                                                                                                  
let g:ale_echo_cursor = 1                                                                                                                                                                      
let g:ale_echo_msg_error_str = 'Error'                                                                                                                                                         
let g:ale_echo_msg_format = '%code: %%s'                                                                                                                                                       
let g:ale_echo_msg_info_str = 'Info'
let g:ale_echo_msg_warning_str = 'Warning'                                                                                                                                                     
let g:ale_enabled = 1                                                                                                                                                                          
let g:ale_fix_on_save = 0                                                                                                                                                                      
let g:ale_fixers = {'javascript': ['eslint']}                                                                                                                                                  
let g:ale_history_enabled = 1                                                                                                                                                                  
let g:ale_history_log_output = 1                                                                                                                                                               
let g:ale_keep_list_window_open = 0                                                                                                                                                            
let g:ale_lint_delay = 200                                                                                                                                                                     
let g:ale_lint_on_enter = 1                                                                                                                                                                    
let g:ale_lint_on_filetype_changed = 1                                                                                                                                                         
let g:ale_lint_on_save = 1                                                                                                                                                                     
let g:ale_lint_on_text_changed = 'always'                                                                                                                                                      
let g:ale_lint_on_insert_leave = 0                                                                                                                                                             
let g:ale_linter_aliases = {}                                                                                                                                                                  
let g:ale_linters = {}                                                                                                                                                                         
let g:ale_linters_explicit = 0                                                                                                                                                                 
let g:ale_list_window_size = 10                                                                                                                                                                
let g:ale_list_vertical = 0                                                                                                                                                                    
let g:ale_loclist_msg_format = '%code: %%s'                                                                                                                                                    
let g:ale_max_buffer_history_size = 20                                                                                                                                                         
let g:ale_max_signs = -1                                                                                                                                                                       
let g:ale_maximum_file_size = v:null                                                                                                                                                           
let g:ale_open_list = 0                                                                                                                                                                        
let g:ale_pattern_options = {}                                                                                                                                                                 
let g:ale_pattern_options_enabled = 0                                                                                                                                                          
let g:ale_set_balloons = 0                                                                                                                                                                     
let g:ale_set_highlights = 1                                                                                                                                                                   
let g:ale_set_loclist = 1                                                                                                                                                                      
let g:ale_set_quickfix = 0                                                                                                                                                                     
let g:ale_set_signs = 1                                                                                                                                                                        
let g:ale_sign_column_always = 0                                                                                                                                                               
let g:ale_sign_error = '>>'                                                                                                                                                                    
let g:ale_sign_info = '--'                                                                                                                                                                     
let g:ale_sign_offset = 1000000                                                                                                                                                                
let g:ale_sign_style_error = '>>'                                                                                                                                                              
let g:ale_sign_style_warning = '--'                                                                                                                                                            
let g:ale_sign_warning = '--'                                                                                                                                                                  
let g:ale_statusline_format = ['⨉ %d', '⚠ %d', '⬥ ok']                                                                                                                                         
let g:ale_type_map = {}                                                                                                                                                                        
let g:ale_use_global_executables = v:null                                                                                                                                                      
let g:ale_warn_about_trailing_blank_lines = 1                                                                                                                                                  
let g:ale_warn_about_trailing_whitespace = 1
  Command History:                                                                                                                                                                             
(started) ['/bin/zsh', '-c', '''/home/jae/code/beat.editor/conda/js/node_modules/.bin/flow'' lsp --from ale-lsp']                                                                              
(executable check - failure) jscs                                                                                                                                                              
(executable check - failure) jshint                                                                                                                                                            
(executable check - failure) standard                                                                                                                                                          
(started) ['/bin/zsh', '-c', 'tsserver']                                                                                                                                                       
(executable check - failure) xo                                                                                                                                                                
(started) ['/bin/zsh', '-c', '''/home/jae/code/beat.editor/conda/js/node_modules/eslint/bin/eslint.js'' -f unix --stdin --stdin-filename ''/home/jae/code/beat.editor/conda/js/src/components/l
ibrary/LibraryEditor.jsx'' < ''/tmp/nvimIm1Jzi/3/LibraryEditor.jsx''']                                                                                                                         
(finished - exit code 0) ['/bin/zsh', '-c', '''/home/jae/code/beat.editor/conda/js/node_modules/.bin/flow'' --version; echo']                                                                  
(executable check - failure) jscs                                                                                                                                                              
(executable check - failure) jshint                                                                                                                                                            
(executable check - failure) standard                                                                                                                                                          
(executable check - failure) xo                                                                                                                                                                
(started) ['/bin/zsh', '-c', '''/home/jae/code/beat.editor/conda/js/node_modules/.bin/flow'' check-contents --respect-pragma --json --from ale ''/home/jae/code/beat.editor/conda/js/src/compon
ents/library/LibraryEditor.jsx'' < ''/tmp/nvimIm1Jzi/6/LibraryEditor.jsx''; echo']                                                                                                             
(finished - exit code 0) ['/bin/zsh', '-c', '''/home/jae/code/beat.editor/conda/js/node_modules/eslint/bin/eslint.js'' -f unix --stdin --stdin-filename ''/home/jae/code/beat.editor/conda/js/s
rc/components/library/LibraryEditor.jsx'' < ''/tmp/nvimIm1Jzi/7/LibraryEditor.jsx''']                                                                                                          
<<<OUTPUT STARTS>>>                                                                                                                                                                            
(node:31153) [ESLINT_LEGACY_OBJECT_REST_SPREAD] DeprecationWarning: The 'parserOptions.ecmaFeatures.experimentalObjectRestSpread' option is deprecated. Use 'parserOptions.ecmaVersion' instead
. (found in "../../../.eslintrc.js")                                                                                                                                                           
<<<OUTPUT ENDS>>>                                                                                                                                                                              
(finished - exit code 0) ['/bin/zsh', '-c', '''/home/jae/code/beat.editor/conda/js/node_modules/.bin/flow'' --version; echo']                                                                  
(executable check - failure) jscs                                                                                                                                                              
(executable check - failure) jshint                                                                                                                                                            
(executable check - failure) standard                                                                                                                                                          
(executable check - failure) xo                                                                                                                                                                
(finished - exit code 0) ['/bin/zsh', '-c', '''/home/jae/code/beat.editor/conda/js/node_modules/.bin/flow'' check-contents --respect-pragma --json --from ale ''/home/jae/code/beat.editor/cond
a/js/src/components/library/LibraryEditor.jsx'' < ''/tmp/nvimIm1Jzi/8/LibraryEditor.jsx''; echo']                                                                                              
<<<OUTPUT STARTS>>>                                                                                                                                                                            
{"flowVersion":"0.76.0","jsonVersion":"1","errors":[{"kind":"infer","level":"error","suppressions":[],"message":[{"context":"export class LibraryEditor extends React.Component<Props, State> {
","descr":"Cannot resolve name `State`.","type":"Blame","loc":{"source":"/home/jae/code/beat.editor/conda/js/src/components/library/LibraryEditor.jsx","type":"SourceFile","start":{"line":46,"
column":59,"offset":1078},"end":{"line":46,"column":63,"offset":1083}},"path":"/home/jae/code/beat.editor/conda/js/src/components/library/LibraryEditor.jsx","line":46,"endline":46,"start":59,
"end":63}]},{"kind":"infer","level":"error","suppressions":[],"extra":[{"message":[{"context":null,"descr":"References:","type":"Blame","path":"","line":0,"endline":0,"start":1,"end":0}]},{"m
essage":[{"context":"  declare export function connect<","descr":"[1]","type":"Blame","loc":{"source":"/home/jae/code/beat.editor/conda/js/flow-typed/npm/react-redux_v5.x.x.js","type":"LibFil
e","start":{"line":78,"column":34,"offset":2277},"end":{"line":91,"column":65,"offset":2664}},"path":"/home/jae/code/beat.editor/conda/js/flow-typed/npm/react-redux_v5.x.x.js","line":78,"endl
ine":91,"start":34,"end":65}]},{"message":[{"context":"  declare export function connect<","descr":"[2]","type":"Blame","loc":{"source":"/home/jae/code/beat.editor/conda/js/flow-typed/npm/rea
ct-redux_v5.x.x.js","type":"LibFile","start":{"line":115,"column":34,"offset":3294},"end":{"line":126,"column":72,"offset":3626}},"path":"/home/jae/code/beat.editor/conda/js/flow-typed/npm/re
act-redux_v5.x.x.js","line":115,"endline":126,"start":34,"end":72}]},{"message":[{"context":"const mapDispatchToProps = (dispatch, ownProps) => ({","descr":"[3]","type":"Blame","loc":{"source
":"/home/jae/code/beat.editor/conda/js/src/components/library/LibraryEditor.jsx","type":"SourceFile","start":{"line":180,"column":29,"offset":4457},"end":{"line":180,"column":36,"offset":4465
}},"path":"/home/jae/code/beat.editor/conda/js/src/components/library/LibraryEditor.jsx","line":180,"endline":180,"start":29,"end":36}]}],"message":[{"context":"export default connect(mapStat
eToProps, mapDispatchToProps)(LibraryEditor);","descr":"Could not decide which case to select. Since case 3 [1] may work but if it doesn't case 6 [2] looks promising too. To fix add a type an
notation to `dispatch` [3].","type":"Blame","loc":{"source":"/home/jae/code/beat.editor/conda/js/src/components/library/LibraryEditor.jsx","type":"SourceFile","start":{"line":188,"column":16,
"offset":4691},"end":{"line":188,"column":59,"offset":4735}},"path":"/home/jae/code/beat.editor/conda/js/src/components/library/LibraryEditor.jsx","line":188,"endline":188,"start":16,"end":59
}]}],"passed":false}                                                                                                                                                                           
<<<OUTPUT ENDS>>>    

What went wrong

ALE inserts an error on every line using type-like notation/keywords, saying that "'types' can only be used in a .ts file". Since I am using Flow (a supported linter, no less!) I would assume these messages wouldn't show up.

Reproducing the bug

Use ALE with flow and eslint. Add flow types to a javascript.jsx filetype file. ALE will start complaining about the types.

This is a HUGE issue! There should be a way to at the very least disable these typescript-centric messages.

Most helpful comment

There is. See :help g:ale_linters or :help g:ale_linters_ignore. What you probably want to do is add let b:ale_linters_ignore = ['tsserver'] to your ftplugin file for JavaScript, or define the option differently for different projects, which you can either control yourself or you can use g:ale_pattern_options for that.

All 11 comments

There is. See :help g:ale_linters or :help g:ale_linters_ignore. What you probably want to do is add let b:ale_linters_ignore = ['tsserver'] to your ftplugin file for JavaScript, or define the option differently for different projects, which you can either control yourself or you can use g:ale_pattern_options for that.

Ahah so the tsserver linter is doing something still.

In case anyone else has a problem with this - I just manually whitelisted the linters for JS files:

let g:ale_linters = {'javascript': ['eslint', 'flow']}                                                                                                                                   

Yeah, that'll work. You can also use b:ale_linters in an ftplugin file, or g:ale_linters_ignore, or b:ale_linters_ignore.

I'm wondering why this is necessary. Shouldn't the tsserver and the tslint linters only be enabled for typescript and typescript.jsx files anyways? They don't make too much sense for javascript or javascript.jsx files.

You can check JS code with tsserver and tslint.

I know but should it really be the default?

Yep.

I'm using coc.vim & passing the diganostics to ALE & have g:ale_linters set

let g:ale_linters = {
      \ 'javascript': ['eslint'],
      \ 'javascript.jsx': ['eslint'],
      \}

even adding this didn't work

let g:ale_linters_ignore = {
      \ 'javascript': ['tsserver'],
      \ 'javascript.jsx': ['tsserver'],
      \}

Yet it still runs through tsserver any idea why?

Open an issue and share the output of :ALEInfo. You probably just need to tweak your settings some more. You may also want to check out :help g:ale_linters_explicit for disabling all linters by default.

I have the same issue, all places where there are flow code related, this errors appears

  • 'types' can only be used in a .ts file
  • 'import ... = ' can only be used in a .ts file
  • 'type arguments' can only be used in a .ts file
  • 'type aliases' can only be used in a .ts file

This is my .vimrc file:

execute pathogen#infect()
set encoding=utf-8
syntax on
filetype plugin indent on

""""""""""""""""""""""""""""""
""""" GENERAL SETTINGS """""""
""""""""""""""""""""""""""""""
set number " Number line
set backspace=indent,eol,start " Allow backspace on INSERT mode
set splitright " To make vsplit put the new buffer on the right of the current buffer
set splitbelow " To make split put the new buffer below the current buffer
" The next two lines were added in order to avoid dd shortcut paste the content to the
" buffer
nnoremap d "_d
vnoremap d "_d
" Clear registers table
command! WipeReg for i in range(34,122) | silent! call setreg(nr2char(i), []) | endfor 
"-- FOLDING --
set foldmethod=syntax " syntax highlighting items specify folds
set foldcolumn=1 " defines 1 col at window left, to indicate folding
let javaScript_fold=1 "activate folding by JS syntax
set foldlevelstart=99 "start file with all folds opened
" Copy to clipboard default leader is basckslash e.g. \y
noremap <Leader>y "*y
noremap <Leader>p "*p
noremap <Leader>Y "+y
noremap <Leader>P "+p
" Config for relative and absolute numbers 
set number relativenumber
set ruler
augroup numbertoggle
 autocmd!
 autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
 autocmd BufLeave,FocusLost,InsertEnter   * set norelativenumber
augroup END
" End Config for relative and absolute numbers
""""""""""""""""""""""""""""""
"""" END GENERAL SETTINGS """"
""""""""""""""""""""""""""""""
" Config for emmet-vim
let g:user_emmet_expandabbr_key = '<tab>'
let g:user_emmet_settings = {
 \  'javascript.jsx' : {
   \      'extends' : 'jsx',
   \  },
 \}
" End config for emmet-vim
" vim-jsx
 let g:jsx_ext_required = 0
" end vim-jsx
" vim-javscript
let g:javascript_plugin_flow = 1
" end vim-javascript
" Config for NERDTree
autocmd vimenter * NERDTree
map <C-g> :NERDTreeToggle<CR>
map <C-m> :NERDTreeFind<CR>
" For mouse click in NERDTree
set mouse=a
let g:NERDTreeMouseMode=3
" End mouse
" End config NERDTree
" Config for LightLine 
set noshowmode " No show Vim default MODE 
set laststatus=2 " Single File LightLine Bar
" End config LightLine
" Config for MatchTagAlways
" JSX - React SetUp
let g:mta_filetypes = {
\ 'javascript.jsx': 1,
\ 'html' : 1,
\ 'xhtml' : 1,
\ 'xml' : 1,
\ 'jinja' : 1,
\}
" End config MatchTagAlways
"""""""""""""""""""""""""""""
" Setup for tab as 4 spaces "
"""""""""""""""""""""""""""""
" show existing tab with 4 spaces width
" set tabstop=2
" when indenting with '>', use 4 spaces width
" set shiftwidth=2
" On pressing tab, insert 4 spaces
" set expandtab
"""""""""""""""""""""""""""""
" End setup tab as 4 spaces " 
"""""""""""""""""""""""""""""
" Setup FZF
set rtp+=/usr/local/opt/fzf
map <C-p> :Files <CR>
" End Setup FZF
" Setup YCM
" Start autocompletion after 4 chars
let g:ycm_min_num_of_chars_for_completion = 4
let g:ycm_min_num_identifier_candidate_chars = 4
let g:ycm_enable_diagnostic_highlighting = 0
" Don't show YCM's preview window [ I find it really annoying ]
set completeopt-=preview
let g:ycm_add_preview_to_completeopt = 0
" UltiNips
" Trigger configuration. Do not use <tab> if you use https://github.com/Valloric/YouCompleteMe.
let g:UltiSnipsExpandTrigger="<c-j>"
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
" End UltiNips
" ALE
let g:ale_sign_error = '✘'
let g:ale_sign_warning = 'âš¡'
highlight ALEErrorSign ctermbg=NONE ctermfg=red
highlight ALEWarningSign ctermbg=NONE ctermfg=yellow
let g:ale_fixers={}
let g:ale_fixers['javascript'] = ['prettier', 'eslint']
let g:ale_fixers['scss'] = ['prettier', 'eslint']
let g:ale_fixers['JSON'] = ['prettier', 'eslint']
let g:ale_linters= {'javascript':['flow-language-server']}
" Set this variable to 1 to fix files when you `save them.
let g:ale_fix_on_save = 1
" End ALE Setup
" Config for Dracula Theme
color dracula
" End config Dracula Theme

this solves the problem for me:

let g:ale_linters_ignore = {
      \ 'javascript': ['tsserver'],
      \ 'javascriptreact': ['tsserver'],
      \}

I use javascriptreact instead of javascript.jsx

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aressler38 picture aressler38  Â·  3Comments

trevordmiller picture trevordmiller  Â·  4Comments

plexigras picture plexigras  Â·  3Comments

catbaron0 picture catbaron0  Â·  3Comments

lervag picture lervag  Â·  3Comments