Skip to content

Nuxt 3: auto imported ref will not trigger vue/no-ref-as-operand warning #1969

Closed
@dsvgl

Description

@dsvgl

Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have read the FAQ and my problem is not listed.

Tell us about your environment

  • **ESLint version: 8.23.1
  • **eslint-plugin-vue version: 9.4.0
  • **Node version: 16.16.0
  • **Operating System: MacOS 12.4

Please show your full configuration:

module.exports = {
  env: {
    browser: true,
    node: true,
  },
  parser: 'vue-eslint-parser',
  parserOptions: {
    ecmaVersion: 2022,
  },
  extends: [
    '@nuxtjs/eslint-config-typescript',
    'plugin:nuxt/recommended',
    'plugin:vue/vue3-recommended',
    'plugin:vuejs-accessibility/recommended',
    // https://github.com/prettier/eslint-plugin-prettier#recommended-configuration
    'plugin:prettier/recommended',
  ],
  plugins: [],
  rules: {
    // re-enable self-closing rule that was disabled by prettier to prevent conflicts
    // no problem to re-enable as per docs:
    // https://github.com/prettier/eslint-config-prettier#vuehtml-self-closing
    'vue/html-self-closing': [
      'error',
      {
        html: {
          void: 'any',
        },
      },
    ],
    'vue/no-v-html': 'off',
    'vue/valid-v-html': 'off',
    'import/order': 'off',
    '@typescript-eslint/explicit-module-boundary-types': 'warn',
    'vue/multi-word-component-names': 'off',
    // NOTE: disable Vue 2 rules
    // @nuxtjs/eslint-config-typescript uses "plugin:vue/recommended" which is for Vue 2
    'vue/no-multiple-template-root': 'off',
  },
};

What did you do?
Context: I am using Nuxt 3 and already filed an issue in their repo: nuxt/nuxt#14882
They said, I should first ask here...

I'm posting here my original question from the linked issue:


I'm constantly forgetting to add .value when working with refs and wondered why eslint is not helping me – no visual hints in VS Code and no error when running eslint in terminal.
There is a rule from eslint-plugin-vue to catch this: vue/no-ref-as-operand
Turns out, the auto imported ref from #imports is somehow "different" than directly importing from vue.
If I do import { ref } from 'vue', I get squiggly lines in VS Code and .value is automatically added when I save the file.
See also simple reproduction below.

<script setup lang="ts">
// uncomment this will throw vue/no-ref-as-operand
// import { ref } from 'vue';

// uncomment this will not help
// import { ref } from '#imports';

const count = ref(1);

// NOTE: should be count.value
const foo = count + 1;

console.log(foo);
</script>

What did you expect to happen?
Lint errors, both visually in VS Code and via terminal.

What actually happened?
No errors reported.

Repository to reproduce this issue
https://stackblitz.com/edit/github-cyy9sn?file=app.vue
run npm run lint to check output

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions