Security News
vlt Debuts New JavaScript Package Manager and Serverless Registry at NodeConf EU
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
stylelint-scss
Advanced tools
The stylelint-scss npm package is a plugin for stylelint that provides linting rules specific to SCSS syntax. It helps enforce consistent conventions and avoid errors in your SCSS files.
Linting SCSS-specific syntax
This feature allows you to lint SCSS-specific syntax such as @rules, $variables, and nesting. The code sample shows how to enable rules in a stylelint configuration file to disallow unknown @rules, enforce a naming pattern for $variables, and prevent redundant nesting selectors.
"rules": {
"scss/at-rule-no-unknown": true,
"scss/dollar-variable-pattern": "^foo-",
"scss/selector-no-redundant-nesting-selector": true
}
Enforcing best practices
This feature helps enforce best practices in SCSS by preventing common mistakes. The code sample demonstrates enabling rules that ensure placeholders are used with @extend, discourage the use of leading underscores in partial names on @import, and prevent duplicate $variable declarations.
"rules": {
"scss/at-extend-no-missing-placeholder": true,
"scss/at-import-no-partial-leading-underscore": true,
"scss/no-duplicate-dollar-variables": true
}
Customizable rules for SCSS
This feature provides customizable rules tailored for SCSS, allowing you to enforce specific stylistic decisions or prevent certain patterns. The code sample shows rules that enforce no spaces around operators, disallow nested properties, and ensure that dimensions only contain numeric values.
"rules": {
"scss/operator-no-unspaced": true,
"scss/declaration-nested-properties": "never",
"scss/dimension-no-non-numeric-values": true
}
sass-lint is a Node-only Sass linter for both sass and scss syntax. It offers similar functionality to stylelint-scss but is not a plugin for stylelint and has its own set of rules and configuration.
postcss-scss is a SCSS parser for PostCSS, which allows you to lint SCSS within PostCSS's ecosystem. It can be used with stylelint but does not provide SCSS-specific linting rules on its own.
scss-lint is a Ruby gem that provides linting for SCSS files. It is similar to stylelint-scss in that it focuses on SCSS syntax but requires Ruby and is not integrated with the stylelint ecosystem.
A collection of SCSS specific linting rules for stylelint (in a form of a plugin).
stylelint by itself supports SCSS syntax very well (as well as other preprocessors' syntaxes). Moreover, it introduces some specific rules that can be used to lint SCSS, e.g. to limit nesting
, control the way @-rules
are written. Yet stylelint is in general focused on standard CSS.
stylelint-scss introduces rules specific to SCSS syntax. That said, the rules from this plugin can be used with other syntaxes, like Less or some PostCSS syntaxes. That's why the rules' names are not tied to SCSS only (at-function-pattern
instead of scss-function-pattern
).
The plugin follows stylelint's guidelines (about rule names, testing and so on).
stylelint-scss is a plugin for stylelint, so it's meant to be used with it.
Node.js v4.2.1 or newer is required. That's because stylelint itself doesn't support Node.js versions below 4.
First, install stylelint-scss (and stylelint, if you haven't done so yet) via NPM:
npm install stylelint stylelint-scss
Create the .stylelintrc.json
config file (or open the existing one), add stylelint-scss
to the plugins array and the rules you need to the rules list. All rules from stylelint-scss need to be namespaced with scss
.
{
"plugins": [
"stylelint-scss"
],
"rules": {
"scss/dollar-variable-pattern": "^foo",
"scss/selector-no-redundant-nesting-selector": true,
...
}
}
Please refer to stylelint docs for the detailed info on using this linter.
Here are stylelint-scss' rules, grouped by the thing they apply to (just like in stylelint).
Please also see the example configs for special cases.
@
-elseat-else-closing-brace-newline-after
: Require or disallow a newline after the closing brace of @else
statements.at-else-closing-brace-space-after
: Require a single space or disallow whitespace after the closing brace of @else
statements.at-else-empty-line-before
: Require an empty line or disallow empty lines before @
-else.@
-extendat-extend-no-missing-placeholder
: Disallow at-extends (@extend
) with missing placeholders.@
-functionat-function-pattern
: Specify a pattern for Sass/SCSS-like function names.@
-ifat-if-closing-brace-newline-after
: Require or disallow a newline after the closing brace of @if
statements.at-if-closing-brace-space-after
: Require a single space or disallow whitespace after the closing brace of @if
statements.@
-importat-import-no-partial-leading-underscore
: Disallow leading underscore in partial names in @import
.at-import-partial-extension-blacklist
: Specify blacklist of disallowed file extensions for partial names in @import
commands.at-import-partial-extension-whitelist
: Specify whitelist of allowed file extensions for partial names in @import
commands.@
-mixinat-mixin-argumentless-call-parentheses
: Require or disallow parentheses in argumentless @mixin
calls.at-mixin-pattern
: Specify a pattern for Sass/SCSS-like mixin names.$
-variabledollar-variable-colon-newline-after
: Require a newline after the colon in $
-variable declarations.dollar-variable-colon-space-after
: Require a single space or disallow whitespace after the colon in $
-variable declarations.dollar-variable-colon-space-before
: Require a single space or disallow whitespace before the colon in $
-variable declarations.dollar-variable-empty-line-before
: Require a single empty line or disallow empty lines before $
-variable declarations.dollar-variable-no-missing-interpolation
: Disallow Sass variables that are used without interpolation with CSS features that use custom identifiers.dollar-variable-pattern
: Specify a pattern for Sass-like variables.%
-placeholderpercent-placeholder-pattern
: Specify a pattern for %
-placeholders.//
-commentdouble-slash-comment-empty-line-before
: Require or disallow an empty line before //
-comments.double-slash-comment-inline
: Require or disallow //
-comments to be inline comments.double-slash-comment-whitespace-inside
: Require or disallow whitespace after the //
in //
-commentsdeclaration-nested-properties
: Require or disallow properties with -
in their names to be in a form of a nested group.declaration-nested-properties-no-divided-groups
: Disallow nested properties of the same "namespace" be divided into multiple groups.media-feature-value-dollar-variable
: Require a media feature value be a $
-variable or disallow $
-variables in media feature values.operator-no-newline-after
: Disallow linebreaks after Sass operators.operator-no-newline-before
: Disallow linebreaks before Sass operators.operator-no-unspaced
: Disallow unspaced operators in Sass operations.partial-no-import
: Disallow non-CSS @import
s in partial files.selector-no-redundant-nesting-selector
: Disallow redundant nesting selectors (&
).There work on the plugin's rules is still in progress, so if you feel like it, you're welcome to help out in any of these (the plugin follows stylelint guidelines so most part of this is based on its docs):
We communicate via issues and pull requests.
There is also stackoverflow, which would be the preferred QA forum.
1.4.4
at-if-closing-brace-newline-after
: support @elseif
.FAQs
A collection of SCSS-specific rules for Stylelint
The npm package stylelint-scss receives a total of 2,192,416 weekly downloads. As such, stylelint-scss popularity was classified as popular.
We found that stylelint-scss demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Security News
Research
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.