Skip to content

feat: name JS/TS arrow functions used as object methods + expand coverage#404

Merged
askpt merged 3 commits into
mainfrom
repo-assist/improve-jslike-arrow-method-and-coverage-20260622-588e53addfdcdf86
Jun 22, 2026
Merged

feat: name JS/TS arrow functions used as object methods + expand coverage#404
askpt merged 3 commits into
mainfrom
repo-assist/improve-jslike-arrow-method-and-coverage-20260622-588e53addfdcdf86

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

🤖 This is an automated pull request from Repo Assist.

Summary

Two improvements in one PR (Task 5 – Coding Improvement + test coverage):

  1. Arrow function object-method naming (UX improvement): JS/TS CodeLens now shows the property key name when an arrow function is the value of an object literal property, instead of the generic (arrow function) label.

  2. Expanded test coverage: 5 new unit tests covering previously-untested code paths in jsLikeAnalyzer. Test count: 126 → 131 passing.


Task 5: Arrow Function Object-Method Naming

Before / After

Code Before After
const api = { getData: () => { if(f){} } } (arrow function) getData
const fn = () => { if(f){} } fn (unchanged) fn
module.exports = () => { if(f){} } (arrow function) (unchanged) (arrow function)

Implementation (jsLikeAnalyzer.ts)

Added a pair parent check inside the arrow_function branch of getFunctionName:

if (parent && parent.type === "pair") {
  // Arrow function as an object property value: { myMethod: () => {} }
  const keyNode = parent.children.find(
    (c) => c.type === "property_identifier" || c.type === "identifier"
  );
  if (keyNode) {
    return this.sourceText.substring(keyNode.startIndex, keyNode.endIndex);
  }
}

Rationale

When a file exports a plain object of functions (common in module patterns, route handlers, service objects), every arrow function showed as (arrow function) in CodeLens. With this fix, each entry shows the property name, making it immediately clear which function a high-complexity CodeLens belongs to.


Test Coverage Added

Test Covers
Arrow function as object method → named by key New feature + pair parent path
While loop in JavaScript getComplexityReason "while loop" branch (line 384)
Nested class method inside a function getFunctionReason "method (nested)" branch (line 168)
module.exports = () => {}(arrow function) "(arrow function)" fallback (line 215)
Anonymous IIFE (function(){})()(anonymous) "(anonymous)" fallback (line 218)

jsLikeAnalyzer coverage: 97.87% → 99.53% stmts, 90.81% → 94.23% branches


Test Status

npm run compile  ✅  (0 errors)
npm run lint     ✅  (0 warnings)
npm run test:unit  ✅  131 passing, 0 failing (was 126 before this PR)

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • releaseassets.githubusercontent.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "releaseassets.githubusercontent.com"

See Network Configuration for more information.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

Add this agentic workflows to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@d63b34de41bc0dc052096e094c732cf28eafc659

…overage

- jsLikeAnalyzer: arrow function assigned as an object property
  (e.g. const api = { getData: () => {} }) now shows 'getData' in
  CodeLens instead of the generic '(arrow function)' label.  Handles
  the 'pair' parent node type alongside the existing 'variable_declarator'
  case.

- 5 new unit tests (126 → 131 passing):
  - object-method arrow function naming (new feature)
  - while loop in JavaScript (covers getComplexityReason 'while loop')
  - nested class method inside a function (covers getFunctionReason
    'method (nested)')
  - module.exports arrow function → '(arrow function)' fallback
  - anonymous IIFE function expression → '(anonymous)' fallback

- jsLikeAnalyzer coverage: 97.87% → 99.53% stmts, 90.81% → 94.23% branches

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@askpt askpt changed the title [repo-assist] improve: name JS/TS arrow functions used as object methods + expand coverage feat: name JS/TS arrow functions used as object methods + expand coverage Jun 22, 2026
@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 77.21%. Comparing base (fb3b47d) to head (2c49574).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/metricsAnalyzer/languages/jsLikeAnalyzer.ts 88.88% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #404      +/-   ##
==========================================
+ Coverage   76.96%   77.21%   +0.24%     
==========================================
  Files          13       13              
  Lines        4107     4116       +9     
  Branches      440      444       +4     
==========================================
+ Hits         3161     3178      +17     
+ Misses        943      934       -9     
- Partials        3        4       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@askpt askpt marked this pull request as ready for review June 22, 2026 19:57
@askpt askpt self-requested a review as a code owner June 22, 2026 19:57
Copilot AI review requested due to automatic review settings June 22, 2026 19:57

Copilot AI left a comment

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.

Pull request overview

This PR improves the JavaScript/TypeScript function naming shown in CodeLens by naming arrow functions used as object-literal property values (e.g., { getData: () => {} }) with the property key, and it expands unit test coverage for JsLikeMetricsAnalyzer to cover additional previously-untested branches.

Changes:

  • Update JsLikeMetricsAnalyzer.getFunctionName() to derive arrow-function names from the enclosing object-literal pair key.
  • Add 5 new unit tests covering: object-method arrow naming, while loop reason/complexity, nested class method handling, and anonymous/arrow fallback names.

Reviewed changes

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

File Description
src/metricsAnalyzer/languages/jsLikeAnalyzer.ts Enhances arrow-function naming by extracting the object property key when the arrow function is the value in an object literal pair.
src/unit/unit.test.ts Adds targeted unit tests to validate the new naming behavior and increase coverage for several existing branches/reason strings.

@askpt askpt merged commit ec952d8 into main Jun 22, 2026
11 checks passed
@askpt askpt deleted the repo-assist/improve-jslike-arrow-method-and-coverage-20260622-588e53addfdcdf86 branch June 22, 2026 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants