Détail du package

sass-render-errors

niksy4.6kMIT2.0.5

Get Sass render errors and deprecations.

sass, render, errors

readme

sass-render-errors

Build Status

Get Sass render errors and deprecations.

Currently there’s no Sass API which reports errors and deprecations in machine readable format (e.g. JSON-like data). This module parses Sass render output and provides render information for easier usage in linters and similar tools.

Undefined functions

Sass currently doesn’t check for undefined functions. This module has additional renderer which tries to guess which functions are undefined by comparing list of known CSS functions with functions defined in file.

This renderer is available as named export undefinedFunctions.

Install

npm install sass-render-errors --save

Usage

import createRenderer from 'sass-render-errors';
import sass from 'sass';

(async () => {
    const renderer = createRenderer(sass);
    const result = await renderer.compile('./index.scss');
    console.log(result);
    /* [
        {
            type: 'deprecation',
            file: '<absolute path>/index.scss',
            message: 'Passing a number (1) to color.invert() is deprecated. Recommendation: invert(1).',
            stack: [
                'at root stylesheet (index.scss:4:24)'
            ],
            source: {
                start: {
                    column: 9,
                    line: 4
                },
                end: {
                    column: 24,
                    line: 4
                },
                pattern: 'color.invert(1)'
            }
        }
    ] */
})();

index.scss

@use 'sass:color';

.becky {
    color: color.invert(1);
}

API

sassRenderErrors(sass[, options])

Creates Sass renderer. All methods return Promise, but internally use original Sass compile methods.

sass

Sass module reference. Only Dart Sass is supported.

Sass is injected as dependancy because each version has different set of errors and deprecations and you should get results for Sass version your application uses.

options

Type: object

For undefined functions:

Property Type Description
disallowedKnownCssFunctions string[] List of disallowed known CSS functions.
additionalKnownCssFunctions string[] List of additional known CSS functions (e.g. v-bind for Vue SFC).

renderer[compile|compileAsync|compileString|compileStringAsync]([options])

Returns: Promise<SassRenderError[]>

Promise with array of errors and deprecations.

If input contains multiple errors, only first one is shown. If you’re using undefined function renderer, all errors are always visible.

All deprecations are always visible.

Each array entry is object which contains following properties:

Property Type Description
file string Absolute path to file or stdin with error or deprecation.
message string Error or deprecation message.
stack string[] Stack trace of error or deprecation.
source.start.column number Pattern start column.
source.start.line number Pattern start line.
source.end.column number Pattern end column.
source.end.line number Pattern end line.
source.pattern string Error or deprecation code or pattern of code.
type string Can be either error or deprecation.

options

Type: sass.Options|sass.StringOptions

compile and compileAsync methods take sass.Options.
compileString and compileStringAsync methods take sass.StringOptions.

License

MIT © Ivan Nikolić

changelog

Changelog

Unreleased

2.0.5 - 2025-03-21

Changed

  • Update tests

2.0.4 - 2025-03-21

Fixed

  • Pass entry point URL as starting point for relative imports

2.0.3 - 2024-04-21

  • Update types referencing

2.0.2 - 2024-04-18

Changed

  • Expose types for render errors and undefined functions

2.0.1 - 2024-04-18

Fixed

  • Add types to package

2.0.0 - 2024-04-18

Changed

  • Use new Sass API
  • Use new logger JS API for simpler deprecation parsing

Removed

  • CommonJS support, only ESM is supported
  • Node 10 support, lowest version is 18
  • Legacy Sass support, lowest version is 1.75

1.9.0 - 2023-09-25

Added

  • Support for additional known CSS functions

1.8.3 - 2023-08-24

Changed

  • Update external dependency referencing when used as ES package

1.8.2 - 2023-07-23

Fixed

  • Use pure style content first for undefined functions check (#6)

1.8.1 - 2023-05-01

Changed

  • Update Sass JSON function signature

1.8.0 - 2021-10-26

Changed

  • Use PostCSS 8 (#3)

1.7.2 - 2021-10-26

Changed

  • Console output parsing

1.7.1 - 2021-09-30

Changed

  • Optimize known CSS functions list

1.7.0 - 2021-09-30

Added

  • Support for disallowed known CSS functions

1.6.1 - 2021-09-09

Fixed

  • Catch error for function with missing arguments

1.6.0 - 2021-09-09

Added

  • Support for functions in @else, @import, @use and @forward blocks

Changed

  • Optimize undefined functions processing

1.5.2 - 2021-09-08

Fixed

  • Parsing of function declaration and invocation errors

1.5.1 - 2021-09-08

Fixed

  • Interpolated strings handling in function names

1.5.0 - 2021-09-07

Added

  • Support for stack trace

1.4.3 - 2021-09-06

Changed

  • Return early if there are no undefined functions to check

1.4.2 - 2021-09-06

Fixed

  • Skip empty function names

1.4.1 - 2021-09-06

Fixed

  • Report functions with processed variables

1.4.0 - 2021-09-06

Changed

  • Clear console output on next cycle

1.3.0 - 2021-09-06

Changed

  • Consolidate console output getter
  • Normalize stdin resolving
  • Handle multiple async process output

1.2.0 - 2021-09-03

Changed

  • Improve regular expression for deprecations
  • Properly return stdin as file

Fixed

  • JSON encode input values

1.1.3 - 2021-09-03

Added

  • Support for checking inside @if at-rules

1.1.2 - 2021-09-03

Fixed

  • Incorrect parsing of namespaced functions

1.1.1 - 2021-09-02

Fixed

  • Handle noop plugin for PostCSS 7

1.1.0 - 2021-09-02

Added

  • Support for checking undefined functions

1.0.0 - 2021-09-01

Added

  • Initial implementation