If you install Package Control and then use its search function you can find plugins for just about anything.

In this case, I'd recommend using HTML-CSS-JS Prettify. Make sure you have node.js installed and in your path, and make sure you read through the setup instructions carefully to get everything up and running. Other options include JSFormat, which doesn't require node, and JavaScript Beautify, which uses the same library as JSFormat but for some reason requires you to install it yourself.

Answer from MattDMo on Stack Exchange
🌐
Package Control
packagecontrol.io › packages › Javascript Beautify
Javascript Beautify - Packages - Package Control
JS Beautify sublime default settings (the same as js-beautify settings),only add // jsbeautify options “format_on_save”: true
🌐
GitHub
github.com › enginespot › js-beautify-sublime
GitHub - enginespot/js-beautify-sublime: js-beautify for sublime
JS Beautify sublime default settings (the same as js-beautify settings),only add // jsbeautify options "format_on_save": true
Starred by 102 users
Forked by 30 users
Languages   Python 53.0% | JavaScript 38.0% | HTML 5.2% | Shell 3.8%
🌐
Beautifier
beautifier.io
Online JavaScript beautifier
Sublime Text 2: JsFormat, a javascript formatting plugin for this nice editor by Davis Clark, vim: sourcebeautify.vim, a plugin by michalliu (requires node.js, V8, SpiderMonkey or cscript js engine), vim: vim-jsbeautify, a plugin by Maksim Ryzhikov (node.js or V8 required), Emacs: Web-beautify formatting package by Yasuyuki Oka,
🌐
Package Control
packagecontrol.io › packages › HTML-CSS-JS Prettify
HTML-CSS-JS Prettify - Packages - Package Control
This is a Sublime Text 2 and 3 plugin allowing you to format your HTML, CSS, JavaScript, JSON, React and Vue code. It uses a set of nice beautifier scripts made by Einar Lielmanis.
🌐
SitePoint
sitepoint.com › blog › javascript › javascript beautifier plugin with sublime 2
Javascript Beautifier Plugin with Sublime 2 — SitePoint
February 12, 2024 - Download the sublime format plugin from GitHub. Type %appdata% in cmd (start>run) and extract the folder renamed to “JsFormat“. ... Select the JavaScript you want to make pretty. Press CTRL+SHIFT+P (or Tools>Command Pallet) and select Format as the command.
Top answer
1 of 2
6

Use:

HTML-CSS-JS Prettify

 


  You can adjust the following settings @:

Menu > Preferences > Package Settings > HTML/CSS/JS Prettify > Set Prettify Preferences

 

"js": {
  "allowed_file_extensions": ["js", "json", "jshintrc", "jsbeautifyrc"],

  "brace_style": "collapse-preserve-inline",
  // collapse:                 (old default) Put braces on the same line as control statements
  // collapse-preserve-inline: (new default) Same as collapse but better support for ES6 destructuring and other features. https: //github.com/victorporof/Sublime-HTMLPrettify/issues/231
  // expand:                   Put braces on own line (Allman / ANSI style)
  // end-expand:               Put end braces on own line
  // none:                     Keep them where they are

  "break_chained_methods":     false, // Break chained method calls across subsequent lines
  "e4x":                       false, // Pass E4X xml literals through untouched
  "end_with_newline":          false, // End output with newline
  "indent_char":               " ",   // Indentation character
  "indent_level":              0,     // Initial indentation level
  "indent_size":               2,     // Indentation size
  "indent_with_tabs":          true,  // Indent with tabs, overrides `indent_size` and `indent_char`
  "jslint_happy":              false, // If true, then jslint-stricter mode is enforced
  "keep_array_indentation":    false, // Preserve array indentation
  "keep_function_indentation": false, // Preserve function indentation
  "max_preserve_newlines":     0,     // Maximum number of line breaks to be preserved in one chunk (0 disables)
  "preserve_newlines":         true,  // Whether existing line breaks should be preserved
  "space_after_anon_function": false, // Should the space before an anonymous function's parens be added, "function()" vs "function ()"
  "space_before_conditional":  true,  // Should the space before conditional statement be added, "if(true)" vs "if (true)"
  "space_in_empty_paren":      false, // Add padding spaces within empty paren, "f()" vs "f( )"
  "space_in_paren":            false, // Add padding spaces within paren, ie. f( a, b )
  "unescape_strings":          false, // Should printable characters in strings encoded in \xNN notation be unescaped, "example" vs "\x65\x78\x61\x6d\x70\x6c\x65"
  "wrap_line_length":          0      // Lines should wrap at next opportunity after this number of characters (0 disables)
}

 


Note:

It does not handle commas within quotes.
I also tested CoolFormat, which does not handle them either.

2 of 2
0

You should check out Will Bond's Alignment plugin, it should do most of what you want, and is pretty configurable as well. There seems to be an issue with the documentation and circular links between packagecontrol.io and wbond.net, but here is the documentation stored in the Wayback Machine.

🌐
GitHub
github.com › sticeap › sublime-beautify
GitHub - sticeap/sublime-beautify: Beautifier for javascript
Beautifier for javascript. Contribute to sticeap/sublime-beautify development by creating an account on GitHub.
Author   sticeap
Find elsewhere
🌐
GitHub
github.com › bitst0rm-pub › Formatter
GitHub - bitst0rm-pub/Formatter: 🧜‍♀️ A Sublime Text plugin to beautify, minify, convert: CSS, SCSS, Sass, HTML, XML, SVG, JS,JavaScript, JSON, GraphQL, Markdown, TypeScript, Vue, Lua, YAML, Go, Perl, PHP, Python, Ruby, Rust, Haskell, Dart, Swift, Crystal, Bash, Shell, SQL, CSV, C, C++, C#, Objective-C, D, Java, Pawn, Julia, Blade, LaTeX, D2, Graphviz, Mermaid, PlantUML, Disasm..
🧜‍♀️ A Sublime Text plugin to beautify, minify, convert: CSS, SCSS, Sass, HTML, XML, SVG, JS,JavaScript, JSON, GraphQL, Markdown, TypeScript, Vue, Lua, YAML, Go, Perl, PHP, Python, Ruby, Rust, Haskell, Dart, Swift, Crystal, Bash, Shell, SQL, CSV, C, C++, C#, Objective-C, D, Java, Pawn, ...
Starred by 146 users
Forked by 26 users
Languages   Python 93.8% | Shell 4.8% | JavaScript 1.2%
🌐
YouTube
youtube.com › codepopular
HTML | CSS | JS Beautify Sublime Text 3 - YouTube
Websitehttps://codepopular.com/Join Facebook Groupwww.facebook.com/groups/codepopularJoin Our Pagewww.facebook.com/codepopularofficialDownload Best Selling W...
Published   April 15, 2020
Views   12K
🌐
GitHub
github.com › CodeByZach › sublime_minify
GitHub - CodeByZach/sublime_minify: Minify for Sublime Text allows you to quickly minify and/or beautify CSS, JavaScript, JSON, HTML and SVG files -- compatible with ST2 and ST3. · GitHub
Minify for Sublime Text allows you to quickly minify and/or beautify CSS, JavaScript, JSON, HTML and SVG files -- compatible with ST2 and ST3. - CodeByZach/sublime_minify
Author   CodeByZach
🌐
npm
npmjs.com › package › sublime-beautify
sublime-beautify - npm
sublime beautify. Latest version: 1.5.4-a, last published: 11 years ago. Start using sublime-beautify in your project by running `npm i sublime-beautify`. There are no other projects in the npm registry using sublime-beautify.
      » npm install sublime-beautify
    
Published   Oct 25, 2014
Version   1.5.4-a
Author   Sticea Paul
Homepage   http://plu.ro/
🌐
GitHub
github.com › ArkahnX › Sublime-JS-Beautifier
GitHub - ArkahnX/Sublime-JS-Beautifier: JS Beautifier (autoformat JavaScript) implementation for Sublime Text 2
JS Beautifier (autoformat JavaScript) implementation for Sublime Text 2 - ArkahnX/Sublime-JS-Beautifier
Author   ArkahnX
🌐
Sublime Forum
forum.sublimetext.com › t › html-css-js-prettify-plugin › 12647
HTML-CSS-JS Prettify Plugin - General Discussion - Sublime Forum
February 22, 2014 - Hi all! I'm using a great plugin (HTML-CSS-JS Prettify) sublime.wbond.net/packages/HTML ... 20Prettify Issue: I have a page that is .html which has now been changed to .php, the page contains basic HTML code, but as…
🌐
Sublime Forum
forum.sublimetext.com › t › javascript-formatter › 1964
Javascript Formatter - Plugin Announcements - Sublime Forum
July 13, 2011 - Project page: https://github.com/jdc0589/JsFormat Javascript formats the selected text or entire file (works great in JSON files too) Updates 3/14/2010 - JsBeautifier has been updated to the latest version 3/6/20…
🌐
GitHub
github.com › jdavisclark › JsFormat
GitHub - jdavisclark/JsFormat: Javascript formatting for Sublime Text 2 & 3
JsFormat is a javascript formatting plugin for Sublime Text 2.
Starred by 1.4K users
Forked by 214 users
Languages   Python 97.0% | Shell 2.7% | JavaScript 0.3%