Skip to content

Add name-property-casing rule. #94

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

Merged
merged 3 commits into from
Jul 22, 2017

Conversation

armano2
Copy link
Contributor

@armano2 armano2 commented Jul 18, 2017

This PR implements rules proposed in #93

DONE:

  • Create documtation
  • Add tests
  • Implement rule

@armano2 armano2 force-pushed the patch-14-name-casing branch from fa9e504 to 8502971 Compare July 19, 2017 17:51
@armano2 armano2 changed the title Add name-casing rule. Add name-property-casing rule. Jul 20, 2017
@@ -0,0 +1,37 @@
# Name property casing for consistency purposes (name-property-casing)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requires specific casing for the name property in Vue components (name-property-casing)

@@ -0,0 +1,37 @@
# Name property casing for consistency purposes (name-property-casing)

Define a style for the `name` property casing for consistency purposes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing dot at the end of the sentence

Default casing is set to `PascalCase`

```
'vue/name-property-casing': [2, 'camelCase'|'kebab-case'|'PascalCase']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camelCase|kebab-case|PascalCase

@@ -0,0 +1,79 @@
/**
* @fileoverview Name property casing for consistency purposes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the same title as in documentation


return utils.executeOnVueComponent(context, (obj) => {
const node = obj.properties
.filter(item => item.type === 'Property' && item.key.name === 'name' && item.value.type === 'Literal')[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wrap this line to make it more readable

return utils.executeOnVueComponent(context, (obj) => {
const node = obj.properties
.filter(item => item.type === 'Property' && item.key.name === 'name' && item.value.type === 'Literal')[0]
if (node) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add empty line above if

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw. you can also do:

if (!node) { return; }

To not introduce unnecessary indentation.

}

function convertCase (str, caseType) {
if (caseType === 'kebab-case') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideal case for switch/case. Or better you can create map with converters:

const convertersMap = {
  'kebab-case': kebabCase,
  'camelCase': camelCase,
  'PascalCase': pascalCase
}

function getConverter(name) {
  return convertersMap[name] || pascalCase
}

And use it like so:

function convertCase (str, caseType) {
  return getConverter(caseType)(str)
}

WDYT?


function create (context) {
const options = context.options[0]
const caseType = ['camelCase', 'kebab-case', 'PascalCase'].indexOf(options) !== -1 ? options : 'PascalCase'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move the array with possible caseTypes out of the create function, it's how it's done in most rules I think.

filename: 'test.js',
code: `
new Vue({
name: 'foo!bar'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add one more test with foo_bar

@armano2
Copy link
Contributor Author

armano2 commented Jul 21, 2017

@michalsnik i applied your suggestions & i wrapped few additional line of code.

Copy link
Member

@michalsnik michalsnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! GJ @armano2 🎉

@michalsnik michalsnik merged commit 29d1cb6 into vuejs:master Jul 22, 2017
@michalsnik
Copy link
Member

I'll release it later :)

@armano2 armano2 deleted the patch-14-name-casing branch July 22, 2017 12:11
@F3n67u
Copy link

F3n67u commented Dec 8, 2018

Make name-property-casing fixable is very dangerous, because the fix code only fix the name and leave the reference code same. I think the fix should leave to manual fix, we just show the alert and do nothing else.

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

Successfully merging this pull request may close these issues.

4 participants