Skip to content

Commit d15978e

Browse files
committed
chore: opimionated code refactor
Update linting rules to match personal preferences Added esbuild for bundling added copilot instructions Signed-off-by: Gordon Smith <GordonJSmith@gmail.com>
1 parent 840f5d0 commit d15978e

File tree

12 files changed

+5582
-2360
lines changed

12 files changed

+5582
-2360
lines changed

.eslintrc.json

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
applyTo: "**"
3+
---
4+
5+
# GitHub Copilot Instructions
6+
7+
- Use 4 spaces for indentation
8+
- Ensure all code passes ESLint checks (`npm run lint`)
9+
- Fix all lint errors before submitting code
10+
- Use explicit types for all function parameters and return values
11+
- Avoid using `any` unless absolutely necessary
12+
- Organize code into logical modules and folders (e.g., `src/components`, `src/utils`)
13+
- Place tests next to the code they test, using `.test.ts` or `.spec.ts` suffixes
14+
- Use npm for package management
15+
- Keep dependencies up to date and remove unused packages
16+
- Write unit tests for all new features and bug fixes
17+
- Use Jest or Vitest for testing
18+
- Run all tests with `npm test` before pushing changes
19+
- Use feature branches for new work
20+
- Write clear, concise commit messages
21+
- Open a pull request for review before merging to `main`
22+
- Document public functions and components with JSDoc comments
23+
- Update the README and other docs for significant changes
24+
- Store sensitive configuration in `.env` files
25+
- Never commit `.env` or secrets to version control
26+
- Ensure all checks pass (lint, build, test) before merging
27+
28+
---
29+
For questions, contact project maintainers or see CONTRIBUTING.md.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
applyTo: "**"
3+
---
4+
5+
# GitHub Copilot Instructions for VS Code Extension Projects
6+
7+
> **Note:** These instructions are in addition to the [general project instructions](.github/instructions/general.instructions.md). If there is any overlap, follow the general instructions and refer to this file for VS Code extension–specific requirements.
8+
9+
- Implement and document the `activate` and `deactivate` functions in `extension.ts`
10+
- Dispose of all resources on deactivation
11+
- Register all commands in `package.json` under `contributes.commands`
12+
- Document each command with a clear description
13+
- Document public functions, classes, and extension APIs with JSDoc comments
14+
- Include usage instructions and examples in the README
15+
- Validate that the extension builds and runs in the VS Code Extension Host
16+
17+
**Useful Links:**
18+
- [VS Code API Reference](https://code.visualstudio.com/api/references/vscode-api)
19+
- [VS Code Extension Authoring Guide](https://code.visualstudio.com/api/get-started/your-first-extension)
20+
- [VS Code Extension Samples](https://github.com/microsoft/vscode-extension-samples)
21+
22+
For questions, contact project maintainers or see CONTRIBUTING.md.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
applyTo: "**/wit.tmLanguage.json"
3+
---
4+
5+
# Instructions for WIT and Official Grammar
6+
7+
## 1. What is WIT?
8+
- WIT (WebAssembly Interface Types) is a language and specification for describing interfaces between WebAssembly modules and their host environments.
9+
- It defines types, functions, resources, and modules in a language-agnostic way.
10+
11+
## 2. Official Grammar
12+
- The official WIT grammar is defined in the `wit.tmLanguage.json` file and is used for syntax highlighting and parsing.
13+
- Refer to the [WIT specification](https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md) for the authoritative grammar and language rules.
14+
- The grammar covers:
15+
- Identifiers, keywords, and comments
16+
- Type definitions (records, variants, enums, flags, etc.)
17+
- Function and resource declarations
18+
- Module and world definitions
19+
- Versioning, namespace, and aliasing
20+
- Markdown in doc comments
21+
22+
## 3. Best Practices
23+
- Follow the official WIT grammar for all `.wit` files.
24+
- Use consistent formatting and indentation for readability.
25+
- Validate `.wit` files using available tools or language support in your editor.
26+
- Place WIT grammar and related files in the appropriate `syntaxes/` directory.
27+
- When updating the grammar, also update or add tests in `tests/grammar/` to cover new features, edge cases, or bug fixes.
28+
- If the WIT specification changes, update both the grammar and the tests to stay in sync.
29+
- For complex or non-obvious grammar rules, add or expand comments in `wit.tmLanguage.json` to help future maintainers.
30+
- Test new or changed grammar rules with both valid and invalid WIT syntax to ensure robust highlighting and error detection.
31+
32+
## 4. Resources
33+
- [WIT Specification](https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md)
34+
- [wit.tmLanguage.json](syntaxes/wit.tmLanguage.json) (project grammar file)
35+
- [WebAssembly Component Model](https://github.com/WebAssembly/component-model)
36+
- [Grammar Tests](tests/grammar/) (test suite for grammar validation)
37+
38+
---
39+
For questions about WIT or its grammar, contact project maintainers or refer to the official specification.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ typings/
7070
.cache
7171

7272
# Typescript Output
73-
out/
73+
dist/
7474

7575
# VSCode extension development
7676
.vscode-test/

.vscode/tasks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"version": "2.0.0",
33
"tasks": [
44
{
5-
"type": "npm",
65
"label": "watch",
6+
"type": "npm",
77
"script": "watch",
88
"problemMatcher": [],
99
"presentation": {

esbuild.mjs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// ESBuild configuration for building the VSCode extension (sample-based)
2+
// See: https://github.com/microsoft/vscode-extension-samples/blob/main/esbuild-sample/esbuild.js
3+
4+
import * as esbuild from "esbuild";
5+
6+
const production = process.argv.includes("--production");
7+
const watch = process.argv.includes("--watch");
8+
9+
/**
10+
* @type {import('esbuild').Plugin}
11+
*/
12+
const esbuildProblemMatcherPlugin = {
13+
name: "esbuild-problem-matcher",
14+
setup(build) {
15+
build.onStart(() => {
16+
console.log("[watch] build started");
17+
});
18+
build.onEnd((result) => {
19+
result.errors.forEach(({ text, location }) => {
20+
console.error(`✘ [ERROR] ${text}`);
21+
if (location) {
22+
console.error(` ${location.file}:${location.line}:${location.column}:`);
23+
}
24+
});
25+
console.log("[watch] build finished");
26+
});
27+
},
28+
};
29+
30+
async function main() {
31+
const ctx = await esbuild.context({
32+
entryPoints: [
33+
"src/extension.ts"
34+
],
35+
bundle: true,
36+
format: "cjs",
37+
minify: production,
38+
sourcemap: !production,
39+
sourcesContent: false,
40+
platform: "node",
41+
outfile: "dist/extension.js",
42+
external: ["vscode"],
43+
logLevel: "silent",
44+
plugins: [
45+
esbuildProblemMatcherPlugin,
46+
],
47+
});
48+
if (watch) {
49+
await ctx.watch();
50+
} else {
51+
await ctx.rebuild();
52+
await ctx.dispose();
53+
}
54+
}
55+
56+
main().catch(e => {
57+
console.error(e);
58+
process.exit(1);
59+
});

eslint.config.mjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import js from "@eslint/js";
2+
import globals from "globals";
3+
import tseslint from "typescript-eslint";
4+
import markdown from "@eslint/markdown";
5+
import css from "@eslint/css";
6+
import { defineConfig } from "eslint/config";
7+
8+
export default defineConfig([
9+
{ files: ["**/*.{js,mjs,cjs,ts,mts,cts}"], plugins: { js }, extends: ["js/recommended"] },
10+
{ files: ["**/*.{js,mjs,cjs,ts,mts,cts}"], languageOptions: { globals: { ...globals.browser, ...globals.node } } },
11+
tseslint.configs.recommended,
12+
{
13+
files: ["**/*.{ts,tsx,js,jsx}"],
14+
rules: {
15+
// Allow unused function parameters (disable rule)
16+
'@typescript-eslint/no-unused-vars': 'off',
17+
'quotes': ['error', 'double']
18+
}
19+
},
20+
{ files: ["**/*.md"], plugins: { markdown }, language: "markdown/gfm", extends: ["markdown/recommended"] },
21+
{ files: ["**/*.css"], plugins: { css }, language: "css/css", extends: ["css/recommended"] },
22+
]);

0 commit comments

Comments
 (0)