Skip to content

Odd formatting with router-link and named routes #956

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

Closed
n8twj opened this issue Sep 11, 2019 · 5 comments
Closed

Odd formatting with router-link and named routes #956

n8twj opened this issue Sep 11, 2019 · 5 comments

Comments

@n8twj
Copy link

n8twj commented Sep 11, 2019

Tell us about your environment

  • ESLint version: "^5.16.0"
  • eslint-plugin-vue version: "^5.0.0"
  • eslint-plugin-prettier version: "^3.1.0"
  • **Node version: v10.16.3 **

Please show your full configuration:

module.exports = {
  root: true,
  env: {
    node: true
  },
  extends: ["plugin:vue/essential", "@vue/prettier"],
  rules: {
    "no-console": process.env.NODE_ENV === "production" ? "error" : "off",
    "no-debugger": process.env.NODE_ENV === "production" ? "error" : "off"
  },
  parserOptions: {
    parser: "babel-eslint"
  }
};

What did you do?

<template>
  <div>
    <h1>Events Listing</h1>
    <p>
       // The next line
      <router-link :to="{ name: 'event-show', params: { id: '1' } }">First Event</router-link>
    </p>
  </div>
</template>

What did you expect to happen?
I expected the formatting of the router-link tag not to be changed

What actually happened?

<template>
  <div>
    <h1>Events Listing</h1>
    <p>
      // this line is auto-formatted poorly
      <router-link :to="{ name: 'event-show', params: { id: '1' } }"
        >First Event</router-link
      >
    </p>
  </div>
</template>

I can also confirm by saving the file in a dumb editor like nano with expected formatting and then running npm run lint the file is updated to the poor formatting. This behavior only happens when using a "named" router-link tag.

@n8twj
Copy link
Author

n8twj commented Sep 11, 2019

VS Code provides the following message from ESLint:

Replace `>First·Event</router-link` with `⏎········>First·Event</router-link⏎······`eslint(prettier/prettier)

aka - adding CR/LFs (or ⏎·Equiv)

@Akash-Preet
Copy link

That's a infinite loop ♾️, when I press ctrl + s line break is removed again 🤕 .

ezgif-7-3c833dbde747

@vpanagiev
Copy link

vpanagiev commented May 22, 2020

Yup, same problem here as @Akash-Preet

EDIT: Found a solution that worked for me here in this comment. Yes, it was as simple as reinstalling the config of prettier.

Alternative solution if you don't like this wrapping behaviour on here.

EDIT2: To solve the annoying problem that @Akash-Preet describe and I too had, what I ultimitaly had to do was to remove this line "editor.formatOnSave": true, from my VSCode settings.json! Keep in mind that I still have ""editor.codeActionsOnSave": {"source.fixAll.eslint": true }" option. It just seems that those two were having a conflict, or more precisely, one was overriding the other. The linter was doing its job on save but then the auto formatting was ruining it on save too. More info and credit for this solution come from here and here.

If you keep having the problem of "Delete CR" lines, then it could be a problem with the prettier config for End Of Line and the config of your VScode. More info and fix here.

@sbillet
Copy link

sbillet commented Sep 19, 2020

I had the same issue. Turns out the root cause was just the line getting longer than Prettier's default printWidth (80 characters), so it recommended a line wrap.

It can be easily fixed by setting the option to a higher value, e.g. 120 (my IDE's line width). One way is to create a .prettierrc.js with following content:

module.exports = {
  printWidth: 120
}

@FloEdelmann
Copy link
Member

That's the result of using Prettier, which likes to format HTML that way. Since this has nothing to do with eslint-plugin-vue, I'll close this issue.

@FloEdelmann FloEdelmann closed this as not planned Won't fix, can't repro, duplicate, stale Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants