Skip to content

Commit 200811c

Browse files
authored
Merge pull request #65 from OpenForgeProject/update-code-quality
Update code quality
2 parents d3e6853 + 029497d commit 200811c

File tree

3 files changed

+84
-7
lines changed

3 files changed

+84
-7
lines changed

.github/copilot-instructions.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# GitHub Copilot Instructions for vscode-ddev-phpstan
2+
3+
You are an expert Visual Studio Code Extension developer specializing in TypeScript and PHP tooling integration. You are working on the `vscode-ddev-phpstan` repository.
4+
5+
## Project Overview
6+
This project is a VS Code extension that integrates PHPStan (Static Analysis) running inside DDEV containers into the VS Code editor. It allows users to run PHPStan analysis on their PHP files without installing PHPStan locally on their host machine.
7+
8+
## Tech Stack & Environment
9+
- **Language**: TypeScript (Target ES2022, Strict Mode).
10+
- **Runtime**: Node.js (via VS Code Extension Host).
11+
- **Bundler**: esbuild.
12+
- **Testing**: mocha, @vscode/test-electron.
13+
- **Core Dependency**: `ddev` CLI tool (must be installed on user's machine).
14+
15+
## Architecture & patterns
16+
17+
### Service-Based Architecture
18+
- Logic logic is encapsulated in "Services" located in `src/services/`.
19+
- `PhpstanService` extends `BasePhpToolService`. If adding new PHP tools, follow this pattern.
20+
- `extension.ts` acts as the composition root, managing service lifecycles and command registrations.
21+
22+
### DDEV Integration
23+
- **Crucial**: All PHP commands are executed inside the DDEV container, not on the host.
24+
- Use `DdevUtils.execDdev` or similar helpers to run commands.
25+
- **Path Mapping**: Be extremely careful with file paths.
26+
- Host path: `/Users/user/project/src/File.php`
27+
- Container path: `/var/www/html/src/File.php`
28+
- The extension must translate paths correctly when parsing output from PHPStan (which reports container paths) to VS Code diagnostics (which expect host paths).
29+
30+
### Error Handling
31+
- User-facing errors: `vscode.window.showErrorMessage` or `showWarningMessage`.
32+
- Internal logs: `console.log` or `console.error`.
33+
- DDEV issues: Use `showDdevError` helper when DDEV is stopped or unconfigured.
34+
35+
### Configuration
36+
- Settings are defined in `package.json` under `contributes.configuration`.
37+
- Access settings via `ConfigurationService`.
38+
- React to configuration changes using `vscode.workspace.onDidChangeConfiguration`.
39+
40+
## Coding Guidelines
41+
42+
1. **TypeScript**:
43+
- Use strict type annotations. Avoid `any` whenever possible.
44+
- Use `async/await` for asynchronous operations.
45+
- interfaces/types should be in `src/models/` if shared.
46+
47+
2. **VS Code API**:
48+
- Use `vscode` namespace imports (`import * as vscode from 'vscode';`).
49+
- managing disposables: Push event listeners and commands to `context.subscriptions`.
50+
51+
3. **Testing**:
52+
- Write unit tests for services in `src/test/`.
53+
- Mock `vscode` API where complex interactions occur, or use integration tests.
54+
55+
4. **UI/UX**:
56+
- Use Status Bar items effectively to show tool status (Ready, Error, etc.).
57+
- Provide "Quick Fixes" or buttons in error messages for common actions (like "Start DDEV").
58+
59+
## Common Tasks
60+
61+
- **Adding a new setting**:
62+
1. Add to `package.json`.
63+
2. Update `ConfigurationService` to read it.
64+
3. Update `PhpstanService` to use it.
65+
66+
- **Parsing PHPStan Output**:
67+
- PHPStan is run with `--error-format=json`.
68+
- The output is parsed in `processToolOutput`.
69+
- Ensure the JSON parsing is robust against non-JSON noise (like PHP warnings printed before JSON).

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This extension integrates [PHPStan](https://phpstan.org/) with Visual Studio Cod
1414

1515
## Requirements
1616

17-
- [VS Code](https://code.visualstudio.com/) 1.100.0 or higher
17+
- [VS Code](https://code.visualstudio.com/) 1.108.0 or higher
1818
- [DDEV](https://github.com/ddev/ddev) project with running container
1919
- PHPStan installed in your DDEV container
2020

@@ -51,10 +51,10 @@ Key settings in VS Code preferences:
5151
- `ddev-phpstan.validateOn`: When to validate (`"save"` or `"type"`)
5252
- `ddev-phpstan.level`: PHPStan analysis level 0-9 (default: `6` - recommended for most projects)
5353
- `ddev-phpstan.minSeverity`: Minimum severity level (`"error"`, `"warning"`, `"info"`)
54-
- `ddev-phpstan.configPath`: Path to custom PHPStan configuration file
54+
- `ddev-phpstan.configPath`: Path to custom PHPStan configuration file. If left empty, the extension automatically looks for common configuration files like `phpstan.neon`, `phpstan.neon.dist`, `phpstan.dist.neon` in the workspace root.
5555
- `ddev-phpstan.excludePaths`: Array of paths to exclude from analysis (includes common exclusions by default)
5656

57-
**Important:** When `configPath` is specified, the extension will only use the configuration file and ignore the `level` and `excludePaths` settings, as these should be defined in the PHPStan configuration file itself.
57+
**Important:** When `configPath` is specified or an auto-detected configuration file is found, the extension will use that configuration file. In this case, the `level` and `excludePaths` settings from VS Code are ignored, as these should be defined in the PHPStan configuration file itself.
5858

5959
### Example Configuration
6060

@@ -82,7 +82,7 @@ Key settings in VS Code preferences:
8282
- **Common Exclusions**: Automatically excludes vendor code, cache directories, and other common paths that shouldn't be analyzed
8383
- **Save-based Validation**: Runs analysis when files are saved for optimal performance
8484

85-
**Note:** When `configPath` is set to a specific PHPStan configuration file, the `level` and `excludePaths` settings will be ignored, and these values should instead be configured in your PHPStan configuration file.
85+
**Note:** When `configPath` is set to a specific PHPStan configuration file (or one is auto-detected), the `level` and `excludePaths` settings will be ignored, and these values should instead be configured in your PHPStan configuration file.
8686

8787
## Status Bar
8888

src/test/ddev-utils.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,17 @@
1919

2020
import * as assert from 'assert';
2121
import * as sinon from 'sinon';
22-
import { afterEach, beforeEach } from 'mocha';
22+
import { afterEach, beforeEach, test } from 'mocha';
2323
import { DdevUtils, sys } from '../shared/utils/ddev-utils';
2424

25+
interface ExecDdevError extends Error {
26+
status: number;
27+
stderr: string;
28+
stdout?: string;
29+
command?: string;
30+
workspacePath?: string;
31+
}
32+
2533
suite('DdevUtils Test Suite', () => {
2634
let sandbox: sinon.SinonSandbox;
2735
let spawnSyncStub: sinon.SinonStub;
@@ -106,7 +114,7 @@ suite('DdevUtils Test Suite', () => {
106114
const result = DdevUtils.validateDdevTool('phpstan', '/test/workspace');
107115

108116
assert.strictEqual(result.isValid, true);
109-
assert.ok(result.errorType === undefined);
117+
assert.strictEqual(result.errorType, undefined);
110118
});
111119

112120
test('validateDdevTool returns error message for DDEV issues', () => {
@@ -159,7 +167,7 @@ suite('DdevUtils Test Suite', () => {
159167

160168
assert.throws(() => {
161169
DdevUtils.execDdev(['ls'], '/test/workspace');
162-
}, (err: { status: number; stderr: string; stdout?: string; command?: string; workspacePath?: string; name?: string }) => {
170+
}, (err: ExecDdevError) => {
163171
return err.status === 1 && err.stderr === 'error';
164172
});
165173
});

0 commit comments

Comments
 (0)