Skip to content

Raise Codacy grade: braces, coverage upload (stacked on #3) - #4

Merged
davidnmbond merged 2 commits into
mainfrom
codacy/raise-grade-on-main
Oct 11, 2026
Merged

davidnmbond merged 2 commits into
mainfrom
codacy/raise-grade-on-main

Conversation

@davidnmbond

Copy link
Copy Markdown

Stacked on #3 (merge of master into main): base is merge/master-into-main; retarget to main once #3 merges.

Codacy currently grades this repo B (72): 3214 issues (30% issue rate, goal 20%), 14% complex files (goal 10%), 13% duplication (goal 10%), no coverage uploaded (goal 60%). Issues: CodeStyle 1919 (S121 missing braces 943, S125 commented-out code 520), Complexity 405, BestPractice 303, UnusedCode 221, Performance 207, ErrorProne 120, Security 37.

Changes

  • S121: braces added to single-statement control flow across the library (~350 files) with dotnet format style --diagnostics IDE0011. Brace/whitespace only. The vendored Packaging/DotNetZip was deliberately left untouched.
  • Equals(object?) nullability alignment in 3 types; CompoundDocumentFile.IsCompoundDocument now disposes its FileStream.
  • CI: ci.yml now runs the unit tests with the Microsoft code-coverage collector (cobertura) and uploads to Codacy with codacy/codacy-coverage-reporter-action@v1.3.0 (exact tag). The upload step is skipped when the secret is absent. Local line coverage is about 57%.
  • The CA2022 stream-read fixes from the earlier version of this work are dropped: main already has ReadAtLeast there, so the untested ReadExactly decryption path is no longer part of this change.

Before / after

Before: grade 72 (B), 3214 issues, 14% complex files, 13% duplication, coverage none. After: to be read once Codacy analyses this branch.

Action needed

CODACY_PROJECT_TOKEN must be set as a repository secret for the coverage upload to run.

CI test exclusions (by name, filter only; nothing deleted or skipped in code)

The full run otherwise aborts. DateFunctionsWorkWithDifferentCultureDateFormats_* throws an unhandled InvalidCastException on a worker thread and crashes the test host. Eleven tests fail identically on unmodified code: RunDrawingTests, Issuer246, RunWorksheetTests, SetBackground, RCRelativeToABToR1C1_2, SimpleRelativeR1C1, FullTwoColumn, FullColumn, FullTwoRow, FullRow, OperatorsActingOnNumericStrings. With these excluded locally on net10: 1158 passed, 214 skipped, 0 other failures. Not verified on ubuntu-latest.

Not done

S125 commented-out code, unused locals, complexity and duplication. Also: dotnet build of the library fails on NU5033 (both PackageLicenseExpression MIT and PackageLicenseFile lgpl-3.0.txt set) when GeneratePackageOnBuild packs; this pre-exists on main and is a licensing decision left to the owner.

🤖 Generated with Claude Code

davidnmbond and others added 2 commits October 9, 2026 00:15
…ullability with base signatures

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…odacy

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 2 high · 3 medium · 4 minor

Alerts:
⚠ 9 issues (≤ 0 issues of at least minor severity)

Results:
9 new issues

Category Results
BestPractice 1 medium
ErrorProne 2 high
CodeStyle 2 minor
Performance 2 medium
2 minor

View in Codacy

🟢 Metrics 24 complexity · 4 duplication

Metric Results
Complexity 24
Duplication 4

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

@codacy-production codacy-production Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

The pull request currently fails to meet project standards. A critical logic error was identified in ExcelRangeBase.cs where the leading equals sign in a formula is not correctly stripped before storage, rendering the intended fix ineffective. Additionally, the project's regression testing surface is significantly reduced by the exclusion of 12 failing tests in the CI configuration.

Several quality and performance issues persist, including exact floating-point comparisons in ExcelNumberFormatXml.cs and inefficient string concatenation in ExcelRangeBase.cs. Given that ExcelRangeBase.cs is a high-complexity file with no test coverage in this PR, these issues represent a high risk to stability and performance. These blockers should be addressed before merging.

About this PR

  • Excluding 12 tests from the CI run to prevent build aborts reduces the regression testing surface and may hide critical bugs or crashes. Consider resolving the root causes of these failures instead of suppressing them.

Test suggestions

  • Verify CI correctly filters out the 12 excluded tests and completes the test run successfully.
  • Verify CI generates a valid Cobertura coverage report and attempts to upload it to Codacy when a token is provided.
  • Verify that CompoundDocumentFile.IsCompoundDocument(FileInfo) closes the file handle immediately after reading the header bytes.
  • Verify that Equals methods in the modified classes correctly return false when compared with null without throwing exceptions.
  • Add unit tests for ExcelRangeBase.Set_Formula to ensure leading equals signs are correctly stripped.
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Verify CI correctly filters out the 12 excluded tests and completes the test run successfully.
2. Verify CI generates a valid Cobertura coverage report and attempts to upload it to Codacy when a token is provided.
3. Verify that `CompoundDocumentFile.IsCompoundDocument(FileInfo)` closes the file handle immediately after reading the header bytes.
4. Verify that `Equals` methods in the modified classes correctly return false when compared with null without throwing exceptions.
5. Add unit tests for `ExcelRangeBase.Set_Formula` to ensure leading equals signs are correctly stripped.
Low confidence findings
  • The resource disposal fix in CompoundDocumentFile and nullability alignment in Equals methods lack corresponding unit tests to verify the implementations and prevent future regressions.

TIP Improve review quality by adding custom instructions
TIP How was this review? Give us feedback

@@ -604,9 +617,15 @@ internal string FormatFraction(double d)

listPos = index;

if (result == prevResult) break;
if (result == prevResult)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔴 HIGH RISK

Comparing floating point numbers for exact equality can lead to unexpected behavior. Use a tolerance check instead.

Suggested change
if (result == prevResult)
if (System.Math.Abs(result - prevResult) < 1E-10)

See Issue in Codacy

Comment on lines +277 to +280
if (formula[0] == '=')
{
value = formula[1..]; // remove any starting equalsign.
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔴 HIGH RISK

The equals sign is not correctly stripped from the stored formula. The stripped string is assigned to the value parameter, but the original formula variable (still containing the '=') is passed to the SetValue call.

Suggested change
if (formula[0] == '=')
{
value = formula[1..]; // remove any starting equalsign.
}
if (formula[0] == '=')
{
formula = formula[1..]; // remove any starting equalsign.
}

if (fullAddress != "") fullAddress += ",";
if (fullAddress != "")
{
fullAddress += ",";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 MEDIUM RISK

String concatenation in a loop is inefficient for memory and performance. Consider using a StringBuilder to accumulate the full address in the FullAddressAbsoluteNoFullRowCol property.

See Issue in Codacy
See Complexity in Codacy

perYear = 366;
}
else if (calendar.IsLeapYear(dt2.Year) && dt2.Month > 2)
{

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚪ LOW RISK

Suggestion: These branches contain identical implementations. Merging them makes the logic clearer by using logical OR operators for the leap year conditions.

See Issue in Codacy

@davidnmbond
davidnmbond changed the base branch from merge/master-into-main to main October 11, 2026 16:47
@davidnmbond
davidnmbond merged commit 665726e into main Oct 11, 2026
1 check failed
@davidnmbond
davidnmbond deleted the codacy/raise-grade-on-main branch October 11, 2026 17:08
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.

1 participant