Skip to content

feat(lint): add noComposingEnterKey rule#10042

Draft
siketyan wants to merge 5 commits into
biomejs:mainfrom
siketyan:fix/no-composing-enter-key
Draft

feat(lint): add noComposingEnterKey rule#10042
siketyan wants to merge 5 commits into
biomejs:mainfrom
siketyan:fix/no-composing-enter-key

Conversation

@siketyan
Copy link
Copy Markdown
Member

@siketyan siketyan commented Apr 19, 2026

Note

This PR was created with AI assistance (Codex).

Summary

Implements the new nursery rule noComposingEnterKey discussed in #10041.

The rule reports Enter-key submit handlers that do not guard against IME composition, including the Safari fallback with keyCode === 229 when enabled. The implementation was aligned with eslint-plugin-ime-safe-form, and its invalid/valid cases were migrated into Biome's spec fixtures.

Test Plan

Added snapshot tests for DOM event listeners, JSX handlers, onkeydown-style assignments, keypress, switch-based Enter checks, Safari fallback handling, and guardFunctions options.

Docs

This PR adds a new lint rule, so the documentation is included in the rule source and diagnostics. No separate website PR is needed.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 19, 2026

🦋 Changeset detected

Latest commit: 998b8a2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added A-Project Area: project A-Linter Area: linter L-JavaScript Language: JavaScript and super languages A-Diagnostic Area: diagnostocis labels Apr 19, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 19, 2026

Merging this PR will not alter performance

✅ 179 untouched benchmarks
⏩ 70 skipped benchmarks1


Comparing siketyan:fix/no-composing-enter-key (998b8a2) with main (eabf54a)

Open in CodSpeed

Footnotes

  1. 70 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Copy link
Copy Markdown
Contributor

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a lot of .to_string() calls, those can likely be avoided with borrowed strings or TokenText.

FYI, the repo skills should have prevented a lot of issues, codex might not be picking up our skills because they are in .claude.

also, consider adding a custom migrator for the rule options. there's a skill for it to get the agent to do it.

/// </form>
/// ```
pub NoComposingEnterKey {
version: "2.4.12",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
version: "2.4.12",
version: "next",

Comment on lines +98 to +117
#[derive(Clone, Debug)]
enum DiagnosticKind {
MissingGuard(Box<str>),
DeprecatedKeypress(Box<str>),
MissingKeyCode229,
}

enum Handler {
Arrow(JsArrowFunctionExpression),
Function(JsFunctionExpression),
}

impl Handler {
fn body(&self) -> Option<JsSyntaxNode> {
match self {
Self::Arrow(handler) => Some(handler.body().ok()?.syntax().clone()),
Self::Function(handler) => Some(handler.body().ok()?.syntax().clone()),
}
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: move below impl Rule

/// ```
pub NoComposingEnterKey {
version: "2.4.12",
name: "noComposingEnterKey",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not totally sold on the name. no prefix means we are banning a concept, but actually we are enforcing that this guard is in place.

some ideas:

  • useComposingInputGuard
  • useComposingGuard

JsArrowFunctionExpression::can_cast(node.kind())
|| JsFunctionExpression::can_cast(node.kind())
|| JsFunctionDeclaration::can_cast(node.kind())
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use this instead

/// Returns `true` if the node kind is any function-like scope boundary.
pub fn is_function_boundary(kind: JsSyntaxKind) -> bool {
AnyFunctionLike::can_cast(kind) || is_sync_only_function_boundary(kind)
}

#[serde(default = "default_check_key_code_for_safari")]
pub check_key_code_for_safari: bool,
#[serde(default)]
pub guard_functions: Vec<String>,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be a boxed slice of str

Comment on lines +7 to +12
pub struct NoComposingEnterKeyOptions {
#[serde(default = "default_check_key_code_for_safari")]
pub check_key_code_for_safari: bool,
#[serde(default)]
pub guard_functions: Vec<String>,
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These must all be Option for configuration merging to make sense

Comment on lines +14 to +25
impl Default for NoComposingEnterKeyOptions {
fn default() -> Self {
Self {
check_key_code_for_safari: default_check_key_code_for_safari(),
guard_functions: Vec::new(),
}
}
}

const fn default_check_key_code_for_safari() -> bool {
true
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look at how other rules deal with default options. they don't access the options directly, they do it through a getter that calls unwrap_or to handle the Option

}
}

fn is_key_code_229_binary_expression(binary: &JsBinaryExpression) -> bool {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider returning Option<bool> to use the try operator

fn is_enter_string_comparison(left: &AnyJsExpression, right: &AnyJsExpression) -> bool {
static_member_name(left)
.is_some_and(|member_name| matches!(member_name.as_ref(), "key" | "code"))
&& string_literal_text(right).is_some_and(|text| text.as_ref() == "Enter")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more keys than just "Enter" matter right? like tab?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CLI Area: CLI A-Diagnostic Area: diagnostocis A-Linter Area: linter A-Project Area: project L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants