Skip to content

react/jsx-handler-names: cannot opt-out of handler prefix independent of prop prefix #2400

Closed
@drewlustro

Description

@drewlustro

Issue

I only want to enforce eventHandlerPropPrefix, but I cannot selectively opt out of eventHandlerPrefix.


1. Rule always plugs in a default value 'handle' into eventHandlerPrefix when supplied value is an empty string '' (falsy)

Problematic code:

// will always be set to 'handle' when falsy
const eventHandlerPrefix = configuration.eventHandlerPrefix || 'handle';

source


2. Rule prevents "whitelist" JS regex workarounds noted in #1687 because a capital letter must succeed the allowed prefix.

Example Config: I want to whitelist submit select verbatim and handle* prefix:

"react/jsx-handler-names": ['error', {
  "eventHandlerPrefix": '(handle|submit|select)',
  "eventHandlerPropPrefix": 'on',
}],

Problematic code:

// [A-Z] succeeding eventHandlerPrefix prevents handler whitelist
const EVENT_HANDLER_REGEX = new RegExp(`^((props\\.${eventHandlerPropPrefix})|((.*\\.)?${eventHandlerPrefix}))[A-Z].*$`);

source

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions