
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
stylelint-prettier
Advanced tools
The stylelint-prettier package integrates Prettier with Stylelint, allowing you to use Prettier as a Stylelint rule. This ensures that your styles are formatted according to Prettier's rules while also being linted by Stylelint.
Integrate Prettier with Stylelint
This configuration in your .stylelintrc file extends the recommended settings for integrating Prettier with Stylelint. It ensures that your styles are formatted according to Prettier's rules and also linted by Stylelint.
{
"extends": [
"stylelint-prettier/recommended"
]
}
Run Prettier as a Stylelint rule
This configuration in your .stylelintrc file sets up Prettier as a Stylelint rule. You can customize Prettier's options, such as using single quotes and adding trailing commas, directly within your Stylelint configuration.
{
"rules": {
"prettier/prettier": [
true,
{
"singleQuote": true,
"trailingComma": "all"
}
]
}
}
eslint-plugin-prettier integrates Prettier with ESLint, allowing you to use Prettier as an ESLint rule. This package is similar to stylelint-prettier but is used for JavaScript and other languages supported by ESLint instead of CSS.
stylelint-config-prettier is a configuration package that turns off all Stylelint rules that are unnecessary or might conflict with Prettier. Unlike stylelint-prettier, it does not run Prettier as a Stylelint rule but ensures that the two tools do not conflict.
Runs Prettier as a Stylelint rule and reports differences as individual Stylelint issues.
Given the input file style.css
:
.insert {
display: block
}
.alter:after {color: red; content: 'example'}
.delete {
display: block;;
}
Running ./node_modules/.bin/stylelint style.css
shall output:
style.css
2:17 ✖ Insert ";" prettier/prettier
5:15 ✖ Replace "color:·red;·content:·'example'" with prettier/prettier
"⏎··color:·red;⏎··content:·"example";⏎"
8:17 ✖ Delete ";" prettier/prettier
npm install --save-dev stylelint-prettier prettier
stylelint-prettier
does not install Prettier or Stylelint for you. You must install these yourself.
Then, in your .stylelintrc
:
{
"plugins": ["stylelint-prettier"],
"rules": {
"prettier/prettier": true
}
}
Alternatively you can extend from the stylelint-prettier/recommended
config,
which does the same thing:
{
"extends": ["stylelint-prettier/recommended"]
}
As of Stylelint v15, Stylelint deprecated all stylistic rules that conflict with prettier, and removed these rules in Stylelint v16. If you are using Stylelint v15 or above and are not using any of these deprecated rules then you do not need to do anything extra; this section does not apply to you.
If you are using Stylelint's stylistic rules, then many of them shall conflict with Prettier. This plugin works best if you disable all other Stylelint rules relating to stylistic opinions. If another active Stylelint rule disagrees with prettier
about how code should be formatted, it will be impossible to avoid lint errors. You should use stylelint-config-prettier to disable all stylistic Stylelint rules.
To integrate this plugin with stylelint-config-prettier
:
In addition to the above installation instructions, install stylelint-config-prettier
:
npm install --save-dev stylelint-config-prettier
Then add stylelint-config-prettier
to the list of extended configs in your .stylelintrc
that you added in the prior section. stylelint-config-prettier
should go last in the array so that it will override other configs:
{
"extends": [
"stylelint-prettier/recommended",
"stylelint-config-prettier"
]
}
You can then set Prettier's own options inside a .prettierrc
file.
stylelint-prettier will honor your .prettierrc
file by default. You only
need this section if you wish to override those settings.
Note: While it is possible to pass options to Prettier via your Stylelint configuration file, it is not recommended because editor extensions such as
prettier-atom
andprettier-vscode
will read.prettierrc
, but won't read settings from Stylelint, which can lead to an inconsistent experience.
Objects are passed directly to Prettier as options. Example:
{
"rules": {
"prettier/prettier": [true, {"singleQuote": true, "tabWidth": 4}]
}
}
NB: This option will merge and override any config set with .prettierrc
files (for Prettier < 1.7.0, config files are ignored)
See CONTRIBUTING.md
The layout for this codebase and base configuration of prettier was taken from https://github.com/prettier/eslint-plugin-prettier
5.0.3 (2025-01-26)
Avoid deprecation warning when encountering parsing errors in Stylelint >=16.13.0 (#385)
FAQs
Runs prettier as an stylelint rule
The npm package stylelint-prettier receives a total of 863,379 weekly downloads. As such, stylelint-prettier popularity was classified as popular.
We found that stylelint-prettier demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.