Sublime Forum

What besides JSPrettier is formatting on save?

#1

Hello! I have JSPrettier installed and by default it is not setup to format on save:

"auto_format_on_save": false,

When I format the code manually (via the context menu with the JSPrettier option) everything looks great, but when I save it, it all gets undone. What else could be formatting on save? One of the linters?

I have this override set for SublimeLinter:

 "lint_mode": "manual",

I don’t see any config for eslint, anywhere? Any suggestions?

0 Likes

#2

Are JSPrettier, SublimeLinter, Eslint all plugins you installed? Don’t let people guess and that will save your time.

Iirc, Eslint doesn’t format. it fixes. If you have a oneline long JS, it won’t look good after being “fixed”.

0 Likes

#3

The only other JS-related packages I have installed are LSP-Volar and Vue Syntax Highlight:

 ayu.sublime-package
'Dracula Color Scheme.sublime-package'
 Gofmt.sublime-package
 LSP-gopls.sublime-package
 LSP.sublime-package
 LSP-volar.sublime-package
'Package Control.sublime-package'
'PostgreSQL Syntax Highlighting.sublime-package'
'Vue Syntax Highlight.sublime-package'

Note that I have this same exact list of plugins installed on 2 separates hosts running ubuntu/kde and only one of them shows this behavior. I can boot into Windows to check if it seems helpful.

Thanks!

0 Likes

#4

You can also try profiling the plugins, it should show what plugins are reacting to save events. Also, it’s always possible you have some tool running outside of Sublime which is watching for file changes - it might make sense to rule that out.

0 Likes

#5

you have some tool running outside of Sublime which is watching for file changes

I was wondering that myself. I am new to Vite but I see nothing its config that has it making changes at save. I will keep looking.

How would I profile the plugins? In the python console? The only reference I see is to analyzing, here.

0 Likes

#6

Tools -> Developer -> Profile Plugins

0 Likes

#7

I closed down everything and rebooted just to get a clean slate. I then loaded sublime, loaded a file, selected JSPrettier Format Code from the context menu, which worked, then saved the file, which undid the JSPrettier formatting. The output of Profile Plugins is below.

This is not a showstopper. More of a vexation. If everything looks ok I’ll write it off to solar flares :+1:

This list shows how much time each plugin has taken to respond to each event:

on_activated:
    Default.history_list: 0.000s total, mean: 0.000s, max: 0.000s

on_hover:
    Default.symbol: 0.000s total
    Gofmt.gofmt: 0.000s total
    LSP.plugin.documents: 0.001s total

on_modified:
    Default.history_list: 0.000s total, mean: 0.000s, max: 0.000s

on_post_text_command:
    Default.history_list: 0.010s total, mean: 0.003s, max: 0.010s
    Default.paste_from_history: 0.000s total, mean: 0.000s, max: 0.000s
    LSP.plugin.documents: 0.000s total, mean: 0.000s, max: 0.000s

on_pre_save:
    Gofmt.gofmt: 0.000s total
    JsPrettier.JsPrettier: 0.000s total

on_query_context:
    LSP.plugin.documents: 0.000s total

on_selection_modified:
    Default.history_list: 0.000s total, mean: 0.000s, max: 0.000s

on_text_changed:
    LSP.plugin.documents: 0.000s total, mean: 0.000s, max: 0.000s

on_text_command:
    Default.history_list: 0.016s total, mean: 0.005s, max: 0.016s
    LSP.plugin.documents: 0.000s total, mean: 0.000s, max: 0.000s

on_window_command:
    Default.history_list: 0.000s total
0 Likes

#8

LSP does have a setting to format on save, but it’s disabled by default:

  // If supported, format a file before saving.
  // This option is also supported in syntax-specific settings and/or in the
  // "settings" section of project files.
  "lsp_format_on_save": false,

You can also enable command logging by running sublime.log_commands(True) in the console and then see which commands are executed when you save (you will likely see LSP’s lsp_save command then, but it should do nothing unless format on save or code actions on save are enabled).

0 Likes

#9

I do see this in the console:

command: save {"async": true}

But lsp_format_on_save is indeed set to false. It will take me some time to parse what I am seeing with sublime.log_commands() running…

0 Likes

#10

So looking through the output in the console (as above), I went looking for the ESLint package. It was visible in “Package Control List Packages” but could not be removed (did not show up in the list for “Package Control Disable Package”. I opted to delete my ~/.config/sublime-text/ directory and re-install these packages and all seems well, now.

Thank you for the help and the hints, this was valuable.

0 Likes