question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

prettier single-line pragma

See original GitHub issue

I have a case of code like so:

import * as cp from 'child_process'
import * as fs from 'fs-jetpack'

const json = cp.spawnSync('yarn',['-s','docs','project','index', '--json'], {encoding:'utf8'})
fs.write('api.json', json)

const md = cp.spawnSync('yarn',['-s','docs','project','index'], {encoding:'utf8'})
fs.write('api.md', md)

Prettier wants to turn it into:

import * as cp from 'child_process'
import * as fs from 'fs-jetpack'

const json = cp.spawnSync(
  'yarn',
  ['-s', 'docs', 'project', 'index', '--json'],
  { encoding: 'utf8' }
)
fs.write('api.json', json)

const md = cp.spawnSync('yarn', ['-s', 'docs', 'project', 'index'], {
  encoding: 'utf8',
})
fs.write('api.md', md)

This is a small script, case, I really don’t want it how prettier wants it.

So I opt out:

import * as cp from 'child_process'
import * as fs from 'fs-jetpack'

// prettier-ignore
const json = cp.spawnSync('yarn',['-s','docs','project','index', '--json'], {encoding:'utf8'})
fs.write('api.json', json)

// prettier-ignore
const md = cp.spawnSync('yarn',['-s','docs','project','index'], {encoding:'utf8'})
fs.write('api.md', md)

But I wish I could still benefit from prettier formatting within the single line. For example turn ('yarn',[ into ('yarn', [ and {encoding:'utf8'} into { encoding: 'utf8' }.

I think such a mode could be made available like so:

import * as cp from 'child_process'
import * as fs from 'fs-jetpack'

// prettier-single-line
const json = cp.spawnSync('yarn',['-s','docs','project','index', '--json'], {encoding:'utf8'})
fs.write('api.json', json)

// prettier-single-line
const md = cp.spawnSync('yarn',['-s','docs','project','index'], {encoding:'utf8'})
fs.write('api.md', md)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jasonkuhrtcommented, Mar 24, 2020

@j-f1 If we define “works” as does it support auto-formatting along a single line, then no.

1reaction
j-f1commented, Mar 24, 2020

Yes! I don’t know why that came out wrong.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Options
(A single-line array, for example, never gets trailing commas.) Valid options: ... This works well when used in tandem with the --require-pragma option....
Read more >
How do I turn off this Eslint error "Expected new line break ...
This warning says that you should avoid single line tags. For example, instead of. <nuxt-link to="/test">Another page</nuxt-link>.
Read more >
Styling Angular apps using Prettier and TSLint (2020)
Code Style Matters: Styling Angular apps using Prettier and TSLint (2020). Share on facebook. Share on google ... "directive-class-suffix": true,.
Read more >
eslint-plugin-react
... default to "createReactClass" "pragma": "React", // Pragma to use, ... jsx-max-props-per-line, Enforce maximum of props on a single line ...
Read more >
Prettier 2.1: new --embedded-language-formatting option ...
Support insertPragma and requirePragma in files with shebang (#8376 by ... Omit trailing semicolon on single line style attributes (#8013 by ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found