Skip to content

Conversation

Planeshifter
Copy link
Member

Description

What is the purpose of this pull request?

This pull request:

  • adds a new ESLint rule flagging function declarations that are unnecessarily nested and can be moved to a higher scope, helping avoid repeated function creation and improving performance, while respecting intentional patterns like closures and IIFEs.

Rationale: Functions defined inside other functions are recreated on each invocation, causing unnecessary memory allocation and performance overhead. Moving independent functions to module scope ensures they are defined only once while preserving legitimate use cases like closures that access outer variables.

Related Issues

Does this pull request have any related issues?

This pull request:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Sep 3, 2025
Copy link
Member

@kgryte kgryte left a comment

Choose a reason for hiding this comment

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

Other than nested usage of this and arguments, this is looking fine.

@kgryte kgryte added Needs Changes Pull request which needs changes before being merged. Tools Issue or pull request related to project tooling. and removed Needs Review A pull request which needs code review. labels Sep 3, 2025
@Planeshifter Planeshifter marked this pull request as draft September 8, 2025 01:36
Planeshifter and others added 9 commits September 7, 2025 21:47
…ible scope

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: na
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: na
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
…guments`

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: passed
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: na
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
@Planeshifter Planeshifter force-pushed the philipp/add-lint-rule-no-unnecessary-nested-functions branch from d4a0b97 to 02b8335 Compare September 8, 2025 02:47
@Planeshifter Planeshifter marked this pull request as ready for review September 8, 2025 02:48
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Sep 8, 2025
@Planeshifter
Copy link
Member Author

Upon reflection, there does indeed appear to be no reason why we couldn't elevate functions accessing this or arguments. Removed the corresponding logic.

@Planeshifter Planeshifter requested a review from kgryte September 8, 2025 02:49
@kgryte kgryte removed the Needs Changes Pull request which needs changes before being merged. label Sep 8, 2025
Signed-off-by: Athan <[email protected]>
Copy link
Member

@kgryte kgryte left a comment

Choose a reason for hiding this comment

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

LGTM

@kgryte kgryte removed the Needs Review A pull request which needs code review. label Sep 8, 2025
@kgryte kgryte merged commit f70ed07 into develop Sep 8, 2025
10 checks passed
@kgryte kgryte deleted the philipp/add-lint-rule-no-unnecessary-nested-functions branch September 8, 2025 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tools Issue or pull request related to project tooling.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC]: Add ESLint rule to enforce inner function declarations are moved to highest level scope
3 participants