Skip to content

vue/attribute-hyphenation changes original code which would break app #924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xianshenglu opened this issue Jul 6, 2019 · 2 comments · Fixed by #2045
Closed

vue/attribute-hyphenation changes original code which would break app #924

xianshenglu opened this issue Jul 6, 2019 · 2 comments · Fixed by #2045

Comments

@xianshenglu
Copy link

Tell us about your environment

  • ESLint version: 5.16.0
  • eslint-plugin-vue version: 5.2.3
  • Node version: 10.14.2

Please show your full configuration:

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

module.exports = {
  root: true,
  parserOptions: {
    parser: 'babel-eslint'
  },
  env: {
    browser: true
  },
  extends: ['plugin:vue/essential'],
  // required to lint *.vue files
  plugins: ['vue'],
  // add your custom rules here
  rules: {
    // 'vue/prop-name-casing': ['error', 'camelCase']
    'vue/attribute-hyphenation': 'error'
  }
}

What did you do?

<!-- HelloWorld/index.vue-->
<template>
  <div class="HelloWorld">
    <TestPara
      :AttrEe="4"
      :attr_ff="5"
      :attr_Gg="6"
      :Attr_Hh="7"
      :_attr_ii="8"
      :_attr_Jj="9"
      :_attrKk="10"
      :_AttrLl="11"
    />
  </div>
</template>

<script>
import TestPara from './TestPara'
export default {
  name: 'HelloWorld',
  components: {
    TestPara
  }
}
</script>
<template>
  <div class="TestPara"></div>
</template>

<script>
<!-- HelloWorld/TestPara.vue-->
export default {
  name: 'TestPara',
  props: [
    'AttrEe',
    'attr_ff',
    'attr_Gg',
    'Attr_Hh',
    '_attr_ii',
    '_attr_Jj',
    '_attrKk',
    '_AttrLl'
  ],
  created () {
    window.vm = this
    console.log(vm.$props)
  }
}
</script>

run

cd .\vue\vue-prop-parse\
npx eslint .\src\components\HelloWorld\index.vue --fix

What did you expect to happen?

I can still access all the $props in the TestPara with the valid value without changing the code in the TestPara.

What actually happened?

<!-- HelloWorld/index.vue-->
<template>
  <div class="HelloWorld">
    <TestPara
      :attr-ee="4"
      :attr_ff="5"
      :attr-gg="6"
      :attr-hh="7"
      :_attr_ii="8"
      :-attr-jj="9"
      :-attr-kk="10"
      :-attr-ll="11"
    />
  </div>
</template>

<script>
import TestPara from './TestPara'
export default {
  name: 'HelloWorld',
  components: {
    TestPara
  }
}
</script>

After lint, I got the error at the console with

'-attr-jj' is not a valid attribute name.

And Attr_Hh, attr_Gg, _AttrLl, _attrKk, _attr_Jj in $props are undefined. I check the test cases and find you didn't consider these situations like _ in the attributes name.

In this case, I thought you shouldn't try to fix the original code? Because that would break the app down.

What do you think?

@ota-meshi ota-meshi added the bug label Dec 28, 2019
@aggmoulik
Copy link
Contributor

Hy @ota-meshi This is still valid ?

@FloEdelmann
Copy link
Member

This is probably still valid. For anyone who wants to work on this:

  1. Please create a test case with these attribute names.
  2. They should still be reported as errors.
  3. They should not be autofixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants