DEV Community

smilelk4
smilelk4

Posted on

4 3

Auto-Format Stylesheet On Save Using WebStorm with 3 Steps

Intro

Linter tools can help keep code clean and consistent, but can get annoying if the issues aren't caught until committing or pushing to remote repository. This article is to omit such pain by utilizing Stylelint.

Linter complaining

The author used SCSS as the stylesheet format, but the same idea is also applicable with other formats like CSS.

Setup

  • Mac
  • WebStorm
  • SCSS

1. Download dependencies

If using npm:

npm i stylelint stylelint-config-standard-scss -D
Enter fullscreen mode Exit fullscreen mode

If using yarn:

yarn add stylelint stylelint-config-standard-scss -D
Enter fullscreen mode Exit fullscreen mode

2. .stylelintrc

Create .stylelintrc.json at the root of the project, and add below:

{
  "extends": "stylelint-config-standard-scss"
}
Enter fullscreen mode Exit fullscreen mode

3. Setting

  • Go into Webstorm > Preferences
  • Under Tools > File Watchers:
    • Click + to create new
    • Select SCSS
    • Set up the configs as below: File Watcher configs
  1. File type: SCSS style sheet
  2. Scope: Project Files
  3. Program: /<PATH_TO_PROJECT>/node_modules/stylelint/bin/stylelint.js
  4. Arguments: $FileName$ --fix
  5. Output paths to refresh: $FileName$

...and see the lint in action as you save your stylesheet πŸŽ‰πŸŽ‰πŸŽ‰

Image description

Resources

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (1)

Collapse
 
ivanovserge profile image
Sergey Ivanov β€’ β€’ Edited

Thanks! It works!

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay