eslint-plugin-backbone icon indicating copy to clipboard operation
eslint-plugin-backbone copied to clipboard

Rule suggestion: events hash key should always be quoted

Open niksy opened this issue 8 years ago • 4 comments

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?

niksy avatar Jul 10 '16 07:07 niksy

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.

ilyavolodin avatar Jul 10 '16 14:07 ilyavolodin

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.

niksy avatar Jul 10 '16 19:07 niksy

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.

ilyavolodin avatar Jul 10 '16 19:07 ilyavolodin

It might be possible to create a plugin version of this rule using eslint-rule-composer.

platinumazure avatar Oct 20 '17 17:10 platinumazure