@ireneliaoliao/todo-checker 1.0.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/LICENSE +21 -0
- package/README.md +13 -0
- package/index.js +115 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ireneliaoliao
|
|
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,13 @@
|
|
|
1
|
+
# @ireneliaoliao/todo-checker
|
|
2
|
+
|
|
3
|
+
📋 TODO 注释检查器,按时间优先级排序
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@ireneliaoliao/todo-checker)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## 📦 安装
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install -g @ireneliaoliao/todo-checker
|
package/index.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from 'fs-extra';
|
|
4
|
+
import { glob } from 'glob';
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
|
|
7
|
+
async function getAllFiles() {
|
|
8
|
+
return glob('**/*.{js,ts,jsx,tsx,vue,html,css,scss,md}', {
|
|
9
|
+
ignore: ['node_modules/**', 'dist/**', 'build/**', '.git/**', '*.log'],
|
|
10
|
+
})
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function extractTodos(content, filePath) {
|
|
14
|
+
const todos = [];
|
|
15
|
+
const lines = content.split('\n');
|
|
16
|
+
|
|
17
|
+
for(let i = 0; i < lines.length; i++) {
|
|
18
|
+
const line = lines[i];
|
|
19
|
+
|
|
20
|
+
const patterns = [
|
|
21
|
+
/\/\/\s*TODO\s*[::]?\s*(.*)/, // // TODO: xxx
|
|
22
|
+
/\/\*\s*TODO\s*[::]?\s*(.*?)\s*\*\//, // /* TODO: xxx */
|
|
23
|
+
/<!--\s*TODO\s*[::]?\s*(.*?)\s*-->/, // <!-- TODO: xxx -->
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
for(const pattern of patterns) {
|
|
27
|
+
const match = line.match(pattern);
|
|
28
|
+
if(match) {
|
|
29
|
+
const text = match[1].trim();
|
|
30
|
+
|
|
31
|
+
const dateMatch = text.match(/(\d{4}-\d{2}-\d{2})/);
|
|
32
|
+
const date = dateMatch ? new Date(dateMatch[1]) : null;
|
|
33
|
+
const age = date ? (Date.now() - date.getTime()) / (1000 * 60 * 60 * 24) : null;
|
|
34
|
+
|
|
35
|
+
todos.push({
|
|
36
|
+
file: filePath,
|
|
37
|
+
line: i + 1,
|
|
38
|
+
text: text,
|
|
39
|
+
date: date,
|
|
40
|
+
age: age,
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return todos;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function main() {
|
|
52
|
+
console.log(chalk.blue.bold('\nTODO 扫描报告\n'));
|
|
53
|
+
|
|
54
|
+
const files = await getAllFiles();
|
|
55
|
+
let allTodos = [];
|
|
56
|
+
|
|
57
|
+
for(const file of files) {
|
|
58
|
+
const content = await fs.readFile(file, 'utf-8');
|
|
59
|
+
const todos = extractTodos(content, file);
|
|
60
|
+
allTodos.push(...todos);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if(allTodos.length === 0) {
|
|
64
|
+
console.log(chalk.green('🎉 没有发现 TODO 注释!'));
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
console.log(chalk.white(`发现 ${allTodos.length}个TODO注释:\n`));
|
|
69
|
+
|
|
70
|
+
const old = allTodos.filter(t => t.age !== null && t.age > 30);
|
|
71
|
+
const medium = allTodos.filter(t => t.age !== null && t.age > 7 && t.age <= 30);
|
|
72
|
+
const recent = allTodos.filter(t => t.age === null || t.age <= 7);
|
|
73
|
+
|
|
74
|
+
if (old.length > 0) {
|
|
75
|
+
console.log(chalk.yellow(`📅 超过 1 个月的 (${old.length} 个):`))
|
|
76
|
+
for (const todo of old.slice(0, 10)) {
|
|
77
|
+
const dateStr = todo.date ? todo.date.toISOString().split('T')[0] : '无日期'
|
|
78
|
+
console.log(chalk.red(` 🔴 ${todo.file}:${todo.line} (${dateStr})`))
|
|
79
|
+
console.log(chalk.gray(` // TODO: ${todo.text}`))
|
|
80
|
+
}
|
|
81
|
+
if (old.length > 10) {
|
|
82
|
+
console.log(chalk.gray(` ... 还有 ${old.length - 10} 个`))
|
|
83
|
+
}
|
|
84
|
+
console.log()
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (medium.length > 0) {
|
|
88
|
+
console.log(chalk.yellow(`📅 超过 1 周的 (${medium.length} 个):`))
|
|
89
|
+
for (const todo of medium.slice(0, 5)) {
|
|
90
|
+
const dateStr = todo.date ? todo.date.toISOString().split('T')[0] : '无日期'
|
|
91
|
+
console.log(chalk.yellow(` 🟡 ${todo.file}:${todo.line} (${dateStr})`))
|
|
92
|
+
}
|
|
93
|
+
if (medium.length > 5) {
|
|
94
|
+
console.log(chalk.gray(` ... 还有 ${medium.length - 5} 个`))
|
|
95
|
+
}
|
|
96
|
+
console.log()
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (recent.length > 0) {
|
|
100
|
+
console.log(chalk.green(`📅 最近 1 周的 (${recent.length} 个):`))
|
|
101
|
+
for (const todo of recent.slice(0, 5)) {
|
|
102
|
+
console.log(chalk.green(` 🟢 ${todo.file}:${todo.line}`))
|
|
103
|
+
}
|
|
104
|
+
if (recent.length > 5) {
|
|
105
|
+
console.log(chalk.gray(` ... 还有 ${recent.length - 5} 个`))
|
|
106
|
+
}
|
|
107
|
+
console.log()
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (old.length > 0) {
|
|
111
|
+
console.log(chalk.blue('💡 建议: 优先处理 🔴 标记的 TODO'))
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
main().catch(console.error);
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ireneliaoliao/todo-checker",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "📋 TODO 注释检查器,按时间优先级排序",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"todo-checker": "./index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"index.js"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"start": "node index.js"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"todo",
|
|
18
|
+
"checker",
|
|
19
|
+
"cli",
|
|
20
|
+
"technical-debt",
|
|
21
|
+
"analyzer",
|
|
22
|
+
"code-quality"
|
|
23
|
+
],
|
|
24
|
+
"author": {
|
|
25
|
+
"name": "ireneliaoliao"
|
|
26
|
+
},
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/ireneliaoliao/todo-checker.git"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/ireneliaoliao/todo-checker#readme",
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/ireneliaoliao/todo-checker/issues"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=18.0.0"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"chalk": "^5.3.0",
|
|
44
|
+
"fs-extra": "^11.2.0",
|
|
45
|
+
"glob": "^10.3.10"
|
|
46
|
+
}
|
|
47
|
+
}
|