Node.js-based linting tool for Sass and SCSS files with 75+ configurable rules and both CLI and programmatic APIs.
npx @tessl/cli install tessl/npm-sass-lint@1.13.0Sass 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.
npm install sass-lintconst sassLint = require('sass-lint');For ES modules:
import sassLint from 'sass-lint';# 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.jsonconst 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);Sass Lint is built around several key components:
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 codeCore 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);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 rulesFlexible 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 objectsinterface 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;
}