dense-analysis / ale

Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
BSD 2-Clause "Simplified" License
13.59k stars 1.44k forks source link

eslint: Initial lint on file open runs with different results than :ALELint #1459

Closed archseer closed 6 years ago

archseer commented 6 years ago

Information

VIM version

NVIM v0.2.2 Build type: Release

Operating System: OS X

:ALEInfo

:ALEInfo
 Current Filetype: typescript
Available Linters: ['eslint', 'tslint', 'tsserver', 'typecheck']
  Enabled Linters: ['eslint', 'tslint', 'tsserver', 'typecheck']
 Linter Variables:

let g:ale_typescript_tslint_config_path = ''
let g:ale_typescript_tslint_executable = 'tslint'
let g:ale_typescript_tslint_ignore_empty_files = 0
let g:ale_typescript_tslint_rules_dir = ''
let g:ale_typescript_tslint_use_global = 0
let g:ale_typescript_tsserver_config_path = ''
let g:ale_typescript_tsserver_executable = 'tsserver'
let g:ale_typescript_tsserver_use_global = 0
 Global Variables:

let g:ale_cache_executable_check_failures = 0
let g:ale_change_sign_column_color = 0
let g:ale_command_wrapper = ''
let g:ale_completion_delay = 100
let g:ale_completion_enabled = 1
let g:ale_completion_max_suggestions = 50
let g:ale_echo_cursor = 1
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = '[%linter%] %s [%severity%]'
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 = 1
let g:ale_fixers = {'vue': ['eslint'], 'javascript': ['eslint', 'tslint']}
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 = 'never'
let g:ale_lint_on_insert_leave = 0
let g:ale_linter_aliases = {'vue': 'typescript'}
let g:ale_linters = {'elixir': ['credo'], 'vue': ['tsserver', 'eslint']}
let g:ale_linters_explicit = 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 = 0
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_warn_about_trailing_blank_lines = 1
let g:ale_warn_about_trailing_whitespace = 1
  Command History:

(executable check - success) xmllint
(finished - exit code 1) ['/usr/local/bin/zsh', '-c', '''xmllint''  --noout - < ''/var/folders/_j/_477qt2d0llgr9vxdkmmc_mw0000gn/T/nvim9j5Eqh/4/main.ts''']

<<<OUTPUT STARTS>>>
-:1: parser error : Start tag expected, '<' not found
import Vue from 'vue';
^
<<<OUTPUT ENDS>>>

(executable check - success) /<my_project>/node_modules/eslint/bin/eslint.js
(finished - exit code 1) ['/usr/local/bin/zsh', '-c', '''/<my_project>/node_modules/eslint/bin/eslint.js'' -f unix --stdin --stdin-filename ''/<my_project>/src/main.ts'' < ''/var/folders/_j/_477qt2d0llgr9vxdkmmc_mw0000gn/T/nvim9j5Eqh/8/main.ts''']

<<<OUTPUT STARTS>>>
/<my_project>/src/main.ts:10:34: Unable to resolve path to module './i18n'. [Error/import/no-unresolved]
/<my_project>/src/main.ts:10:34: Missing file extension for "./i18n" [Error/import/extensions]
/<my_project>/src/main.ts:16:20: Unable to resolve path to module './router'. [Error/import/no-unresolved]
/<my_project>/src/main.ts:16:20: Missing file extension for "./router" [Error/import/extensions]
/<my_project>/src/main.ts:17:19: Unable to resolve path to module './store'. [Error/import/no-unresolved]
/<my_project>/src/main.ts:17:19: Missing file extension for "./store" [Error/import/extensions]
/<my_project>/src/main.ts:18:32: Unable to resolve path to module './vue-apollo'. [Error/import/no-unresolved]
/<my_project>/src/main.ts:18:32: Missing file extension for "./vue-apollo" [Error/import/extensions]
/<my_project>/src/main.ts:26:9: Unexpected require(). [Error/global-require]
/<my_project>/src/main.ts:27:9: Unexpected require(). [Error/global-require]
/<my_project>/src/main.ts:70:9: Unexpected require(). [Error/global-require]
/<my_project>/src/main.ts:71:11: Unexpected require(). [Error/global-require]
12 problems
<<<OUTPUT ENDS>>>

(executable check - success) /<my_project>/node_modules/.bin/tslint
(finished - exit code 0) ['/usr/local/bin/zsh', '-c', 'cd ''/<my_project>/src'' && /<my_project>/node_modules/.bin/tslint --format json ''/var/folders/_j/_477qt2d
0llgr9vxdkmmc_mw0000gn/T/nvim9j5Eqh/9/main.ts''']

<<<OUTPUT STARTS>>>
[]
<<<OUTPUT ENDS>>>

(started) ['/usr/local/bin/zsh', '-c', '/<my_project>/node_modules/.bin/tsserver']
(executable check - failure) typecheck
(finished - exit code 1) ['/usr/local/bin/zsh', '-c', '''/<my_project>/node_modules/eslint/bin/eslint.js'' -f unix --stdin --stdin-filename ''/<my_project>/src/main.ts'' < ''/var/folders/_j/_477qt2d0llgr9vxdkmmc_mw0000gn/T/nvim9j5Eqh/10/main.ts''']

<<<OUTPUT STARTS>>>
/<my_project>/src/main.ts:26:9: Unexpected require(). [Error/global-require]
/<my_project>/src/main.ts:27:9: Unexpected require(). [Error/global-require]
/<my_project>/src/main.ts:70:9: Unexpected require(). [Error/global-require]
/<my_project>/src/main.ts:71:11: Unexpected require(). [Error/global-require]

4 problems
<<<OUTPUT ENDS>>>

(finished - exit code 0) ['/usr/local/bin/zsh', '-c', 'cd ''/<my_project>/src'' && /<my_project>/node_modules/.bin/tslint --format json ''/var/folders/_j/_477qt2d
0llgr9vxdkmmc_mw0000gn/T/nvim9j5Eqh/11/main.ts''']

<<<OUTPUT STARTS>>>
[]
<<<OUTPUT ENDS>>>

(executable check - failure) typecheck

What went wrong

The first lint somehow fails to pick up the extra .ts files I have. Running :ALELint triggers a second lint and the list of errors corrects itself. I initially thought that maybe it's linting from the wrong directory, but it doesn't seem to be the case.

w0rp commented 6 years ago

This was probably an issue with new files, and can't be fixed in ALE.

archseer commented 6 years ago

It's not, it's still reproducible in a vanilla Vue project, meanwhile VS Code / Vetur doesn't have such issues. I haven't been able to figure out exactly what happens, but I think it's ran via a different current directory between cases.

archseer commented 6 years ago

Here's me opening a file in vim, then running :ALELint

  Command History:
(executable check - success) /<path>/ui/node_modules/eslint/bin/eslint.js
(finished - exit code 1) ['/usr/local/bin/zsh', '-c', '''/<path>/ui/node_modules/eslint/bin/eslint.js'' -f unix --stdin --stdin-filename ''/<path>/ui/src/vi
ews/Calendar.vue'' < ''/var/folders/_j/_477qt2d0llgr9vxdkmmc_mw0000gn/T/nvimEhL8RI/7/Calendar.vue''']
<<<OUTPUT STARTS>>>
/<path>/ui/src/views/Calendar.vue:92:23: Unable to resolve path to module '@/components/calendar/MonthView.vue'. [Error/import/no-unresolved]
/<path>/ui/src/views/Calendar.vue:93:21: Unable to resolve path to module '@/components/calendar/DayView.vue'. [Error/import/no-unresolved]
/<path>/ui/src/views/Calendar.vue:94:22: Unable to resolve path to module '@/components/calendar/WeekView.vue'. [Error/import/no-unresolved]
/<path>/ui/src/views/Calendar.vue:95:26: Unable to resolve path to module '@/components/calendar/timeline/View.vue'. [Error/import/no-unresolved]
/<path>/ui/src/views/Calendar.vue:96:31: Unable to resolve path to module '@/mixins/CalendarMathMixin'. [Error/import/no-unresolved]
/<path>/ui/src/views/Calendar.vue:96:31: Missing file extension for "@/mixins/CalendarMathMixin" [Error/import/extensions]
6 problems
<<<OUTPUT ENDS>>>
(finished - exit code 0) ['/usr/local/bin/zsh', '-c', '''/<path>/ui/node_modules/eslint/bin/eslint.js'' -f unix --stdin --stdin-filename ''/<path>/ui/src/vi
ews/Calendar.vue'' < ''/var/folders/_j/_477qt2d0llgr9vxdkmmc_mw0000gn/T/nvimEhL8RI/8/Calendar.vue''']
<<<NO OUTPUT RETURNED>>>

I think potentially, when I initially open vim, it runs eslint according to project (git) root, whereas I opened the editor inside /ui, so when I run :ALELint it runs relative to that directory and picks up my config files correctly.

w0rp commented 6 years ago

Okay, this is a problem with an ESLint plugin, and they should fix it: https://github.com/benmosher/eslint-plugin-import/issues/1158

ALE can't automatically determine which working directory to use for ESLint, and ESLint plugins shouldn't care what your working directory is. The plugin authors will have to fix it.

w0rp commented 6 years ago

I revert that commit because it just broke the same thing for other people in different ways.

sdeleon28 commented 5 years ago

It looks like eslint doesn't intend to fix this on their side. Is there a workaround for this or is ALE no longer usable for javascript projects?

w0rp commented 5 years ago

It's a bug in the ESLint plugin, and the bug should be fixed in the plugin. You can work around the issue by writing your configuration file in JavaScript and by defining the packageDir variable with __dirname.

sdeleon28 commented 5 years ago

Unlike import/no-extraneous-dependencies.md, import/no-unresolved doesn't have a packageDir option.

Is there nothing else that can be done about this?

sdeleon28 commented 5 years ago

BTW, I've suggested the change that would fix this in the plugin's GitHub, but if they choose to not accept it, it would require a fork, which seems pretty high-maintenance for future users that may stumble upon this.