tslint-plugin-prettier
raw JSON → 2.3.0 verified Sat Apr 25 auth: no javascript deprecated
Runs Prettier as a TSLint rule and reports differences as individual TSLint issues. Stable version 2.3.0, low release cadence (last update 2019). Integrates Prettier formatting into TSLint workflows, emitting each difference as a separate lint failure. Unlike other tools, it supports both TSLint 5/6 and Prettier 1.x/2.x, but TSLint itself is deprecated in favor of ESLint. No active development expected.
Common errors
error Cannot find module 'tslint-plugin-prettier' ↓
cause Package not installed or peer dependencies missing.
fix
npm install tslint-plugin-prettier --save-dev
error Could not find rule: 'prettier' ↓
cause tslint.json not configured correctly or plugin not loaded.
fix
Add 'tslint-plugin-prettier' to 'extends' or 'rulesDirectory' in tslint.json.
error Invalid 'prettier' rule options ↓
cause The 'prettier' rule accepts only boolean (true) or an object with options.
fix
Use "prettier": true or "prettier": true in tslint.json.
Warnings
deprecated TSLint itself is deprecated. Prettier integration is better done via eslint-plugin-prettier. ↓
fix Migrate to ESLint + eslint-plugin-prettier.
gotcha The rule reports each difference as a separate failure, which can flood output in large files. ↓
fix Use Prettier directly for formatting, or limit rule scope to specific files.
breaking Version 2.0.0 dropped support for Prettier <1.9 and TSLint <5.0. ↓
fix Upgrade to Prettier >=1.9 and TSLint >=5.0.
Install
npm install tslint-plugin-prettier yarn add tslint-plugin-prettier pnpm add tslint-plugin-prettier Imports
- default wrong
import plugin from 'tslint-plugin-prettier'correctconst plugin = require('tslint-plugin-prettier') - Rules wrong
import { Rules } from 'tslint-plugin-prettier'correctconst { Rules } = require('tslint-plugin-prettier') - PrettierRule wrong
import { PrettierRule } from 'tslint-plugin-prettier'correctconst { PrettierRule } = require('tslint-plugin-prettier')
Quickstart
// tslint.json
{
"extends": ["tslint-plugin-prettier"],
"rules": {
"prettier": true
}
}
// Run: tslint --config tslint.json 'src/**/*.ts'