Skip to content

fix(shacl-parser): address Sonar reduce warnings#71

Merged
SeanBerrieHRI merged 1 commit into
mainfrom
fix/sonar-reduce-initial-value
May 15, 2026
Merged

fix(shacl-parser): address Sonar reduce warnings#71
SeanBerrieHRI merged 1 commit into
mainfrom
fix/sonar-reduce-initial-value

Conversation

@qplevier
Copy link
Copy Markdown

@qplevier qplevier commented May 15, 2026

Summary

  • add an explicit initial value to reduce calls in parseAll and parseAllAndGroup
  • replace direct reducer function references with inline callbacks
  • keep existing merge behavior by reducing from createEmptyShape()

Motivation

This addresses SonarQube findings:

  • typescript:S6959 (Array.reduce should include an initial value)
  • typescript:S7727 (Function references should not be passed directly to iterator methods)

Testing

  • not run (logic-only TypeScript change)

Checklist [optional]

Just a friendly reminder to update any of the following, if applicable:

  • changelog
  • readme
  • documentation
  • version

Summary by Sourcery

Bug Fixes:

  • Prevent potential runtime or analysis issues in SHACL shape aggregation by providing an explicit initial value to reduce operations in parseAll and parseAllAndGroup.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 15, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors SHACLParser reduction logic in parseAll and parseAllAndGroup to satisfy SonarQube rules by adding explicit initial values and inlining the reducer callbacks while preserving existing shape merge behavior.

File-Level Changes

Change Details Files
Update SHACLParser reduce calls to use explicit initial accumulator values and inline reducer callbacks while preserving merge semantics.
  • Change parseAll to reduce loaded shapes using an inline callback that delegates to mergeShapes and starts from createEmptyShape() as the initial accumulator.
  • Change parseAllAndGroup to build the combined shape using the same inline reduce callback with createEmptyShape() as the initial accumulator before grouping.
src/components/ShaclForm/Parser/SHACLParser.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@kburger
Copy link
Copy Markdown

kburger commented May 15, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Using this.createEmptyShape() as the initial accumulator changes the reduction semantics compared to the previous implementation; please double-check that createEmptyShape() is a true identity for mergeShapes, or consider handling the empty-array case separately (e.g., early-return or slice(1) pattern) to preserve behavior for non-empty collections while still satisfying the Sonar rules.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Using `this.createEmptyShape()` as the initial accumulator changes the reduction semantics compared to the previous implementation; please double-check that `createEmptyShape()` is a true identity for `mergeShapes`, or consider handling the empty-array case separately (e.g., early-return or `slice(1)` pattern) to preserve behavior for non-empty collections while still satisfying the Sonar rules.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@SeanBerrieHRI SeanBerrieHRI merged commit b645174 into main May 15, 2026
4 checks passed
@qplevier qplevier deleted the fix/sonar-reduce-initial-value branch May 15, 2026 08:55
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.

3 participants