vuejs / eslint-plugin-vue

Official ESLint plugin for Vue.js
https://eslint.vuejs.org/
MIT License
4.47k stars 665 forks source link

vue/no-unused-vars reports error when the var is used in the child component #690

Closed adcentury closed 5 years ago

adcentury commented 5 years ago

Tell us about your environment

Please show your full configuration:

// https://eslint.org/docs/user-guide/configuring

module.exports = {
  root: true,
  parserOptions: {
    parser: 'babel-eslint'
  },
  env: {
    browser: true,
  },
  // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
  // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
  extends: ['plugin:vue/essential', 'airbnb-base'],
  // required to lint *.vue files
  plugins: [
    'vue'
  ],
  globals: {
    "require": true
  },
  // check if imports actually resolve
  settings: {
    'import/resolver': {
      webpack: {
        config: 'build/webpack.base.conf.js'
      }
    }
  },
  // add your custom rules here
  rules: {
    // don't require .vue extension when importing
    'import/extensions': ['error', 'always', {
      js: 'never',
      vue: 'never'
    }],
    // disallow reassignment of function parameters
    // disallow parameter object manipulation except for specific exclusions
    'no-param-reassign': ['error', {
      props: true,
      ignorePropertyModificationsFor: [
        'state', // for vuex state
        'acc', // for reduce accumulators
        'e' // for e.returnvalue
      ]
    }],
    // allow optionalDependencies
    'import/no-extraneous-dependencies': ['error', {
      optionalDependencies: ['test/unit/index.js']
    }],
    // allow debugger during development
    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    // others
    'no-new': 0,
    'max-len': 0,
    'no-else-return': 0,
    'arrow-body-style': 0,
    'func-names': 0,
    'default-case': 0,
    'no-alert': 0,
    'no-underscore-dangle': 0,
    'no-empty-pattern': 0,
    'no-restricted-syntax': 0,
    'guard-for-in': 0,
    'no-param-reassign': 0,
    'no-plusplus': 0,
    "vue/no-parsing-error": [2, {
      "x-invalid-end-tag": false,
    }],
  }
}

What did you do?

<!-- this project uses iview components -->
<MenuItem
  v-for="(item, index) in someList"
  :key="item.name"
  ...
>
  <Row>
      <Col>
        <Tooltip :placement="getPlacementByIndex(index)">
        ...
</MenuItem>

What did you expect to happen? Pass the lint.

What actually happened?

error  'index' is defined but never used  vue/no-unused-vars
mysticatea commented 5 years ago

Thank you for the report.

But I couldn't reproduce it on our online demo.

adcentury commented 5 years ago

@mysticatea This demo's version is not same with my env. Maybe it's the reason.

michalsnik commented 5 years ago

Please try eslint-plugin-vue@next @adcentury and let us know if you still have this issue :)

michalsnik commented 5 years ago

Closing for now. Feel free to reopen if you're still having this problem.

roland-reed commented 5 years ago
<template>
    <Row class="row">
        <Col v-for="(tpl, idx) in tplList" :key="tpl.id">
            <Card
                :id="tpl.id"
                :index="idx"
            ></Card>
        </Col>
    </Row>
</template>
<script>
export default {
}
</script>

I can reproduce the issue with the code above. Problem will disappear when changing <Col> to <div>, which is:

<template>
    <Row class="row">
        <div v-for="(tpl, idx) in tplList" :key="tpl.id">
            <Card
                :id="tpl.id"
                :index="idx"
            ></Card>
        </div>
    </Row>
</template>
<script>
export default {
}
</script>
roland-reed commented 5 years ago

Here is the online demo.

ota-meshi commented 5 years ago

The <Col> element is recognized as an HTML <col> element. Since the HTML <col> element is a void element, it is treated as if there are no internal elements. Also, </col> will cause a parsing error as an invalid end tag.

Please rename the <Col> component.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/col