@aiready/consistency 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +24 -0
- package/CONTRIBUTING.md +153 -0
- package/LICENSE +21 -0
- package/README.md +170 -0
- package/dist/chunk-BDDMOIU2.mjs +385 -0
- package/dist/chunk-CF4LU7KE.mjs +384 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +626 -0
- package/dist/cli.mjs +224 -0
- package/dist/index.d.mts +77 -0
- package/dist/index.d.ts +77 -0
- package/dist/index.js +415 -0
- package/dist/index.mjs +12 -0
- package/package.json +63 -0
- package/src/__tests__/analyzer.test.ts +127 -0
- package/src/analyzer.ts +182 -0
- package/src/analyzers/naming.ts +134 -0
- package/src/analyzers/patterns.ts +192 -0
- package/src/cli.ts +254 -0
- package/src/index.ts +11 -0
- package/src/types.ts +62 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
> @aiready/consistency@0.2.0 build /Users/pengcao/projects/aiready/packages/consistency
|
|
4
|
+
> tsup src/index.ts src/cli.ts --format cjs,esm --dts
|
|
5
|
+
|
|
6
|
+
[34mCLI[39m Building entry: src/cli.ts, src/index.ts
|
|
7
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
8
|
+
[34mCLI[39m tsup v8.5.1
|
|
9
|
+
[34mCLI[39m Target: es2020
|
|
10
|
+
[34mCJS[39m Build start
|
|
11
|
+
[34mESM[39m Build start
|
|
12
|
+
[32mCJS[39m [1mdist/cli.js [22m[32m22.47 KB[39m
|
|
13
|
+
[32mCJS[39m [1mdist/index.js [22m[32m14.13 KB[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 47ms
|
|
15
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m220.00 B[39m
|
|
16
|
+
[32mESM[39m [1mdist/cli.mjs [22m[32m8.08 KB[39m
|
|
17
|
+
[32mESM[39m [1mdist/chunk-CF4LU7KE.mjs [22m[32m12.90 KB[39m
|
|
18
|
+
[32mESM[39m ⚡️ Build success in 48ms
|
|
19
|
+
DTS Build start
|
|
20
|
+
DTS ⚡️ Build success in 588ms
|
|
21
|
+
DTS dist/cli.d.ts 20.00 B
|
|
22
|
+
DTS dist/index.d.ts 2.60 KB
|
|
23
|
+
DTS dist/cli.d.mts 20.00 B
|
|
24
|
+
DTS dist/index.d.mts 2.60 KB
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# Contributing to @aiready/consistency
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing to AIReady Consistency Checker! We welcome bug reports, feature requests, and code contributions.
|
|
4
|
+
|
|
5
|
+
## 🐛 Reporting Issues
|
|
6
|
+
|
|
7
|
+
Found a bug or have a feature request? [Open an issue](https://github.com/caopengau/aiready-consistency/issues) with:
|
|
8
|
+
- Clear description of the problem or feature
|
|
9
|
+
- Sample code that demonstrates the issue
|
|
10
|
+
- Expected vs actual behavior
|
|
11
|
+
- Your environment (Node version, OS)
|
|
12
|
+
|
|
13
|
+
## 🔧 Development Setup
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# Clone your fork
|
|
17
|
+
git clone https://github.com/YOUR_USERNAME/aiready-consistency
|
|
18
|
+
cd aiready-consistency
|
|
19
|
+
|
|
20
|
+
# Install dependencies
|
|
21
|
+
pnpm install
|
|
22
|
+
|
|
23
|
+
# Build
|
|
24
|
+
pnpm build
|
|
25
|
+
|
|
26
|
+
# Run tests
|
|
27
|
+
pnpm test
|
|
28
|
+
|
|
29
|
+
# Test CLI locally
|
|
30
|
+
./dist/cli.js ../test-project
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 📝 Making Changes
|
|
34
|
+
|
|
35
|
+
1. **Fork the repository** and create a new branch:
|
|
36
|
+
```bash
|
|
37
|
+
git checkout -b fix/naming-detection
|
|
38
|
+
# or
|
|
39
|
+
git checkout -b feat/new-pattern-check
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
2. **Make your changes** following our code style:
|
|
43
|
+
- Use TypeScript strict mode
|
|
44
|
+
- Add tests for new detectors
|
|
45
|
+
- Update README with new features
|
|
46
|
+
- Keep analyzers modular and focused
|
|
47
|
+
|
|
48
|
+
3. **Test your changes**:
|
|
49
|
+
```bash
|
|
50
|
+
pnpm build
|
|
51
|
+
pnpm test
|
|
52
|
+
|
|
53
|
+
# Test on real projects
|
|
54
|
+
./dist/cli.js path/to/test-project
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
4. **Commit and push**:
|
|
58
|
+
```bash
|
|
59
|
+
git add .
|
|
60
|
+
git commit -m "feat: add camelCase detection for Python"
|
|
61
|
+
git push origin your-branch
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
5. **Open a Pull Request** with:
|
|
65
|
+
- Description of changes
|
|
66
|
+
- Test results
|
|
67
|
+
- Screenshots (if applicable)
|
|
68
|
+
|
|
69
|
+
## 🧪 Testing Guidelines
|
|
70
|
+
|
|
71
|
+
- Add tests for new naming patterns
|
|
72
|
+
- Test on multiple file types (TS, JS, Python, etc.)
|
|
73
|
+
- Verify false positive rate is acceptable
|
|
74
|
+
- Check performance with large codebases
|
|
75
|
+
|
|
76
|
+
## 🏗️ Architecture
|
|
77
|
+
|
|
78
|
+
### Directory Structure
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
src/
|
|
82
|
+
├── analyzers/ # Individual analyzers
|
|
83
|
+
│ ├── naming.ts # Naming quality & conventions
|
|
84
|
+
│ ├── patterns.ts # Code pattern consistency
|
|
85
|
+
│ └── architecture.ts # (future) Architecture checks
|
|
86
|
+
├── analyzer.ts # Main orchestrator
|
|
87
|
+
├── types.ts # Type definitions
|
|
88
|
+
├── cli.ts # CLI interface
|
|
89
|
+
└── index.ts # Public API exports
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Adding a New Analyzer
|
|
93
|
+
|
|
94
|
+
1. Create `src/analyzers/your-analyzer.ts`:
|
|
95
|
+
```typescript
|
|
96
|
+
import type { YourIssueType } from '../types';
|
|
97
|
+
|
|
98
|
+
export async function analyzeYourThing(files: string[]): Promise<YourIssueType[]> {
|
|
99
|
+
// Your detection logic
|
|
100
|
+
return issues;
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
2. Update `src/types.ts` with new issue types
|
|
105
|
+
|
|
106
|
+
3. Integrate in `src/analyzer.ts`
|
|
107
|
+
|
|
108
|
+
4. Add CLI options in `src/cli.ts`
|
|
109
|
+
|
|
110
|
+
5. Export from `src/index.ts`
|
|
111
|
+
|
|
112
|
+
6. Add tests in `src/__tests__/`
|
|
113
|
+
|
|
114
|
+
## 📊 Pattern Detection Guidelines
|
|
115
|
+
|
|
116
|
+
When adding new consistency checks:
|
|
117
|
+
|
|
118
|
+
1. **Focus on AI Impact**: Does this inconsistency confuse AI models?
|
|
119
|
+
2. **Minimize False Positives**: Acceptable patterns should not be flagged
|
|
120
|
+
3. **Provide Context**: Include file, line, and clear suggestions
|
|
121
|
+
4. **Categorize Properly**: Is it naming, pattern, or architecture?
|
|
122
|
+
5. **Consider Performance**: Avoid expensive operations on every line
|
|
123
|
+
|
|
124
|
+
## 🎯 Code Style
|
|
125
|
+
|
|
126
|
+
- Follow existing patterns in the codebase
|
|
127
|
+
- Use descriptive variable names (we're checking naming, after all!)
|
|
128
|
+
- Add comments for complex logic
|
|
129
|
+
- Keep functions focused and small
|
|
130
|
+
- Prefer composition over inheritance
|
|
131
|
+
|
|
132
|
+
## 🔄 Monorepo Development
|
|
133
|
+
|
|
134
|
+
This package is part of the AIReady monorepo. If contributing to the monorepo:
|
|
135
|
+
|
|
136
|
+
1. Work in `packages/consistency/`
|
|
137
|
+
2. Use `pnpm` for package management
|
|
138
|
+
3. Follow hub-and-spoke patterns (only import from `@aiready/core`)
|
|
139
|
+
4. Test integration with `@aiready/cli`
|
|
140
|
+
|
|
141
|
+
## 📚 Resources
|
|
142
|
+
|
|
143
|
+
- [AIReady Main Repo](https://github.com/caopengau/aiready)
|
|
144
|
+
- [AIReady Documentation](.github/copilot-instructions.md)
|
|
145
|
+
- [TypeScript Best Practices](https://github.com/labs42io/clean-code-typescript)
|
|
146
|
+
|
|
147
|
+
## 🤝 Code of Conduct
|
|
148
|
+
|
|
149
|
+
Be respectful, constructive, and inclusive. We're all learning and improving together.
|
|
150
|
+
|
|
151
|
+
## 📄 License
|
|
152
|
+
|
|
153
|
+
By contributing, you agree that your contributions will be licensed under the MIT License.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AIReady Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# @aiready/consistency
|
|
2
|
+
|
|
3
|
+
> **Detect consistency issues in naming, patterns, and architecture that confuse AI models**
|
|
4
|
+
|
|
5
|
+
Helps teams maintain consistent coding practices across their codebase, making it easier for AI tools to understand and work with your code.
|
|
6
|
+
|
|
7
|
+
## 🚀 Quick Start
|
|
8
|
+
|
|
9
|
+
**Recommended: Use the unified CLI** (includes consistency checking + more tools):
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install -g @aiready/cli
|
|
13
|
+
aiready consistency ./src
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
**Or use this package directly:**
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install -g @aiready/consistency
|
|
20
|
+
aiready-consistency ./src
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 🎯 What It Does
|
|
24
|
+
|
|
25
|
+
Inconsistent code patterns confuse AI models and reduce their effectiveness. This tool analyzes:
|
|
26
|
+
|
|
27
|
+
### 🏷️ Naming Quality & Conventions
|
|
28
|
+
- Single-letter variables (except loop counters)
|
|
29
|
+
- Unclear abbreviations
|
|
30
|
+
- Mixed naming conventions (camelCase vs snake_case)
|
|
31
|
+
- Boolean naming (should use is/has/can prefixes)
|
|
32
|
+
- Function naming (should start with action verbs)
|
|
33
|
+
|
|
34
|
+
### 🔄 Pattern Consistency
|
|
35
|
+
- Error handling strategies (try-catch vs returns)
|
|
36
|
+
- Async patterns (async/await vs promises vs callbacks)
|
|
37
|
+
- Import styles (ES modules vs CommonJS)
|
|
38
|
+
- API design patterns
|
|
39
|
+
|
|
40
|
+
### 🏗️ Architectural Consistency *(coming soon)*
|
|
41
|
+
- File organization patterns
|
|
42
|
+
- Module structure
|
|
43
|
+
- Export/import patterns
|
|
44
|
+
|
|
45
|
+
## 📊 Example Output
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
📊 Summary
|
|
49
|
+
|
|
50
|
+
Files Analyzed: 47
|
|
51
|
+
Total Issues: 23
|
|
52
|
+
Naming: 15
|
|
53
|
+
Patterns: 8
|
|
54
|
+
Architecture: 0
|
|
55
|
+
|
|
56
|
+
🏷️ Naming Issues
|
|
57
|
+
|
|
58
|
+
MINOR src/utils/helpers.ts:12
|
|
59
|
+
poor-naming: x
|
|
60
|
+
→ Use descriptive variable name instead of single letter 'x'
|
|
61
|
+
|
|
62
|
+
MINOR src/components/User.ts:45
|
|
63
|
+
convention-mix: user_name
|
|
64
|
+
→ Use camelCase 'userName' instead of snake_case in TypeScript/JavaScript
|
|
65
|
+
|
|
66
|
+
🔄 Pattern Issues
|
|
67
|
+
|
|
68
|
+
MAJOR multiple files
|
|
69
|
+
Inconsistent error handling strategies across codebase
|
|
70
|
+
→ Standardize error handling strategy (prefer try-catch with typed errors)
|
|
71
|
+
|
|
72
|
+
💡 Recommendations
|
|
73
|
+
|
|
74
|
+
1. Standardize naming conventions: Found 7 snake_case variables in TypeScript
|
|
75
|
+
2. Improve variable naming: Found 8 single-letter or unclear variable names
|
|
76
|
+
3. Use async/await consistently instead of mixing with promise chains
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## ⚙️ Usage
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# Full analysis
|
|
83
|
+
aiready-consistency ./src
|
|
84
|
+
|
|
85
|
+
# Skip naming checks
|
|
86
|
+
aiready-consistency ./src --no-naming
|
|
87
|
+
|
|
88
|
+
# Skip pattern checks
|
|
89
|
+
aiready-consistency ./src --no-patterns
|
|
90
|
+
|
|
91
|
+
# Show only major issues
|
|
92
|
+
aiready-consistency ./src --min-severity major
|
|
93
|
+
|
|
94
|
+
# Export to JSON
|
|
95
|
+
aiready-consistency ./src --output json > report.json
|
|
96
|
+
|
|
97
|
+
# Export to Markdown
|
|
98
|
+
aiready-consistency ./src --output markdown --output-file report.md
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## 🎛️ Options
|
|
102
|
+
|
|
103
|
+
| Option | Description | Default |
|
|
104
|
+
|--------|-------------|---------|
|
|
105
|
+
| `--naming` | Enable naming analysis | `true` |
|
|
106
|
+
| `--no-naming` | Skip naming analysis | - |
|
|
107
|
+
| `--patterns` | Enable pattern analysis | `true` |
|
|
108
|
+
| `--no-patterns` | Skip pattern analysis | - |
|
|
109
|
+
| `--min-severity` | Minimum severity: info\|minor\|major\|critical | `info` |
|
|
110
|
+
| `--include` | File patterns to include | All files |
|
|
111
|
+
| `--exclude` | File patterns to exclude | - |
|
|
112
|
+
| `--output` | Output format: console\|json\|markdown | `console` |
|
|
113
|
+
| `--output-file` | Output file path | - |
|
|
114
|
+
|
|
115
|
+
## 📝 Configuration File
|
|
116
|
+
|
|
117
|
+
Create `aiready.json` in your project root:
|
|
118
|
+
|
|
119
|
+
```json
|
|
120
|
+
{
|
|
121
|
+
"consistency": {
|
|
122
|
+
"checkNaming": true,
|
|
123
|
+
"checkPatterns": true,
|
|
124
|
+
"minSeverity": "minor",
|
|
125
|
+
"exclude": ["**/dist/**", "**/node_modules/**"]
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## 🔧 Programmatic API
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import { analyzeConsistency } from '@aiready/consistency';
|
|
134
|
+
|
|
135
|
+
const report = await analyzeConsistency({
|
|
136
|
+
rootDir: './src',
|
|
137
|
+
checkNaming: true,
|
|
138
|
+
checkPatterns: true,
|
|
139
|
+
minSeverity: 'minor'
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
console.log(`Found ${report.summary.totalIssues} issues`);
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## 🤝 Why This Matters for AI
|
|
146
|
+
|
|
147
|
+
AI models work best with consistent codebases because:
|
|
148
|
+
|
|
149
|
+
1. **Pattern Recognition**: Consistent patterns help AI understand your coding style
|
|
150
|
+
2. **Context Efficiency**: Less variation = more useful code fits in context window
|
|
151
|
+
3. **Accurate Suggestions**: AI can predict conventions and follow them
|
|
152
|
+
4. **Reduced Errors**: AI makes fewer mistakes with clear, consistent patterns
|
|
153
|
+
|
|
154
|
+
## 📦 Integration with AIReady
|
|
155
|
+
|
|
156
|
+
This tool is part of the [AIReady](https://github.com/caopengau/aiready) ecosystem:
|
|
157
|
+
|
|
158
|
+
- **@aiready/cli** - Unified interface for all analysis tools
|
|
159
|
+
- **@aiready/pattern-detect** - Semantic duplicate detection
|
|
160
|
+
- **@aiready/context-analyzer** - Context window cost analysis
|
|
161
|
+
- **@aiready/consistency** - Consistency analysis (this tool)
|
|
162
|
+
|
|
163
|
+
## 📖 Documentation
|
|
164
|
+
|
|
165
|
+
- [Contributing Guide](./CONTRIBUTING.md)
|
|
166
|
+
- [AIReady Main Repo](https://github.com/caopengau/aiready)
|
|
167
|
+
|
|
168
|
+
## 📄 License
|
|
169
|
+
|
|
170
|
+
MIT © AIReady Team
|