• Stars
    star
    328
  • Rank 123,716 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 6 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Stylelint plugin for Prettier formatting

stylelint-prettier Build Status

Runs Prettier as a Stylelint rule and reports differences as individual Stylelint issues.

Sample

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

Installation

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"]
}

Disabling rules that may conflict with Prettier

As of Stylelint v15, Stylelint deprecated all stylistic rules that conflict with prettier. If you are using Stylelint v15 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:

  1. In addition to the above installation instructions, install stylelint-config-prettier:

    npm install --save-dev stylelint-config-prettier
  2. 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.

Options

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 and prettier-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)


Contributing

See CONTRIBUTING.md

Inspiration

The layout for this codebase and base configuration of prettier was taken from https://github.com/prettier/eslint-plugin-prettier

More Repositories

1

prettier

Prettier is an opinionated code formatter.
JavaScript
48,344
star
2

eslint-config-prettier

Turns off all rules that are unnecessary or might conflict with Prettier.
JavaScript
5,171
star
3

prettier-vscode

Visual Studio Code extension for Prettier
TypeScript
5,003
star
4

prettier-eslint

Code ➡️ prettier ➡️ eslint --fix ➡️ Formatted Code ✨
JavaScript
3,933
star
5

eslint-plugin-prettier

ESLint plugin for Prettier formatting
JavaScript
3,140
star
6

pretty-quick

⚡ Get Pretty Quick
TypeScript
2,173
star
7

vim-prettier

A Vim plugin for Prettier
Vim Script
1,751
star
8

plugin-php

Prettier PHP Plugin
PHP
1,707
star
9

plugin-ruby

Prettier Ruby Plugin
JavaScript
1,443
star
10

tslint-config-prettier

Use TSLint with Prettier without any conflict
TypeScript
1,233
star
11

prettier-atom

An atom package for the prettier formatter.
JavaScript
756
star
12

prettier-eslint-cli

CLI for prettier-eslint
JavaScript
531
star
13

plugin-python

Prettier Python Plugin
JavaScript
516
star
14

stylelint-config-prettier

Turns off all rules that are unnecessary or might conflict with prettier.
JavaScript
373
star
15

prettier-emacs

Minor mode to format JS code on file save
Emacs Lisp
368
star
16

plugin-swift

[DEPRECATED] Prettier Swift Plugin - WARNING: The AST parser is not stable yet
JavaScript
276
star
17

tslint-plugin-prettier

Runs Prettier as a TSLint rule and reports differences as individual TSLint issues
TypeScript
235
star
18

plugin-xml

Prettier XML plugin
JavaScript
218
star
19

prettier-browser-extension

Prettier Browser Extension
JavaScript
198
star
20

plugin-pug

Prettier Pug Plugin
TypeScript
193
star
21

plugin-lua

Prettier Lua Plugin (WIP)
Lua
79
star
22

prettier-logo

The Prettier logo.
JavaScript
38
star
23

prettier-cli

TypeScript
24
star
24

prettier-printer

Library for building and pretty printing text documents
JavaScript
23
star
25

yaml-unist-parser

A YAML parser that produces output compatible with unist
TypeScript
22
star
26

stylelint-config-prettier-scss

Turns off all CSS and SCSS rules that are unnecessary or might conflict with prettier.
JavaScript
19
star
27

prettier-linter-helpers

Helper functions for exposing prettier changes within linting tools
JavaScript
17
star
28

angular-estree-parser

A parser that converts Angular source code into an ESTree-compatible form
TypeScript
16
star
29

prettier-synchronized

Synchronous version of Prettier
JavaScript
14
star
30

prettier-rpc

Single-file build of prettier with JSON-RPC communication
JavaScript
13
star
31

prettier-regression-testing

Automates the prettier/prettier regression checks with GitHub Actions.
TypeScript
11
star
32

parse-srcset

A spec-conformant JavaScript parser for the HTML5 srcset attribute
JavaScript
8
star
33

plugin-haml

Plugin for the HAML template language
JavaScript
5
star
34

pre-commit

Mirror of Prettier package for pre-commit.
JavaScript
5
star
35

is-es5-identifier-name

Check if provided string is an `IdentifierName` as specified in ECMA262 edition 5.1 section 7.6.
JavaScript
2
star
36

core-test-fixtures

Test fixtures for Prettier core.
JavaScript
2
star
37

html-ua-styles

User agent stylesheet defined in the WHATWG HTML specification.
JavaScript
1
star
38

eslint-plugin-prettier-internal-rules

Wrapper for Prettier internal rules
JavaScript
1
star