David
David

Reputation: 3614

Tslint: Max-line-length not fixed by prettier

I'm using VSCode with prettier plugin and typescript and also tslint.

Leaving aside the convenience to use this configuration, I get a

[tslint] Exceeds maximum line length of 120 (max-line-length)

For a line like this:

import { MyComponent } from "../../some_very_long_path";

I've prettier configured with a print-width of 100, so I was expecting that on Format Document this line would be refactored into something like this:

import { MyComponent } 
  from "../../some_very_long_path";

or like this:

import {
  MyComponent
} from "../../some_very_long_path";

But it is not. Any ideas why?

Upvotes: 24

Views: 46029

Answers (3)

Prakash Dahal
Prakash Dahal

Reputation: 540

The documentation says printWidth. The documentation link is here

printWidth: 120

Probably this should solve the problem.

Upvotes: 31

merlosy
merlosy

Reputation: 607

You can add exception for specific regex. Prettier will have the lead for managing imports and exports, since it has a special way to deal with them.

// edit your tslint.json
"max-line-length": [
     true, 
    { 
        "limit": 140, 
        "ignore-pattern": "^import |^export {(.*?)}" 
    }
],

Upvotes: 9

Lipis
Lipis

Reputation: 21835

Prettier is not breaking down imports and the best thing you can do is to remove all the stylistic errors (including the max-line-length) from tslint rules and let Prettier to handle those and tslint the code related ones.

Upvotes: 2

Related Questions