Skip to content

csharpier

GitHub stars formatter GitHub release (latest SemVer) GitHub last commit GitHub commit activity GitHub contributors

csharpier documentation

csharpier - GitHub

Configuration in MegaLinter

Variable Description Default value
CSHARP_CSHARPIER_ARGUMENTS User custom arguments to add in linter CLI call
Ex: -s --foo "bar"
CSHARP_CSHARPIER_COMMAND_REMOVE_ARGUMENTS User custom arguments to remove from command line before calling the linter
Ex: -s --foo "bar"
CSHARP_CSHARPIER_FILTER_REGEX_INCLUDE Custom regex including filter
Ex: (src\|lib)
Include every file
CSHARP_CSHARPIER_FILTER_REGEX_EXCLUDE Custom regex excluding filter
Ex: (test\|examples)
Exclude no file
CSHARP_CSHARPIER_CLI_LINT_MODE Override default CLI lint mode
- file: Calls the linter for each file
- list_of_files: Call the linter with the list of files as argument
- project: Call the linter from the root of the project
list_of_files
CSHARP_CSHARPIER_FILE_EXTENSIONS Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all files
Ex: [".py", ""]
[".cs"]
CSHARP_CSHARPIER_FILE_NAMES_REGEX File name regex filters. Regular expression list for filtering files by their base names using regex full match. Empty list includes all files
Ex: ["Dockerfile(-.+)?", "Jenkinsfile"]
Include every file
CSHARP_CSHARPIER_PRE_COMMANDS List of bash commands to run before the linter None
CSHARP_CSHARPIER_POST_COMMANDS List of bash commands to run after the linter None
CSHARP_CSHARPIER_UNSECURED_ENV_VARIABLES List of env variables explicitly not filtered before calling CSHARP_CSHARPIER and its pre/post commands None
CSHARP_CSHARPIER_CONFIG_FILE csharpier configuration file nameUse LINTER_DEFAULT to let the linter find it .csharpierrc
CSHARP_CSHARPIER_RULES_PATH Path where to find linter configuration file Workspace folder, then MegaLinter default rules
CSHARP_CSHARPIER_DISABLE_ERRORS Run linter but consider errors as warnings true
CSHARP_CSHARPIER_DISABLE_ERRORS_IF_LESS_THAN Maximum number of errors allowed 0
CSHARP_CSHARPIER_CLI_EXECUTABLE Override CLI executable ['dotnet-csharpier']

IDE Integration

Use csharpier in your favorite IDE to catch errors before MegaLinter !

IDE Extension Name Install
rider csharpier Visit Web Site
visual_studio CSharpier Visit Web Site
Visual Studio Code csharpier-vscode Install in VSCode

MegaLinter Flavours

This linter is available in the following flavours

Flavor Description Embedded linters Info
all Default MegaLinter Flavor 125 Docker Image Size (tag) Docker Pulls
dotnet Optimized for C, C++, C# or VB based projects 63 Docker Image Size (tag) Docker Pulls
dotnetweb Optimized for C, C++, C# or VB based projects with JS/TS 72 Docker Image Size (tag) Docker Pulls
formatters Contains only formatters 17 Docker Image Size (tag) Docker Pulls

Behind the scenes

How are identified applicable files

  • File extensions: .cs

How the linting is performed

  • csharpier is called once with the list of files as arguments (list_of_files CLI lint mode)

Example calls

dotnet csharpier --check myfile.cs myfile2.cs
dotnet csharpier myfile.cs myfile2.cs

Help content

dotnet-csharpier

Usage:
  dotnet-csharpier [options] [<directoryOrFile>...]

Arguments:
  <directoryOrFile>  One or more paths to a directory containing c# files to format or a c# file to format. If a path is not specified the current directory is used

Options:
  --check                      Check that files are formatted. Will not write any changes.
  --loglevel <loglevel>        Specify the log level - Debug, Information (default), Warning, Error, None [default: Information]
  --no-cache                   Bypass the cache to determine if a file needs to be formatted.
  --no-msbuild-check           Bypass the check to determine if a csproj files references a different version of CSharpier.MsBuild.
  --include-generated          Include files generated by the SDK and files that begin with <autogenerated /> comments
  --fast                       Skip comparing syntax tree of formatted file to original file to validate changes.
  --skip-write                 Skip writing changes. Generally used for testing to ensure csharpier doesn't throw any errors or cause syntax tree validation failures.
  --write-stdout               Write the results of formatting any files to stdout.
  --pipe-multiple-files        Keep csharpier running so that multiples files can be piped to it via stdin.
  --server                     Run CSharpier as a server so that multiple files may be formatted.
  --server-port <server-port>  Specify the port that CSharpier should start on. Defaults to a random unused port.
  --config-path <config-path>  Path to the CSharpier configuration file
  --version                    Show version information
  -?, -h, --help               Show help and usage information

Installation on mega-linter Docker image

  • Dockerfile commands :
# Parent descriptor install
RUN apk add --no-cache dotnet8-sdk
ENV PATH="${PATH}:/root/.dotnet/tools"
# Linter install
RUN dotnet tool install --global csharpier