Installation
Presentation
A mighty, modern linter that helps you avoid errors and enforce conventions in your styles.
stylelint comes with Mozaic and it is launched at compilation time. It means that if you write CSS and bundle them using our PostCSS config, you'll get linting out of the box.
Create a root styleling configuration file
You don't need to configure stylelint for it to warn you about errors, it's included in the PostCSS pipeline
In some cases, you may want to configure it, for example, to configure prettier-stylelint on your IDE, or to use stylelint outside of the compilation pipeline.
For example, you may want to create an NPM script to automatically fix linting issues.
In this case, you can create a stylelint.config.js file in the root dir of your project.
and you just have to export the styleling config from Mozaic
module.exports = require('@mozaic-ds/css-dev-tools/styleLintConfig.js')
Usage
Linter options customization
Our stylelint plugin allows developers to customize some options in the global Mozaic configuration.
It needs to be added in your root mozaic.config.js file.
Default configuration:
defaultConfig: { caseStyle: 'kebab-case', bemEntitiesDelimiters: { modifier: '--', element: '__', media: '@', }, prefixes: ['mc-', 'ml-', 'mu-', 'mt-', 'mdu-'], },
Please checkout Mozaic configuration for more information.
Add custom rules
Sometimes you may need to customize stylelint rules or add new ones. To do this, you can expand your stylelint.config.js file this way:
'use strict';const mozaicRules = require('@mozaic-ds/css-dev-tools/styleLintConfig.js');
const customRules = { 'color-no-invalid-hex': null, 'font-family-no-duplicate-names': null};
const stylelintConfig = mozaicRules;stylelintConfig.rules = {...mozaicRules.rules, ...customRules};
module.exports = stylelintConfig;
Disabling stylelint rules using inline comments
/* stylelint-disable plugin/mozaic-bem-pattern */.mc-block-Name__element-Name {}/* stylelint-enable */