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.

Respect `disable_tab_width_auto_detection` when Prettier config is present

See original GitHub issue

Explain the Issue and Expected Behavior

By default JsPrettier derives tabWidth Prettier option from indentation detected by Sublime Text (which is controlled by disable_tab_width_auto_detection setting). However, if there is a Prettier config file present, this setting isn’t respected instead falling back to Prettier default setting tabWidth: 2 even if tabWidth isn’t set in Prettier config file.

It is expected for JsPrettier to obey disable_tab_width_auto_detection parameter unless tabWidth is set in Prettier config file as described in README.md.

Prettier version

1.16.4

JsPrettier Plug-in Version

1.25.0

Platform Details

  • Sublime Text Version: 3.2
  • Sublime Text Build: 3200
  • Sublime Text Architecture: x64
  • Operating System Name: macOS
  • Operating System Version: 10.14.3 (18D109)
  • Operating System Architecture: x64

Generated Prettier command line arguments

[JsPrettier DEBUG]: Prettier config file discovered at '/Users/schrodinger_cat/.prettierrc.json'

-----------------------------------------
 JsPrettier DEBUG - Prettier CLI Command 
-----------------------------------------

/usr/local/bin/prettier --stdin --config /Users/schrodinger_cat/.prettierrc.json --config-precedence cli-override --parser babel --use-tabs false --stdin-filepath /Users/schrodinger_cat/Documents/Source/macos/dotfiles/Library/Scripts/Applications/Transmit/SyncFavourite.js --loglevel debug --cursor-offset 706

Prettier reported the following output:

[debug] normalized argv: {"_":[],"color":true,"editorconfig":true,"stdin":true,"use-tabs":false,"config":"/Users/schrodinger_cat/.prettierrc.json","config-precedence":"cli-override","parser":"babel","stdin-filepath":"/Users/schrodinger_cat/Documents/Source/macos/dotfiles/Library/Scripts/Applications/Transmit/SyncFavourite.js","loglevel":"debug","cursor-offset":706,"plugin-search-dir":[],"plugin":[],"ignore-path":".prettierignore","debug-repeat":0}
[debug] load config file from '/Users/schrodinger_cat/.prettierrc.json'
[debug] loaded options `{"semi":false,"singleQuote":true}`
[debug] applied config-precedence (cli-override): {"filepath":"/Users/schrodinger_cat/Documents/Source/macos/dotfiles/Library/Scripts/Applications/Transmit/SyncFavourite.js","cursorOffset":706,"parser":"babel","semi":false,"singleQuote":true,"useTabs":false}

Prettier process finished with exit code 0.

Is the same behavior observed when run against Prettier directly?

Yes.

The contents of your User/JsPrettier.sublime-settings file

Empty.

The contents of your <project_name>.sublime-project file

Empty.

The contents of your .prettierrc.json file

Doesn’t contain tabWidth parameter:

{
    "semi": false,
    "singleQuote": true
}

Steps to reproduce the behavior

  1. Create Prettier config file without tabWidth parameter set.
  2. Omit disable_tab_width_auto_detection parameter or set it to false in JsPrettier settings.
  3. Open file where Sublime Text detects indentation 4.
  4. Use JsPrettier to format file.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
andreiborisovcommented, Mar 22, 2019

Especially since the plugin seems to be already ignoring parser and useTabs settings from config files:

/usr/local/bin/prettier --stdin --config /Users/schrodinger_cat/.prettierrc.json --config-precedence cli-override --parser babel --use-tabs false --stdin-filepath /Users/schrodinger_cat/Documents/Source/macos/dotfiles/Library/Scripts/Applications/Transmit/SyncFavourite.js --loglevel debug --cursor-offset 706

Maybe it’s still a bug?

I think using detected Sublime Text indentation for tabWidth unless disable_tab_width_auto_detection is set to true is the most logical behaviour.

0reactions
lock[bot]commented, Aug 1, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuration File - Prettier
This is to make sure that when a project is copied to another computer, Prettier's behavior stays the same. Otherwise, Prettier wouldn't be...
Read more >
How to configure Prettier and VSCode - Gleb Bahmutov
I like using JSON configuration format so my code editor helps me. In fact, VSCode understands the Prettier configuration file format via the ......
Read more >
Prettier does not consistently respect .prettierrc, .eslintrc nor ...
eslintrc file and even vscode settings with the same 80 print-width settings, but the extension just doesn't respect it. It does try to...
Read more >
visual studio code - prettier settings for vscode - Stack Overflow
For those trying to quickly change Prettier settings for VS Code. Here are the steps: Go to FILE -> PREFERENCES -> SETTINGS.
Read more >
How to use Prettier with ESLint - Robin Wieruch
How to combine Prettier and ESLint for VSCode, Sublime, ... The Prettier configuration file itself and the "format on save"-feature should ...
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