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

JavaScript: Configures prettier to use single quotes #34

Closed

Conversation

aaronmcadam
Copy link

I've had to change the formatter for prettier directly to achieve this. There doesn't seem to be a configuration file for prettier, or a way to globally configure it.

I think a better idea would be to set a variable like let g:neoformat_javascript_args in my neovim configuration, but I'm not sure how to do that.

@fortes
Copy link

fortes commented Jan 11, 2017

@sbdchd
Copy link
Owner

sbdchd commented Jan 11, 2017

Also, since prettier can now use stdin, I would suggest the following:

let g:neoformat_javascript_prettier = {
            \ 'exe': 'prettier',
            \ 'args': ['--stdin', '--single-quote'],
            \ 'stdin': 1,
            \ }

@fortes
Copy link

fortes commented Jan 11, 2017

@sbdchd any reason to prefer using standard in?

@sbdchd
Copy link
Owner

sbdchd commented Jan 11, 2017

@fortes

with stdin, buffer --> formatter --> buffer,

without stdin, buffer --> tmp_file <-- formatter --> buffer

There isn't any usability difference that I know of, but not having to write to a tmp file is a plus.

@fortes
Copy link

fortes commented Jan 11, 2017

@sbdchd got it, I'll switch my config. Thanks.

@aaronmcadam
Copy link
Author

Thanks @fortes @sbdchd! Closing 👍

@aaronmcadam
Copy link
Author

aaronmcadam commented Jan 12, 2017

@sbdchd Using your version, I now see Neoformat: attempted all formatters for current filetype when calling the plugin in a JavaScript buffer. If I switch back to my fork, it formats correctly. How would I go about debugging?

@aaronmcadam
Copy link
Author

@sbdchd It seems to be enabling stdin for prettier that makes the plugin not see the formatter for me. I've reproduced it in my fork.

@sbdchd
Copy link
Owner

sbdchd commented Jan 12, 2017

@aaronmcadam Have you updated prettier? Stdin is a relatively new option.

Otherwise, can you set verbose=1 before running :Neoformat and copy the output of :messages to here?

@aaronmcadam
Copy link
Author

aaronmcadam commented Jan 12, 2017

Hi @sbdchd

Yeah I've updated prettier to 0.0.5.

Here's the output when I turn :Neoformat:

Neoformat: executable: js-beautify is not an executable
Neoformat: ['import R from ''ramda'';', '', '/**', '  * mediaState is a collection of functions that deal with mediaState', '  * [Media State on Confluence]{@link https://crowdlab.atlassian.net/wiki/display/DATA/Transcode+State+Machine}',
 '  * Possible States', '  * undefined', '  * no_media', '  * pending', '  * transcoding', '  * uploading', '  * preview', '  * ready', '  * failed', ' */', '', 'const stateContains = R.flip(R.contains);', '', 'const mediaFailed = R.equal
s(''failed'');', '', 'const flashIsNeeded = stateContains(', '  [''failed'', ''pending'', ''transcoding'', ''uploading'', ''preview'']', ');', '', 'const noFlashIsNeeded = R.compose(R.not, flashIsNeeded);', '', 'const message = (mediaStat
e) => (', '  mediaFailed(mediaState) ? ''media.failed'' : ''media.processing''', ');', '', 'const icon = (mediaState) => (mediaFailed(mediaState) ? ''cross'' : ''info'');', '', 'const mediaRequiresPlaceholder = stateContains(', '  [''pend
ing'', ''transcoding'', ''uploading'']', ');', '', 'const mediaIsAvailable = stateContains(', '  [undefined, ''no_media'', ''ready'', ''preview'']', ');', '', 'const mediaState = {', '  mediaFailed,', '  flashIsNeeded,', '  noFlashIsNeede
d,', '  message,', '  icon,', '  mediaRequiresPlaceholder,', '  mediaIsAvailable', '};', '', 'export default mediaState;']
Neoformat: prettier --stdin
Neoformat: ['Usage: prettier [opts] [filename]', '', 'Available options:', '  --write              Edit the file in-place (beware!)', '  --print-width <int>  Specify the length of line that the printer will wrap on. Defaults to 80.', '  -
-tab-width <int>    Specify the number of spaces per indentation-level. Defaults to 2.', '  --flow-parser        Use the flow parser instead of babylon', '  --single-quote       Use single quotes instead of double', '  --trailing-comma
  Print trailing commas wherever possible', '  --bracket-spacing    Put spaces between brackets. Defaults to true, set false to turn off']
Neoformat: 1
Neoformat: trying next formatter
Neoformat: executable: prettydiff is not an executable
Neoformat: executable: clang-format is not an executable
Neoformat: executable: esformatter is not an executable
Neoformat: attempted all formatters for current filetype

@sbdchd
Copy link
Owner

sbdchd commented Jan 12, 2017

If you run prettier with no arguments, do you get the following output?

Usage: prettier [opts] [filename ...]

Available options:
  --write              Edit the file in-place (beware!)
  --stdin              Read input from stdin
  --print-width <int>  Specify the length of line that the printer will wrap on. Defaults to 80.
  --tab-width <int>    Specify the number of spaces per indentation-level. Defaults to 2.
  --flow-parser        Use the flow parser instead of babylon
  --single-quote       Use single quotes instead of double
  --trailing-comma     Print trailing commas wherever possible
  --bracket-spacing    Put spaces between brackets. Defaults to true, set false to turn off

From your output of :Neoformat it appears you are on a version without stdin:

Usage: prettier [opts] [filename]  
Available options:   
--write              Edit the file in-place (beware!)   
--print-width <int>  Specify the length of line that the printer will wrap on. Defaults to 80.   
--tab-width <int>    Specify the number of spaces per indentation-level. Defaults to 2.   
--flow-parser        Use the flow parser instead of babylon   
--single-quote       Use single quotes instead of double   
--trailing-comma     Print trailing commas wherever possible   
--bracket-spacing    Put spaces between brackets. Defaults to true, set false to turn off

@aaronmcadam
Copy link
Author

Yeah, that's what it looks like, but running prettier outputs:

❯ prettier
Usage: prettier [opts] [filename ...]

Available options:
  --write              Edit the file in-place (beware!)
  --stdin              Read input from stdin
  --print-width <int>  Specify the length of line that the printer will wrap on. Defaults to 80.
  --tab-width <int>    Specify the number of spaces per indentation-level. Defaults to 2.
  --flow-parser        Use the flow parser instead of babylon
  --single-quote       Use single quotes instead of double
  --trailing-comma     Print trailing commas wherever possible
  --bracket-spacing    Put spaces between brackets. Defaults to true, set false to turn off

@sbdchd
Copy link
Owner

sbdchd commented Jan 12, 2017

Hmm. Can you try removing all versions of prettier and then reinstall prettier.

For some reason :Neoformat is accessing an older version without --stdin, which is odd.

@aaronmcadam
Copy link
Author

@sbdchd I managed to sort it, my global node was set to the wrong version. I'd been tinkering with my nvm setup. Sorry for the confusion!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants