Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,43 @@ Scripts require a debug build first (`dotnet build src/Fantomas/Fantomas.fsproj`

## Code Style

Annotate every parameter and the return type on a function, even where inference would manage
without it:
Annotate every `let` binding, even where inference would manage without it. On a function that
means every parameter and the return type; on a value it means the type:

```fsharp
let writeRow (column: int) (left: string) (right: string) : unit = ...

let extensions: Set<string> = set [| ".fs"; ".fsx"; ".fsi"; ".ml"; ".mli" |]
```

A written signature reads as documentation, and a wrong assumption fails at the definition
rather than at a call site somewhere else. Both matter more when the reader is skimming
unfamiliar code, which is most of the time. Modules with a signature file already state this at
the boundary; annotate the implementation as well.
A written type reads as documentation, and a wrong assumption fails at the definition rather than
at a call site somewhere else. Both matter more when the reader is skimming unfamiliar code, which
is most of the time, and a reader should not have to run the inference in their head to find out
what a name holds. Modules with a signature file already state this at the boundary; annotate the
implementation as well.

This applies inside a function as much as at the top level: a local `let` in a long body is
exactly where a reader loses track of what something is.

This is guidance for code you are writing or revisiting, not a reason to sweep the codebase.
When you touch a function for some other reason, add the annotations it is missing. Leave the
functions you had no reason to open alone.
When you touch a binding for some other reason, add the annotations it is missing. Leave the
bindings you had no reason to open alone.

In a file that has a signature file, the signature file is the visibility boundary: anything it
does not list is already hidden. Do not write `let private` there. The keyword adds nothing and
suggests the `.fsi` says something it does not.

Documentation comments belong in the signature file only, never in both. A `///` in the `.fs`
alongside one in the `.fsi` is a second copy to keep in step, and the one readers and tooling see
is the signature.

## Changelog

When updating `CHANGELOG.md`, add new entries to the **end** of the relevant section (e.g. `### Fixed`), not the top. One entry per issue.

## Post-task Steps

Run these after completing a task, not during iterative development — analyzers can be slow.
Run these after completing a task rather than during iterative development.

### Format

Expand All @@ -59,4 +73,13 @@ dotnet fsi build.fsx -- -p FormatAll
dotnet fsi build.fsx -- -p Analyze
```

Output goes to `analysis.sarif` in the repo root.
Output goes to `analysis.sarif` in the repo root. This is safe to run whenever you need it; it no
longer saturates the machine.

**Read `analysis.sarif` afterwards.** The pipeline writes its findings there and exits 0 whatever
it found, so a run finishing tells you nothing. GitHub raises the same findings as code scanning
alerts on the pull request, which is a slower way to learn about them.

When you read it, read the results for every project you touched. Filtering the paths down to
`src/Fantomas/` looks right and silently drops `src/Fantomas.Tests/`, which does not contain that
substring. Match on `src/` and look at what comes back.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
- Breaking: the `--help` page is written by Fantomas instead of by Argu. It carries the version, worked examples, what an input path may be, and links to the documentation, the F# Discord and the `llms.txt` files an LLM can read. Colours are used when the terminal supports them and dropped when standard out is redirected. `-h` is now accepted alongside `--help`. An argument error reports the complaint on standard error followed by a pointer to `--help`, where it used to print Argu's usage block. [#3402](https://github.com/fsprojects/fantomas/pull/3402)
- Breaking: a run over a single file reports the path it was given instead of only the file name, so `fantomas src/A.fs` prints `src/A.fs was formatted.` where it printed `A.fs was formatted.`. The same applies to the unchanged, ignored and failure messages. A run over several files already reported the path, so the two now agree. [#3404](https://github.com/fsprojects/fantomas/pull/3404)
- Breaking: a file that cannot be parsed is reported with the position of every diagnostic the parser produced, one MSBuild style line each, followed by a snippet of the source with two lines of context either side and a caret under the offending range. This replaces `Could not parse the file.` for a format run, the `%A` record dump and stack trace for a `--check` run, and the same `%A` dump the daemon used to hand editors. Diagnostics are ordered by position and columns are one based, matching what the F# compiler prints for the same file. [#3405](https://github.com/fsprojects/fantomas/pull/3405)
- Breaking: the messages for an input path Fantomas cannot work with are now the same whether the run formats or checks. `--check` used to report `Input path 'x' is unsupported file type` and `Input path 'x' not found` without a full stop where a format run ended both with one, and a run with no input path at all said `No input path provided.` when checking and `Input path is missing.` when formatting. Both now report `Input path 'x' is an unsupported file type.`, `Input path 'x' not found.` and `No input path provided. Call with --help for usage information.` [#3406](https://github.com/fsprojects/fantomas/pull/3406)
- Breaking: a single file that `.fantomasignore` matches is reported the same way as an ignored file found while walking a folder. `fantomas A.fs` on an ignored file printed nothing unless `--verbosity d` was given, where `fantomas ./folder` containing only that file printed `A.fs was ignored.` Both now print it. A `--check` run reports the files it ignored at detailed verbosity whether they were named directly or found in a folder, where before only a directly named file was reported. [#3406](https://github.com/fsprojects/fantomas/pull/3406)
- At detailed verbosity, a run writing to `--out` now notes a file it found already formatted, as a run formatting in place always did. Both paths decide what formatting came to in the same place, so they say the same things about it. [#3406](https://github.com/fsprojects/fantomas/pull/3406)

### Fixed

Expand All @@ -22,6 +25,11 @@
- `--out <file>` failed with `Failed to format file` and exit code 1 when the folder of the given path did not exist. Fantomas now creates it, along with the subfolders that mirroring an input folder needs. [#3403](https://github.com/fsprojects/fantomas/pull/3403)
- `--out` naming the input folder under a different spelling, such as `fantomas src --out ./src`, emptied every file it was given. The output file was opened, and therefore truncated, before the input was read. Nothing is written now until formatting has produced the text to write, which also leaves the previous output in place when formatting fails. [#3403](https://github.com/fsprojects/fantomas/pull/3403)
- `--out` pointing inside the input folder, such as `fantomas src --out src/formatted`, formatted the previous run's output again and nested it one folder deeper on every run. The output folder is left out of the input scan. [#3403](https://github.com/fsprojects/fantomas/pull/3403)
- `fantomas src/ --out src` formatted nothing and reported an empty table, where `fantomas src --out src` formatted the folder in place. A trailing separator made the two paths compare as different places, so every file below the input folder was taken for a previous run's output and skipped. The same applied to `fantomas src --out src/`. [#3406](https://github.com/fsprojects/fantomas/pull/3406)
- A file whose extension is not lowercase, such as `A.FS`, was refused as an unsupported file type, and one found while walking a folder was skipped. The extension is now compared without case, which is what a volume that ignores case, as macOS and Windows usually do, means by the same file. [#3406](https://github.com/fsprojects/fantomas/pull/3406)
- Given several input paths, a folder whose name contains a dot, such as `fantomas my.stuff src`, was taken for a file and reported as `Failed to format file`. A file with no extension was taken for a folder. Which one a path is, is now asked of the file system rather than guessed from the name. A single input path was already classified this way. [#3406](https://github.com/fsprojects/fantomas/pull/3406)
- A `.fantomasignore` pattern that cannot be matched against a path reported the raw exception, with its stack trace, through `%A`. It now names the file and the ignore file that could not be told apart, and keeps the exception for detailed verbosity. [#3406](https://github.com/fsprojects/fantomas/pull/3406)
- `--profile` reported `Line count: 0` for a file whose line endings are not the ones the platform uses, because it counted occurrences of the platform's newline rather than line breaks. A file saved with line feeds counted nothing on Windows, and one saved with carriage returns counted nothing elsewhere. [#3406](https://github.com/fsprojects/fantomas/pull/3406)

## [8.0.0-alpha-014] - 2026-08-20

Expand Down
70 changes: 56 additions & 14 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,25 @@ let packagesDir = artifactsDir </> "package" </> "release"
let analysisReportsDir = __SOURCE_DIRECTORY__ </> "analysisreports"
let coverageReportDir = __SOURCE_DIRECTORY__ </> "coveragereport"

let coverageXml =
__SOURCE_DIRECTORY__ </> "src" </> "Fantomas.Core.Tests" </> "coverage.xml"
/// Every test project, by name. Each writes its raw coverage beside its own project file.
let coverageProjects: string list =
[ "Fantomas.Core.Tests"; "Fantomas.Tests"; "Fantomas.Client.Tests" ]

let coverageXmlFiles: string list =
coverageProjects
|> List.map (fun (name: string) -> __SOURCE_DIRECTORY__ </> "src" </> name </> "coverage.xml")

/// Run one test project under AltCover, measuring the one assembly it is there to exercise.
///
/// The filter is a negative lookahead: instrument that assembly and nothing else, which keeps the
/// generated Fantomas.FCS parser and the test assembly itself out of the report and makes the run
/// fast. It cannot name several assemblies at once, because AltCover reads `|` as the separator
/// between filters rather than as alternation, so each project is run with its own.
let coverageCommand (name: string) (assemblyPattern: string) : string =
let project: string = __SOURCE_DIRECTORY__ </> "src" </> name </> $"{name}.fsproj"

$"dotnet test {project} -c Release /p:AltCover=true "
+ $"\"/p:AltCoverAssemblyFilter=^(?!{assemblyPattern}$)\""

let benchmarkAssembly =
binDir </> "Fantomas.Benchmarks" </> "release" </> "Fantomas.Benchmarks.dll"
Expand Down Expand Up @@ -108,29 +125,54 @@ pipeline "Benchmark" {
runIfOnlySpecified true
}

// Line and branch coverage for Fantomas.Core, via AltCover's MSBuild integration.
// Line and branch coverage for the three projects Fantomas ships, via AltCover's MSBuild
// integration. Every test project is run under AltCover, each measuring the one assembly it is
// there to exercise, and ReportGenerator merges the three results into a single report.
//
// The filter is a negative lookahead: instrument Fantomas.Core and nothing else, which keeps the
// generated Fantomas.FCS parser (and the test assembly itself) out of the report and makes the
// run fast. AltCover writes OpenCover XML, which is for tooling rather than reading, so
// ReportGenerator turns it into a browsable HTML report afterwards.
// So `Fantomas.Core`'s figure comes from `Fantomas.Core.Tests` alone, even though `Fantomas.Tests`
// exercises Core heavily through real formatting. Core is understated here rather than wrong.
//
// The filter is a negative lookahead naming the three assemblies to instrument. Everything else
// is left alone, which keeps the generated Fantomas.FCS parser and the test assemblies
// themselves out of the report. AltCover writes OpenCover XML, which is for tooling rather than
// reading, so ReportGenerator turns it into a browsable HTML report afterwards.
//
// A test that starts the fantomas process, as those in Fantomas.Tests/Integration do, adds
// nothing here, because the child process is not instrumented. That is the point rather than a
// flaw: what this measures is how much of the tool can be reached without starting one.
//
// Produces:
// src/Fantomas.Core.Tests/coverage.xml raw OpenCover XML
// coveragereport/index.html browsable report, per file and per line
// src/<project>/coverage.xml raw OpenCover XML, one per test project
// coveragereport/index.html browsable report, per file and per line
pipeline "Coverage" {
workingDir __SOURCE_DIRECTORY__
stage "RestoreTools" { run "dotnet tool restore" }
stage "Clean" { run (cleanFolders [| coverageReportDir |]) }

stage "Clean" {
run (cleanFolders [| coverageReportDir |])
// A stale coverage.xml from an earlier run would otherwise be merged into the report.
run (fun _ ->
async {
for file in coverageXmlFiles do
if File.Exists file then
File.Delete file

return 0
})
}

stage "Coverage" {
run
@"dotnet test src/Fantomas.Core.Tests/Fantomas.Core.Tests.fsproj -c Release /p:AltCover=true ""/p:AltCoverAssemblyFilter=^(?!Fantomas\.Core$)"""
run (coverageCommand "Fantomas.Core.Tests" @"Fantomas\.Core")
run (coverageCommand "Fantomas.Tests" "fantomas")
run (coverageCommand "Fantomas.Client.Tests" @"Fantomas\.Client")
}

stage "Report" {
run
$"dotnet reportgenerator -reports:{coverageXml} -targetdir:{coverageReportDir} -reporttypes:Html;TextSummary"
run (
$"dotnet reportgenerator -reports:{String.Join(';', coverageXmlFiles)} "
+ $"-targetdir:{coverageReportDir} -reporttypes:Html;TextSummary"
)

run (fun _ ->
async {
let summary = coverageReportDir </> "Summary.txt"
Expand Down
5 changes: 5 additions & 0 deletions docs/docs/end-users/UpgradeGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ fsharp_experimental_stroustrup_style = true
- A file that cannot be parsed is reported with the position of each diagnostic instead of `Could not parse the file.`, one line per diagnostic in the shape `src/A.fs(3,9): error FS0583: Unmatched '('`, followed by the source around the failure with a caret under it. `--check` reported the same failure as an exception dump with a stack trace and now uses this as well. A script that matched on `Could not parse the file.` needs to match on the new text.
- The `--help` page is written by Fantomas instead of by Argu, and `-h` is accepted alongside `--help`. An argument error prints its complaint on standard error followed by a pointer to `--help`, where it used to print Argu's usage block.
- `--out` now mirrors the structure of the input folder, and creates the folders it needs.
- The message for an input path Fantomas cannot work with is the same whether the run formats or checks. `--check` reported `Input path 'x' is unsupported file type` and `Input path 'x' not found` without a full stop, and a run with no input path at all said `Input path is missing.` when formatting and `No input path provided.` when checking. All of them now read `Input path 'x' is an unsupported file type.`, `Input path 'x' not found.` and `No input path provided. Call with --help for usage information.` A script matching on the old text needs updating.
- A file whose extension is not lowercase, such as `A.FS`, is now formatted. Up to `v7` it was refused as an unsupported file type when named directly, and passed over when found while walking a folder, so a folder run can now touch files it used to leave alone.
- `fantomas src/ --out src` now formats the folder in place. Up to `v7` a trailing separator made the two paths count as different places, so every file was taken for the previous run's output and skipped: the run printed an empty table and exited 0 without formatting anything. The same applied to `fantomas src --out src/`. A build step that used either spelling was doing nothing and will start doing the work.
- Several input paths are told apart by asking the file system rather than by whether they carry an extension. Up to `v7`, `fantomas my.stuff src` reported `Failed to format file: my.stuff` and exited 1, because a folder whose name contains a dot was taken for a file. It now formats the folder. The converse also held: a path with no extension was taken for a folder, so naming a file that way ended the whole run rather than that one file.
- A single file matched by `.fantomasignore` reports `A.fs was ignored.` on standard out. Up to `v7` it printed nothing unless `--verbosity d` was given, even though a folder run whose only file was that same one reported it at normal verbosity. The two now agree.

#### `--out <folder>` mirrors the input folder

Expand Down
1 change: 1 addition & 0 deletions src/Fantomas.Client.Tests/Fantomas.Client.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="AltCover" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions src/Fantomas.Client.Tests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
"version": 2,
"dependencies": {
"net10.0": {
"altcover": {
"type": "Direct",
"requested": "[9.0.102, )",
"resolved": "9.0.102",
"contentHash": "q3Rf5t0M9kXlcO5qhsaAe6NrFSNd5enrhKmF/Ezgmomqw34PbUTbRSYjSDNhS3YGDyUrPTkyPn14EfLDJWztcA=="
},
"CliWrap": {
"type": "Direct",
"requested": "[3.10.0, )",
Expand Down
Loading