'Warning: This line has a length of 82. Maximum allowed is 80

VSCode is showing this warning: Warning: This line has a length of 82. Maximum allowed is 80

The affected line is this:

function getThatNewPath (myParam, myFirstParam, mySecondParam, anotherParam) {

How can I fix it?



Solution 1:[1]

Well, since it is a warning, you don't really need to fix it, but if you want anyway, I'd suggest making the line shorter, either by shortening your param names or by using multiple lines to achieve the same result.

Of course, if you split the line into multiple lines this depends on the coding guidelines you apply.

E.g.:

function getVideoAlbumResource (myParam, myFirstParam, mySecondParam,
                                anotherParam, ..., finalParam) {

Since you're using JavaScript you could also pass an object containing your params, which you could destructure later on inside the function.

E.g.:

function getVideoAlbumResource (params) {
    const { myParam, myFirstParam, mySecondParam, anotherParam } = params;

Of course you could refer to your params by using the dot notation (params.myParam, etc.) too.

Solution 2:[2]

You can do one of those 3 things :

  • Reformat your line into multiple line to not exceed 80
  • or change your eslint config of max-len to put more than 80
  • or add an es-lint ignore on top of your line to ignore this rule for this particular line

Solution 3:[3]

I like listing each parameter on their own line when there are 4 or more of them:

function getVideoalbumResource (
  myParam,
  myFirstParam,
  mySecondParam,
  anotherParam
) {
  // code
}

Solution 4:[4]

I think it is your tslint.json which is causing the warning. In tslint.json, change the value of max-line-length to your desired value. eg-

"max-line-length": [
      true,
      140
    ],

Solution 5:[5]

Add this to your rules:

"max-len": ["error", { code: 140 }]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 zomilanovic
Solution 2 Anas Bud
Solution 3 CertainPerformance
Solution 4 Akash Bhardwaj
Solution 5 Armar