Skip to content

Commit c5e23ab

Browse files
committed
Document methods in use-v-on-exact
1 parent c6c41d6 commit c5e23ab

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

lib/rules/use-v-on-exact.js

+42-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ const KEY_ALIASES = new Set(keyAliases)
2626
/**
2727
* Finds and returns all keys for event directives
2828
*
29-
* @param {Array} attributes Element attributes
30-
* @returns {Array}
29+
* @param {array} attributes Element attributes
30+
* @returns {array[object]} [{ name, node, modifiers }]
3131
*/
3232
function getEventDirectives (attributes) {
3333
return attributes
@@ -42,6 +42,12 @@ function getEventDirectives (attributes) {
4242
}))
4343
}
4444

45+
/**
46+
* Checks whether given modifier is KEY
47+
*
48+
* @param {string} modifier
49+
* @returns {boolean}
50+
*/
4551
function isKeyModifier (modifier) {
4652
return (
4753
KEY_MODIFIERS.has(modifier) ||
@@ -54,10 +60,24 @@ function isKeyModifier (modifier) {
5460
)
5561
}
5662

63+
/**
64+
* Checks whether given any of provided modifiers
65+
* has KEY modifier
66+
*
67+
* @param {array} modifiers
68+
* @returns {boolean}
69+
*/
5770
function hasKeyModifier (modifiers) {
5871
return modifiers.some(isKeyModifier)
5972
}
6073

74+
/**
75+
* Groups all events in object,
76+
* with keys represinting each event name
77+
*
78+
* @param {array} events
79+
* @returns {object} { click: [], keypress: [] }
80+
*/
6181
function groupEvents (events) {
6282
return events.reduce((acc, event) => {
6383
if (acc[event.name]) {
@@ -70,10 +90,24 @@ function groupEvents (events) {
7090
}, {})
7191
}
7292

93+
/**
94+
* Creates alphabetically sorted string with key modifiers
95+
*
96+
* @param {array[string]} modifiers
97+
* @returns {string} e.g. "alt,ctrl,del,shift"
98+
*/
7399
function getKeyModifiersString (modifiers) {
74100
return modifiers.filter(isKeyModifier).sort().join(',')
75101
}
76102

103+
/**
104+
* Compares two events based on their modifiers
105+
* to detect possible event leakeage
106+
*
107+
* @param {object} baseEvent
108+
* @param {object} event
109+
* @returns {boolean}
110+
*/
77111
function hasConflictedModifiers (baseEvent, event) {
78112
if (
79113
event.node === baseEvent.node ||
@@ -90,6 +124,12 @@ function hasConflictedModifiers (baseEvent, event) {
90124
)
91125
}
92126

127+
/**
128+
* Searches for events that might conflict with each other
129+
*
130+
* @param {array} events
131+
* @returns {array} conflicted events, without duplicates
132+
*/
93133
function findConflictedEvents (events) {
94134
return events.reduce((acc, event) => {
95135
return [

0 commit comments

Comments
 (0)