Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

tslint-plugin-prettier

prettier264kMIT2.3.0TypeScript support: included

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

prettier, tslint, tslint-plugin, tslint-rules

readme

tslint-plugin-prettier

npm build coverage

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

Changelog

Sample

a();;;
    ~~
;;;
~~~ [Delete `;;⏎;;;`]
var foo = ''
          ~~ [Replace `''` with `"";⏎`]
var foo= "";
       ~ [Insert `·`]

Install

# using npm
npm install --save-dev tslint-plugin-prettier prettier

# using yarn
yarn add --dev tslint-plugin-prettier prettier

(require prettier@^1.9.0)

Usage

(tslint.json)

for tslint@^5.2.0

{
  "rulesDirectory": ["tslint-plugin-prettier"],
  "rules": {
    "prettier": true
  }
}

for tslint@^5.0.0

{
  "extends": ["tslint-plugin-prettier"],
  "rules": {
    "prettier": true
  }
}

NOTE: To use this plugin, it'd better to also use tslint-config-prettier to disable all prettier-related rules, so as to avoid conflicts between existed rules.

Options

  • If there is no option provided, it'll try to load config file and/or .editorconfig if possible, uses Prettier's default option if not found.

    {
      "extends": ["tslint-plugin-prettier"],
      "rules": {
        "prettier": true
      }
    }

    If you don't want to load .editorconfig, disable it in the third argument.

    {
      "extends": ["tslint-plugin-prettier"],
      "rules": {
        "prettier": [true, null, { "editorconfig": false }]
      }
    }
  • If you'd like to specify which config file to use, just put its path (relative to process.cwd()) in the second argument, the following example shows how to load the config file from <cwd>/configs/.prettierrc:

    {
      "extends": ["tslint-plugin-prettier"],
      "rules": {
        "prettier": [true, "configs/.prettierrc"]
      }
    }
  • If you'd like to specify options manually, just put Prettier Options in the second argument, for example:

    {
      "extends": ["tslint-plugin-prettier"],
      "rules": {
        "prettier": [true, { "singleQuote": true }]
      }
    }

Ignoring files

  • It will respect your .prettierignore file in your project root ( process.cwd() ) but if you would like to use a different file you can provide it in the third argument, for example:

    {
      "extends": ["tslint-plugin-prettier"],
      "rules": {
        "prettier": [true, null, { "ignorePath": "otherDirectory/.prettierignore" }]
      }
    }
    

Development

# lint
yarn run lint

# build
yarn run build

# test
yarn run test

License

MIT © Ika

changelog

Change Log

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

2.3.0 (2020-03-26)

Features

2.2.0 (2020-03-14)

Features

2.1.0 (2019-12-21)

Features

2.0.1 (2018-10-28)

Bug Fixes

  • report syntax error instead of throw (#272) (8b62595)

2.0.0 (2018-09-16)

Bug Fixes

  • specify config file correctly (a46bb9f)

Features

BREAKING CHANGES

  • require prettier@^1.9.0
  • load .editorconfig by default
  • specify config file via filepath instead of directory

1.3.0 (2017-09-28)

Features

  • add ability to specify config file search path (#48) (fe39a1d)

1.2.0 (2017-09-15)

Features

1.1.0 (2017-08-16)

Bug Fixes

  • deps: remove peerDeps for typescript (888868e)

Features

1.0.0 (2017-07-30)

Features