eslint-plugin-backbone
eslint-plugin-backbone copied to clipboard
Rule suggestion: events hash key should always be quoted
When you use events hash, you always quote key since it contains spaces:
{
'click .foo': function ( e ) {
// ...
}
}
But if you try to set event handle on el
itself, it is allowed to omit those quotes:
{
click: function ( e ) {
// ...
}
}
Suggested rule will warn user to always put quotes around events hash key to keep it consistent with majority of use cases.
Potential issue I can see is that it could clash with quote-props
rule.
What do you think?
You are correct. It would clash with quote-props
rule in the core. I don't usually quote click
when it's set on the root object, but it's a personal preference. I'd be fine with including this in. Do you want to submit a PR for this? I'd name it something like quoted-events
, maybe.
Is there any rule on how to handle clashing rules? It seems like that kind of behavior is greatly discouraged and should probably be handled inside original rule with custom option.
Yes, usually you would want to resolve it in the core rule. However, ESLint doesn't make exceptions for specific frameworks, all of the rules are framework agnostic. Now that I'm looking at the rule, I think you can just use 'quote-props': ['error', 'consistant']
that will enforce the rule you are looking for. It will apply to everything, but I figured that if you want it in events, you probably wouldn't mind it in other places as well.
It might be possible to create a plugin version of this rule using eslint-rule-composer.