Skip to content

Commit 3d8d081

Browse files
committed
feat: Add TypeScript linter for AI Context Convention files
1 parent e4578e9 commit 3d8d081

File tree

7 files changed

+469
-94
lines changed

7 files changed

+469
-94
lines changed

linters/typescript/.npmignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Source files
2+
src/
3+
4+
# TypeScript config
5+
tsconfig.json
6+
7+
# Development files
8+
.gitignore
9+
.npmignore
10+
11+
# Tests
12+
__tests__/
13+
*.test.ts
14+
15+
# Editor directories and files
16+
.vscode/
17+
.idea/
18+
19+
# Logs
20+
*.log
21+
22+
# Environment variables
23+
.env
24+
25+
# Build artifacts
26+
*.tsbuildinfo
27+
28+
# Dependency directories
29+
node_modules/

linters/typescript/README.md

Lines changed: 55 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,87 @@
11
# AI Context Convention TypeScript Linter
22

3-
This is a TypeScript implementation of the linter for validating AI Context Convention files.
3+
This is a TypeScript-based CLI linter for validating AI Context Convention files, including `.context.md`, `.context.yaml`, `.context.json`, `.contextdocs.md`, and `.contextignore` files.
44

55
## Installation
66

7-
1. Ensure you have Node.js (v14+) and npm installed.
8-
2. Clone the entire repository:
9-
```
10-
git clone https://github.com/your-repo/ai-context-convention.git
11-
```
12-
3. Navigate to the `linters/typescript` directory:
13-
```
14-
cd ai-context-convention/linters/typescript
15-
```
16-
4. Run `npm install` to install the dependencies.
17-
18-
## Usage
19-
20-
To use the TypeScript linter:
21-
22-
1. Build the TypeScript code:
23-
```
24-
npm run build
25-
```
26-
27-
2. Run the linter on a directory:
28-
```
29-
npm run lint <directory_to_lint>
30-
```
31-
32-
Replace `<directory_to_lint>` with the path to the directory containing the context files you want to lint.
33-
34-
Note: You can use relative paths. For example, to lint the parent directory:
35-
```
36-
npm run lint ../..
37-
```
38-
39-
## Example Output
40-
41-
When you run the linter, you'll see output similar to this:
7+
You can install the linter globally using npm:
428

439
```
44-
========================================================
45-
AI Context Convention TypeScript Linter (v1.0.0)
46-
========================================================
10+
npm install -g ai-context-convention-linter
11+
```
4712

48-
Linting directory: ../..
13+
## Usage
4914

50-
Linting file: .context.md
51-
- Validating Markdown structure
52-
- Checking YAML frontmatter
53-
- Verifying content against AI Context Convention Specification
15+
After installation, you can use the linter from the command line:
5416

55-
Linting completed.
17+
```
18+
ai-context-lint <directory_to_lint>
5619
```
5720

58-
## Features
21+
Replace `<directory_to_lint>` with the path to the directory containing your AI Context Convention files.
5922

60-
The TypeScript linter performs the following checks:
23+
## Features
6124

62-
- Identifies and processes .context.md, .context.yaml, and .context.json files
63-
- Validates the structure of context files
64-
- Ensures required fields are present
65-
- Checks for proper YAML frontmatter in Markdown files
66-
- Verifies the content adheres to the AI Context Convention Specification
25+
- Validates the structure and content of `.context.md`, `.context.yaml`, and `.context.json` files
26+
- Checks for required fields and sections
27+
- Verifies the format of `.contextdocs.md` files
28+
- Validates ignore patterns in `.contextignore` files
29+
- Provides detailed error messages and warnings
6730

6831
## Development
6932

70-
To contribute to the development of this linter:
33+
To contribute to this project:
7134

72-
1. Make your changes in the `typescript_linter.ts` file.
73-
2. Build the TypeScript code:
35+
1. Clone the repository:
7436
```
75-
npm run build
37+
git clone https://github.com/your-repo/ai-context-convention-typescript-linter.git
38+
cd ai-context-convention-typescript-linter
7639
```
77-
3. Test your changes by running the linter on sample files.
7840

79-
Note: The `dist` directory, which contains the compiled JavaScript files, is ignored by git. Make sure to rebuild the project after making changes.
41+
2. Install dependencies:
42+
```
43+
npm install
44+
```
8045

81-
## Contributing
46+
3. Build the project:
47+
```
48+
npm run build
49+
```
8250

83-
When working on the TypeScript linter:
51+
4. To test the CLI locally, you can use:
52+
```
53+
npm link
54+
```
55+
This will create a symlink to your local development version of the package.
8456

85-
1. Follow TypeScript best practices and coding conventions.
86-
2. Use strict mode and appropriate type annotations.
87-
3. Write unit tests for new functionality.
88-
4. Keep the linter consistent with other language implementations.
89-
5. Update comments and documentation as necessary.
57+
5. Create your feature branch (`git checkout -b feature/AmazingFeature`)
58+
6. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
59+
7. Push to the branch (`git push origin feature/AmazingFeature`)
60+
8. Open a Pull Request
9061

91-
Refer to the main README.md in the project root for the full AI Context Convention Specification and contribution guidelines.
62+
## Publishing to npm
9263

93-
## Troubleshooting
64+
To publish the package to npm:
9465

95-
If you encounter any issues:
66+
1. Make sure you have an npm account and are logged in:
67+
```
68+
npm login
69+
```
9670

97-
1. Ensure you've run `npm install` to install all dependencies.
98-
2. Make sure you've built the project using `npm run build` before running the linter.
99-
3. Check that you're in the correct directory (`linters/typescript`) when running npm commands.
100-
4. If you see "unknown" as the version number, it means the linter couldn't read the package.json file. This doesn't affect functionality but you may want to check file permissions.
71+
2. Update the version in `package.json`:
72+
```
73+
npm version patch # for bug fixes
74+
npm version minor # for new features
75+
npm version major # for breaking changes
76+
```
10177

102-
## License
78+
3. Publish the package:
79+
```
80+
npm publish
81+
```
10382

104-
This project is licensed under the ISC License.
83+
Note: Make sure you have the necessary permissions to publish to the npm registry under the chosen package name.
10584

106-
## Future Enhancements
85+
## License
10786

108-
- Integration with VSCode extension for in-editor linting
109-
- More detailed error reporting and suggestions for fixing issues
110-
- Configuration options for customizing linting rules
111-
- Support for custom file extensions and naming conventions
87+
This project is licensed under the ISC License.

linters/typescript/package.json

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,40 @@
11
{
2-
"name": "ai-context-convention-typescript-linter",
3-
"version": "1.0.0",
4-
"description": "TypeScript linter for AI Context Convention files",
2+
"name": "ai-context-convention-linter",
3+
"version": "0.0.1",
4+
"description": "CLI linter for AI Context Convention files",
55
"main": "dist/typescript_linter.js",
6+
"bin": {
7+
"ai-context-lint": "./dist/cli.js"
8+
},
69
"scripts": {
710
"build": "tsc",
8-
"start": "node dist/typescript_linter.js",
9-
"lint": "node dist/typescript_linter.js",
10-
"test": "echo \"Error: no test specified\" && exit 1"
11+
"start": "node dist/cli.js",
12+
"lint": "node dist/cli.js",
13+
"test": "echo \"Error: no test specified\" && exit 1",
14+
"prepublishOnly": "npm run build"
1115
},
12-
"keywords": ["linter", "typescript", "ai", "context", "convention"],
13-
"author": "",
16+
"keywords": ["linter", "typescript", "ai", "context", "convention", "cli"],
17+
"author": "Your Name <[email protected]>",
1418
"license": "ISC",
19+
"repository": {
20+
"type": "git",
21+
"url": "https://github.com/your-repo/ai-context-convention-typescript-linter.git"
22+
},
23+
"bugs": {
24+
"url": "https://github.com/your-repo/ai-context-convention-typescript-linter/issues"
25+
},
26+
"homepage": "https://github.com/your-repo/ai-context-convention-typescript-linter#readme",
1527
"devDependencies": {
1628
"@types/js-yaml": "^4.0.9",
1729
"@types/markdown-it": "^14.1.2",
1830
"@types/node": "^22.5.1",
19-
"js-yaml": "^4.1.0",
20-
"markdown-it": "^14.1.0",
2131
"typescript": "^5.5.4"
32+
},
33+
"dependencies": {
34+
"js-yaml": "^4.1.0",
35+
"markdown-it": "^14.1.0"
36+
},
37+
"engines": {
38+
"node": ">=14.0.0"
2239
}
2340
}

linters/typescript/src/cli.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env node
2+
3+
import { TypeScriptLinter } from './typescript_linter';
4+
import { getPackageVersion } from './utils';
5+
6+
async function main() {
7+
const args = process.argv.slice(2);
8+
if (args.length !== 1) {
9+
console.error(`
10+
Usage: ai-context-lint <directory_to_lint>
11+
12+
AI Context Convention TypeScript Linter
13+
This tool validates context files, including .contextdocs.md and .contextignore, according to the AI Context Convention Specification.
14+
`);
15+
process.exit(1);
16+
}
17+
18+
const directoryToLint = args[0];
19+
const packageVersion = await getPackageVersion();
20+
const linter = new TypeScriptLinter();
21+
await linter.lintDirectory(directoryToLint, packageVersion);
22+
}
23+
24+
main().catch(error => {
25+
console.error('An error occurred:', error);
26+
process.exit(1);
27+
});

0 commit comments

Comments
 (0)