CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-sass-lint

Node.js-based linting tool for Sass and SCSS files with 75+ configurable rules and both CLI and programmatic APIs.

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

index.mddocs/

Sass Lint

Sass Lint is a Node.js-based linting tool for Sass and SCSS files that provides comprehensive code quality enforcement through 73 configurable rules. It offers both command-line interface and programmatic API with extensive configuration options, multiple output formats, and integration support for build systems and editors.

Package Information

  • Package Name: sass-lint
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install sass-lint

Core Imports

const sassLint = require('sass-lint');

For ES modules:

import sassLint from 'sass-lint';

Basic Usage

CLI Usage

# Lint all Sass/SCSS files in current directory
sass-lint '**/*.scss' -v

# Use custom config file
sass-lint -c .sass-lint.yml 'src/**/*.scss'

# Output results to file
sass-lint '**/*.scss' -f json -o results.json

Programmatic Usage

const sassLint = require('sass-lint');

// Get configuration
const config = sassLint.getConfig();

// Lint text content
const file = {
  text: '.foo { color: red; }',
  format: 'scss',
  filename: 'test.scss'
};

const results = sassLint.lintText(file);
console.log(results);

// Lint multiple files
const fileResults = sassLint.lintFiles('src/**/*.scss');
sassLint.outputResults(fileResults);

Architecture

Sass Lint is built around several key components:

  • Rule System: 73 rules covering syntax, formatting, best practices, and Sass-specific concerns
  • Configuration Engine: YAML/JSON configuration with inheritance and rule customization
  • AST Parser: Integration with gonzales-pe-sl for Sass/SCSS syntax tree generation
  • CLI Interface: Command-line tool with extensive options and output formats
  • Programmatic API: Full Node.js API for integration with build tools and editors
  • Formatter Integration: ESLint-compatible formatters for various output formats

Capabilities

Command Line Interface

Complete CLI tool for linting Sass/SCSS files with configurable options, output formats, and ignore patterns.

sass-lint [options] [pattern]

Options:

  • -c, --config [path] - path to custom config file
  • -i, --ignore [pattern] - pattern to ignore files
  • -q, --no-exit - do not exit on errors
  • -v, --verbose - verbose output
  • -f, --format [format] - output format (stylish, compact, json, etc.)
  • -o, --output [output] - output file path
  • -s, --syntax [syntax] - syntax type (sass or scss)
  • --max-warnings [integer] - max warnings before exit code

CLI Usage

Programmatic API

Core Node.js API for integrating sass-lint into applications, build tools, and editors with full configuration and result processing.

// Main constructor
function sassLint(config);

// Configuration
function sassLint.getConfig(config, configPath);

// Linting functions
function sassLint.lintText(file, options, configPath);
function sassLint.lintFileText(file, options, configPath);
function sassLint.lintFiles(files, options, configPath);

// Result processing
function sassLint.errorCount(results);
function sassLint.warningCount(results);
function sassLint.resultCount(results);
function sassLint.format(results, options, configPath);
function sassLint.outputResults(results, options, configPath);
function sassLint.failOnError(results, options, configPath);

Programmatic API

Linting Rules

Comprehensive rule system with 73 rules covering indentation, spacing, naming conventions, selector complexity, property ordering, and Sass-specific concerns.

// Rule categories include:
// - Extends and Mixins rules
// - Line spacing and formatting rules  
// - Disallow/restriction rules
// - Nesting depth and structure rules
// - Name format convention rules
// - Style guide enforcement rules
// - Spacing and punctuation rules
// - Final formatting rules

Linting Rules

Configuration System

Flexible configuration system supporting YAML/JSON files, package.json integration, rule inheritance, and custom property sort orders.

// Configuration sources
// - .sass-lint.yml (primary config file)
// - .sasslintrc (alternative config file)
// - package.json sasslintConfig property
// - Command-line options
// - Programmatic config objects

Configuration

Types

interface LintResult {
  filePath: string;
  warningCount: number;
  errorCount: number;
  messages: LintMessage[];
}

interface LintMessage {
  ruleId: string;
  line: number;
  column: number;
  message: string;
  severity: number; // 1 = warning, 2 = error
}

interface FileObject {
  text: string;
  format: string; // 'sass' or 'scss'
  filename: string;
}

interface ConfigObject {
  rules: { [ruleName: string]: RuleConfig };
  files: {
    include: string | string[];
    ignore: string | string[];
  };
  options: {
    formatter: string;
    'merge-default-rules': boolean;
    'cache-config': boolean;
    'max-warnings': number;
    'output-file'?: string;
  };
}

interface RuleConfig {
  severity: number; // 0 = off, 1 = warning, 2 = error
  [option: string]: any; // Rule-specific options
}

interface CountResult {
  count: number;
  files: string[];
}

class SassLintFailureError extends Error {
  name: 'SassLintFailureError';
  message: string;
}

class MaxWarningsExceededError extends Error {
  name: 'MaxWarningsExceededError';
  message: string;
}

docs

api.md

cli.md

configuration.md

index.md

rules.md

tile.json