简体   繁体   English

奇怪的 Vue linter 行为:H2 多行标签内的“123 {{ v }} 123”导致错误

[英]Weird Vue linter behavior: “123 {{ v }} 123” within H2 multi-line tag caused error

I just setup my development environment, with the newly installed linter & prettier for Vue.js & NUXTJS I've checked my configuration with我刚刚设置了我的开发环境,新安装的 linter & prettier for Vue.js & NUXTJS 我检查了我的配置

npx eslint --print-config ./pages/index.vue | npx eslint-config-prettier-check

and

No rules that are unnecessary or conflict with Prettier were found.没有发现不必要的或与 Prettier 冲突的规则。

When I write something like the following and the eslint pop-ups and say, hey, the prettier don't want you to do that, does anyone know why?当我写如下内容和 eslint 弹出窗口并说,嘿,更漂亮的不希望你这样做时,有人知道为什么吗? I don't want to just make the linter ignore in this case since this kind of style seems to be very usual in my codes.在这种情况下,我不想让 linter 忽略,因为这种风格在我的代码中似乎很常见。 Any help would be appreciated!任何帮助,将不胜感激!

Error:错误:

为什么

The codes:代码:

  <h2 class="subtitle">
    123 {{ env }} 123
  </h2>
  <h2 class="subtitle">
    {{ env }}
  </h2>
  <h1 class="title">
    reborn
  </h1>

Also my.eslintrc.js is showed below: my.eslintrc.js 如下所示:

module.exports = {
  root: true,
  env: {
    browser: true,
    node: true
  },
  parserOptions: {
    parser: 'babel-eslint'
  },
  plugins: ['prettier', 'vue'],
  rules: {
    'vue/component-name-in-template-casing': ['error', 'PascalCase'],
    'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    'no-debuger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    'vue/max-attributes-per-line': 'off',
    'nuxt/no-cjs-in-config': 'off'
  },
  globals: {
    $nuxt: true
  },
  extends: [
    '@nuxtjs',
    'plugin:prettier/recommended',
    'plugin:nuxt/recommended',
    'plugin:vue/recommended',
    'prettier',
    'prettier/babel',
    'prettier/vue',
    'prettier/unicorn'
  ]
}

The linter is complaining about your return characters, notice the return character at the beginning and just after the second 123. linter 抱怨您的返回字符,请注意开头和第二个 123 之后的返回字符。

I believe it is saying you should put them all on the same line, ie我相信这是说你应该把它们都放在同一条线上,即

<h2 class="subtitle">123 {{ env }} 123</h2>

Of course, I wouldn't be surprised if there was a conflicting rule on the auto formatter that says not to put it on one line.当然,如果自动格式化程序上有一条相互冲突的规则,即不要将其放在一行上,我不会感到惊讶。 You will need to decide which you rather.你需要决定你更喜欢哪一个。 Personally, I would find and turn off that spacing rule because I prefer the formatting you have already.就个人而言,我会找到并关闭该间距规则,因为我更喜欢您已经拥有的格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM