Tslint: Max-line-length not fixed by prettier
Asked Answered
A

3

21

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?

Altdorfer answered 22/1, 2018 at 15:29 Comment(0)
A
27

The documentation says printWidth. The documentation link is here

printWidth: 120

Probably this should solve the problem.

Ardyce answered 31/8, 2020 at 12:1 Comment(2)
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"Altdorfer
printWidth is used for Printers only.Toadflax
N
9

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 {(.*?)}" 
    }
],
Numb answered 25/5, 2018 at 9:10 Comment(0)
P
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.

Planoconcave answered 7/2, 2018 at 13:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.