Visitar URL original
GitHub - dprint/dprint-plugin-csharpier: Wrapper formatting plugin around csharpier. · GitHub
Skip to content

About

Wrapper formatting plugin around csharpier.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

dprint-plugin-csharpier

npm version CI

Wrapper around CSharpier in order to use it as a dprint plugin for C# and XML code formatting.

Install

  1. Install dprint 0.61.0 or later
  2. Run dprint init
  3. Run dprint add csharpier

It formats the same files as CSharpier: .cs and .csx files as C#, and .csproj, .props, .targets, .slnx, .config, .xml, .xaml, and .axaml files as XML. Use dprint's "associations" property to change this.

Like CSharpier, it doesn't format generated files (ex. *.g.cs, *.designer.cs, or a C# file starting with an <auto-generated> comment) unless "includeGenerated" is true.

Configuration

Specify a "csharpier" configuration property in dprint.json if desired:

{
  // etc...
  "csharpier": {
    "lineWidth": 120,
    "xml.indentWidth": 4
  }
}
Property CSharpier option Default
lineWidth printWidth 100
indentWidth indentSize 4 for C# and 2 for XML
useTabs useTabs false
newLineKind endOfLine "auto"
includeGenerated --include-generated false
xmlWhitespaceSensitivity xmlWhitespaceSensitivity "ignore" for .xaml and .axaml, otherwise "strict"

The lineWidth, indentWidth, useTabs, and newLineKind properties use the global configuration when not specified, and may be specified for only C# or XML files by prefixing them with csharp. or xml. (ex. "csharp.lineWidth": 120).

The plugin doesn't read CSharpier's configuration files (.csharpierrc or .editorconfig) because dprint plugins don't have access to the file system, so configure it in the dprint configuration file instead.

Development

The plugin is compiled to a Wasm module using NativeAOT-LLVM.

  1. Run the tests with dotnet test
  2. Install version 29 of the WASI SDK and set the WASI_SDK_PATH environment variable to its directory.
  3. Run dotnet publish DprintPluginCSharpier -c Release -r wasi-wasm, which creates DprintPluginCSharpier/bin/Release/net10.0/wasi-wasm/publish/dprint-plugin-csharpier.wasm
  4. Reference the path to the .wasm file in the "plugins" array of a dprint configuration file to try it out.
  5. Update the generated configuration schema at deployment/schema.json by running dotnet test with the UPDATE=1 environment variable.
  6. Run the tests that format with the .wasm file in dprint by setting the DPRINT_CSHARPIER_WASM_PATH environment variable to its path and running dotnet test --filter TestCategory=Wasm. These use the dprint on the path or the executable at the DPRINT_PATH environment variable.

dprint only provides the WASI preview 1 functions to Wasm plugins, so the module must not import anything else. DprintPluginCSharpier/ILLink.Substitutions.xml and the feature switches in the project file keep code that would import other functions out of the module.

Releasing

Run the release workflow, which bumps the version and pushes a tag. The CI workflow then publishes the GitHub release and the npm package for the tag.

About

Wrapper formatting plugin around csharpier.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages