Sass Formatter

0.8.0 · active · verified Sun Apr 19

Sass Formatter is a TypeScript-based utility for automatically formatting Sass, SCSS, CSS, and Less syntax files. It provides consistent code styling by correcting indentation, spacing, and other common formatting issues. The current stable version is 0.8.0, indicating it is still in active development with potential for minor breaking changes before a 1.0 release. It features both a programmatic API for integration into tools and a powerful command-line interface (CLI) for direct file processing and CI/CD pipelines. A key differentiator is its ability to convert CSS or SCSS to Sass syntax, alongside customizable formatting rules through a `.sassformatterrc.json` configuration file. It is notably used in the VS Code Sass extension. While a specific release cadence isn't published, the project is actively maintained with frequent updates.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import and use the `SassFormatter` class to format a Sass string programmatically and print the result.

import { SassFormatter } from 'sass-formatter';

const unformattedSass = `
// This is an unformatted Sass snippet
span
  color: none
  @for $i from 0 through 2
    &:nth-child(#{$i})
        color: none
    @each $author in $list
      .photo-#{$author}
                background: image-url("avatars/#{$author}.png") no-repeat

@while $types > 0
      .while-#{$types}
 width: $type-width + $types
`;

console.log('--- Original Sass ---');
console.log(unformattedSass);

const formattedSass = SassFormatter.Format(unformattedSass);

console.log('\n--- Formatted Sass ---');
console.log(formattedSass);

view raw JSON →