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_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_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 ['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 113 Docker Image Size (tag) Docker Pulls
dotnet Optimized for C, C++, C# or VB based projects 59 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.
  --no-cache                   Bypass the cache to determine if a file needs to be formatted.
  --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
  --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 wget --tries=5 -q -O dotnet-install.sh https://dot.net/v1/dotnet-install.sh \
    && chmod +x dotnet-install.sh \
    && ./dotnet-install.sh --install-dir /usr/share/dotnet -channel 6.0 -version latest

ENV PATH="${PATH}:/root/.dotnet/tools:/usr/share/dotnet"
# Linter install
RUN /usr/share/dotnet/dotnet tool install -g csharpier