-
-
Notifications
You must be signed in to change notification settings - Fork 681
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
Conversation
fa9e504
to
8502971
Compare
docs/rules/name-property-casing.md
Outdated
@@ -0,0 +1,37 @@ | |||
# Name property casing for consistency purposes (name-property-casing) |
There was a problem hiding this comment.
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)
docs/rules/name-property-casing.md
Outdated
@@ -0,0 +1,37 @@ | |||
# Name property casing for consistency purposes (name-property-casing) | |||
|
|||
Define a style for the `name` property casing for consistency purposes |
There was a problem hiding this comment.
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
docs/rules/name-property-casing.md
Outdated
Default casing is set to `PascalCase` | ||
|
||
``` | ||
'vue/name-property-casing': [2, 'camelCase'|'kebab-case'|'PascalCase'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
camelCase|kebab-case|PascalCase
lib/rules/name-property-casing.js
Outdated
@@ -0,0 +1,79 @@ | |||
/** | |||
* @fileoverview Name property casing for consistency purposes |
There was a problem hiding this comment.
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
lib/rules/name-property-casing.js
Outdated
|
||
return utils.executeOnVueComponent(context, (obj) => { | ||
const node = obj.properties | ||
.filter(item => item.type === 'Property' && item.key.name === 'name' && item.value.type === 'Literal')[0] |
There was a problem hiding this comment.
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
lib/rules/name-property-casing.js
Outdated
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
lib/rules/name-property-casing.js
Outdated
} | ||
|
||
function convertCase (str, caseType) { | ||
if (caseType === 'kebab-case') { |
There was a problem hiding this comment.
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?
lib/rules/name-property-casing.js
Outdated
|
||
function create (context) { | ||
const options = context.options[0] | ||
const caseType = ['camelCase', 'kebab-case', 'PascalCase'].indexOf(options) !== -1 ? options : 'PascalCase' |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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
@michalsnik i applied your suggestions & i wrapped few additional line of code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! GJ @armano2 🎉
I'll release it later :) |
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. |
This PR implements rules proposed in #93
DONE: