This package provides a shared Stylelint configuration for SCSS/CSS linting in HubSpot Marketing WebTeam projects.
- Install the package and stylelint dependencies:
npm install --save-dev @hs-web-team/eslint-config-node stylelint stylelint-config-standard-scssCreate a .stylelintrc.json file in your project root:
{
"extends": "@hs-web-team/eslint-config-node/.stylelintrc.json"
}Alternatively, create a .stylelintrc.js file:
module.exports = {
extends: '@hs-web-team/eslint-config-node/.stylelintrc.json',
// Add your custom rules here
rules: {
// Custom overrides
},
};Add the following scripts to your package.json:
{
"scripts": {
"stylelint:check": "stylelint '**/*.{css,scss}'",
"stylelint:fix": "stylelint '**/*.{css,scss}' --fix"
}
}Then run:
npm run stylelint:check- Check for style issuesnpm run stylelint:fix- Automatically fix style issues
The configuration extends stylelint-config-standard-scss with custom rules for HubSpot projects:
- Extends:
stylelint-config-standard-scss(Standard SCSS linting rules)
The following rules are disabled to allow more flexibility in HubSpot projects:
- length-zero-no-unit: Allows units on zero values (e.g.,
0px) - declaration-empty-line-before: No empty line requirement before declarations
- no-empty-source: Allows empty source files
- selector-class-pattern: No pattern enforcement for class names
- declaration-block-no-redundant-longhand-properties: Allows longhand properties
- shorthand-property-no-redundant-values: Allows redundant shorthand values
- no-duplicate-selectors: Allows duplicate selectors
- font-family-name-quotes: No quote requirement for font family names
The following SCSS rules are customized:
- at-rule-no-unknown: Configured to ignore SCSS directives (
@function,@if,@else,@for,@each,@include,@mixin,@extend) - scss/dollar-variable-pattern: No pattern enforcement for variable names
- scss/at-import-no-partial-leading-underscore: Allows leading underscores in imports
- scss/at-import-partial-extension: Allows file extensions in imports
- scss/percent-placeholder-pattern: No pattern enforcement for placeholders
- scss/at-mixin-argumentless-call-parentheses: Flexible parentheses for mixins
- scss/dollar-variable-empty-line-before: No empty line requirement before variables
- scss/double-slash-comment-whitespace-inside: Flexible comment whitespace
- alpha-value-notation: No specific alpha value notation required
- color-function-notation: Flexible color function notation
- media-feature-range-notation: Set to
"context"with warning severity - value-keyword-case: Enforces lowercase keywords with camelCase for SVG keywords
By default, Stylelint will process:
**/*.css**/*.scss
Create a .stylelintignore file to exclude files from linting:
node_modules/
dist/
build/
*.min.css
Add stylelint checks to your CI pipeline:
# Example GitHub Actions
- name: Run Stylelint
run: npm run stylelint:checkTo override rules for your project, add them to your .stylelintrc.json:
{
"extends": "@hs-web-team/eslint-config-node/.stylelintrc.json",
"rules": {
"selector-class-pattern": "^[a-z][a-zA-Z0-9]+$",
"max-nesting-depth": 3
}
}If you get a module not found error, ensure you have installed all dependencies:
npm install --save-dev stylelint stylelint-config-standard-scssIf using Prettier for CSS/SCSS formatting, ensure Stylelint focuses on code quality rules rather than formatting. The shared configuration already disables many formatting-related rules.