Skip to content

Commit af01019

Browse files
purkhusidalexeagle
andauthored
feat: Add formatting support for C# and F# (#650)
## What? Adds formatting support for F# and C# using fantomas(F#) and CSharpier(C#) The formatters are not avilable as standalone executables and are provided as NuGet packages via rules_dotnet by the end-user for rules_lint --- ### Changes are visible to end-users: yes <!-- If no, please delete this section. --> - Searched for relevant documentation and updated as needed: yes - Breaking change (forces users to change their own code or config): no - Suggested release notes appear below: yes ### Test plan - New test cases added --------- Co-authored-by: Alex Eagle <[email protected]>
1 parent 56a314b commit af01019

File tree

18 files changed

+120
-0
lines changed

18 files changed

+120
-0
lines changed

example/3rdparty/nuget/BUILD.bazel

Whitespace-only changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"GENERATED"
2+
3+
load("@rules_dotnet//dotnet:defs.bzl", "nuget_repo")
4+
5+
def main():
6+
"main"
7+
nuget_repo(
8+
name = "paket.main",
9+
packages = [
10+
{"name": "CSharpier", "id": "CSharpier", "version": "1.1.2", "sha512": "sha512-YG6asSE2fsk56QAqlPmuY8QHemWyJa+UDUh53PzynIONM9sC/u1hUjlZw/gsjx/AF+DOT3Q7Xm/U/BMhuoW/Hw==", "sources": ["https://api.nuget.org/v3/index.json"], "dependencies": {"net11": [], "net20": [], "net30": [], "net35": [], "net40": [], "net403": [], "net45": [], "net451": [], "net452": [], "net46": [], "net461": [], "net462": [], "net47": [], "net471": [], "net472": [], "net48": [], "net5.0": [], "net6.0": [], "net7.0": [], "net8.0": [], "net9.0": [], "netcoreapp1.0": [], "netcoreapp1.1": [], "netcoreapp2.0": [], "netcoreapp2.1": [], "netcoreapp2.2": [], "netcoreapp3.0": [], "netcoreapp3.1": [], "netstandard": [], "netstandard1.0": [], "netstandard1.1": [], "netstandard1.2": [], "netstandard1.3": [], "netstandard1.4": [], "netstandard1.5": [], "netstandard1.6": [], "netstandard2.0": [], "netstandard2.1": []}, "targeting_pack_overrides": [], "framework_list": [], "tools": {"net10.0": [{"name": "csharpier", "entrypoint": "CSharpier.dll", "runner": "dotnet"}], "net8.0": [{"name": "csharpier", "entrypoint": "CSharpier.dll", "runner": "dotnet"}], "net9.0": [{"name": "csharpier", "entrypoint": "CSharpier.dll", "runner": "dotnet"}]}},
11+
{"name": "fantomas", "id": "fantomas", "version": "7.0.3", "sha512": "sha512-CCpCQzxLUh+r9sxTGYUKmtNoTBE/J/XDiVSwf+ge+4l9lnW7+R4pLuL7K4sOIbok8l95IvGA4XLFjS0B0ZEQdA==", "sources": ["https://api.nuget.org/v3/index.json"], "dependencies": {"net11": [], "net20": [], "net30": [], "net35": [], "net40": [], "net403": [], "net45": [], "net451": [], "net452": [], "net46": [], "net461": [], "net462": [], "net47": [], "net471": [], "net472": [], "net48": [], "net5.0": [], "net6.0": [], "net7.0": [], "net8.0": [], "net9.0": [], "netcoreapp1.0": [], "netcoreapp1.1": [], "netcoreapp2.0": [], "netcoreapp2.1": [], "netcoreapp2.2": [], "netcoreapp3.0": [], "netcoreapp3.1": [], "netstandard": [], "netstandard1.0": [], "netstandard1.1": [], "netstandard1.2": [], "netstandard1.3": [], "netstandard1.4": [], "netstandard1.5": [], "netstandard1.6": [], "netstandard2.0": [], "netstandard2.1": []}, "targeting_pack_overrides": [], "framework_list": [], "tools": {"net8.0": [{"name": "fantomas", "entrypoint": "fantomas.dll", "runner": "dotnet"}]}},
12+
{"name": "Paket", "id": "Paket", "version": "9.0.2", "sha512": "sha512-VPMh+F1IvraKlKUJlVjI/nyr5eyKQMNLKbGcFo+pKpcvN2bAnrFl5WafGZ4A/ZTzLl0eyjb3AVcLx8Z/S8DF0g==", "sources": ["https://api.nuget.org/v3/index.json"], "dependencies": {"net11": [], "net20": [], "net30": [], "net35": [], "net40": [], "net403": [], "net45": [], "net451": [], "net452": [], "net46": [], "net461": [], "net462": [], "net47": [], "net471": [], "net472": [], "net48": [], "net5.0": [], "net6.0": [], "net7.0": [], "net8.0": [], "net9.0": [], "netcoreapp1.0": [], "netcoreapp1.1": [], "netcoreapp2.0": [], "netcoreapp2.1": [], "netcoreapp2.2": [], "netcoreapp3.0": [], "netcoreapp3.1": [], "netstandard": [], "netstandard1.0": [], "netstandard1.1": [], "netstandard1.2": [], "netstandard1.3": [], "netstandard1.4": [], "netstandard1.5": [], "netstandard1.6": [], "netstandard2.0": [], "netstandard2.1": []}, "targeting_pack_overrides": [], "framework_list": [], "tools": {"netcoreapp3.1": [{"name": "paket", "entrypoint": "paket.dll", "runner": "dotnet"}]}},
13+
],
14+
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"Generated"
2+
3+
load(":paket.main.bzl", _main = "main")
4+
5+
def _main_impl(module_ctx):
6+
_main()
7+
return module_ctx.extension_metadata(reproducible = True)
8+
9+
main_extension = module_extension(
10+
implementation = _main_impl,
11+
)

example/MODULE.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ bazel_dep(name = "aspect_rules_swc", version = "2.0.0")
99
bazel_dep(name = "aspect_rules_ts", version = "3.0.0")
1010
bazel_dep(name = "bazel_lib", version = "3.0.0-rc.0")
1111
bazel_dep(name = "rules_buf", version = "0.5.2")
12+
bazel_dep(name = "rules_dotnet", version = "0.20.5")
1213
bazel_dep(name = "bazel_features", version = "1.29.0")
1314
bazel_dep(name = "bazel_skylib", version = "1.4.2")
1415
bazel_dep(name = "toolchains_llvm", version = "1.1.2")
@@ -130,6 +131,16 @@ rust.toolchain(
130131
versions = ["1.75.0"],
131132
)
132133

134+
# Configure .Net toolchains
135+
dotnet = use_extension("@rules_dotnet//dotnet:extensions.bzl", "dotnet")
136+
dotnet.toolchain(dotnet_version = "9.0.306")
137+
use_repo(dotnet, "dotnet_toolchains")
138+
139+
register_toolchains("@dotnet_toolchains//:all")
140+
141+
main_extension = use_extension("//3rdparty/nuget:paket.main_extension.bzl", "main_extension")
142+
use_repo(main_extension, "paket.main")
143+
133144
ruby = use_extension("@rules_ruby//ruby:extensions.bzl", "ruby")
134145
ruby.toolchain(
135146
name = "ruby",

example/paket.dependencies

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
framework: net9.0
2+
source https://api.nuget.org/v3/index.json
3+
storage: none
4+
5+
nuget Paket 9.0.2
6+
nuget fantomas 7.0.3
7+
nuget CSharpier 1.1.2

example/paket.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
STORAGE: NONE
2+
RESTRICTION: == net9.0
3+
NUGET
4+
remote: https://api.nuget.org/v3/index.json
5+
CSharpier (1.1.2)
6+
fantomas (7.0.3)
7+
Paket (9.0.2)

example/src/hello.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace HelloWorldApp {
4+
5+
class Geeks {
6+
7+
static void Main(string[] args) {
8+
Console.WriteLine("Hello World!");Console.ReadKey();
9+
}
10+
}
11+
}

example/src/hello.fs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
open System
2+
3+
[<EntryPoint>]
4+
let main argv =
5+
printfn "Hello World";Console.ReadLine() |> ignore
6+
0

example/tools/BUILD.bazel

Whitespace-only changes.

example/tools/bzlmod.bzl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""Utility functions for Bzlmod-related checks."""
2+
3+
def bzlmod_is_enabled():
4+
"""Returns True if Bzlmod is enabled, False otherwise."""
5+
str(Label("//:invalid")).startswith("@@")

0 commit comments

Comments
 (0)