16

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?

user3382203
  • 169
  • 1
  • 6
  • 25
David
  • 3,364
  • 10
  • 41
  • 84

3 Answers3

20

The documentation says printWidth. The documentation link is here

printWidth: 120

Probably this should solve the problem.

Prakash Dahal
  • 430
  • 3
  • 6
  • 6
    The documentation specifically says printWidth is not the same: "In other words, don’t try to use printWidth as if it was ESLint’s max-len" – David Jan 11 '21 at 08:45
8

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 {(.*?)}" 
    }
],
merlosy
  • 587
  • 5
  • 12
2

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.

Lipis
  • 21,388
  • 20
  • 94
  • 121