How to disable vue/multi-word-component-names eslint rule for just one .vue file?
Asked Answered
J

11

47

I am using the Vue ESLint plugin and it has a rule for not allowing single word component names.

However, I am also using Nuxt, and to set a default Layout in Nuxt you need a .vue component named default.vue which throws the ES Lint rule errors.

I can't seem to get it to just disable in that one .vue file that is actually pretty small...

<template>
    <div>
        <Header/>
        <Nuxt/>
    </div>
</template>

But if I disable the rule in my .eslintrc.js then it works.

module.exports = {
  root: true,
  env: {
    browser: true,
    node: true,
  },
  extends: [
    '@nuxtjs/eslint-config-typescript',
    'plugin:nuxt/recommended',
    'prettier',
  ],
  plugins: [],
  // add your custom rules here
  rules: {
    'vue/multi-word-component-names': 'off',
  },
}

Is there a way to disable the rule for just one Vue file?

Jefferson answered 3/1, 2022 at 20:16 Comment(3)
Does this answer your question? Turning off eslint rule for a specific fileEpifaniaepifano
FWIW, this rule is totally impractical and could be disabled forever.Epifaniaepifano
This is marked as essential here: vuejs.org/v2/style-guide/#Multi-word-component-names-essentialGeostatic
R
49

In your case, you can replace

'vue/multi-word-component-names': 'off'

with:

'vue/multi-word-component-names': ['error', {
  'ignores': ['default']
}]

this will set the rule to 'allow' for all files named 'default'

you can read more about it here: https://eslint.vuejs.org/rules/multi-word-component-names.html

Robbery answered 4/1, 2022 at 10:30 Comment(3)
Thanks, it's working.Jasmine
I get the error Definition for rule ' vue/no-reserved-component-names' was not found vue/no-reserved-component-names.Way
where to find it ?Dozy
W
31

rules: { 'vue/multi-word-component-names': 0 } try this way

Wolfram answered 9/3, 2022 at 1:10 Comment(4)
Isn't this functionally equivalent to the existing answer?Roberts
@JeremyCaney Same as which one? It's 0 not offWolfram
This working for me. ThanksJasmine
This worked for me. Thanks. The anwer above from Ahmad Ibrahim did not workJazminejazz
F
15

Go to package.json and in the eslintConfig object add the following rule: "vue/multi-word-component-names": "off"

or even better: "vue/multi-word-component-names": 0

Like so:

enter image description here

Fawcette answered 27/10, 2022 at 10:57 Comment(0)
H
5

You can override the rule to apply only for the specific files.

Here's the .eslintrc.js configuration

module.exports = {
  root: true,
  env: {
    browser: true,
    node: true,
  },
  extends: [
    '@nuxtjs/eslint-config-typescript',
    'plugin:nuxt/recommended',
    'prettier',
  ],
  plugins: [],
  overrides: [
    {
      files: ['src/components/default.vue'],  // Change this to default.vue path
      rules: {
        'vue/multi-word-component-names': 'off',
      }
    }
  ]
}
Highstrung answered 31/5, 2023 at 11:14 Comment(0)
W
3

You should have eslintConfig in package.json.

You need just set vue/multi-word-component-names to 0

rules: { 'vue/multi-word-component-names': 0 }

Williford answered 13/8, 2022 at 8:33 Comment(0)
C
0
  1. Run Command npm install standardx --global.

  2. In vue.config.js, add lintOnSave:false.

  3. In App.vue inside template, add div as parent element and wrap your image and component that you are using in that.

Cariole answered 15/9, 2022 at 5:14 Comment(0)
O
0

Here are the two ways to actually resolve this problem.

1 Use CamelCase minimum two words to for Component Name.

export default {
name: "HeaderComponent" // Header to HeaderComponent
}

2 Add the following code to the package.json:eslintConfig.rules to disable this rule.

"vue/multi-word-component-names": 0

3 Remove the eslint package from node_modules.

$ npm remove @vue/cli-plugin-eslint
Ossification answered 30/5, 2023 at 11:26 Comment(0)
U
0

I tried all the answers above for a component named "Header.vue", but none of them worked. I finally added a comment to disable the rule in eslint, like so,

From:

<script lang="js">
    export default {        
        name: 'Header',
    };
</script>

To:

<script lang="js">
    export default {
        // eslint-disable-next-line
        name: 'Header',
    };
</script>
Uthrop answered 13/6, 2023 at 16:34 Comment(0)
C
-1

Just the below line the vue.config.js file:

module.exports = defineConfig({
  ....
  lintOnSave: false
})
Cusco answered 24/3, 2022 at 21:28 Comment(0)
C
-1

You can replace vue.config.js with:

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: true,
  lintOnSave: false,
})
Chiastolite answered 26/3, 2022 at 11:22 Comment(0)
L
-1
  1. Go to the vue.config.js file

  2. Add lintOnSave:false to the file.

Levity answered 5/7, 2022 at 13:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.