Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CSharpier linter #2185

Merged
merged 12 commits into from
Dec 29, 2022
Merged
20 changes: 20 additions & 0 deletions .automation/generated/linter-helps.json
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,26 @@
" processed by linter, in the current directory (where the .cfg",
" file is located) and all sub-directories."
],
"csharpier": [
"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",
" --version Show version information",
" -?, -h, --help Show help and usage information",
""
],
"cspell": [
"Usage: cspell [options] [command]",
"",
Expand Down
5 changes: 5 additions & 0 deletions .automation/generated/linter-links-previews.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@
"image": "https://avatars3.githubusercontent.com/u/23239423?s=400&v=4",
"title": "cpplint/cpplint"
},
"csharpier": {
"description": "An Opinionated Code Formatter.",
"image": null,
"title": "CSharpier"
},
"cspell": {
"description": "A Spell Checker for Code! Contribute to streetsidesoftware/cspell development by creating an account on GitHub.",
"image": "https://avatars0.githubusercontent.com/u/50543896?s=400&v=4",
Expand Down
1 change: 1 addition & 0 deletions .automation/generated/linter-versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"clj-kondo": "2022.12.10",
"coffeelint": "5.2.11",
"cpplint": "1.6.1",
"csharpier": "0.21.0",
"cspell": "6.18.0",
"dartanalyzer": "0.0.0",
"devskim": "0.6.9",
Expand Down
12 changes: 12 additions & 0 deletions .automation/test/csharp_csharpier/csharp_bad_01.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
12 changes: 12 additions & 0 deletions .automation/test/csharp_csharpier/csharp_good_01.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
4 changes: 3 additions & 1 deletion .github/linters/.cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
"Cpagerefrange",
"Crefrange",
"Cres",
"csharpierignore",
"csharpierrc",
"Csrf",
"C\u00e9dric",
"DARTANALYZER",
Expand Down Expand Up @@ -1350,4 +1352,4 @@
"\u0636clojure",
"\u077bcbad"
]
}
}
1 change: 1 addition & 0 deletions .trivyignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ CVE-2022-38013
CVE-2022-39286
CVE-2022-39353
CVE-2022-40674
CVE-2022-40897
CVE-2022-40898
CVE-2022-41032
CVE-2022-42003
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-linter.yml file, or with `oxsecurity/megalinter:beta` docker image

- New linters
- Add [CSharpier](https://csharpier.com/) linter

- Linter versions upgrades
<!-- linter-versions-end -->

Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@ RUN curl --retry 5 --retry-delay 5 -sLO "${ARM_TTK_URI}" \
# dotnet-format installation
&& /usr/share/dotnet/dotnet tool install -g dotnet-format \

# csharpier installation
&& /usr/share/dotnet/dotnet tool install -g csharpier --version 0.16.0 \

# dartanalyzer installation
&& wget --tries=50 -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
&& wget --tries=5 -q https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-${GLIBC_VERSION}.apk \
Expand Down
3 changes: 3 additions & 0 deletions flavors/dotnet/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ RUN curl --retry 5 --retry-delay 5 -sLO "${ARM_TTK_URI}" \
# dotnet-format installation
&& /usr/share/dotnet/dotnet tool install -g dotnet-format \

# csharpier installation
&& /usr/share/dotnet/dotnet tool install -g csharpier --version 0.16.0 \

# hadolint installation
# Managed with COPY --from=hadolint /bin/hadolint /usr/bin/hadolint

Expand Down
1 change: 1 addition & 0 deletions flavors/dotnet/flavor.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"COPYPASTE_JSCPD",
"CPP_CPPLINT",
"CSHARP_DOTNET_FORMAT",
"CSHARP_CSHARPIER",
"CSS_STYLELINT",
"CSS_SCSS_LINT",
"DOCKERFILE_HADOLINT",
Expand Down
1 change: 1 addition & 0 deletions megalinter/descriptors/all_flavors.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
"COPYPASTE_JSCPD",
"CPP_CPPLINT",
"CSHARP_DOTNET_FORMAT",
"CSHARP_CSHARPIER",
"CSS_STYLELINT",
"CSS_SCSS_LINT",
"DOCKERFILE_HADOLINT",
Expand Down
31 changes: 31 additions & 0 deletions megalinter/descriptors/csharp.megalinter-descriptor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,34 @@ linters:
install:
dockerfile:
- RUN /usr/share/dotnet/dotnet tool install -g dotnet-format
# CSharpier
- class: DotnetLinter
linter_name: csharpier
is_formatter: true
linter_url: https://csharpier.com/
linter_repo: https://github.com/belav/csharpier
linter_image_url: https://csharpier.com/img/logo.svg
linter_rules_configuration_url: https://csharpier.com/docs/Configuration
linter_rules_ignore_config_url: https://csharpier.com/docs/Ignore
ignore_file_name: .csharpierignore
cli_lint_extra_args:
- "--check"
cli_lint_fix_remove_args:
- "--check"
test_folder: csharp_csharpier
examples:
- "dotnet csharpier --check myfile.cs"
- "dotnet csharpier myfile.cs" # Fix
install:
dockerfile:
- RUN /usr/share/dotnet/dotnet tool install -g csharpier --version 0.16.0
ide:
rider:
- name: csharpier
url: https://plugins.jetbrains.com/plugin/18243-csharpier
visual_studio:
- name: CSharpier
url: https://marketplace.visualstudio.com/items?itemName=csharpier.CSharpier
vscode:
- name: csharpier-vscode
url: https://marketplace.visualstudio.com/items?itemName=csharpier.csharpier-vscode
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
"COPYPASTE_JSCPD",
"CPP_CPPLINT",
"CSHARP_DOTNET_FORMAT",
"CSHARP_CSHARPIER",
"CSS_STYLELINT",
"CSS_SCSS_LINT",
"DART_DARTANALYZER",
Expand Down
21 changes: 21 additions & 0 deletions megalinter/linters/DotnetLinter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3
"""
Class for all linters using dotnet tools
"""

from megalinter import Linter


class DotnetLinter(Linter):

def build_lint_command(self, file=None):
cmd = ["dotnet"] + super().build_lint_command(file)
return cmd

def build_version_command(self):
cmd = ["dotnet"] + super().build_version_command()
return cmd

def build_help_command(self):
cmd = ["dotnet"] + super().build_help_command()
return cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# !/usr/bin/env python3
"""
Unit tests for CSHARP linter csharpier
This class has been automatically @generated by .automation/build.py, please do not update it manually
"""

from unittest import TestCase

from megalinter.tests.test_megalinter.LinterTestRoot import LinterTestRoot


class csharp_csharpier_test(TestCase, LinterTestRoot):
descriptor_id = "CSHARP"
linter_name = "csharpier"