Skip to content

Commit 3e6ea0f

Browse files
committed
chore: use Fantomas with editorconfig settings
1 parent e078a76 commit 3e6ea0f

File tree

5 files changed

+356
-0
lines changed

5 files changed

+356
-0
lines changed

.config/dotnet-tools.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
"fornax"
1616
],
1717
"rollForward": false
18+
},
19+
"fantomas": {
20+
"version": "7.0.2",
21+
"commands": [
22+
"fantomas"
23+
],
24+
"rollForward": false
1825
}
1926
}
2027
}

.editorconfig

Lines changed: 296 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,296 @@
1+
# EditorConfig is awesome:
2+
http://EditorConfig.org
3+
4+
# top-most EditorConfig file
5+
root = true
6+
7+
###############################
8+
# Core EditorConfig Options #
9+
###############################
10+
# All files
11+
[*] # Do not apply to all files not to break something
12+
guidelines = 120 dashed, 130
13+
# Either crlf | lf, default is system-dependent (when not specified at all)
14+
# end_of_line=crlf
15+
# Remove whitespace at the end of any line
16+
17+
# Visual Studio Solution Files
18+
[*.sln]
19+
indent_style = tab
20+
21+
# Code files
22+
[*.{cs,csx,fs,fsi,fsx}]
23+
trim_trailing_whitespace = true
24+
insert_final_newline = true
25+
indent_style = space # default=space
26+
indent_size = 4 # default=4
27+
charset = utf-8
28+
29+
# Project files and app specific XML files
30+
[*.{csproj,fsproj,shproj,sfproj,projitems,props,xaml,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
31+
trim_trailing_whitespace = true
32+
insert_final_newline = true
33+
indent_style = space
34+
indent_size = 2
35+
36+
# XML configuration files
37+
[{app.config,nuget.config,packages.config,web.config}]
38+
trim_trailing_whitespace = true
39+
insert_final_newline = true
40+
indent_style = space
41+
indent_size = 2
42+
43+
# XML files
44+
[*.xml]
45+
trim_trailing_whitespace = false # do not trim as it affects CData
46+
insert_final_newline = true
47+
indent_style = space
48+
indent_size = 2
49+
50+
# JSON and YAML files
51+
[*.{json,yml,yaml}]
52+
trim_trailing_whitespace = true
53+
insert_final_newline = true
54+
indent_style = space
55+
indent_size = 2
56+
57+
# Proto files
58+
[*.proto]
59+
trim_trailing_whitespace = true
60+
insert_final_newline = true
61+
indent_style = space
62+
indent_size = 4
63+
64+
# Markdown Files
65+
[*.{md,mdx}]
66+
trim_trailing_whitespace = false
67+
68+
# Bash Files
69+
[*.{sh}]
70+
end_of_line = lf
71+
72+
# Batch Files
73+
[*.{cmd,bat}]
74+
end_of_line = crlf
75+
76+
# Powershell Files
77+
[*.{ps1, psm1}]
78+
end_of_line = crlf
79+
80+
# Paket files
81+
[paket.*]
82+
trim_trailing_whitespace = true
83+
indent_size = 2
84+
85+
[*.paket.references]
86+
trim_trailing_whitespace = true
87+
indent_size = 2
88+
89+
###############################
90+
# F# Coding Conventions #
91+
###############################
92+
# https://fsprojects.github.io/fantomas/docs/end-users/Configuration.html
93+
94+
# filetypes that need to be formatted by Fantomas:
95+
[*.{fs,fsi,fsx}]
96+
97+
# files to be ignored for Fantomas may go into this file, if present:
98+
# .fantomasignore
99+
100+
# indentation size, default=4
101+
indent_size=4
102+
103+
# line length before it gets broken down into multiple lines
104+
# default 120
105+
max_line_length=130
106+
107+
# Either crlf | lf, default is system-dependent (when not specified at all)
108+
# end_of_line=crlf
109+
110+
# Whether end-of-file has a newline, default=true
111+
insert_final_newline=true
112+
113+
# false: someLineOfCode
114+
# true: someLineOfCode;
115+
# default false
116+
fsharp_semicolon_at_end_of_line=false
117+
118+
# false: f(1,2)
119+
# true: f(1, 2)
120+
# default true
121+
fsharp_space_before_parameter=true
122+
123+
# false: Option.map(fun x -> x)
124+
# true: Option.map (fun x -> x)
125+
# default true
126+
fsharp_space_before_lowercase_invocation=true
127+
128+
# false: x.ToString()
129+
# true: x.ToString ()
130+
# default false
131+
fsharp_space_before_uppercase_invocation=true
132+
133+
# false: new Ship(withBeans)
134+
# true: new Ship (withBeans)
135+
# default false
136+
fsharp_space_before_class_constructor=true
137+
138+
# false: __.member Foo(x) = x
139+
# true: __.member Foo (x) = x
140+
# default false
141+
fsharp_space_before_member=true
142+
143+
# false: type Point = { x: int; y: int }
144+
# true: type Point = { x : int; y : int }
145+
# default false
146+
fsharp_space_before_colon=true
147+
148+
# false: (a,b,c)
149+
# true: (a, b, c)
150+
# default true
151+
fsharp_space_after_comma=true
152+
153+
# false: [a; b; 42]
154+
# true: [a ; b ; 42]
155+
# default false
156+
fsharp_space_before_semicolon=false
157+
158+
# false: [a;b;42]
159+
# true: [a; b; 42]
160+
# default true
161+
fsharp_space_after_semicolon=true
162+
163+
# false: let a = [1;2;3]
164+
# true: let a = [ 1;2;3 ]
165+
# default true
166+
fsharp_space_around_delimiter=true
167+
168+
# breaks an if-then-else in smaller parts if it is on one line
169+
# default 40
170+
fsharp_max_if_then_else_short_width=60
171+
172+
# breaks an infix operator expression if it is on one line
173+
# infix: a + b + c
174+
# default 50
175+
fsharp_max_infix_operator_expression=60
176+
177+
# breaks a single-line record declaration
178+
# i.e. if this gets too wide: { X = 10; Y = 12 }
179+
# default 40
180+
fsharp_max_record_width=80
181+
182+
# breaks a record into one item per line if items exceed this number
183+
# i.e. if set to 1, this will be on three lines: { X = 10; Y = 12 }
184+
# requires fsharp_record_multiline_formatter=number_of_items to take effect
185+
# default 1
186+
fsharp_max_record_number_of_items=1
187+
188+
# whether to use line-length (by counting chars) or items (by counting fields)
189+
# for the record settings above
190+
# either number_of_items or character_width
191+
# default character_width
192+
fsharp_record_multiline_formatter=character_width
193+
194+
# breaks a single line array or list if it exceeds this size
195+
# default 40
196+
fsharp_max_array_or_list_width=100
197+
198+
# breaks an array or list into one item per line if items exceeds this number
199+
# i.e. if set to 1, this will be shown on three lines [1; 2; 3]
200+
# requires fsharp_array_or_list_multiline_formatter=number_of_items to take effect
201+
# default 1
202+
fsharp_max_array_or_list_number_of_items=1
203+
204+
# whether to use line-length (by counting chars) or items (by counting fields)
205+
# for the list and array settings above
206+
# either number_of_items or character_width
207+
# default character_width
208+
fsharp_array_or_list_multiline_formatter=character_width
209+
210+
# maximum with of a value binding, does not include keyword "let"
211+
# default 80
212+
fsharp_max_value_binding_width=100
213+
214+
# maximum width for function and member binding (rh-side)
215+
# default 40
216+
fsharp_max_function_binding_width=80
217+
218+
# maximum width for expressions like X.DoY().GetZ(10).Help()
219+
# default 50
220+
fsharp_max_dot_get_expression_width=80
221+
222+
# whether open/close brackets go on the same column
223+
# cramped: type Range =
224+
# { From: float
225+
# To: float }
226+
# aligned: type Range =
227+
# {
228+
# From: float
229+
# To: float
230+
# }
231+
# stroustrup: type Range = {
232+
# From: float
233+
# To: float
234+
# }
235+
# default cramped
236+
fsharp_multiline_bracket_style=stroustrup
237+
238+
# whether to move the beginning of compuitation expression to the new line
239+
# true: let x =
240+
# computation {
241+
# ...
242+
# }
243+
# false: let x = computation {
244+
# ..
245+
# }
246+
fsharp_newline_before_multiline_computation_expression=false
247+
248+
# whether a newline should be placed before members
249+
# false: type Range =
250+
# { From: float }
251+
# member this.Length = this.To - this.From
252+
# true: type Range =
253+
# { From: float }
254+
#
255+
# member this.Length = this.To - this.From
256+
# default false
257+
fsharp_newline_between_type_definition_and_members=true
258+
259+
# if a function sign exceeds max_line_length, then:
260+
# false: do not place the equal-sign on a single line
261+
# true: place the equal-sign on a single line
262+
# default false
263+
fsharp_align_function_signature_to_indentation=false
264+
265+
# see docs: https://github.com/fsprojects/fantomas/blob/master/docs/Documentation.md#fsharp_alternative_long_member_definitions
266+
# default false
267+
fsharp_alternative_long_member_definitions=true
268+
269+
# places closing paren in lambda on a newline in multiline lambdas
270+
# default false
271+
fsharp_multi_line_lambda_closing_newline=true
272+
273+
# allows the 'else'-branch to be aligned at same level as 'else' if the ret type allows it
274+
# false: match x with
275+
# | null -> ()
276+
# | _ -> ()
277+
# true: match x with
278+
# | null -> ()
279+
# | _ ->
280+
# ()
281+
# default false
282+
fsharp_keep_indent_in_branch=true
283+
284+
# whether a bar is placed before DU
285+
# false: type MyDU = Short of int
286+
# true: type MyDU = | Short of int
287+
# default false
288+
fsharp_bar_before_discriminated_union_declaration=false
289+
290+
# multiline, nested expressions must be surrounded by blank lines
291+
# default true
292+
fsharp_blank_lines_around_nested_multiline_expressions=false
293+
294+
# set maximal number of consecutive blank lines to keep from original source
295+
# it doesn't change number of new blank lines generated by Fantomas
296+
fsharp_keep_max_number_of_blank_lines=2

.fantomasignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Ignore AssemblyInfo files
2+
AssemblyInfo.fs

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
- Add `.editorconfig` with F# settings #727 [@xperiandri]
11+
812
## [0.25.0] - 2025-07-11
913

1014
- Migrate from `Paket` to `Directory.Packages.props` #722 [@xperiandri]

Directory.Build.targets

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!--
2+
This file allows overriding of properties for all projects in the directory.
3+
See https://learn.microsoft.com/en-us/visualstudio/msbuild/customize-by-directory?view=vs-2022#directorybuildprops-and-directorybuildtargets
4+
-->
5+
<Project>
6+
7+
<PropertyGroup>
8+
<_BuildProjBaseIntermediateOutputPath>$(MSBuildThisFileDirectory)build/obj/</_BuildProjBaseIntermediateOutputPath>
9+
<_DotnetToolManifestFile>$(MSBuildThisFileDirectory).config/dotnet-tools.json</_DotnetToolManifestFile>
10+
<_DotnetToolRestoreOutputFile>$(_BuildProjBaseIntermediateOutputPath)/dotnet-tool-restore-$(NETCoreSdkVersion)-$(OS)</_DotnetToolRestoreOutputFile>
11+
<_DotnetFantomasOutputFile>$(BaseIntermediateOutputPath)dotnet-fantomas-msbuild-$(NETCoreSdkVersion)-$(OS)</_DotnetFantomasOutputFile>
12+
</PropertyGroup>
13+
14+
<!-- Make sure that dotnet tools are up to date before restoring any project -->
15+
<Target Name="ToolUpdate"
16+
BeforeTargets="ResolveNuGetPackageAssets;BeforeCompile"
17+
Condition=" '$(BuildingProject)' == 'false' OR '$(DesignTimeBuild)' == 'true' "
18+
Inputs="$(_DotnetToolManifestFile)"
19+
Outputs="$(_DotnetToolUpdateOutputFile)">
20+
<Message Text="Updating dotnet tools..." Importance="High" />
21+
<Exec Command="dotnet tool update --all" WorkingDirectory="$(MSBuildThisFileDirectory)" StandardOutputImportance="High" StandardErrorImportance="High" />
22+
<MakeDir Directories="$(_BuildProjBaseIntermediateOutputPath)"/>
23+
<Touch Files="$(_DotnetToolUpdateOutputFile)" AlwaysCreate="True" ForceTouch="True" />
24+
<Message Text="All tools updated successfully. Updates marked as complete." Importance="High" />
25+
</Target>
26+
27+
<!-- Make sure that dotnet tools are restored before restoring any project -->
28+
<Target Name="ToolRestore"
29+
BeforeTargets="ResolveNuGetPackageAssets;BeforeCompile"
30+
AfterTargets="ToolUpdate"
31+
Condition=" '$(BuildingProject)' == 'false' OR '$(DesignTimeBuild)' == 'true' "
32+
Inputs="$(_DotnetToolManifestFile)"
33+
Outputs="$(_DotnetToolRestoreOutputFile)">
34+
<Message Text="Restoring dotnet tools..." Importance="High" />
35+
<Exec Command="dotnet tool restore" WorkingDirectory="$(MSBuildThisFileDirectory)" StandardOutputImportance="High" StandardErrorImportance="High" />
36+
<MakeDir Directories="$(_BuildProjBaseIntermediateOutputPath)"/>
37+
<Touch Files="$(_DotnetToolRestoreOutputFile)" AlwaysCreate="True" ForceTouch="True" />
38+
<Message Text="All .NET tools restored successfully." Importance="High" />
39+
</Target>
40+
41+
<!-- Make sure that files are formatted before building -->
42+
<Target Name="Format" Condition=" '$(MSBuildProjectExtension)' == '.fsproj' AND '$(DesignTimeBuild)' != 'true' " BeforeTargets="BeforeBuild" Inputs="@(Compile)" Outputs="$(_DotnetFantomasOutputFile)" >
43+
<Exec Command="dotnet tool run fantomas $(MSBuildProjectDirectory)" StandardOutputImportance="High" StandardErrorImportance="High" WorkingDirectory="$(MSBuildThisFileDirectory)" ContinueOnError="WarnAndContinue" />
44+
<Touch Files="$(_DotnetFantomasOutputFile)" AlwaysCreate="True" ForceTouch="True" />
45+
</Target>
46+
47+
</Project>

0 commit comments

Comments
 (0)