From e05e75fc0b3c59f8b7e25633e1bf6b9c28949b59 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Sat, 26 Oct 2024 05:25:01 -0500 Subject: [PATCH] Add type definitions --- .github/workflows/ci.yml | 18 ++++++++++++++++++ configs.js | 16 +++++++++------- index.js | 11 +++++++---- package.json | 28 ++++++++++++++++++++++++---- tsconfig.json | 21 +++++++++++++++++++++ types/configs.d.ts | 11 +++++++++++ types/index.d.ts | 7 +++++++ 7 files changed, 97 insertions(+), 15 deletions(-) create mode 100644 tsconfig.json create mode 100644 types/configs.d.ts create mode 100644 types/index.d.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6e5048d..469497a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -97,6 +97,24 @@ jobs: - name: ⬆️ Upload coverage report uses: codecov/codecov-action@v4 + are-the-types-wrong: + name: 🤔 Are the types wrong? + runs-on: ubuntu-latest + steps: + - name: ⬇️ Checkout repo + uses: actions/checkout@v4 + + - name: ⎔ Setup Node + uses: actions/setup-node@v4 + with: + node-version: 18 + + - name: 📥 Install dependencies + run: npm install --legacy-peer-deps + + - name: ▶️ Run test:types script + run: npm run test:types -- --format=table + release: name: 🚀 Release needs: [ lint, test ] diff --git a/configs.js b/configs.js index 7e0bd30..dd6fa39 100644 --- a/configs.js +++ b/configs.js @@ -9,14 +9,16 @@ const plugin = { rules, } +const recommended = { + name: "@eslint-community/eslint-comments/recommended", + plugins: { + "@eslint-community/eslint-comments": plugin, + }, + rules: rulesRecommended, +} + module.exports = { - recommended: { - name: '@eslint-community/eslint-comments/recommended', - plugins: { - "@eslint-community/eslint-comments": plugin, - }, - rules: rulesRecommended, - }, + recommended, } module.exports.default = module.exports diff --git a/index.js b/index.js index 5ace35b..78db10c 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,11 @@ -/** DON'T EDIT THIS FILE WHICH WAS CREATED BY 'scripts/generate-index.js'. */ "use strict" +const rules = require("./lib/rules") +const utils = require("./lib/utils") +const configs = require("./lib/configs") + module.exports = { - configs: require("./lib/configs"), - rules: require("./lib/rules"), - utils: require("./lib/utils"), + configs, + rules, + utils, } diff --git a/package.json b/package.json index b8e1af6..596cfd7 100644 --- a/package.json +++ b/package.json @@ -6,13 +6,29 @@ "node": "^12.22.0 || ^14.17.0 || >=16.0.0" }, "main": "index.js", + "types": "./types/index.d.ts", "files": [ "configs.js", - "lib" + "lib", + "types" ], - "exports": { - "./configs": "./configs.js", - ".": "./index.js" + "exports": { + "./package.json": "./package.json", + "./configs": { + "types": "./types/configs.d.ts", + "default": "./configs.js" + }, + ".": { + "types": "./types/index.d.ts", + "default": "./index.js" + } + }, + "typesVersions": { + "*": { + "configs": [ + "./types/configs.d.ts" + ] + } }, "peerDependencies": { "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0" @@ -22,9 +38,11 @@ "ignore": "^5.2.4" }, "devDependencies": { + "@arethetypeswrong/cli": "^0.17.0", "@babel/core": "^7.22.9", "@babel/eslint-parser": "^7.22.9", "@eslint-community/eslint-plugin-mysticatea": "^15.5.1", + "@types/eslint": "^8", "@types/node": "^14.18.54", "@vuepress/plugin-pwa": "^1.9.9", "cross-spawn": "^7.0.3", @@ -37,6 +55,7 @@ "opener": "^1.5.2", "rimraf": "^3.0.2", "semver": "^7.5.4", + "typescript": "^5.6.3", "vite-plugin-eslint4b": "^0.2.1", "vitepress": "^1.0.0-rc.15" }, @@ -49,6 +68,7 @@ "docs:watch": "vitepress dev docs", "lint": "eslint lib scripts tests", "test": "nyc mocha \"tests/lib/**/*.js\" --reporter dot --timeout 8000", + "test:types": "attw --pack", "coverage": "nyc report --reporter lcov && opener coverage/lcov-report/index.html", "watch": "npm run -s test -- --watch --growl" }, diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..fff2a40 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "allowSyntheticDefaultImports": false, + "esModuleInterop": false, + "exactOptionalPropertyTypes": true, + "forceConsistentCasingInFileNames": true, + "isolatedModules": true, + "lib": ["ESNext"], + "module": "NodeNext", + "moduleResolution": "NodeNext", + "noEmit": true, + "resolveJsonModule": true, + "skipLibCheck": false, + "strict": true, + "target": "ESNext", + "useDefineForClassFields": true, + "useUnknownInCatchVariables": true, + "verbatimModuleSyntax": true + }, + "include": ["."] +} diff --git a/types/configs.d.ts b/types/configs.d.ts new file mode 100644 index 0000000..3cf8d1a --- /dev/null +++ b/types/configs.d.ts @@ -0,0 +1,11 @@ +import type { Linter } from "eslint" + +declare namespace Configs { + import defaultExports = Configs + + export const recommended: Linter.Config + + export { defaultExports as default } +} + +export = Configs diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..ee11f5e --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,7 @@ +import type { ESLint, Linter } from "eslint" + +export declare const configs: { recommended: Linter.Config } + +export declare const rules: NonNullable + +export declare const utils: { patch: (ruleId?: string) => void }