Skip to content

[All] Fix ~45 code scanning warnings in Fable.Transforms#4357

Merged
dbrattli merged 2 commits intomainfrom
dbrattli/fable-warnings
Feb 28, 2026
Merged

[All] Fix ~45 code scanning warnings in Fable.Transforms#4357
dbrattli merged 2 commits intomainfrom
dbrattli/fable-warnings

Conversation

@dbrattli
Copy link
Collaborator

@dbrattli dbrattli commented Feb 23, 2026

Summary

  • Address four categories of code scanning analyzer warnings across 15 files in src/Fable.Transforms/
  • GRA-STRING-001/002/004: Add explicit StringComparison.Ordinal to StartsWith, EndsWith, and LastIndexOf string overloads
  • IONIDE-007: Replace cons-nil list patterns (x :: []) with list literal patterns ([x]), also improving readability of complex multi-element patterns in Rust/Replacements.fs
  • IONIDE-005: Replace s = "" conditionals with String.IsNullOrEmpty(s) for more efficient empty string testing
  • GRA-TYPE-ANNOTATE-001: Add type annotations to ambiguous string function calls using string<type> syntax

Note: GRA-INTERPOLATED-001 (:s/:d format specifiers) was attempted but reverted — the Standalone tests compile the compiler to JavaScript via Fable, which doesn't handle .NET-style format specifiers correctly.

Test plan

  • dotnet build src/Fable.Transforms/Fable.Transforms.fsproj — 0 errors, 0 warnings
  • ./build.sh test javascript --skip-fable-library — 2,603/2,607 passed (4 failures are pre-existing locale-dependent Convert format tests)
  • CI pipeline passes

🤖 Generated with Claude Code

Address five categories of analyzer warnings across 23 files:
- GRA-STRING-001/002/004: Add StringComparison.Ordinal to string operations
- IONIDE-007: Replace cons-nil patterns (x :: []) with list literals ([x])
- IONIDE-005: Replace empty string comparisons with String.IsNullOrEmpty
- GRA-TYPE-ANNOTATE-001: Add type annotations to ambiguous `string` calls
- GRA-INTERPOLATED-001: Add format specifiers (:s, :d) to interpolated strings

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dbrattli dbrattli changed the title Fix ~150 code scanning warnings in Fable.Transforms [All] Fix ~150 code scanning warnings in Fable.Transforms Feb 23, 2026
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Ionide.Analyzers.Cli found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@github-actions
Copy link

Python Type Checking Results (Pyright)

Metric Value
Total errors 18
Files with errors 4
Excluded files 4
New errors ✅ No
Excluded files with errors (4 files)

These files have known type errors and are excluded from CI. Remove from pyrightconfig.ci.json as errors are fixed.

File Errors Status
temp/tests/Python/test_applicative.py 12 Excluded
temp/tests/Python/test_hash_set.py 3 Excluded
temp/tests/Python/test_nested_and_recursive_pattern.py 2 Excluded
temp/tests/Python/fable_modules/thoth_json_python/encode.py 1 Excluded

…tations

Revert all :s and :d format specifiers added to interpolated strings
because Fable's Standalone tests compile the compiler to JavaScript,
and Fable doesn't handle .NET-style format specifiers correctly —
they produce literal % characters in the JS output.

Also fix string type annotations to use string<type> syntax instead
of string (x: type), which the analyzer still flagged.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Helper.ConstructorCall(constructor com ent, t, [], ?loc = r) |> Some
| t ->
$"Cannot create instance of type unresolved at compile time: %A{t}"
$"Cannot create instance of type unresolved at compile time: {t}"

Check warning

Code scanning / Ionide.Analyzers.Cli

Warns about missing type specifiers in interpolated strings Warning

Interpolated hole expression without format detected. Use prefix with the correct % to enforce type safety.
@dbrattli dbrattli changed the title [All] Fix ~150 code scanning warnings in Fable.Transforms Fix ~45 code scanning warnings in Fable.Transforms Feb 23, 2026
@dbrattli dbrattli changed the title Fix ~45 code scanning warnings in Fable.Transforms [All] Fix ~45 code scanning warnings in Fable.Transforms Feb 24, 2026
@dbrattli
Copy link
Collaborator Author

dbrattli commented Feb 27, 2026

The though with this is to reduce the number of code scanning security warnings for Fable, starting with Fable.Transforms. Currently 726 warnings which doesn't look too good. What do you think? @MangelMaxime @ncave

@MangelMaxime
Copy link
Member

I think it is a good idea to reduce the number of warnings.

Especially, because right now even if we have the F# analyzers in place personally I don't look at it because their are too many warnings. 🙈

If we get the number of warning down, or even reach zero we can then only merge a PR when it does not increase it or add new warnings 🙂

@ncave
Copy link
Collaborator

ncave commented Feb 27, 2026

@dbrattli But I miss my cons-nil list patterns (x :: []) /jk

Joking aside, it was only done just to avoid the horrible source formatting that list literals have, so the source can stay human readable. But since human readability is no longer important anyway, nobody cares, so it's all good. The less warnings, the better. 👍

@dbrattli dbrattli merged commit d9f7054 into main Feb 28, 2026
24 checks passed
@dbrattli dbrattli deleted the dbrattli/fable-warnings branch February 28, 2026 11:19
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