Skip to content

Auto-lint: convert .map(lambda → JSX) to list comprehension syntax (W3039)#5622

Open
SupulHeshan wants to merge 9 commits intojaseci-labs:mainfrom
SupulHeshan:auto-lint-map-lambda-to-jsx-comprehension
Open

Auto-lint: convert .map(lambda → JSX) to list comprehension syntax (W3039)#5622
SupulHeshan wants to merge 9 commits intojaseci-labs:mainfrom
SupulHeshan:auto-lint-map-lambda-to-jsx-comprehension

Conversation

@SupulHeshan
Copy link
Copy Markdown
Collaborator

Summary

Adds a new auto-lint rule W3039 (map-lambda-to-comprehension) that automatically
converts verbose React-style .map() lambda patterns to Jac's native JSX comprehension syntax.

Before:

items.map(lambda item: any, idx: int -> any {
    return <li key={idx}>{item.name}</li>;
})

After:

[<li key={idx}>{item.name}</li> for (idx, item) in enumerate(items)]

When the lambda has no index parameter, the simpler form is used:

<li>{item.name}</li> for item in items]

Changes

  • diagnostics.jac - adds W3039 warning with kebab alias map-lambda-to-comprehension
  • jac_auto_lint_pass.jac - imports W3039, declares _make_name_node and _convert_map_to_comprehension
  • jac_auto_lint_pass.impl.jac - implements the detection + AST rewrite; wired into exit_func_call

Pattern matched

  • Target is <expr>.map(lambda ...)
  • Lambda has a block body ({ ... }) with exactly one statement: return <JsxElement>
  • Lambdas with pre-computation (multiple statements before the return) are intentionally skipped
  • A second int-typed parameter is recognized as the loop index → enumerate() is injected automatically

Copilot AI review requested due to automatic review settings April 19, 2026 18:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new auto-lint rule W3039 (map-lambda-to-comprehension) to rewrite React-style .map(lambda ... { return <jsx>; }) patterns into Jac list comprehension JSX syntax, improving idiomatic Jac output during auto-lint formatting.

Changes:

  • Adds W3039 diagnostic text + kebab-case alias mapping.
  • Extends JacAutoLintPass API with helpers for building synthetic Name nodes and performing the .map(...)ListCompr AST rewrite.
  • Wires the conversion into exit_func_call so it runs during auto-lint formatting.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
jac/jaclang/jac0core/diagnostics.jac Defines W3039 warning message and adds alias mapping for config/back-compat.
jac/jaclang/compiler/passes/tool/jac_auto_lint_pass.jac Imports W3039 and declares the new conversion helpers on the pass.
jac/jaclang/compiler/passes/tool/impl/jac_auto_lint_pass.impl.jac Implements detection + AST rewrite and invokes it from exit_func_call.

Comment thread jac/jaclang/compiler/passes/tool/impl/jac_auto_lint_pass.impl.jac
Comment thread jac/jaclang/compiler/passes/tool/impl/jac_auto_lint_pass.impl.jac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants