mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
The previous names were confusing, long and partially redundant. The new names are: - blaze-consistent-eventmap-params -> eventmap-params - no-blaze-lifecycle-assignment -> no-template-lifecycle-assignments - template-naming-convention -> template-names BREAKING CHANGE: Rule names have changed.
75 lines
2.1 KiB
JavaScript
75 lines
2.1 KiB
JavaScript
/**
|
|
* @fileoverview Ensures consistent parameter names in blaze event maps
|
|
* @author Philipp Sporrer, Dominik Ferber
|
|
* @copyright 2015 Philipp Sporrer. All rights reserved.
|
|
* See LICENSE file in root directory for full license.
|
|
*/
|
|
|
|
import { isFunction, isTemplateProp } from '../util/ast'
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// Rule Definition
|
|
// -----------------------------------------------------------------------------
|
|
|
|
export default context => {
|
|
// ---------------------------------------------------------------------------
|
|
// Helpers
|
|
// ---------------------------------------------------------------------------
|
|
|
|
function ensureParamName(param, expectedParamName) {
|
|
if (param && param.name !== expectedParamName) {
|
|
context.report(
|
|
param,
|
|
`Invalid parameter name, use "${expectedParamName}" instead`
|
|
)
|
|
}
|
|
}
|
|
|
|
function validateEventDef(eventDefNode) {
|
|
const eventHandler = eventDefNode.value
|
|
if (isFunction(eventHandler.type)) {
|
|
ensureParamName(
|
|
eventHandler.params[0],
|
|
context.options[0] ? context.options[0].eventParamName : 'event'
|
|
)
|
|
|
|
ensureParamName(
|
|
eventHandler.params[1],
|
|
context.options[0] ? context.options[0].templateInstanceParamName : 'templateInstance'
|
|
)
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Public
|
|
// ---------------------------------------------------------------------------
|
|
|
|
return {
|
|
CallExpression: (node) => {
|
|
if (node.arguments.length === 0 || !isTemplateProp(node.callee, 'events')) {
|
|
return
|
|
}
|
|
const eventMap = node.arguments[0]
|
|
|
|
if (eventMap.type === 'ObjectExpression') {
|
|
eventMap.properties.forEach((eventDef) => validateEventDef(eventDef))
|
|
}
|
|
},
|
|
}
|
|
}
|
|
|
|
export const schema = [
|
|
{
|
|
type: 'object',
|
|
properties: {
|
|
eventParamName: {
|
|
type: 'string',
|
|
},
|
|
templateInstanceParamName: {
|
|
type: 'string',
|
|
},
|
|
},
|
|
additionalProperties: false,
|
|
},
|
|
]
|