nuxt-modules / eslint

ESLint module for Nuxt.js
MIT License
160 stars 15 forks source link

vue-shim.d.ts throws eslint errors #62

Closed stephenjason89 closed 3 years ago

stephenjason89 commented 3 years ago

creating a vue-shim.d.ts on the root directory throws

declare module '*.vue' {
    import Vue from 'vue'
    export default Vue
}

ESLINT ERROR Parsing error: Imports within a declare module body must always be import type or import typeof.

Please let me know how to fix this

Thank you

danielroe commented 3 years ago

What is your eslint config, and what is the full error message? Make sure you are using @typescript-eslint/parser.

stephenjason89 commented 3 years ago

Hello, thank you for the fast reply, "@nuxtjs/eslint-config-typescript": "^6.0.1",

    The whole error

image

    my whole eslintrc.js is this

    ```
    module.exports = {
root: true,
env: {
    browser: true,
    node: true,
    es6: true,
},
parserOptions: {
    parser: 'babel-eslint',
},
extends: ['@nuxtjs', 'prettier', 'plugin:prettier/recommended', 'plugin:nuxt/recommended'],
plugins: ['prettier'],
ignorePatterns: '**/*.d.ts',                   <----------- I am not sure adding this is the right way to remove the error
// add your custom rules here
rules: {
    'vue/component-name-in-template-casing': ['error', 'PascalCase'],
    'vue/html-self-closing': [
        'error',
        {
            html: {
                void: 'always',
            },
        },
    ],
    'vue/v-bind-style': ['error', 'shorthand'],
    'vue/v-on-style': ['error', 'shorthand'],
    'vue/v-slot-style': ['error'],
    'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    'prefer-const': [
        'error',
        {
            destructuring: 'all',
        },
    ],
    'import/no-named-as-default': 0,
},

}

stephenjason89 commented 3 years ago

And here is the script i am running

    "lint:js": "eslint --ext .ts,.js,.vue --ignore-path .gitignore .",

adding parser: '@typescript-eslint/parser', on my eslintrc.js

results in an error

image

normal eslint works fine by the way, i am just new to typescript and wanted to setup everything before learning it .

Thank you for your time

stephenjason89 commented 3 years ago

Found what was causing it.

it was this line from my eslintrc.js is it okay to remove this?

parserOptions: {
    parser: 'babel-eslint',
},
danielroe commented 3 years ago

@stephenjason89 Yes, you should replace it with the parser I linked in my previous comment.

stephenjason89 commented 3 years ago

Thank you @danielroe Everything is working perfectly now 🙂

I actually just removed it

I saw it in this doc

Screenshot_2021-08-24-02-33-56-738_com.microsoft.emmx.jpg

Would there be any difference defining the parser?

danielroe commented 3 years ago

Great! 😊

stephenjason89 commented 3 years ago

Is there a difference if i add the parser or not? I'm new to this and i don't know what to expect with the parser defined and not

danielroe commented 3 years ago

If you use the nuxt typescript eslint preset, then you don't need to explicitly define the parser.

stephenjason89 commented 3 years ago

Thank you for the reply 🙂