ale icon indicating copy to clipboard operation
ale copied to clipboard

Local Prettier config .prettierrc ignored for prettier-eslint fixer

Open jondkinney opened this issue 6 years ago • 3 comments
trafficstars

Information

VIM version

NVIM v0.3.1 Build type: Release

Operating System: macOS Mojave 10.14.1

What went wrong

Attempting to use prettier-eslint doesn't load the local .prettierrc config file. So when you save, prettier only formats with the defaults.

let g:ale_fixers = {
\   'javascript': ['prettier_eslint'],
\}

let g:ale_fix_on_save = 1

Reproducing the bug

Save the file, and prettier will run, but with the default settings. Then ESLint will run --fix on the result.

I think that this is similar to https://github.com/w0rp/ale/issues/983 and if you look at the bottom of the ALEInfo below, you can see that --stdin-filename is not being passed to prettier-eslint. So if that's the flag you need for it to infer the local .prettierrc file and/or traverse up the path until it finds one, then that'd be the issue, I think.

Looking back at lots of issues and commits, it seems that we can specify the fixers as both prettier and eslint (shown below) to achieve the same end results. Is that correct? Or are we missing out on some of the nuance of prettier-eslint by letting ALE do the passing of the prettier formatted output to eslint's --fix?

let g:ale_fixers = {
\   'javascript': ['prettier', 'eslint'],
\}

:ALEInfo

 Current Filetype: javascript.jsx
Available Linters: ['eslint', 'flow', 'flow-language-server', 'jscs', 'jshint', 'standard', 'tsserver', 'xo']
  Enabled Linters: ['eslint']
 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
 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 = '%linter% says %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 = 1
let g:ale_fixers = {'ruby': ['rubocop'], 'javascript': ['prettier_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 = 250
let g:ale_lint_on_enter = 1
let g:ale_lint_on_filetype_changed = 1
let g:ale_lint_on_insert_leave = 0
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 'normal'
let g:ale_linter_aliases = {}
let g:ale_linters = {'commitmessage': ['gitlint'], 'sass': ['sass-lint'], 'erb': ['erb'], 'ruby': ['ruby', 'rubocop', 'reek'], 'javascript': ['eslint'], 'slim': ['slim-lint']}
let g:ale_linters_explicit = 0
let g:ale_list_vertical = 0
let g:ale_list_window_size = 10
let g:ale_loclist_msg_format = '%linter% says %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 = v:null
let g:ale_pattern_options_enabled = v:null
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 = 1
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 = ['X %d', '? %d', '']
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 - success) /Users/jon/Sites/user-app/node_modules/eslint/bin/eslint.js
(started) ['/bin/zsh', '-c', '''/Users/jon/Sites/user-app/node_modules/eslint/bin/eslint.js'' -f unix --stdin --stdin-filename ''/Users/jon/Sites/user-app/src/App.js'' < ''/var/folders/d4/9zbq2yyx6j955t4zgqjxghn40000gn/T/nvimJsm6Wo/9/App.js''']
(finished - exit code 1) ['/bin/zsh', '-c', '''/Users/jon/Sites/user-app/node_modules/eslint/bin/eslint.js'' -f unix --stdin --stdin-filename ''/Users/jon/Sites/user-app/src/App.js'' < ''/var/folders/d4/9zbq2yyx6j955t4zgqjxghn40000gn/T/nvimJsm6Wo/10/App.js''']

<<<OUTPUT STARTS>>>
/Users/jon/Sites/user-app/src/App.js:5:11: Missing trailing comma. [Error/comma-dangle]
/Users/jon/Sites/user-app/src/App.js:6:8: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:7:8: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:8:26: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:9:45: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:10:26: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:11:33: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:12:30: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:13:26: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:14:31: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:15:31: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:16:32: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:17:35: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:18:35: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:19:55: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:20:22: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:21:19: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:22:27: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:23:27: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:24:24: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:25:19: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:26:26: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:27:26: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:28:26: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:29:20: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:30:22: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:38:52: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:38:64: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:47:25: Missing trailing comma. [Error/comma-dangle]
/Users/jon/Sites/user-app/src/App.js:53:20: Missing trailing comma. [Error/comma-dangle]
/Users/jon/Sites/user-app/src/App.js:54:4: Missing trailing comma. [Error/comma-dangle]
/Users/jon/Sites/user-app/src/App.js:60:21: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:60:60: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:63:11: Missing trailing comma. [Error/comma-dangle]
/Users/jon/Sites/user-app/src/App.js:68:29: Missing trailing comma. [Error/comma-dangle]

35 problems
<<<OUTPUT ENDS>>>

(finished - exit code 0) ['/bin/zsh', '-c', '''/Users/jon/Sites/user-app/node_modules/prettier-eslint-cli/dist/index.js'' --version']
(finished - exit code 0) ['/bin/zsh', '-c', '''/Users/jon/Sites/user-app/node_modules/prettier-eslint-cli/dist/index.js'' ''/var/folders/d4/9zbq2yyx6j955t4zgqjxghn40000gn/T/nvimJsm6Wo/11/App.js'' --write']
(finished - exit code 1) ['/bin/zsh', '-c', '''/Users/jon/Sites/user-app/node_modules/eslint/bin/eslint.js'' -f unix --stdin --stdin-filename ''/Users/jon/Sites/user-app/src/App.js'' < ''/var/folders/d4/9zbq2yyx6j955t4zgqjxghn40000gn/T/nvimJsm6Wo/12/App.js''']

<<<OUTPUT STARTS>>>
/Users/jon/Sites/user-app/src/App.js:5:11: Missing trailing comma. [Error/comma-dangle]
/Users/jon/Sites/user-app/src/App.js:6:8: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:7:8: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:8:26: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:9:45: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:10:26: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:11:33: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:12:30: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:13:26: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:14:31: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:15:31: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:16:32: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:17:35: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:18:35: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:19:55: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:20:22: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:21:19: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:22:27: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:23:27: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:24:24: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:25:19: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:26:26: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:27:26: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:28:26: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:29:20: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:30:22: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:38:52: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:38:64: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:47:25: Missing trailing comma. [Error/comma-dangle]
/Users/jon/Sites/user-app/src/App.js:53:20: Missing trailing comma. [Error/comma-dangle]
/Users/jon/Sites/user-app/src/App.js:54:4: Missing trailing comma. [Error/comma-dangle]
/Users/jon/Sites/user-app/src/App.js:60:21: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:60:60: Strings must use singlequote. [Error/quotes]
/Users/jon/Sites/user-app/src/App.js:63:11: Missing trailing comma. [Error/comma-dangle]
/Users/jon/Sites/user-app/src/App.js:68:29: Missing trailing comma. [Error/comma-dangle]

35 problems
<<<OUTPUT ENDS>>>

jondkinney avatar Jan 20 '19 20:01 jondkinney

Correct me if I'm wrong but,

Use let g:ale_javascript_prettier_use_local_config = 1. Loading configuration files is off by default, because passing the option only works on newer versions of prettier. The default will change in maybe half a year or a year, after enough people have had the opportunity to upgrade.

It looks like you don't have that set?

RyanSquared avatar Jan 24 '19 04:01 RyanSquared

Actually it looks like that's eslint loading prettier rather than prettier itself. I'm not sure how to tell eslint to use the local eslint config.

RyanSquared avatar Jan 24 '19 04:01 RyanSquared

I personally recommend installing eslint-plugin-prettier and fixing your files with eslint instead. That seems to be the best way to combine the two. You can also combine this with eslint_d for some faster reporting of problems in a file.

w0rp avatar Jan 27 '19 10:01 w0rp