Skip to content

Commit 8485548

Browse files
authored
show error diagnostics for invalid rules (#34)
1 parent 37969c3 commit 8485548

6 files changed

Lines changed: 67 additions & 8 deletions

File tree

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# be identified in the format @org/team-name. Teams must have
2323
# explicit write access to the repository. In this example,
2424
# the octocats team in the octo-org organization owns all .txt files.
25-
*.txt @octo-org/octocats
25+
*.txt @octo-org/@test_one/octocats
2626

2727
# In this example, @doctocat owns any files in the build/logs
2828
# directory at the root of the repository and any of its

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## 4.2.0 - 2026-03-14
11+
12+
### Added
13+
14+
- Show error diagnostics for invalid CODEOWNERS patterns (#34).
15+
1016
## 4.1.0 - 2024-04-13
1117

1218
### Changed

package-lock.json

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Quickly see GitHub Code Owners for the current file. Add syntax highlighting for CODEOWNERS files.",
55
"publisher": "chdsbd",
66
"license": "SEE LICENSE IN LICENSE",
7-
"version": "4.1.0",
7+
"version": "4.2.0",
88
"icon": "images/logo256.png",
99
"homepage": "https://github.com/chdsbd/vscode-github-code-owners/blob/master/README.md",
1010
"keywords": [
@@ -229,7 +229,7 @@
229229
"typescript": "^4.9.5"
230230
},
231231
"dependencies": {
232-
"@snyk/github-codeowners": "github:chdsbd/github-codeowners#chris/line-number-information",
232+
"@snyk/github-codeowners": "github:chdsbd/github-codeowners#da8b03fa3cb4de086f3a564f1af03cc44288e43c",
233233
"lodash": "^4.17.21"
234234
},
235235
"volta": {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import vscode from "vscode"
2+
import { OwnershipEngine } from "@snyk/github-codeowners/dist/lib/ownership"
3+
4+
function updateDiagnostics(
5+
document: vscode.TextDocument,
6+
collection: vscode.DiagnosticCollection,
7+
): void {
8+
if (document.languageId !== "codeowners") {
9+
return
10+
}
11+
12+
const engine = OwnershipEngine.FromCodeownersFile(document.uri.fsPath)
13+
14+
const diagnostics = engine.errors.map((err) => {
15+
const line = document.lineAt(err.lineno)
16+
return new vscode.Diagnostic(line.range, err.message, vscode.DiagnosticSeverity.Error)
17+
})
18+
19+
collection.set(document.uri, diagnostics)
20+
}
21+
22+
export function registerCodeownersDiagnostics(
23+
context: vscode.ExtensionContext,
24+
): void {
25+
const collection = vscode.languages.createDiagnosticCollection("codeowners")
26+
context.subscriptions.push(collection)
27+
28+
vscode.workspace.textDocuments.forEach((doc) =>
29+
updateDiagnostics(doc, collection),
30+
)
31+
32+
vscode.workspace.onDidOpenTextDocument(
33+
(doc) => updateDiagnostics(doc, collection),
34+
null,
35+
context.subscriptions,
36+
)
37+
38+
vscode.workspace.onDidChangeTextDocument(
39+
(e) => updateDiagnostics(e.document, collection),
40+
null,
41+
context.subscriptions,
42+
)
43+
44+
vscode.workspace.onDidCloseTextDocument(
45+
(doc) => collection.delete(doc.uri),
46+
null,
47+
context.subscriptions,
48+
)
49+
}

src/extension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { showOwnersCommandHandler } from "./show-owners-command"
77
import { CodeownersHoverProvider } from "./codeowners-hover-provider"
88
import { statusBarTextEditorListener } from "./status-bar-text-editor-listener"
99
import { AlignOwnersFormattingProvider } from "./align-codeowners"
10+
import { registerCodeownersDiagnostics } from "./codeowners-diagnostic-provider"
1011

1112
const COMMAND_ID = "github-code-owners.show-owners"
1213

@@ -74,6 +75,8 @@ export function activate(context: vscode.ExtensionContext) {
7475
),
7576
)
7677

78+
registerCodeownersDiagnostics(context)
79+
7780
vscode.workspace.onDidChangeConfiguration(() => {
7881
outputChannel.appendLine("Configuration changed: Reloading link provider")
7982
handles.linkProvider.dispose()

0 commit comments

Comments
 (0)