Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/core/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var FormatByExtension = map[string][]string{
`\.(?:clj|cljs|cljc|cljd)$`: {".clj", "code"},
`\.(?:cpp|cc|c|cp|cxx|c\+\+|h|hpp|h\+\+)$`: {".cpp", "code"},
`\.(?:css)$`: {".css", "code"},
`\.(?:cs|csx)$`: {".c", "code"},
`\.(?:cs|csx)$`: {".cs", "code"},
`\.(?:dita)$`: {".dita", "markup"},
`\.(?:ex|exs)$`: {".ex", "code"},
`\.(?:go)$`: {".go", "code"},
Expand Down
4 changes: 2 additions & 2 deletions internal/core/notebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ var kernelExts = map[string]string{
"elixir": ".ex",
"clojure": ".clj",
"perl": ".r",
"csharp": ".c",
"c#": ".c",
"csharp": ".cs",
"c#": ".cs",
"scala": ".c",
"powershell": ".ps1",
}
Expand Down
27 changes: 27 additions & 0 deletions internal/lint/code/cs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package code

import (
"regexp"

"github.com/smacker/go-tree-sitter/csharp"
"github.com/vale-cli/vale/v3/internal/core"
)

// CSharp extracts `//` line comments, `///` XML documentation comments and
// `/* */` block comments, all of which the grammar parses as `comment`.
func CSharp() *Language {
return &Language{
Delims: regexp.MustCompile(`///?|/\*|\*/`),
Prefix: cStylePrefix,
Parser: csharp.GetLanguage(),
Queries: []core.Scope{
{Name: "", Expr: "(comment) @comment", Type: ""},
},
// `///` is listed so that a documentation comment's padding matches
// what Delims takes off; cStyle alone stops at `//`.
Padding: func(s string) int {
return computePadding(s, []string{"//", "///", "/*"})
},
Directive: csharpDirective,
}
}
1 change: 1 addition & 0 deletions internal/lint/code/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,6 @@ var (
javaDirective = regexp.MustCompile(`^//[ \t]*(?:NOPMD|NOSONAR|CHECKSTYLE|noinspection|@formatter:|\$NON-NLS)`)
kotlinDirective = regexp.MustCompile(`^//[ \t]*(?:ktlint|NOSONAR|noinspection|@formatter:)`)
cDirective = regexp.MustCompile(`^//[ \t]*(?:NOLINT|clang-format|cppcheck-suppress)|^/\*[ \t]*(?:NOLINT|clang-format)`)
csharpDirective = regexp.MustCompile(`^//[ \t]*(?:ReSharper (?:disable|restore)\b|NOSONAR)`)
rubyDirective = regexp.MustCompile(`^#[ \t]*(?:rubocop:|frozen_string_literal:|encoding:|typed:|sorbet:|-\*-)`)
)
2 changes: 2 additions & 0 deletions internal/lint/code/lang.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ func newLanguage(ext string) (*Language, error) {
return Cpp(), nil
case ".c":
return C(), nil
case ".cs":
return CSharp(), nil
case ".js", ".jsx":
return JavaScript(), nil
case ".hs":
Expand Down
16 changes: 16 additions & 0 deletions testdata/comments/in/12.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// A line comment
// continued on the next line.
namespace Demo
{
/// <summary>An XML documentation comment.</summary>
class Paths
{
static string Dir = @"C:\temp\"; /* A block comment after a verbatim string. */
static string Raw = """
// Not a comment: inside a raw string literal.
""";
static string Url = $"{Dir}// not a comment";
// ReSharper disable once UnusedMember.Local
static int x = 1; // A trailing comment.
}
}
30 changes: 30 additions & 0 deletions testdata/comments/out/12.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[
{
"Text": "A line comment\ncontinued on the next line.\n",
"Source": "// A line comment\n// continued on the next line.\n",
"Line": 1,
"Offset": 0,
"Scope": "text.comment.line"
},
{
"Text": "\u003csummary\u003eAn XML documentation comment.\u003c/summary\u003e",
"Source": "/// \u003csummary\u003eAn XML documentation comment.\u003c/summary\u003e",
"Line": 5,
"Offset": 4,
"Scope": "text.comment.line"
},
{
"Text": "A block comment after a verbatim string. ",
"Source": "/* A block comment after a verbatim string. */",
"Line": 8,
"Offset": 41,
"Scope": "text.comment.line"
},
{
"Text": "A trailing comment.",
"Source": "// A trailing comment.",
"Line": 14,
"Offset": 26,
"Scope": "text.comment.line"
}
]
11 changes: 11 additions & 0 deletions testdata/e2e/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ cases:
test.kt:17:4:vale.Annotations:'XXX' left in text
test.kt:21:5:vale.Annotations:'NOTE' left in text

- name: csharp
args: test.cs
exit: 0
want: |
test.cs:1:4:vale.Annotations:'NOTE' left in text
test.cs:2:4:vale.Annotations:'XXX' left in text
test.cs:5:18:vale.Annotations:'TODO' left in text
test.cs:8:12:vale.Annotations:'NOTE' left in text
test.cs:15:37:vale.Annotations:'FIXME' left in text
test.cs:16:33:vale.Annotations:'XXX' left in text

- name: proto
args: test.proto
exit: 0
Expand Down
19 changes: 19 additions & 0 deletions testdata/fixtures/formats/test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// NOTE: a line comment
// XXX: continued on the next line
namespace Test
{
/// <summary>TODO: an XML documentation comment.</summary>
public class Test
{
/* NOTE: a block comment */
private const string Raw = """
// TODO: a raw string, not a comment
""";

public string Greet(string name)
{
var s = @"C:\temp\"; // FIXME: a comment after a verbatim string
return s + name; // XXX: a trailing comment
}
}
}
Loading