Standard shareable config for Stylelint with modern CSS conventions
npx @tessl/cli install tessl/npm-stylelint-config-standard@39.0.0Stylelint Config Standard provides a standard shareable configuration for Stylelint that extends stylelint-config-recommended and adds additional rules to enforce modern CSS conventions found in CSS specifications and Baseline/Widely Available standards.
npm install stylelint-config-standard --save-devconst config = require('stylelint-config-standard');Note: This is a CommonJS module. ES module import is not officially supported, but some bundlers may allow:
import config from 'stylelint-config-standard';Set your Stylelint config to:
{
"extends": "stylelint-config-standard"
}Add a "rules" key to your config, then add your overrides and additions there:
{
"extends": "stylelint-config-standard",
"rules": {
"selector-class-pattern": null,
"unit-allowed-list": ["em", "rem", "s"]
}
}The main export is a Stylelint configuration object that can be used directly or extended.
/**
* Main module export - CommonJS module.exports
* @returns {StylelintConfig} Complete Stylelint configuration object
*/
module.exports = StylelintConfig;
/**
* Stylelint configuration object with extends and rules properties
*/
interface StylelintConfig {
extends: "stylelint-config-recommended";
rules: StylelintRules;
}
/**
* Collection of Stylelint rule configurations
*/
interface StylelintRules {
[ruleName: string]: boolean | string | [string, object] | [boolean, object];
}The configuration object contains:
"stylelint-config-recommended" - Base configurationThe configuration includes rules for the following categories:
alpha-value-notation: Forces percentage notation for alpha values (except opacity properties)color-function-notation: Enforces modern color function notationcolor-function-alias-notation: Uses color functions without alphacolor-hex-length: Enforces short hex color notationhue-degree-notation: Uses angle notation for hue valueslightness-notation: Uses percentage notation for lightnesscontainer-name-pattern: Enforces kebab-case for container namescustom-media-pattern: Enforces kebab-case for custom media query namescustom-property-pattern: Enforces kebab-case for custom property nameskeyframes-name-pattern: Enforces kebab-case for keyframe nameslayer-name-pattern: Enforces kebab-case for layer namesselector-class-pattern: Enforces kebab-case for class selectorsselector-id-pattern: Enforces kebab-case for ID selectorsat-rule-empty-line-before: Controls empty lines before at-rulescomment-empty-line-before: Controls empty lines before commentscomment-whitespace-inside: Requires whitespace inside commentscustom-property-empty-line-before: Controls empty lines before custom propertiesdeclaration-empty-line-before: Controls empty lines before declarationsrule-empty-line-before: Controls empty lines before rulesfont-family-name-quotes: Quotes font family names where recommendedfunction-name-case: Enforces lowercase function namesfunction-url-quotes: Requires quotes for URLs in functionsimport-notation: Uses URL notation for importsselector-attribute-quotes: Requires quotes for attribute selectorsvalue-keyword-case: Enforces lowercase for keyword valuesat-rule-no-vendor-prefix: Disallows vendor prefixes for at-rulesmedia-feature-name-no-vendor-prefix: Disallows vendor prefixes for media featuresproperty-no-vendor-prefix: Disallows vendor prefixes for propertiesselector-no-vendor-prefix: Disallows vendor prefixes for selectorsvalue-no-vendor-prefix: Disallows vendor prefixes for values (except 'box', 'inline-box')block-no-redundant-nested-style-rules: Disallows redundant nested style rulesdeclaration-block-no-redundant-longhand-properties: Disallows redundant longhand propertiesdeclaration-block-single-line-max-declarations: Limits single-line blocks to 1 declarationkeyframe-selector-notation: Uses percentage notation unless within keyword-only blocklength-zero-no-unit: Disallows units for zero lengths (except custom properties)media-feature-range-notation: Uses context-based media feature range notationnumber-max-precision: Limits number precision to 4 decimal placesselector-not-notation: Uses complex :not() notationselector-pseudo-element-colon-notation: Uses double colon notation for pseudo-elementsselector-type-case: Enforces lowercase for type selectorsshorthand-property-no-redundant-values: Disallows redundant shorthand property valuesconst config = require('stylelint-config-standard');
// Access the extends property
console.log(config.extends); // "stylelint-config-recommended"
// Access specific rules
console.log(config.rules['color-hex-length']); // "short"
console.log(config.rules['selector-class-pattern']); // [pattern, options]const config = require('stylelint-config-standard');
// Use in custom Stylelint configuration
const customConfig = {
...config,
rules: {
...config.rules,
'custom-rule': true
}
};/**
* The main configuration object exported by the module
*/
interface StylelintConfig {
extends: "stylelint-config-recommended";
rules: StylelintRules;
}
/**
* Collection of 41 Stylelint rule configurations
*/
interface StylelintRules {
'alpha-value-notation': [string, object];
'at-rule-empty-line-before': [string, object];
'at-rule-no-vendor-prefix': boolean;
'block-no-redundant-nested-style-rules': boolean;
'color-function-alias-notation': string;
'color-function-notation': string;
'color-hex-length': string;
'comment-empty-line-before': [string, object];
'comment-whitespace-inside': string;
'container-name-pattern': [string, object];
'custom-property-empty-line-before': [string, object];
'custom-media-pattern': [string, object];
'custom-property-pattern': [string, object];
'declaration-block-no-redundant-longhand-properties': boolean;
'declaration-block-single-line-max-declarations': number;
'declaration-empty-line-before': [string, object];
'font-family-name-quotes': string;
'function-name-case': string;
'function-url-quotes': string;
'hue-degree-notation': string;
'import-notation': string;
'keyframe-selector-notation': string;
'keyframes-name-pattern': [string, object];
'layer-name-pattern': [string, object];
'length-zero-no-unit': [boolean, object];
'lightness-notation': string;
'media-feature-name-no-vendor-prefix': boolean;
'media-feature-range-notation': string;
'number-max-precision': number;
'property-no-vendor-prefix': boolean;
'rule-empty-line-before': [string, object];
'selector-attribute-quotes': string;
'selector-class-pattern': [string, object];
'selector-id-pattern': [string, object];
'selector-no-vendor-prefix': boolean;
'selector-not-notation': string;
'selector-pseudo-element-colon-notation': string;
'selector-type-case': string;
'shorthand-property-no-redundant-values': boolean;
'value-keyword-case': string;
'value-no-vendor-prefix': [boolean, object];
}