Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable eslint rule max line length for paragraph in <template> of vue.js?

I am using airbnb eslint and currently I am getting error:

error: Line 6 exceeds the maximum line length of 100 (max-len) at path/to/file.vue:6:1:

<template lang="pug">   div     .container       .row         .col-xl-10.mx-auto           p Please let us know how you got here, and use the header buttons to navigate back to safe harbor. </template> 

Is there a way to disable lint for paragraph text like above?
Also, how to increase the line length from 100 to 120?

like image 774
Syed Avatar asked May 22 '18 13:05

Syed


People also ask

How do I disable ESLint rule Vue?

To disable ESLint in Vue CLI, we just remove the @vue/cli-plugin-eslint package from the Vue CLI project. to remove the @vue/cli-plugin-eslint package, which will disable ESLint in the Vue CLI project.

How do I disable ESLint for multiple lines?

For those converting eslint-disable-next-line to eslint-disable (for multiple lines), remember two things. 1. /* */ instead of // 2. It's eslint-disable and not eslint-disable-next-line . Just reiterating coz I did the same and had to search many more things due to the 2nd point.

How do I get ESLint to ignore a line?

The // eslint-disable-line comment disables the no-eval rule for just that line. You can also disable the no-eval rule for an entire function block by using /* eslint-disable */ .


1 Answers

Update

There has been some updates to eslint-plugin-vue in the past 4 years. The comments in templates can now be used to override eslint settings.

For next line only

<!-- eslint-disable-next-line max-len --> <my-reasonably-long-component>...</my-reasonably-long-component> 

For multi-line purpose

<!-- eslint-disable max-len --> <my-reasonably-long-component>   ... </my-reasonably-long-component> <!-- eslint-enable max-len --> 

In addition, as of eslint-plugin-vue v6.1.0 the vue/max-len rule was added, which ads more control about how the length rules

{     "vue/max-len": ["error", {         "code": 80,         "template": 80,         "tabWidth": 2,         "comments": 80,         "ignorePattern": "",         "ignoreComments": false,         "ignoreTrailingComments": false,         "ignoreUrls": false,         "ignoreStrings": false,         "ignoreTemplateLiterals": false,         "ignoreRegExpLiterals": false,         "ignoreHTMLAttributeValues": false,         "ignoreHTMLTextContents": false,     }] } 

If you have more than a couple outliers, tweaking the globals for templates-specifically might work better.


Original Answer

AFAIK, there is no way to apply eslint rules to the template, and specifically to one line in a template. I hope to be proven wrong though.

anyway, because I have a file with lots of text, to get around it, I've added this rule 'max-len': ["error", { "code": 120 }], in my .eslintrc.js file.

here is the structure (with other settings removed)

module.exports {   rules: {     'max-len': ["error", { "code": 120 }]   } } 
like image 188
Daniel Avatar answered Sep 22 '22 06:09

Daniel