Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE]: support max-len in Vue components #1063

Closed
1 task done
alonsogb opened this issue Feb 6, 2023 · 0 comments
Closed
1 task done

[FEATURE]: support max-len in Vue components #1063

alonsogb opened this issue Feb 6, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@alonsogb
Copy link
Contributor

alonsogb commented Feb 6, 2023

How can the project be improved?

In the Playboard team, we use the eslint-plugin-x and during development, we found out that eslint with its max-len rule and prettier didn't work together. The main problem is there are some cases that prettier doesn't want to transform the code even when the code's length surpasses the limit.

Some cases:

  • Strings length (e.g: long imports paths, long attribute names in vue files, long describe() titles, long URL ). Further info
  • Template Literals when there are some expressions inside prettier doesn't do a wrap transformation itself. It is a known discussion topic of the prettier formatter.
imports { foo } from 'very-long-long-long-long-long-long-long-long-long-import-path'; // ERROR: eslint max-len

const x = `${msgs?.explanation1}<br>${msgs?.explanation2}<ul><li>"${promotions[0].title}" with queries: ${promotions[0].keywords[0]}</li></ul>`// ERROR: eslint max-len

describe('very-long-long-long-long-long-long-long-long-long-long-title')// ERROR: eslint max-len
  • CSS long lines. There are some cases in that you can not add a line break.
@include example( 'very-long-long-long-long-long-long-long-long-long-long-class');
  • long attributes in Vue components. There are some cases that you can not add a line break in an attribute.
<div  class="example-component example-component--expanded">
<path
   d="M11 .5c-1.7.2-3.4.9-4.7 2-1.1.9-2 2-2.5 3.2-1.2 2.4-1.2 5.1-.1 7.7 1.1 2.6 2.8 5 5.3 7.5 1.2 1.2 2.8 2.7 3 2.7 0 0
/>"

How can this be solved?

  • Make the linter ignore strings
  • Make the linter ignore template literals
  • Make the linter ignore long CSS lines inside Vue
  • Make the linter ignore Vue components' attributes

Proposed solution

In Play team core repository we defined a configuration in .eslintrc.js which solved these issues.

Customizations supported

I would suggest using our approach or something along those lines in eslint-plugin-x so everyone could have a general config that solves these issues.

Suggestions:

  • Do an override in .vue files, which disabled the original max/len but used the extended one vue/max-len
{
      files: ['*.vue'],
      rules: {
        'max-len': 'off',
        'vue/max-len': [
          'error',
          {
           ignoreStrings: true,
           ignoreTemplateLiterals: true,
            ignoreUrls: true,
            ignoreHTMLAttributeValues: true
          }
        ]
      }
  • Change config for max-len
{
  rules: {
      'max-len': ['error', {
                         ignoreStrings: true,
                         ignoreTemplateLiterals: true,
                         ignoreUrls: true      
                         }],
  }
}

Additional information

Previously prettier would have formatted this with one class per line. like so:

 <div class="example-component
                        example-component--expanded
                         example-component--collapsed"
  >

But it is no longer an option since prettier@2.5.0.

Further info:

Code of Conduct

  • I agree to follow this project's Code of Conduct.
@alonsogb alonsogb added the enhancement New feature or request label Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants