From bc58790f1f8fd496f8e9cc739d90de5a20289446 Mon Sep 17 00:00:00 2001 From: Christopher Dignam Date: Sat, 14 Mar 2026 15:51:49 -0400 Subject: [PATCH 1/2] show error diagnostics for invalid rules --- .github/CODEOWNERS | 2 +- CHANGELOG.md | 6 ++++ package-lock.json | 11 +++--- package.json | 4 +-- src/codeowners-diagnostic-provider.ts | 49 +++++++++++++++++++++++++++ src/extension.ts | 3 ++ 6 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 src/codeowners-diagnostic-provider.ts diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 8c0d802..ab1f6f7 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -22,7 +22,7 @@ # be identified in the format @org/team-name. Teams must have # explicit write access to the repository. In this example, # the octocats team in the octo-org organization owns all .txt files. -*.txt @octo-org/octocats +*.txt @octo-org/@test_one/octocats # In this example, @doctocat owns any files in the build/logs # directory at the root of the repository and any of its diff --git a/CHANGELOG.md b/CHANGELOG.md index 26da346..7ac7a3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## 4.2.0 - 2026-03-14 + +### Added + +- Show error diagnostics for invalid CODEOWNERS patterns. + ## 4.1.0 - 2024-04-13 ### Changed diff --git a/package-lock.json b/package-lock.json index b822d89..0bcc889 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { "name": "github-code-owners", - "version": "4.1.0", + "version": "4.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "github-code-owners", - "version": "4.1.0", + "version": "4.2.0", "license": "SEE LICENSE IN LICENSE", "dependencies": { - "@snyk/github-codeowners": "github:chdsbd/github-codeowners#chris/line-number-information", + "@snyk/github-codeowners": "github:chdsbd/github-codeowners#da8b03fa3cb4de086f3a564f1af03cc44288e43c", "lodash": "^4.17.21" }, "devDependencies": { @@ -632,7 +632,8 @@ } }, "node_modules/@snyk/github-codeowners": { - "resolved": "git+ssh://git@github.com/chdsbd/github-codeowners.git#64dc4df353de62f0c96dae96897e283e66d5be37", + "resolved": "git+ssh://git@github.com/chdsbd/github-codeowners.git#da8b03fa3cb4de086f3a564f1af03cc44288e43c", + "integrity": "sha512-sKJAAPWO++0CBHEuWxljAdJdgj/7OtAQHUzxWlFjZmKvDuAPtyEOz8Mi9nXqveZx1z1egcxMXoClM90br0jAeg==", "license": "MIT", "dependencies": { "commander": "^4.1.1", @@ -643,7 +644,7 @@ "github-codeowners": "dist/cli.js" }, "engines": { - "node": ">=8.10" + "node": ">=22" } }, "node_modules/@snyk/github-codeowners/node_modules/commander": { diff --git a/package.json b/package.json index ece2ea5..baf2ccc 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Quickly see GitHub Code Owners for the current file. Add syntax highlighting for CODEOWNERS files.", "publisher": "chdsbd", "license": "SEE LICENSE IN LICENSE", - "version": "4.1.0", + "version": "4.2.0", "icon": "images/logo256.png", "homepage": "https://github.com/chdsbd/vscode-github-code-owners/blob/master/README.md", "keywords": [ @@ -229,7 +229,7 @@ "typescript": "^4.9.5" }, "dependencies": { - "@snyk/github-codeowners": "github:chdsbd/github-codeowners#chris/line-number-information", + "@snyk/github-codeowners": "github:chdsbd/github-codeowners#da8b03fa3cb4de086f3a564f1af03cc44288e43c", "lodash": "^4.17.21" }, "volta": { diff --git a/src/codeowners-diagnostic-provider.ts b/src/codeowners-diagnostic-provider.ts new file mode 100644 index 0000000..7e48ee4 --- /dev/null +++ b/src/codeowners-diagnostic-provider.ts @@ -0,0 +1,49 @@ +import vscode from "vscode" +import { OwnershipEngine } from "@snyk/github-codeowners/dist/lib/ownership" + +function updateDiagnostics( + document: vscode.TextDocument, + collection: vscode.DiagnosticCollection, +): void { + if (document.languageId !== "codeowners") { + return + } + + const engine = OwnershipEngine.FromCodeownersFile(document.uri.fsPath) + + const diagnostics = engine.errors.map((err) => { + const line = document.lineAt(err.lineno) + return new vscode.Diagnostic(line.range, err.message, vscode.DiagnosticSeverity.Error) + }) + + collection.set(document.uri, diagnostics) +} + +export function registerCodeownersDiagnostics( + context: vscode.ExtensionContext, +): void { + const collection = vscode.languages.createDiagnosticCollection("codeowners") + context.subscriptions.push(collection) + + vscode.workspace.textDocuments.forEach((doc) => + updateDiagnostics(doc, collection), + ) + + vscode.workspace.onDidOpenTextDocument( + (doc) => updateDiagnostics(doc, collection), + null, + context.subscriptions, + ) + + vscode.workspace.onDidChangeTextDocument( + (e) => updateDiagnostics(e.document, collection), + null, + context.subscriptions, + ) + + vscode.workspace.onDidCloseTextDocument( + (doc) => collection.delete(doc.uri), + null, + context.subscriptions, + ) +} diff --git a/src/extension.ts b/src/extension.ts index e6068b4..648ff96 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -7,6 +7,7 @@ import { showOwnersCommandHandler } from "./show-owners-command" import { CodeownersHoverProvider } from "./codeowners-hover-provider" import { statusBarTextEditorListener } from "./status-bar-text-editor-listener" import { AlignOwnersFormattingProvider } from "./align-codeowners" +import { registerCodeownersDiagnostics } from "./codeowners-diagnostic-provider" const COMMAND_ID = "github-code-owners.show-owners" @@ -74,6 +75,8 @@ export function activate(context: vscode.ExtensionContext) { ), ) + registerCodeownersDiagnostics(context) + vscode.workspace.onDidChangeConfiguration(() => { outputChannel.appendLine("Configuration changed: Reloading link provider") handles.linkProvider.dispose() From 5d0bf76a844ebd5c800cb2704c162714e23aee12 Mon Sep 17 00:00:00 2001 From: Christopher Dignam Date: Sat, 14 Mar 2026 15:53:38 -0400 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ac7a3e..d1e568c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Show error diagnostics for invalid CODEOWNERS patterns. +- Show error diagnostics for invalid CODEOWNERS patterns (#34). ## 4.1.0 - 2024-04-13