vim-syntastic / syntastic

Syntax checking hacks for vim
Do What The F*ck You Want To Public License
11.31k stars 1.14k forks source link

Syntastic doesn't use checker for {javascript, typescript}react files #2385

Closed theahura closed 2 years ago

theahura commented 2 years ago

With the following syntastic config:

set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*

let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
let g:syntastic_python_python_exec = 'python3'
let g:syntastic_javascript_checkers = ['eslint']
let g:syntastic_javascriptreact_checkers = ['eslint']
let g:syntastic_typescript_checkers = ['eslint']
let g:syntastic_typescriptreact_checkers = ['eslint']

I get the following output from SyntasticInfo on a typescriptreact (tsx) file or a javascriptreact (jsx) file:

Syntastic version: 3.10.0-27 (Vim 801, Linux)
Info for filetype: typescriptreact
Global mode: active
Filetype typescriptreact is active
Available checkers: -
Currently enabled checkers: -

eslint works fine for other file types, e.g. typescript files:

Syntastic version: 3.10.0-27 (Vim 801, Linux)
Info for filetype: typescript
Global mode: active
Filetype typescript is active
The current file will be checked automatically
Available checker: eslint
Currently enabled checker: eslint

eslint works fine for tsx and jsx files, for e.g. i can run eslint foo.tsx and get warnings/errors from the CLI.

Why does syntastic ignore eslint even though it is explicitly set for these filetypes?

If the *react filetypes are unique, this should probably be mentioned in the documentation for syntastic_\<filetype>_checkers

Relatedly, many of the suggested checkers for js/ts files in the syntastic-checkers.txt are deprecated and explicitly point to eslint. For example, JSXHint, Syntastic-React, TSLint.

lcd047 commented 2 years ago

Why does syntastic ignore eslint even though it is explicitly set for these filetypes?

Because you can't just make up a filetype, define some variables, and expect syntastic to run checks based on those. A lot more is needed, the filetype and the corresponding linters have to be known to syntastic in advance, and code has to be written for each pair (filetype, linter) to parse the errors.

The known filetypes and linters are listed in the manual. Beyond that you can do some redirections (f.i. you can run :SyntasticCheck javascript/eslint regardless of the current filetype), but you certainly can't expect syntastic to run checks automatically on made up filetypes. All of these are described in the manual, you can save a lot of time just reading how things are meant to work. shrug

theahura commented 2 years ago

:SyntasticInfo returns typescriptreact and javascriptreact for .tsx and .jsx files without additional configuration. This is happening in vim. I'm surprised you think these filetypes are 'made up', they've been around for 2+ years now.

It's fine if syntastic doesn't support these filetypes/every filetype that vim supports, but as I mentioned in my initial post if specific filetypes aren't supported, this should be mentioned in the docs for syntastic_<filetype>_checkers. Happy to send a PR.

For other folks who stumble on this post, I found #2283 as a reasonable workaround. Specifically, add the following to your .vimrc:

let g:syntastic_filetype_map = {"javascriptreact": "javascript", "typescriptreact": "typescript"}

For typescriptreact files, you will likely also need a typescript eslint parser. Run the following in your project:

npm install eslint @typescript-eslint/eslint-plugin @typescript-eslint/parser --save-dev

You may also need an .eslintrc in your project or globally that looks something like this:

{
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "jsx": true,
    "useJSXTextNode": true
  },
  "rules": {
    "@typescript-eslint/no-explicit-any": "off"
  },
  "extends": ["plugin:@typescript-eslint/recommended"],
  "plugins": ["@typescript-eslint"]
}

I appreciate the work you're doing on this and understand the difficulty in maintaining an open source project, especially for answering other people's questions. That said, dismissively telling someone to RTFM when they've looked at the docs and posted links to places where the docs could be improved is harsh.

lcd047 commented 2 years ago

I'm surprised you think these filetypes are 'made up', they've been around for 2+ years now.

They're made up from the point of view of syntastic. There is nothing syntastic can do to stop you from setting syntastic_javascriptreact_checkers and friends, they just won't have the effect you seem to expect.

as I mentioned in my initial post if specific filetypes aren't supported, this should be mentioned in the docs for syntastic_<filetype>_checkers.

Except that's unreasonable. There are a lot more filetypes that syntastic doesn't know of than filetypes it supports. There is a list of what syntastic can do, use it. Don't expect syntastic to consider what you might want to do and warn you if it isn't possible. shrug

On a side note: syntastic is dead. It has been that way for a few years now. Please consider switching to ALE instead, which is actively maintained and takes advantage of Vim 8+ features.

theahura commented 2 years ago

Will do re ALE, thanks for the heads up