Skip to content

JavaScript: Configures prettier to use single quotes - #34

Closed
aaronmcadam wants to merge 1 commit into
sbdchd:masterfrom
aaronmcadam:js-prettier-single-quotes
Closed

aaronmcadam wants to merge 1 commit into
sbdchd:masterfrom
aaronmcadam:js-prettier-single-quotes

Conversation

@aaronmcadam

Copy link
Copy Markdown

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

fortes commented Jan 11, 2017

Copy link
Copy Markdown

@sbdchd

sbdchd commented Jan 11, 2017

Copy link
Copy Markdown
Owner

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

fortes commented Jan 11, 2017

Copy link
Copy Markdown

@sbdchd any reason to prefer using standard in?

@sbdchd

sbdchd commented Jan 11, 2017

Copy link
Copy Markdown
Owner

@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

fortes commented Jan 11, 2017

Copy link
Copy Markdown

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

@aaronmcadam

Copy link
Copy Markdown
Author

Thanks @fortes @sbdchd! Closing 👍

@aaronmcadam

aaronmcadam commented Jan 12, 2017 •

Copy link
Copy Markdown
Author

@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
Copy Markdown
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

sbdchd commented Jan 12, 2017

Copy link
Copy Markdown
Owner

@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

aaronmcadam commented Jan 12, 2017 •

Copy link
Copy Markdown
Author

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

sbdchd commented Jan 12, 2017

Copy link
Copy Markdown
Owner

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
Copy Markdown
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

sbdchd commented Jan 12, 2017

Copy link
Copy Markdown
Owner

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
Copy Markdown
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.

3 participants