Skip to content

Commit d00e2cc

Browse files
committed
feat(development): add development testing setup 🤓
- Add documentation for testing development rules - Add configuration examples for excluding unwanted rules during testing - Add development deno.json with plugin configuration and rule exclusions - Add development README with testing instructions and configuration guide - Add problematic.ts test file with sample code violating multiple lint rules
1 parent 252a569 commit d00e2cc

3 files changed

Lines changed: 112 additions & 0 deletions

File tree

development/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Development Rules Testing
2+
3+
This directory contains development files for testing additional lint rules that leverage Deno's full AST capabilities to fill gaps in the official Deno rules. See [DENO-RULES.md](./DENO-RULES.md) for a complete reference of all official Deno lint rules.
4+
5+
These rules leverage Deno's amazing AST capabilities to provide enhanced auto-fix functionality with better performance than traditional LSP-based approaches, offering more customization opportunities for developers.
6+
7+
## ⚠️ Important Note
8+
9+
> **Known Issue**: Due to [Deno issue #31017](https://github.com/denoland/deno/issues/31017), the `include` configuration in `deno.json` rules section doesn't work for plugin rules. Only `exclude` works. This forces you to load all plugin rules and then disable unwanted ones until the issue is resolved.
10+
11+
## 📋 How to Test
12+
13+
### 1. Configure Rules to Test
14+
15+
Edit `deno.json` and add rules you don't want to test into the `exclude` section:
16+
17+
```json
18+
{
19+
"lint": {
20+
"rules": {
21+
"exclude": [
22+
"deno-lint/prefer-early-return",
23+
"deno-lint/explicit-parameter-types"
24+
// Exclude any rules you don't want to use
25+
]
26+
}
27+
}
28+
}
29+
```
30+
31+
> **Note**: You should use `exclude` instead of `include` due to the aforementioned Deno limitation.
32+
33+
### 2. Write Problematic Code
34+
35+
Create test files with problematic code related to the rules you want to test. This is like regular code that intentionally violates the lint rules to verify they work correctly. Consider mixing problematic code with other valid code to catch more bugs and edge cases.
36+
37+
**Example**: See `problematic.ts` for reference.
38+
39+
### 3. Run Linting
40+
41+
Navigate to the development directory and run:
42+
43+
```bash
44+
cd development
45+
deno lint problematic.ts
46+
```
47+
48+
For automatic fixes:
49+
50+
```bash
51+
deno lint problematic.ts --fix
52+
```

development/deno.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"links": [".."],
3+
"lint": {
4+
"plugins": ["jsr:@neabyte/deno-lint@0.2.1"],
5+
"rules": {
6+
"exclude": [
7+
"deno-lint/async-function-naming",
8+
"deno-lint/explicit-parameter-types",
9+
"deno-lint/explicit-return-types",
10+
"deno-lint/prefer-const-assertions",
11+
"deno-lint/prefer-nullish-coalescing",
12+
"deno-lint/prefer-optional-chain",
13+
"deno-lint/prefer-template-literals",
14+
"deno-lint/prefer-early-return",
15+
"deno-lint/prefer-promise-reject-errors",
16+
"deno-lint/require-error-handling"
17+
]
18+
}
19+
}
20+
}

development/problematic.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Write problematic code here
2+
3+
// Missing return type annotation
4+
function getUserData(id: string) {
5+
return { id, name: 'John' }
6+
}
7+
8+
// Missing parameter type annotation
9+
function processData(data) {
10+
return data.toString()
11+
}
12+
13+
// Using logical OR instead of nullish coalescing
14+
const result = user?.name || 'default'
15+
16+
// Missing async suffix
17+
async function fetchData() {
18+
return await fetch('/api/data')
19+
}
20+
21+
// Nested if statements (should use early return)
22+
function validateUser(user) {
23+
if (user) {
24+
if (user.isActive) {
25+
if (user.role === 'admin') {
26+
return true
27+
}
28+
}
29+
}
30+
return false
31+
}
32+
33+
// Missing const assertion
34+
const config = { apiUrl: 'https://api.example.com' }
35+
36+
// Promise.reject without Error object
37+
Promise.reject('Something went wrong')
38+
39+
// Export to avoid "no unused variable" warnings
40+
export { getUserData, processData, fetchData, validateUser, config, result }

0 commit comments

Comments
 (0)