.editorconfig 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. ; EditorConfig to support per-solution formatting.
  2. ; Use the EditorConfig VS add-in to make this work.
  3. ; http://editorconfig.org/
  4. ;
  5. ; Here are some resources for what's supported for .NET/C#
  6. ; https://kent-boogaart.com/blog/editorconfig-reference-for-c-developers
  7. ; https://learn.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference
  8. ;
  9. ; Be **careful** editing this because some of the rules don't support adding a severity level
  10. ; For instance if you change to `dotnet_sort_system_directives_first = true:warning` (adding `:warning`)
  11. ; then the rule will be silently ignored.
  12. ; This is the default for the codeline.
  13. root = true
  14. [*]
  15. indent_style = space
  16. charset = utf-8
  17. trim_trailing_whitespace = true
  18. insert_final_newline = true
  19. [*.cs]
  20. indent_size = 4
  21. dotnet_sort_system_directives_first = true
  22. # Don't use this. qualifier
  23. dotnet_style_qualification_for_field = false:suggestion
  24. dotnet_style_qualification_for_property = false:suggestion
  25. # use int x = .. over Int32
  26. dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
  27. # use int.MaxValue over Int32.MaxValue
  28. dotnet_style_predefined_type_for_member_access = true:suggestion
  29. # Require var all the time.
  30. csharp_style_var_for_built_in_types = true:suggestion
  31. csharp_style_var_when_type_is_apparent = true:suggestion
  32. csharp_style_var_elsewhere = true:suggestion
  33. # Disallow throw expressions.
  34. csharp_style_throw_expression = false:suggestion
  35. # Newline settings
  36. csharp_new_line_before_open_brace = all
  37. csharp_new_line_before_else = true
  38. csharp_new_line_before_catch = true
  39. csharp_new_line_before_finally = true
  40. csharp_new_line_before_members_in_object_initializers = true
  41. csharp_new_line_before_members_in_anonymous_types = true
  42. # Namespace settings
  43. csharp_style_namespace_declarations = file_scoped
  44. # Brace settings
  45. csharp_prefer_braces = true # Prefer curly braces even for one line of code
  46. # name all constant fields using PascalCase
  47. dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
  48. dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
  49. dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
  50. dotnet_naming_symbols.constant_fields.applicable_kinds = field
  51. dotnet_naming_symbols.constant_fields.required_modifiers = const
  52. dotnet_naming_style.pascal_case_style.capitalization = pascal_case
  53. # internal and private fields should be _camelCase
  54. dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion
  55. dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
  56. dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
  57. dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
  58. dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal
  59. dotnet_naming_style.camel_case_underscore_style.required_prefix = _
  60. dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case
  61. [*.{xml,config,*proj,nuspec,props,resx,targets,yml,tasks}]
  62. indent_size = 2
  63. # Xml config files
  64. [*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
  65. indent_size = 2
  66. [*.json]
  67. indent_size = 2
  68. [*.{ps1,psm1}]
  69. indent_size = 4
  70. [*.sh]
  71. indent_size = 4
  72. end_of_line = lf
  73. [*.{razor,cshtml}]
  74. charset = utf-8-bom
  75. [*.{cs,vb}]
  76. # SYSLIB1054: Use 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
  77. dotnet_diagnostic.SYSLIB1054.severity = warning
  78. # CA1018: Mark attributes with AttributeUsageAttribute
  79. dotnet_diagnostic.CA1018.severity = warning
  80. # CA1047: Do not declare protected member in sealed type
  81. dotnet_diagnostic.CA1047.severity = warning
  82. # CA1305: Specify IFormatProvider
  83. dotnet_diagnostic.CA1305.severity = warning
  84. # CA1507: Use nameof to express symbol names
  85. dotnet_diagnostic.CA1507.severity = warning
  86. # CA1510: Use ArgumentNullException throw helper
  87. dotnet_diagnostic.CA1510.severity = warning
  88. # CA1511: Use ArgumentException throw helper
  89. dotnet_diagnostic.CA1511.severity = warning
  90. # CA1512: Use ArgumentOutOfRangeException throw helper
  91. dotnet_diagnostic.CA1512.severity = warning
  92. # CA1513: Use ObjectDisposedException throw helper
  93. dotnet_diagnostic.CA1513.severity = warning
  94. # CA1725: Parameter names should match base declaration
  95. dotnet_diagnostic.CA1725.severity = suggestion
  96. # CA1802: Use literals where appropriate
  97. dotnet_diagnostic.CA1802.severity = warning
  98. # CA1805: Do not initialize unnecessarily
  99. dotnet_diagnostic.CA1805.severity = warning
  100. # CA1810: Do not initialize unnecessarily
  101. dotnet_diagnostic.CA1810.severity = warning
  102. # CA1821: Remove empty Finalizers
  103. dotnet_diagnostic.CA1821.severity = warning
  104. # CA1822: Make member static
  105. dotnet_diagnostic.CA1822.severity = warning
  106. dotnet_code_quality.CA1822.api_surface = private, internal
  107. # CA1823: Avoid unused private fields
  108. dotnet_diagnostic.CA1823.severity = warning
  109. # CA1825: Avoid zero-length array allocations
  110. dotnet_diagnostic.CA1825.severity = warning
  111. # CA1826: Do not use Enumerable methods on indexable collections. Instead use the collection directly
  112. dotnet_diagnostic.CA1826.severity = suggestion
  113. # CA1827: Do not use Count() or LongCount() when Any() can be used
  114. dotnet_diagnostic.CA1827.severity = warning
  115. # CA1828: Do not use CountAsync() or LongCountAsync() when AnyAsync() can be used
  116. dotnet_diagnostic.CA1828.severity = warning
  117. # CA1829: Use Length/Count property instead of Count() when available
  118. dotnet_diagnostic.CA1829.severity = warning
  119. # CA1830: Prefer strongly-typed Append and Insert method overloads on StringBuilder
  120. dotnet_diagnostic.CA1830.severity = warning
  121. # CA1831: Use AsSpan or AsMemory instead of Range-based indexers when appropriate
  122. dotnet_diagnostic.CA1831.severity = warning
  123. # CA1832: Use AsSpan or AsMemory instead of Range-based indexers when appropriate
  124. dotnet_diagnostic.CA1832.severity = warning
  125. # CA1833: Use AsSpan or AsMemory instead of Range-based indexers when appropriate
  126. dotnet_diagnostic.CA1833.severity = warning
  127. # CA1834: Consider using 'StringBuilder.Append(char)' when applicable
  128. dotnet_diagnostic.CA1834.severity = warning
  129. # CA1835: Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync'
  130. dotnet_diagnostic.CA1835.severity = warning
  131. # CA1836: Prefer IsEmpty over Count
  132. dotnet_diagnostic.CA1836.severity = warning
  133. # CA1837: Use 'Environment.ProcessId'
  134. dotnet_diagnostic.CA1837.severity = warning
  135. # CA1838: Avoid 'StringBuilder' parameters for P/Invokes
  136. dotnet_diagnostic.CA1838.severity = warning
  137. # CA1839: Use 'Environment.ProcessPath'
  138. dotnet_diagnostic.CA1839.severity = warning
  139. # CA1840: Use 'Environment.CurrentManagedThreadId'
  140. dotnet_diagnostic.CA1840.severity = warning
  141. # CA1841: Prefer Dictionary.Contains methods
  142. dotnet_diagnostic.CA1841.severity = warning
  143. # CA1842: Do not use 'WhenAll' with a single task
  144. dotnet_diagnostic.CA1842.severity = warning
  145. # CA1843: Do not use 'WaitAll' with a single task
  146. dotnet_diagnostic.CA1843.severity = warning
  147. # CA1844: Provide memory-based overrides of async methods when subclassing 'Stream'
  148. dotnet_diagnostic.CA1844.severity = warning
  149. # CA1845: Use span-based 'string.Concat'
  150. dotnet_diagnostic.CA1845.severity = warning
  151. # CA1846: Prefer AsSpan over Substring
  152. dotnet_diagnostic.CA1846.severity = warning
  153. # CA1847: Use string.Contains(char) instead of string.Contains(string) with single characters
  154. dotnet_diagnostic.CA1847.severity = warning
  155. # CA1852: Seal internal types
  156. dotnet_diagnostic.CA1852.severity = warning
  157. # CA1854: Prefer the IDictionary.TryGetValue(TKey, out TValue) method
  158. dotnet_diagnostic.CA1854.severity = warning
  159. # CA1855: Prefer 'Clear' over 'Fill'
  160. dotnet_diagnostic.CA1855.severity = warning
  161. # CA1856: Incorrect usage of ConstantExpected attribute
  162. dotnet_diagnostic.CA1856.severity = error
  163. # CA1857: A constant is expected for the parameter
  164. dotnet_diagnostic.CA1857.severity = warning
  165. # CA1858: Use 'StartsWith' instead of 'IndexOf'
  166. dotnet_diagnostic.CA1858.severity = warning
  167. # CA2007: Consider calling ConfigureAwait on the awaited task
  168. dotnet_diagnostic.CA2007.severity = warning
  169. # CA2008: Do not create tasks without passing a TaskScheduler
  170. dotnet_diagnostic.CA2008.severity = warning
  171. # CA2009: Do not call ToImmutableCollection on an ImmutableCollection value
  172. dotnet_diagnostic.CA2009.severity = warning
  173. # CA2011: Avoid infinite recursion
  174. dotnet_diagnostic.CA2011.severity = warning
  175. # CA2012: Use ValueTask correctly
  176. dotnet_diagnostic.CA2012.severity = warning
  177. # CA2013: Do not use ReferenceEquals with value types
  178. dotnet_diagnostic.CA2013.severity = warning
  179. # CA2014: Do not use stackalloc in loops.
  180. dotnet_diagnostic.CA2014.severity = warning
  181. # CA2016: Forward the 'CancellationToken' parameter to methods that take one
  182. dotnet_diagnostic.CA2016.severity = warning
  183. # CA2022: Avoid inexact read with `Stream.Read`
  184. dotnet_diagnostic.CA2022.severity = warning
  185. # CA2200: Rethrow to preserve stack details
  186. dotnet_diagnostic.CA2200.severity = warning
  187. # CA2201: Do not raise reserved exception types
  188. dotnet_diagnostic.CA2201.severity = warning
  189. # CA2208: Instantiate argument exceptions correctly
  190. dotnet_diagnostic.CA2208.severity = warning
  191. # CA2245: Do not assign a property to itself
  192. dotnet_diagnostic.CA2245.severity = warning
  193. # CA2246: Assigning symbol and its member in the same statement
  194. dotnet_diagnostic.CA2246.severity = warning
  195. # CA2249: Use string.Contains instead of string.IndexOf to improve readability.
  196. dotnet_diagnostic.CA2249.severity = warning
  197. # IDE0005: Remove unnecessary usings
  198. dotnet_diagnostic.IDE0005.severity = warning
  199. # IDE0011: Curly braces to surround blocks of code
  200. dotnet_diagnostic.IDE0011.severity = warning
  201. # IDE0020: Use pattern matching to avoid is check followed by a cast (with variable)
  202. dotnet_diagnostic.IDE0020.severity = warning
  203. # IDE0029: Use coalesce expression (non-nullable types)
  204. dotnet_diagnostic.IDE0029.severity = warning
  205. # IDE0030: Use coalesce expression (nullable types)
  206. dotnet_diagnostic.IDE0030.severity = warning
  207. # IDE0031: Use null propagation
  208. dotnet_diagnostic.IDE0031.severity = warning
  209. # IDE0035: Remove unreachable code
  210. dotnet_diagnostic.IDE0035.severity = warning
  211. # IDE0036: Order modifiers
  212. csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion
  213. dotnet_diagnostic.IDE0036.severity = warning
  214. # IDE0038: Use pattern matching to avoid is check followed by a cast (without variable)
  215. dotnet_diagnostic.IDE0038.severity = warning
  216. # IDE0043: Format string contains invalid placeholder
  217. dotnet_diagnostic.IDE0043.severity = warning
  218. # IDE0044: Make field readonly
  219. dotnet_diagnostic.IDE0044.severity = warning
  220. # IDE0051: Remove unused private members
  221. dotnet_diagnostic.IDE0051.severity = warning
  222. # IDE0055: All formatting rules
  223. dotnet_diagnostic.IDE0055.severity = suggestion
  224. # IDE0059: Unnecessary assignment to a value
  225. dotnet_diagnostic.IDE0059.severity = warning
  226. # IDE0060: Remove unused parameter
  227. dotnet_code_quality_unused_parameters = non_public
  228. dotnet_diagnostic.IDE0060.severity = warning
  229. # IDE0062: Make local function static
  230. dotnet_diagnostic.IDE0062.severity = warning
  231. # IDE0073: File header
  232. dotnet_diagnostic.IDE0073.severity = warning
  233. file_header_template = Licensed to the .NET Foundation under one or more agreements.\nThe .NET Foundation licenses this file to you under the MIT license.
  234. # IDE0161: Convert to file-scoped namespace
  235. dotnet_diagnostic.IDE0161.severity = warning
  236. # IDE0200: Lambda expression can be removed
  237. dotnet_diagnostic.IDE0200.severity = warning
  238. # IDE2000: Disallow multiple blank lines
  239. dotnet_style_allow_multiple_blank_lines_experimental = false
  240. dotnet_diagnostic.IDE2000.severity = warning
  241. [{eng/tools/**.cs,**/{test,testassets,samples,Samples,perf,benchmarkapps,scripts,stress}/**.cs,src/Hosting/Server.IntegrationTesting/**.cs,src/Servers/IIS/IntegrationTesting.IIS/**.cs,src/Shared/Http2cat/**.cs,src/Testing/**.cs}]
  242. # CA1018: Mark attributes with AttributeUsageAttribute
  243. dotnet_diagnostic.CA1018.severity = suggestion
  244. # CA1507: Use nameof to express symbol names
  245. dotnet_diagnostic.CA1507.severity = suggestion
  246. # CA1510: Use ArgumentNullException throw helper
  247. dotnet_diagnostic.CA1510.severity = suggestion
  248. # CA1511: Use ArgumentException throw helper
  249. dotnet_diagnostic.CA1511.severity = suggestion
  250. # CA1512: Use ArgumentOutOfRangeException throw helper
  251. dotnet_diagnostic.CA1512.severity = suggestion
  252. # CA1513: Use ObjectDisposedException throw helper
  253. dotnet_diagnostic.CA1513.severity = suggestion
  254. # CA1802: Use literals where appropriate
  255. dotnet_diagnostic.CA1802.severity = suggestion
  256. # CA1805: Do not initialize unnecessarily
  257. dotnet_diagnostic.CA1805.severity = suggestion
  258. # CA1810: Do not initialize unnecessarily
  259. dotnet_diagnostic.CA1810.severity = suggestion
  260. # CA1822: Make member static
  261. dotnet_diagnostic.CA1822.severity = suggestion
  262. # CA1823: Avoid zero-length array allocations
  263. dotnet_diagnostic.CA1825.severity = suggestion
  264. # CA1826: Do not use Enumerable methods on indexable collections. Instead use the collection directly
  265. dotnet_diagnostic.CA1826.severity = suggestion
  266. # CA1827: Do not use Count() or LongCount() when Any() can be used
  267. dotnet_diagnostic.CA1827.severity = suggestion
  268. # CA1829: Use Length/Count property instead of Count() when available
  269. dotnet_diagnostic.CA1829.severity = suggestion
  270. # CA1831: Use AsSpan or AsMemory instead of Range-based indexers when appropriate
  271. dotnet_diagnostic.CA1831.severity = suggestion
  272. # CA1832: Use AsSpan or AsMemory instead of Range-based indexers when appropriate
  273. dotnet_diagnostic.CA1832.severity = suggestion
  274. # CA1833: Use AsSpan or AsMemory instead of Range-based indexers when appropriate
  275. dotnet_diagnostic.CA1833.severity = suggestion
  276. # CA1834: Consider using 'StringBuilder.Append(char)' when applicable
  277. dotnet_diagnostic.CA1834.severity = suggestion
  278. # CA1835: Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync'
  279. dotnet_diagnostic.CA1835.severity = suggestion
  280. # CA1837: Use 'Environment.ProcessId'
  281. dotnet_diagnostic.CA1837.severity = suggestion
  282. # CA1838: Avoid 'StringBuilder' parameters for P/Invokes
  283. dotnet_diagnostic.CA1838.severity = suggestion
  284. # CA1841: Prefer Dictionary.Contains methods
  285. dotnet_diagnostic.CA1841.severity = suggestion
  286. # CA1844: Provide memory-based overrides of async methods when subclassing 'Stream'
  287. dotnet_diagnostic.CA1844.severity = suggestion
  288. # CA1845: Use span-based 'string.Concat'
  289. dotnet_diagnostic.CA1845.severity = suggestion
  290. # CA1846: Prefer AsSpan over Substring
  291. dotnet_diagnostic.CA1846.severity = suggestion
  292. # CA1847: Use string.Contains(char) instead of string.Contains(string) with single characters
  293. dotnet_diagnostic.CA1847.severity = suggestion
  294. # CA1852: Seal internal types
  295. dotnet_diagnostic.CA1852.severity = suggestion
  296. # CA1854: Prefer the IDictionary.TryGetValue(TKey, out TValue) method
  297. dotnet_diagnostic.CA1854.severity = suggestion
  298. # CA1855: Prefer 'Clear' over 'Fill'
  299. dotnet_diagnostic.CA1855.severity = suggestion
  300. # CA1856: Incorrect usage of ConstantExpected attribute
  301. dotnet_diagnostic.CA1856.severity = suggestion
  302. # CA1857: A constant is expected for the parameter
  303. dotnet_diagnostic.CA1857.severity = suggestion
  304. # CA1858: Use 'StartsWith' instead of 'IndexOf'
  305. dotnet_diagnostic.CA1858.severity = suggestion
  306. # CA2007: Consider calling ConfigureAwait on the awaited task
  307. dotnet_diagnostic.CA2007.severity = suggestion
  308. # CA2008: Do not create tasks without passing a TaskScheduler
  309. dotnet_diagnostic.CA2008.severity = suggestion
  310. # CA2012: Use ValueTask correctly
  311. dotnet_diagnostic.CA2012.severity = suggestion
  312. # CA2022: Avoid inexact read with `Stream.Read`
  313. dotnet_diagnostic.CA2022.severity = suggestion
  314. # CA2201: Do not raise reserved exception types
  315. dotnet_diagnostic.CA2201.severity = suggestion
  316. # CA2249: Use string.Contains instead of string.IndexOf to improve readability.
  317. dotnet_diagnostic.CA2249.severity = suggestion
  318. # IDE0005: Remove unnecessary usings
  319. dotnet_diagnostic.IDE0005.severity = suggestion
  320. # IDE0020: Use pattern matching to avoid is check followed by a cast (with variable)
  321. dotnet_diagnostic.IDE0020.severity = suggestion
  322. # IDE0029: Use coalesce expression (non-nullable types)
  323. dotnet_diagnostic.IDE0029.severity = suggestion
  324. # IDE0030: Use coalesce expression (nullable types)
  325. dotnet_diagnostic.IDE0030.severity = suggestion
  326. # IDE0031: Use null propagation
  327. dotnet_diagnostic.IDE0031.severity = suggestion
  328. # IDE0038: Use pattern matching to avoid is check followed by a cast (without variable)
  329. dotnet_diagnostic.IDE0038.severity = suggestion
  330. # IDE0044: Make field readonly
  331. dotnet_diagnostic.IDE0044.severity = suggestion
  332. # IDE0051: Remove unused private members
  333. dotnet_diagnostic.IDE0051.severity = suggestion
  334. # IDE0059: Unnecessary assignment to a value
  335. dotnet_diagnostic.IDE0059.severity = suggestion
  336. # IDE0060: Remove unused parameters
  337. dotnet_diagnostic.IDE0060.severity = suggestion
  338. # IDE0062: Make local function static
  339. dotnet_diagnostic.IDE0062.severity = suggestion
  340. # IDE0200: Lambda expression can be removed
  341. dotnet_diagnostic.IDE0200.severity = suggestion
  342. # CA2016: Forward the 'CancellationToken' parameter to methods that take one
  343. dotnet_diagnostic.CA2016.severity = suggestion
  344. # Defaults for content in the shared src/ and shared runtime dir
  345. [{**/Shared/runtime/**.{cs,vb},src/Shared/test/Shared.Tests/runtime/**.{cs,vb},**/microsoft.extensions.hostfactoryresolver.sources/**.{cs,vb}}]
  346. # CA1822: Make member static
  347. dotnet_diagnostic.CA1822.severity = silent
  348. # IDE0011: Use braces
  349. dotnet_diagnostic.IDE0011.severity = silent
  350. # IDE0055: Fix formatting
  351. dotnet_diagnostic.IDE0055.severity = silent
  352. # IDE0060: Remove unused parameters
  353. dotnet_diagnostic.IDE0060.severity = silent
  354. # IDE0062: Make local function static
  355. dotnet_diagnostic.IDE0062.severity = silent
  356. # IDE0161: Convert to file-scoped namespace
  357. dotnet_diagnostic.IDE0161.severity = silent
  358. [{**/Shared/**.cs,**/microsoft.extensions.hostfactoryresolver.sources/**.{cs,vb}}]
  359. # IDE0005: Remove unused usings. Ignore for shared src files since imports for those depend on the projects in which they are included.
  360. dotnet_diagnostic.IDE0005.severity = silent