-
-
Notifications
You must be signed in to change notification settings - Fork 681
Add rules: no-dupe-keys
and no-reserved-keys
#88
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
Add rules: no-dupe-keys
and no-reserved-keys
#88
Conversation
@michalsnik its ready to review |
Let's do it one after another. It's really good to see you work so fast and being so committed! 💪 , however we didn't even approved the proposition yet. I hope you don't mind if we'll wait a while until merging all of your PRs? We'd like to focus and gracefully add more and more rules while constantly keeping everything well organized. |
@michalsnik we are just need them in our project to improve quality of code. |
87fe19d
to
cecd4bf
Compare
I added suggestion in #86 |
@michalsnik rule splited to:
|
8df0324
to
f645e0b
Compare
lib/rules/no-dupe-keys.js
Outdated
if (usedNames.indexOf(name) !== -1) { | ||
context.report({ | ||
node: node, | ||
message: "Duplicate key '{{name}}'.", |
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.
Duplicated
lib/rules/no-dupe-keys.js
Outdated
module.exports = { | ||
meta: { | ||
docs: { | ||
description: 'Prevent duplicate field names', |
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.
Prevents duplication of field names
lib/utils/index.js
Outdated
@@ -384,5 +426,48 @@ module.exports = { | |||
cb(node.arguments[0]) | |||
} | |||
} | |||
}, | |||
|
|||
iterateProperties (node, scopeNames, cb) { |
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 comments that will describe those new functions
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.
Also, what do you think about calling scopeNames
-> groups
instead? Scope is actually the same so being semantically correct we'd call it rather a group. At least I think so
lib/rules/no-reservered-keys.js
Outdated
const scopeNames = SCOPE_NAMES | ||
|
||
const options = context.options[0] || {} | ||
if (options.reserved) { |
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.
You can actually simplify config with:
const options = context.options[0] || {}
const reservedKeys = new Set([...RESERVED_KEYS, ...options.reserved || []])
const scopes = new Set([...SCOPE_NAMES, ...options.scopes || []])
Plus you can then set RESERVED_KEYS
and SCOPE_NAMES
as arrays above.
I changed names of variables so keep it in mind :)
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.
spread operator is not working with node 4
lib/rules/no-reservered-keys.js
Outdated
// Rule Definition | ||
// ------------------------------------------------------------------------------ | ||
|
||
const RESERVER_NAMES = new Set(require('../utils/vue-reserved.json')) |
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.
RESERVED
, not RESERVER
lib/rules/no-reservered-keys.js
Outdated
if (groupName === 'data' && name.substr(0, 1) === '_') { | ||
context.report({ | ||
node: node, | ||
message: "Field '{{name}}' which start with _ in data is reserved.", |
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.
What do you think about this message: Keys starting with with "_" are reserved in "data" group.
?
lib/rules/no-reservered-keys.js
Outdated
} else if (reservedNames.has(name)) { | ||
context.report({ | ||
node: node, | ||
message: "Reserved key '{{name}}'.", |
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.
Key '{{name}}' is reserved
lib/rules/no-reservered-keys.js
Outdated
module.exports = { | ||
meta: { | ||
docs: { | ||
description: 'Prevent overwrite reserved keys', |
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.
I added suggestion for description above
lib/utils/index.js
Outdated
}, | ||
|
||
iterateArrayExpression (node, groupName, cb) { | ||
node.elements.forEach(item => { |
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.
I'd check type of the passed node in each of those functions first.
foo: String | ||
}, | ||
computed: { | ||
...mapGetters({ |
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.
We don't support checking mapGetters
and mapState
case yet right? It's probably something worth considering but only once we have vuex
environment available in this plugin.
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.
@michalsnik we are not supporting it yet, and i'm waiting with it for respond about environments 💃 this is just example with spread operator.
no-dupe-keys
rule.no-dupe-keys
and no-reserved-keys
bfb41ef
to
239dff6
Compare
@michalsnik suggestions applied |
lib/utils/index.js
Outdated
@@ -398,5 +440,69 @@ module.exports = { | |||
cb(node.arguments.slice(-1)[0]) | |||
} | |||
} | |||
}, | |||
|
|||
iterateProperties (node, groups, cb) { |
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.
There is the reason you avoid generator functions by callback style?
I like for-of
.
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.
Node 4
Node 4 :D |
Node 4 supports generators and for-of 😄 |
Aaaa I was almost 100% sure than it's not supported.... Than I can change it after launch |
@mysticatea updated |
@armano2 Thank you for prompt update! I'm sorry that I give up today... (AM 1:30 of Monday in my timezone). |
1347b26
to
270754e
Compare
* @param {ASTNode} node - The node to get. | ||
* @return {string|null} The property name if static. Otherwise, null. | ||
*/ | ||
getStaticPropertyName (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.
Can you please add test for this method?
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.
@michalsnik added
270754e
to
56e1422
Compare
* master: Add rule `vue/require-valid-default-prop`. (vuejs#119) 3.10.0 Update readme to 3.10.0 Chore: remove package-lock.json (vuejs#128) Fix: parserService must exist always (fixes vuejs#125) (vuejs#127) Add rule `require-render-return`. (vuejs#114) 3.9.0 Update package-lock Update: options for `no-duplicate-attributes` (fixes vuejs#112)(vuejs#113) New: add rule `attribute-hyphenation`. (fixes vuejs#92)(vuejs#95) Add namespace check of svg & mathML instead of tag names (vuejs#120)⚠️ Add support for deprecated state in update-rules⚠️ (vuejs#121) Add rules: `no-dupe-keys` and `no-reserved-keys`. (vuejs#88) Chore: Improve tests for name-property-casing & improve documentation (vuejs#115) New: add `require-prop-types` rule (fixes vuejs#19)(vuejs#85) Update: upgrade vue-eslint-parser (fixes vuejs#36, fixes vuejs#56, fixes vuejs#96) (vuejs#116)
This PR implements rules proposed in #86
DONE: