1. prettier-stylelint
code > prettier > stylelint > formatted code
prettier-stylelint
Package: prettier-stylelint
Created by: hugomrdias
Last modified: Fri, 13 May 2022 09:27:10 GMT
Version: 0.4.2
License: MIT
Downloads: 160,091
Repository: https://github.com/hugomrdias/prettier-stylelint

Install

npm install prettier-stylelint
yarn add prettier-stylelint

prettier-stylelint NPM Version NPM Downloads NPM License Build Status codecov

Format your styles with ease!

code > prettier > stylelint > formatted code

prettier-stylelint attempts to create a prettier config based on the stylelint config, then format with prettier followed by stylelint --fix. So after that you should end up with formatted code with no linting errors.

Install

 yarn add prettier-stylelint -D
npm install prettier-stylelint --save-dev

Usage

This package has a stylelint config to disable some rules that conflict with prettier.

 "stylelint": {
    "extends": [
        "stylelint-config-idiomatic-order",
        "./node_modules/prettier-stylelint/config.js"
    ],
    "rules": {
        "indentation": 4,
        "string-quotes": "single"
    }
}

After adding the disabling config you can just prettier-stylelint --write and its done. Check the CLI options below for more information.
Also in a near future we should have support for prettier-stylelint in prettier-vscode follow this PR.

API

 const format = require('prettier-eslint')
const sourceCode = 'a[id="foo"] { content: "x"; }'
const options = {
  text: sourceCode
}
const formatted = format(options)


// formatted 
a[id='foo'] {
    content: 'x';
}

CLI Options

The cli automatically ignores .gitignore and .prettierignore.

NOTE: It is recommended that you keep your files under source control and committed
before running prettier-stylelint --write as it will overwrite your files!

Usage
  $ prettier-stylelint [<file|glob> ...]

Options
  --ignore          Additional paths to ignore  [Can be set multiple times]
  --extension       Additional extension to lint [Can be set multiple times]
  --cwd=<dir>       Working directory for files
  --stdin           Validate/fix code from stdin ('prettier-stylelint -' also works)
  --write           Edit files in place (DRAGONS AHEAD !!)
  --quiet -q        Only log stderr

Examples
  $ prettier-stylelint
  $ prettier-stylelint index.js
  $ prettier-stylelint *.js !foo.js
  $ echo 'a[id="foo"] { content: "x"; }' | prettier-stylelint --stdin

Default pattern when no arguments:
  **/*.{css,scss,less,sss}

License

MIT © Hugo Dias

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code