Skip to content

Commit f97657e

Browse files
committed
feat: Generate types based on javascript source
Closes #16 Replaces #17
1 parent f6f324c commit f97657e

5 files changed

Lines changed: 35 additions & 8 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
/yarn.lock
33
/package-lock.json
44
/pnpm-lock.yaml
5-
/bun.lockb
5+
/bun.lockb
6+
/types

package.json

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-only-warn",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"license": "MIT",
55
"description": "Downgrade errors to warnings",
66
"keywords": [
@@ -16,17 +16,22 @@
1616
},
1717
"type": "commonjs",
1818
"main": "src/only-warn.js",
19+
"types": "types/only-warn.d.ts",
1920
"prettier": {},
2021
"scripts": {
21-
"lint": "prettier --check . && eslint .",
22+
"lint": "prettier --check . && eslint . && tsc",
2223
"format": "eslint --fix . && prettier --write .",
2324
"test": "vitest run",
24-
"test:watch": "vitest"
25+
"test:watch": "vitest",
26+
"prepublish": "rm -rf types && tsc"
2527
},
2628
"devDependencies": {
27-
"eslint": "^9.4.0",
28-
"eslint-config-prettier": "^9.1.0",
29-
"prettier": "^3.2.5",
30-
"vitest": "^1.6.0"
29+
"@eslint/js": "^10.0.1",
30+
"@types/node": "^25.3.2",
31+
"eslint": "^10.0.2",
32+
"eslint-config-prettier": "^10.1.8",
33+
"prettier": "^3.8.1",
34+
"typescript": "^5.9.3",
35+
"vitest": "^4.0.18"
3136
}
3237
}

src/get-eslint-modules.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
// @ts-check
12
const path = require("path");
23

34
const SEARCH_STR = `${path.sep}node_modules${path.sep}eslint${path.sep}`;
45

56
module.exports = function getEslintModules() {
7+
/** @type {Record<string, any>} */
68
const map = {};
79
Object.keys(require.cache).forEach((modulePath) => {
810
const pos = modulePath.indexOf(SEARCH_STR);

src/only-warn.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1+
// @ts-check
12
const getEslintModules = require("./get-eslint-modules");
23

34
const unpatchedVerify = Symbol("verify");
45

56
/**
67
* Patch the verify method and downgrade the errors to warnings.
8+
* @param {Record<string | symbol, any>} LinterPrototype
79
*/
810
function patch(LinterPrototype) {
911
if (LinterPrototype[unpatchedVerify]) {
1012
return;
1113
}
1214
LinterPrototype[unpatchedVerify] = LinterPrototype.verify;
1315
LinterPrototype.verify = function () {
16+
/** @type ReturnType<import("eslint").Linter["verify"]> */
1417
const messages = LinterPrototype[unpatchedVerify].apply(this, arguments);
1518
messages.forEach((message) => {
1619
if (!message.fatal && message.severity === 2) {
@@ -23,6 +26,7 @@ function patch(LinterPrototype) {
2326

2427
/**
2528
* Remove the patch
29+
* @param {Record<string | symbol, any>} LinterPrototype
2630
*/
2731
function unpatch(LinterPrototype) {
2832
if (LinterPrototype[unpatchedVerify]) {

tsconfig.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"compilerOptions": {
3+
"module": "nodenext",
4+
"target": "esnext",
5+
"declaration": true,
6+
"noUncheckedIndexedAccess": true,
7+
"exactOptionalPropertyTypes": true,
8+
"strict": true,
9+
"skipLibCheck": true,
10+
"allowJs": true,
11+
"emitDeclarationOnly": true,
12+
"outDir": "./types"
13+
},
14+
"include": ["./src"]
15+
}

0 commit comments

Comments
 (0)