Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      The AI productivity paradox in software engineering: Balancing efficiency and human skill retention

      July 2, 2025

      The impact of gray work on software development

      July 2, 2025

      CSS Intelligence: Speculating On The Future Of A Smarter Language

      July 2, 2025

      Hallucinated code, real threat: How slopsquatting targets AI-assisted development

      July 1, 2025

      Xbox is cancelling Rare’s ‘Everwild’ and ZeniMax’s new MMORPG IP as part of broader cuts — with ‘Perfect Dark’ impacted as well

      July 2, 2025

      Microsoft is closing down Xbox studio The Initiative, with Perfect Dark killed as well — joining Everwild and ZeniMax’s new IP, and other unannounced projects

      July 2, 2025

      No, Microsoft and Xbox’s Phil Spencer isn’t stepping down any time soon — here’s the truth

      July 2, 2025

      Everwild’s cancellation has me worried for one of my favorite dev teams and Xbox itself — It needs creative new games to thrive and refresh its identity

      July 2, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Trust but Verify: The Curious Case of AI Hallucinations

      July 2, 2025
      Recent

      Trust but Verify: The Curious Case of AI Hallucinations

      July 2, 2025

      From Flow to Fabric: Connecting Power Automate to Microsoft Fabric

      July 2, 2025

      Flutter Web Hot Reload Has Landed – No More Refreshes!

      July 2, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Xbox is cancelling Rare’s ‘Everwild’ and ZeniMax’s new MMORPG IP as part of broader cuts — with ‘Perfect Dark’ impacted as well

      July 2, 2025
      Recent

      Xbox is cancelling Rare’s ‘Everwild’ and ZeniMax’s new MMORPG IP as part of broader cuts — with ‘Perfect Dark’ impacted as well

      July 2, 2025

      Microsoft is closing down Xbox studio The Initiative, with Perfect Dark killed as well — joining Everwild and ZeniMax’s new IP, and other unannounced projects

      July 2, 2025

      No, Microsoft and Xbox’s Phil Spencer isn’t stepping down any time soon — here’s the truth

      July 2, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Operating Systems»Linux»Automatically Format Code On File Save in Visual Studio Code

    Automatically Format Code On File Save in Visual Studio Code

    May 18, 2025

    Automatically Format Code On File Save in Visual Studio Code

    Manually formatting code can be tedious, especially in fast-paced or collaborative development environments.

    While consistent formatting is essential for readability and maintainability, doing it by hand slows you down and sometimes leads to inconsistent results across a project.

    In this article, I’ll walk you through the steps to configure Visual Studio Code to automatically format your code each time you save a file.

    We’ll use the VS Code extension called Prettier, one of the most widely adopted tools for enforcing code style in JavaScript, TypeScript, and many other languages.

    By the end of this guide, you’ll have a setup that keeps your code clean with zero extra effort.

    Step 1: Install Prettier extension in VS Code

    To start, you’ll need the Prettier – Code Formatter extension. This tool supports JavaScript, TypeScript, HTML, CSS, React, Vue, and more.

    Open VS Code, go to the Extensions sidebar (or press Ctrl + Shift + X), and search for Prettier.

    Click on Install and reload VS Code if prompted.

    Automatically Format Code On File Save in Visual Studio Code

    Step 2: Enable format on save

    Now that Prettier is installed, let’s make it run automatically whenever you save a file.

    Open Settings via Ctrl + , or by going to File > Preferences > Settings.

    Automatically Format Code On File Save in Visual Studio Code

    In the search bar at the top, type format on save and then Check the box for Editor: Format On Save.

    Automatically Format Code On File Save in Visual Studio Code

    This tells VS Code to auto-format your code whenever you save a file, but that’s only part of the setup.

    Troubleshooting

    If saving a file doesn’t automatically format your code, it’s likely due to multiple formatters being installed in VS Code. Here’s how to make sure Prettier is set as the default:

    • Open any file in VS Code and press Ctrl + Shift + P (or Cmd + Shift + P on Mac) to bring up the Command Palette.
    • Type “Format Document” and select the option that appears.
    Automatically Format Code On File Save in Visual Studio Code
    • If multiple formatters are available, VS Code will prompt you to choose one.
    Automatically Format Code On File Save in Visual Studio Code
    • Select “Prettier – Code formatter” from the list.
    Automatically Format Code On File Save in Visual Studio Code

    Now try saving your file again. If Prettier is correctly selected, it should instantly reformat the code on save.

    In some cases, you might want to save a file without applying formatting, for example, when working with generated code or temporary formatting quirks. To do that, open the Command Palette again and run “Save Without Formatting.”

    Automatically Format Code On File Save in Visual Studio Code

    Optional: Advanced configuration

    Prettier works well out of the box, but you can customize how it formats your code by adding a .prettierrc configuration file at the root of your project.

    Here’s a simple example:

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

    This configuration tells Prettier to use single quotes, add trailing commas where valid in ES5 (like in objects and arrays), and omit semicolons at the end of statements.

    There are many other options available such as adjusting print width, tab width, or controlling how JSX and HTML are handled.

    You can find the full list of supported options in Prettier’s documentation, but for most projects, a few key settings in .prettierrc go a long way.

    Try It Out

    Create or open any file, JavaScript, TypeScript, HTML, etc. Add some poorly formatted code.

    <html><head><style>body{background:#fff;color:#333;font-family:sans-serif}</style></head><body><h1>Hello</h1><script>document.querySelector("h1").addEventListener("click",()=>{alert("Hello World!")})</script></body></html>
    
    Automatically Format Code On File Save in Visual Studio Code

    Then simply save the file (Ctrl + S or Cmd + S), and watch Prettier instantly clean it up.

    Automatically Format Code On File Save in Visual Studio Code

    As you can see, Prettier neatly indents and spaces each part of the html code, even across different embedded languages.

    Wrapping Up

    It doesn’t matter if you are vibe coding or doing everything on your own, proper formatting is a sign of writing good code.

    We’ve already covered the fundamentals of writing clean, consistent code – indentation, spacing, and word wrap, and automatic formatting builds directly on top of those fundamentals.

    Once configured, it removes the need to think about structure while coding, letting you focus on the logic.

    If you’re also wondering how to actually run JavaScript or HTML inside VS Code, we’ve covered that as well, so check those guides if you’re setting up your workflow from scratch.

    If you’re not already using automatic formatting, it’s worth making part of your workflow.

    And if you use a different tool or approach, I’d be interested to hear how you’ve set it up, let us know in the comments. 🧑‍💻

    Source: Read More

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleopenVidu is a platform to develop WebRTC real-time applications
    Next Article Rilasciata Debian 12.11: Aggiornamento di Sicurezza e Stabilità

    Related Posts

    News & Updates

    Xbox is cancelling Rare’s ‘Everwild’ and ZeniMax’s new MMORPG IP as part of broader cuts — with ‘Perfect Dark’ impacted as well

    July 2, 2025
    News & Updates

    Microsoft is closing down Xbox studio The Initiative, with Perfect Dark killed as well — joining Everwild and ZeniMax’s new IP, and other unannounced projects

    July 2, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    Microsoft may have pulled the plug on the Surface Laptop Studio 2

    Operating Systems

    CVE-2025-23169 – Versa Networks Director Cross-Site Scripting Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    How to Get Your First SaaS Customers

    Development

    CVE-2025-2828 – Apache Langchain SSRF

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    CVE-2025-4787 – SourceCodester Oretnom23 Stock Management System SQL Injection Vulnerability

    May 16, 2025

    CVE ID : CVE-2025-4787

    Published : May 16, 2025, 4:15 p.m. | 47 minutes ago

    Description : A vulnerability classified as critical has been found in SourceCodester/oretnom23 Stock Management System 1.0. Affected is an unknown function of the file /admin/?page=sales/view_sale. The manipulation of the argument ID leads to sql injection. It is possible to launch the attack remotely. The exploit has been disclosed to the public and may be used.

    Severity: 6.3 | MEDIUM

    Visit the link for more details, such as CVSS details, affected products, timeline, and more…

    5 steps to improve your charity website’s navigation

    May 1, 2025

    Don’t Tread on Me Penguins Against Trump Shirt https://viralstyle.com/graydesigner/dont-tread-on-me-penguins-against-trump Make a bold statement with our “Don’t Tread on Me Penguins Against Trump” shirt. This eye-catching design features rebellious penguins standing up to Trump, blending humor with political activism. Perfect for protests, casual wear, or sparking conversation. Soft, high-quality cotton for all-day comfort. Wear your values loud and proud!

    April 5, 2025
    LLMs Can Now Learn to Try Again: Researchers from Menlo Introduce ReZero, a Reinforcement Learning Framework That Rewards Query Retrying to Improve Search-Based Reasoning in RAG Systems

    LLMs Can Now Learn to Try Again: Researchers from Menlo Introduce ReZero, a Reinforcement Learning Framework That Rewards Query Retrying to Improve Search-Based Reasoning in RAG Systems

    April 19, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.