2.0.3 • Published 12 days ago

sass-render-errors v2.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
12 days ago

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:

PropertyTypeDescription
disallowedKnownCssFunctionsstring[]List of disallowed known CSS functions.
additionalKnownCssFunctionsstring[]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:

PropertyTypeDescription
filestringAbsolute path to file or stdin with error or deprecation.
messagestringError or deprecation message.
stackstring[]Stack trace of error or deprecation.
source.start.columnnumberPattern start column.
source.start.linenumberPattern start line.
source.end.columnnumberPattern end column.
source.end.linenumberPattern end line.
source.patternstringError or deprecation code or pattern of code.
typestringCan be either error or deprecation.

options

Type: sass.Options|sass.StringOptions

compile and compileAsync methods take [sass.Options](https://sass-lang.com/documentation/js-api/interfaces/options/).
compileString and compileStringAsync methods take [sass.StringOptions](https://sass-lang.com/documentation/js-api/interfaces/stringoptions/).

License

MIT © [Ivan Nikolić](http://ivannikolic.com)

2.0.3

12 days ago

2.0.2

15 days ago

2.0.1

15 days ago

2.0.0

15 days ago

1.9.0

7 months ago

1.8.2

10 months ago

1.8.3

8 months ago

1.8.1

1 year ago

1.7.2

3 years ago

1.8.0

3 years ago

1.7.1

3 years ago

1.7.0

3 years ago

1.6.1

3 years ago

1.5.2

3 years ago

1.6.0

3 years ago

1.5.1

3 years ago

1.5.0

3 years ago

1.4.3

3 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.0.0

3 years ago