@vibelint/eslint-plugin-vibelint 0.1.7
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/README.md +39 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +162 -0
- package/dist/index.js.map +1 -0
- package/package.json +35 -0
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @vibelint/eslint-plugin-vibelint
|
|
2
|
+
|
|
3
|
+
ESLint plugin to suppress approved warnings.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -D @vibelint/eslint-plugin-vibelint
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Flat Config
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import suppressApprovedPlugin from "@vibelint/eslint-plugin-vibelint"
|
|
15
|
+
|
|
16
|
+
export default [
|
|
17
|
+
{
|
|
18
|
+
files: ["**/*.{js,ts,jsx,tsx}"],
|
|
19
|
+
plugins: { "suppress-approved": suppressApprovedPlugin },
|
|
20
|
+
processor: "suppress-approved/js" // or /ts, /jsx, /tsx
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Legacy Config
|
|
26
|
+
|
|
27
|
+
```json
|
|
28
|
+
{
|
|
29
|
+
"plugins": ["@vibelint/vibelint"],
|
|
30
|
+
"overrides": [
|
|
31
|
+
{ "files": ["*.js"], "processor": "@vibelint/vibelint/js" },
|
|
32
|
+
{ "files": ["*.ts"], "processor": "@vibelint/vibelint/ts" },
|
|
33
|
+
{ "files": ["*.jsx"], "processor": "@vibelint/vibelint/jsx" },
|
|
34
|
+
{ "files": ["*.tsx"], "processor": "@vibelint/vibelint/tsx" }
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**Note:** Reads from `.eslint-warnings-cache.json` (created by `@vibelint/vibelint-wizard`).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA4HA,QAAA,MAAM,sBAAsB,EAAE;IAC5B,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAA;IACvC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACnC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAA;CAwFpC,CAAA;AAoCD,eAAe,sBAAsB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { createHash } from "crypto";
|
|
2
|
+
import { existsSync, readFileSync } from "fs";
|
|
3
|
+
import { join, relative } from "path";
|
|
4
|
+
const CACHE_FILE = join(process.cwd(), ".eslint-warnings-cache.json");
|
|
5
|
+
function computeCodeHash(lineContent) {
|
|
6
|
+
const trimmed = lineContent.trim();
|
|
7
|
+
return createHash("sha256").update(trimmed).digest("hex");
|
|
8
|
+
}
|
|
9
|
+
function createFingerprint(filePath, ruleId, message, lineContent) {
|
|
10
|
+
const relativePath = relative(process.cwd(), filePath).replace(/\\/g, "/");
|
|
11
|
+
const codeHash = computeCodeHash(lineContent);
|
|
12
|
+
return {
|
|
13
|
+
file: relativePath,
|
|
14
|
+
ruleId: ruleId || "unknown",
|
|
15
|
+
codeHash,
|
|
16
|
+
message
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function fingerprintMatches(fp1, fp2) {
|
|
20
|
+
return (fp1.file === fp2.file && fp1.ruleId === fp2.ruleId && fp1.codeHash === fp2.codeHash && fp1.message === fp2.message);
|
|
21
|
+
}
|
|
22
|
+
function loadCache() {
|
|
23
|
+
try {
|
|
24
|
+
if (!existsSync(CACHE_FILE)) {
|
|
25
|
+
return { approvedWarnings: [] };
|
|
26
|
+
}
|
|
27
|
+
const content = readFileSync(CACHE_FILE, "utf-8");
|
|
28
|
+
const parsed = JSON.parse(content);
|
|
29
|
+
const warnings = parsed.approvedWarnings || [];
|
|
30
|
+
return {
|
|
31
|
+
approvedWarnings: warnings
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return { approvedWarnings: [] };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function readSourceLine(filePath, lineNumber) {
|
|
39
|
+
try {
|
|
40
|
+
const content = readFileSync(filePath, "utf-8");
|
|
41
|
+
const lines = content.split("\n");
|
|
42
|
+
if (lineNumber > 0 && lineNumber <= lines.length) {
|
|
43
|
+
return lines[lineNumber - 1];
|
|
44
|
+
}
|
|
45
|
+
return "";
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return "";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function filterApprovedMessages(messages, filename) {
|
|
52
|
+
const cache = loadCache();
|
|
53
|
+
if (cache.approvedWarnings.length === 0) {
|
|
54
|
+
return messages;
|
|
55
|
+
}
|
|
56
|
+
if (!filename || !messages || messages.length === 0) {
|
|
57
|
+
return messages;
|
|
58
|
+
}
|
|
59
|
+
const filtered = messages.filter((message) => {
|
|
60
|
+
// Only filter warnings (severity 1), not errors (severity 2)
|
|
61
|
+
if (!message || message.severity !== 1) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
const lineContent = message.source || readSourceLine(filename, message.line || 0);
|
|
66
|
+
const fingerprint = createFingerprint(filename, message.ruleId || null, message.message || "", lineContent);
|
|
67
|
+
// Check if this warning is approved
|
|
68
|
+
const isApproved = cache.approvedWarnings.some((approved) => fingerprintMatches(approved, fingerprint));
|
|
69
|
+
// Return false to suppress approved warnings
|
|
70
|
+
return !isApproved;
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
// If there's an error filtering, keep the message
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
return filtered;
|
|
78
|
+
}
|
|
79
|
+
// ESLint 9 flat config plugin
|
|
80
|
+
const suppressApprovedPlugin = {
|
|
81
|
+
meta: {
|
|
82
|
+
name: "@vibelint/eslint-plugin-vibelint",
|
|
83
|
+
version: "0.1.0"
|
|
84
|
+
},
|
|
85
|
+
processors: {
|
|
86
|
+
js: {
|
|
87
|
+
postprocess(messages, filename) {
|
|
88
|
+
if (!messages)
|
|
89
|
+
return [];
|
|
90
|
+
// Flatten if messages is an array of arrays
|
|
91
|
+
const flatMessages = messages.flat();
|
|
92
|
+
return filterApprovedMessages(flatMessages, filename || "");
|
|
93
|
+
},
|
|
94
|
+
supportsAutofix: false
|
|
95
|
+
},
|
|
96
|
+
ts: {
|
|
97
|
+
postprocess(messages, filename) {
|
|
98
|
+
if (!messages)
|
|
99
|
+
return [];
|
|
100
|
+
// Flatten if messages is an array of arrays
|
|
101
|
+
const flatMessages = messages.flat();
|
|
102
|
+
return filterApprovedMessages(flatMessages, filename || "");
|
|
103
|
+
},
|
|
104
|
+
supportsAutofix: false
|
|
105
|
+
},
|
|
106
|
+
tsx: {
|
|
107
|
+
postprocess(messages, filename) {
|
|
108
|
+
if (!messages)
|
|
109
|
+
return [];
|
|
110
|
+
// Flatten if messages is an array of arrays
|
|
111
|
+
const flatMessages = messages.flat();
|
|
112
|
+
return filterApprovedMessages(flatMessages, filename || "");
|
|
113
|
+
},
|
|
114
|
+
supportsAutofix: false
|
|
115
|
+
},
|
|
116
|
+
jsx: {
|
|
117
|
+
postprocess(messages, filename) {
|
|
118
|
+
if (!messages)
|
|
119
|
+
return [];
|
|
120
|
+
// Flatten if messages is an array of arrays
|
|
121
|
+
const flatMessages = messages.flat();
|
|
122
|
+
return filterApprovedMessages(flatMessages, filename || "");
|
|
123
|
+
},
|
|
124
|
+
supportsAutofix: false
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
// Add configs after the plugin is defined to avoid circular reference
|
|
129
|
+
suppressApprovedPlugin.configs = {
|
|
130
|
+
recommended: [
|
|
131
|
+
{
|
|
132
|
+
files: ["**/*.js"],
|
|
133
|
+
plugins: {
|
|
134
|
+
"suppress-approved": suppressApprovedPlugin
|
|
135
|
+
},
|
|
136
|
+
processor: "suppress-approved/js"
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
files: ["**/*.ts"],
|
|
140
|
+
plugins: {
|
|
141
|
+
"suppress-approved": suppressApprovedPlugin
|
|
142
|
+
},
|
|
143
|
+
processor: "suppress-approved/ts"
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
files: ["**/*.jsx"],
|
|
147
|
+
plugins: {
|
|
148
|
+
"suppress-approved": suppressApprovedPlugin
|
|
149
|
+
},
|
|
150
|
+
processor: "suppress-approved/jsx"
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
files: ["**/*.tsx"],
|
|
154
|
+
plugins: {
|
|
155
|
+
"suppress-approved": suppressApprovedPlugin
|
|
156
|
+
},
|
|
157
|
+
processor: "suppress-approved/tsx"
|
|
158
|
+
}
|
|
159
|
+
]
|
|
160
|
+
};
|
|
161
|
+
export default suppressApprovedPlugin;
|
|
162
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,IAAI,CAAA;AAC7C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAA;AAErC,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,6BAA6B,CAAC,CAAA;AAarE,SAAS,eAAe,CAAC,WAAmB;IAC1C,MAAM,OAAO,GAAG,WAAW,CAAC,IAAI,EA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,MAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAA;gBACpC,OAAO,sBAAsB,CAAC,YAAY,EAAE,QAAQ,IAAI,EAAE,CAAC,CAAA;YAC7D,CAAC;YACD,eAAe,EAAE,KAAK;SACvB;QACD,GAAG,EAAE;YACH,WAAW,CACT,QAQC,EACD,QAAiB;gBAEjB,IAAI,CAAC,QAAQ;oBAAE,OAAO,EAAE,CAAA;gBACxB,4CAA4C;gBAC5C,MAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAA;gBACpC,OAAO,sBAAsB,CAAC,YAAY,EAAE,QAAQ,IAAI,EAAE,CAAC,CAAA;YAC7D,CAAC;YACD,eAAe,EAAE,KAAK;SACvB;KACF;CACF,CAAA;AAED,sEAAsE;AACtE,sBAAsB,CAAC,OAAO,GAAG;IAC/B,WAAW,EAAE;QACX;YACE,KAAK,EAAE,CAAC,SAAS,CAAC;YAClB,OAAO,EAAE;gBACP,mBAAmB,EAAE,sBAAsB;aAC5C;YACD,SAAS,EAAE,sBAAsB;SAClC;QACD;YACE,KAAK,EAAE,CAAC,SAAS,CAAC;YAClB,OAAO,EAAE;gBACP,mBAAmB,EAAE,sBAAsB;aAC5C;YACD,SAAS,EAAE,sBAAsB;SAClC;QACD;YACE,KAAK,EAAE,CAAC,UAAU,CAAC;YACnB,OAAO,EAAE;gBACP,mBAAmB,EAAE,sBAAsB;aAC5C;YACD,SAAS,EAAE,uBAAuB;SACnC;QACD;YACE,KAAK,EAAE,CAAC,UAAU,CAAC;YACnB,OAAO,EAAE;gBACP,mBAAmB,EAAE,sBAAsB;aAC5C;YACD,SAAS,EAAE,uBAAuB;SACnC;KACF;CACF,CAAA;AAED,eAAe,sBAAsB,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vibelint/eslint-plugin-vibelint",
|
|
3
|
+
"version": "0.1.7",
|
|
4
|
+
"description": "ESLint plugin to suppress approved warnings based on cache file",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"keywords": [
|
|
18
|
+
"eslint",
|
|
19
|
+
"eslint-plugin",
|
|
20
|
+
"warnings",
|
|
21
|
+
"suppress",
|
|
22
|
+
"approval"
|
|
23
|
+
],
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=18"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"eslint": ">=9.0.0"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc",
|
|
33
|
+
"clean": "rm -rf dist"
|
|
34
|
+
}
|
|
35
|
+
}
|