Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eslint enabled by default on JSON files without proper dependency check #4004

Closed
theycallmeswift opened this issue Dec 5, 2021 · 6 comments
Labels

Comments

@theycallmeswift
Copy link

Information

VIM version

IM - Vi IMproved 8.2 (2019 Dec 12, compiled Oct 1 2021 22:47:36)
macOS version - x86_64

Operating System: Mac OS 12.0.1 (21A559)

What went wrong

When I open any JSON file in a project using eslint, I receive a parsing error. This is because #3873 made eslint enabled on JSON files by default even though eslint does not support JSON parsing out of the box. This can be fixed by adding a JSON parsing plugin to the eslint config, but not everyone realizes this is the behavior and we really should either (1) install all the dependencies or (2) check for them before bubbling up unnecessary errors to the user.

Example error:

[eslint] Parsing error: /Users/theycallmeswift/dev/foo/.eslintrc.json: Missing semicolon. (2:11)  1 | {> 2 |   "extends": "next/core-web-vitals"    |            ^  3 | }  4 | [E]

Reproducing the bug

  1. Enable ALE with default JSON linters
  2. Install eslint
  3. Create any .estlint config to enable and any JSON file
  4. Edit the JSON file to see the error.

:ALEInfo

ALEInfo
 Current Filetype: json
Available Linters: ['cspell', 'eslint', 'jq', 'jsonlint', 'spectral']
  Enabled Linters: ['cspell', 'eslint', 'jq', 'jsonlint', 'spectral']
  Ignored Linters: []
 Suggested Fixers:
  'fixjson' - Fix JSON files with fixjson.
  'jq' - Fix JSON files with jq.
  'prettier' - Apply prettier to a file.
  'remove_trailing_lines' - Remove all blank lines at the end of a file.
  'trim_whitespace' - Remove all trailing whitespace characters at the end of every line.
 Linter Variables:

let g:ale_json_jq_executable = 'jq'
let g:ale_json_jq_filters = '.'
let g:ale_json_jq_options = ''
let g:ale_json_jsonlint_executable = 'jsonlint'
let g:ale_json_jsonlint_use_global = 0
let g:ale_json_spectral_executable = 'spectral'
let g:ale_json_spectral_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_disable_lsp = 0
let g:ale_echo_cursor = 1
let g:ale_echo_msg_error_str = 'E'
let g:ale_echo_msg_format = '[%linter%] %s [%severity%]'
let g:ale_echo_msg_info_str = 'Info'
let g:ale_echo_msg_warning_str = 'W'
let g:ale_enabled = 1
let g:ale_fix_on_save = 1
let g:ale_fixers = {'rust': ['rustfmt', 'trim_whitespace', 'remove_trailing_lines'], 'typescript': ['prettier', 'eslint'], 'json': [], 'javascriptreact': ['prettier', 'eslint'], 'ruby': ['rubocop'], 'javascript': ['prettier', 'eslint'], 'typescriptreact': ['prettier', 'es
lint'], 'css': ['prettier'], 'python': ['yapf']}
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_insert_leave = 1
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 'normal'
let g:ale_linter_aliases = {}
let g:ale_linters = {'json': ['cspell', 'eslint', 'jq', 'jsonlint', 'spectral']}
let g:ale_linters_explicit = 0
let g:ale_linters_ignore = {}
let g:ale_list_vertical = 0
let g:ale_list_window_size = 10
let g:ale_loclist_msg_format = '[%linter%] %s [%severity%]'
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 = v:null
let g:ale_pattern_options_enabled = v:null
let g:ale_root = {}
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_sign_highlight_linenrs = 0
let g:ale_statusline_format = v:null
let g:ale_type_map = {}
let g:ale_use_global_executables = v:null
let g:ale_virtualtext_cursor = 0
let g:ale_warn_about_trailing_blank_lines = 1
let g:ale_warn_about_trailing_whitespace = 1
  Command History:
(executable check - failure) cspell
(executable check - success) /Users/theycallmeswift/dev/nftstudio/node_modules/eslint/bin/eslint.js
(finished - exit code 1) ['/bin/zsh', '-c', 'cd ''/Users/theycallmeswift/dev/nftstudio'' && ''/Users/theycallmeswift/dev/nftstudio/node_modules/eslint/bin/eslint.js'' -f json --stdin --stdin-filename ''/Users/theycallmeswift/dev/nftstudio/.eslintrc.json'' < ''/var/folders
/28/3d8v62rj037fm00z5cr0gg380000gn/T/vEAdyEr/1/.eslintrc.json''']
<<<OUTPUT STARTS>>>
[{"filePath":"/Users/theycallmeswift/dev/nftstudio/.eslintrc.json","messages":[{"ruleId":null,"fatal":true,"severity":2,"message":"Parsing error: /Users/theycallmeswift/dev/nftstudio/.eslintrc.json: Missing semicolon. (2:11)\n\n  1 | {\n> 2 |   \"extends\": [\n    |
      ^\n  3 |     \"next/core-web-vitals\"\n  4 |   ]\n  5 | }","line":2,"column":11}],"errorCount":1,"fatalErrorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":"{\n  \"extends\": [\n    \"next/core-web-vitals\"\n  ]\n}\n","usedDeprecated
Rules":[]}]
<<<OUTPUT ENDS>>>
(executable check - failure) jqkkjjj
(executable check - failure) jsonlint
(executable check - failure) spectral
@hsanson
Copy link
Contributor

hsanson commented Dec 9, 2021

This is something I was afraid would happen (#3873 (comment)). Currently I see no way to check if the dependency is available or not. There seems to be a way to have linters disabled by default but have no had time to figure it out.

@theycallmeswift
Copy link
Author

I also could not find a way to accomplish this. My instinct says revert as it's highly unlikely that >80% of projects would have this secondary dependency and eslint is not designed for json.

@flipjs
Copy link

flipjs commented Dec 20, 2021

Not sure if this is related but I notice recently when opening json files, I get "parsing error: unexpected token" error. Adding jsonlint for json files explicitly in my config makes this error go away.

let g:ale_linters = {
  \ 'javascript': ['eslint'],
  \ 'json': ['jsonlint'],
\ }

@theycallmeswift
Copy link
Author

@flipjs that's because you're overriding the linters list to remove eslint. It's not actually a fix for this problem sadly

@hsanson
Copy link
Contributor

hsanson commented Dec 24, 2021

@theycallmeswift this is an attempt to disable eslint by default for json files: #4023 appreciated if you can test this.

@hsanson
Copy link
Contributor

hsanson commented Jan 5, 2022

Assuming fixed with #4023.

@hsanson hsanson closed this as completed Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants