From 95211dc09ccf485aae1bb6c0ffe08ce0fc56cebb Mon Sep 17 00:00:00 2001 From: alex8088 <244096523@qq.com> Date: Mon, 24 Jul 2023 23:23:43 +0800 Subject: [PATCH] chore: ESLint config for Electron-TypeScript projects --- packages/eslint-config-ts/LICENSE | 21 ++++++++ packages/eslint-config-ts/README.md | 49 +++++++++++++++++++ .../eslint-config-ts/eslint-recommended.js | 20 ++++++++ packages/eslint-config-ts/index.js | 18 +++++++ packages/eslint-config-ts/package.json | 44 +++++++++++++++++ packages/eslint-config-ts/recommended.js | 3 ++ pnpm-lock.yaml | 34 +++++-------- 7 files changed, 168 insertions(+), 21 deletions(-) create mode 100644 packages/eslint-config-ts/LICENSE create mode 100644 packages/eslint-config-ts/README.md create mode 100644 packages/eslint-config-ts/eslint-recommended.js create mode 100644 packages/eslint-config-ts/index.js create mode 100644 packages/eslint-config-ts/package.json create mode 100644 packages/eslint-config-ts/recommended.js diff --git a/packages/eslint-config-ts/LICENSE b/packages/eslint-config-ts/LICENSE new file mode 100644 index 0000000..ca59cb7 --- /dev/null +++ b/packages/eslint-config-ts/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022-present, Alex.Wei + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/eslint-config-ts/README.md b/packages/eslint-config-ts/README.md new file mode 100644 index 0000000..7e31792 --- /dev/null +++ b/packages/eslint-config-ts/README.md @@ -0,0 +1,49 @@ +# @electron-toolkit/eslint-config-ts + +> Basic ESLint config for Electron-TypeScript projects. + +Requires `eslint >= 8.0.0`. + +This config is specifically designed to be used by `@quick-start/create-electron` setups. + +See [@typescript-eslint/eslint-plugin](https://typescript-eslint.io/rules/) for available rules. + +## Installation + +```sh +npm add -D @electron-toolkit/eslint-config-ts +``` + +## Usage + +This package comes with 3 rulesets. + +### @electron-toolkit/eslint-config-ts + +This ruleset is the base configuration for Electron-TypeScript projects. + +```js +module.exports = { + extends: ['@electron-toolkit/eslint-config-ts'] +} +``` + +### @electron-toolkit/eslint-config-ts/eslint-recommended + +Built-in some recommended rules for Electron-TypeScript projects. + +```js +module.exports = { + extends: ['@electron-toolkit/eslint-config-ts/eslint-recommended'] +} +``` + +### @electron-toolkit/eslint-config-ts/recommended + +This is extended from `@electron-toolkit/eslint-config-ts` and `@electron-toolkit/eslint-config-ts/eslint-recommended` ruleset. + +```js +module.exports = { + extends: ['@electron-toolkit/eslint-config-ts/recommended'] +} +``` diff --git a/packages/eslint-config-ts/eslint-recommended.js b/packages/eslint-config-ts/eslint-recommended.js new file mode 100644 index 0000000..197ea23 --- /dev/null +++ b/packages/eslint-config-ts/eslint-recommended.js @@ -0,0 +1,20 @@ +module.exports = { + rules: { + '@typescript-eslint/ban-ts-comment': ['error', { 'ts-ignore': 'allow-with-description' }], + '@typescript-eslint/explicit-function-return-type': 'error', + '@typescript-eslint/explicit-module-boundary-types': 'off', + '@typescript-eslint/no-empty-function': ['error', { allow: ['arrowFunctions'] }], + '@typescript-eslint/no-empty-interface': ['error', { allowSingleExtends: true }], + '@typescript-eslint/no-explicit-any': 'error', + '@typescript-eslint/no-non-null-assertion': 'off', + '@typescript-eslint/no-var-requires': 'off' + }, + overrides: [ + { + files: ['*.js'], + rules: { + '@typescript-eslint/explicit-function-return-type': 'off' + } + } + ] +} diff --git a/packages/eslint-config-ts/index.js b/packages/eslint-config-ts/index.js new file mode 100644 index 0000000..cf927a2 --- /dev/null +++ b/packages/eslint-config-ts/index.js @@ -0,0 +1,18 @@ +module.exports = { + env: { + browser: true, + commonjs: true, + es6: true, + node: true + }, + parser: '@typescript-eslint/parser', + parserOptions: { + ecmaFeatures: { + jsx: true + }, + sourceType: 'module', + ecmaVersion: 2021 + }, + plugins: ['@typescript-eslint'], + extends: ['plugin:@typescript-eslint/recommended', 'plugin:@typescript-eslint/eslint-recommended'] +} diff --git a/packages/eslint-config-ts/package.json b/packages/eslint-config-ts/package.json new file mode 100644 index 0000000..5c50292 --- /dev/null +++ b/packages/eslint-config-ts/package.json @@ -0,0 +1,44 @@ +{ + "name": "@electron-toolkit/eslint-config-ts", + "version": "0.0.0", + "description": "Basic ESLint config for Electron-TypeScript projects.", + "main": "index.js", + "files": [ + "eslint-recommended.js", + "index.js", + "recommended.js" + ], + "author": "Alex Wei", + "license": "MIT", + "repository": { + "type": "git", + "url": "git+https://github.com/alex8088/electron-toolkit.git", + "directory": "packages/eslint-config-ts" + }, + "bugs": { + "url": "https://github.com/alex8088/electron-toolkit/issues" + }, + "homepage": "https://github.com/alex8088/electron-toolkit/tree/master/packages/eslint-config-ts#readme", + "keywords": [ + "electron", + "eslint", + "typescript" + ], + "dependencies": { + "@typescript-eslint/eslint-plugin": "^6.1.0", + "@typescript-eslint/parser": "^6.1.0" + }, + "devDependencies": { + "eslint": "^8.45.0", + "typescript": "^4.5.4" + }, + "peerDependencies": { + "eslint": ">=8.0.0", + "typescript": "*" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } +} diff --git a/packages/eslint-config-ts/recommended.js b/packages/eslint-config-ts/recommended.js new file mode 100644 index 0000000..a73f2a5 --- /dev/null +++ b/packages/eslint-config-ts/recommended.js @@ -0,0 +1,3 @@ +module.exports = { + extends: [require.resolve('./index'), require.resolve('./eslint-recommended')] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cdf01d9..b8c6886 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -65,6 +65,19 @@ importers: eslint: 8.45.0 prettier: 3.0.0 + packages/eslint-config-ts: + specifiers: + '@typescript-eslint/eslint-plugin': ^6.1.0 + '@typescript-eslint/parser': ^6.1.0 + eslint: ^8.45.0 + typescript: ^4.5.4 + dependencies: + '@typescript-eslint/eslint-plugin': 6.1.0_y5sn6uztqxc52vsd3gowksip2i + '@typescript-eslint/parser': 6.1.0_34bnyqoxsac45lgkbz54epaynm + devDependencies: + eslint: 8.45.0 + typescript: 4.5.4 + packages/playground: specifiers: '@electron-toolkit/preload': workspace:* @@ -320,7 +333,6 @@ packages: /@types/json-schema/7.0.12: resolution: {integrity: sha512-Hr5Jfhc9eYOQNPYO5WLDq/n4jqijdHNlDXjuAQkkt+mWdQR+XJToOHrsD4cPaMXpn6KO7y2+wM8AZEs8VpBLVA==} - dev: true /@types/keyv/3.1.4: resolution: {integrity: sha512-BQ5aZNSCpj7D6K2ksrRCTmKRLEpnPvWDiLPfoGyhZ++8YtiK9d/3DBKPJgry359X/P1PfruyYwvnvwFjuEiEIg==} @@ -354,7 +366,6 @@ packages: /@types/semver/7.5.0: resolution: {integrity: sha512-G8hZ6XJiHnuhQKR7ZmysCeJWE08o8T0AXtk5darsCaTVsYZhhgUrq53jizaR2FvsoeCwJhlmwTjkXBY5Pn/ZHw==} - dev: true /@typescript-eslint/eslint-plugin/6.1.0_y5sn6uztqxc52vsd3gowksip2i: resolution: {integrity: sha512-qg7Bm5TyP/I7iilGyp6DRqqkt8na00lI6HbjWZObgk3FFSzH5ypRwAHXJhJkwiRtTcfn+xYQIMOR5kJgpo6upw==} @@ -384,7 +395,6 @@ packages: typescript: 4.5.4 transitivePeerDependencies: - supports-color - dev: true /@typescript-eslint/parser/6.1.0_34bnyqoxsac45lgkbz54epaynm: resolution: {integrity: sha512-hIzCPvX4vDs4qL07SYzyomamcs2/tQYXg5DtdAfj35AyJ5PIUqhsLf4YrEIFzZcND7R2E8tpQIZKayxg8/6Wbw==} @@ -405,7 +415,6 @@ packages: typescript: 4.5.4 transitivePeerDependencies: - supports-color - dev: true /@typescript-eslint/scope-manager/6.1.0: resolution: {integrity: sha512-AxjgxDn27hgPpe2rQe19k0tXw84YCOsjDJ2r61cIebq1t+AIxbgiXKvD4999Wk49GVaAcdJ/d49FYel+Pp3jjw==} @@ -413,7 +422,6 @@ packages: dependencies: '@typescript-eslint/types': 6.1.0 '@typescript-eslint/visitor-keys': 6.1.0 - dev: true /@typescript-eslint/type-utils/6.1.0_34bnyqoxsac45lgkbz54epaynm: resolution: {integrity: sha512-kFXBx6QWS1ZZ5Ni89TyT1X9Ag6RXVIVhqDs0vZE/jUeWlBv/ixq2diua6G7ece6+fXw3TvNRxP77/5mOMusx2w==} @@ -433,12 +441,10 @@ packages: typescript: 4.5.4 transitivePeerDependencies: - supports-color - dev: true /@typescript-eslint/types/6.1.0: resolution: {integrity: sha512-+Gfd5NHCpDoHDOaU/yIF3WWRI2PcBRKKpP91ZcVbL0t5tQpqYWBs3z/GGhvU+EV1D0262g9XCnyqQh19prU0JQ==} engines: {node: ^16.0.0 || >=18.0.0} - dev: true /@typescript-eslint/typescript-estree/6.1.0_typescript@4.5.4: resolution: {integrity: sha512-nUKAPWOaP/tQjU1IQw9sOPCDavs/iU5iYLiY/6u7gxS7oKQoi4aUxXS1nrrVGTyBBaGesjkcwwHkbkiD5eBvcg==} @@ -459,7 +465,6 @@ packages: typescript: 4.5.4 transitivePeerDependencies: - supports-color - dev: true /@typescript-eslint/utils/6.1.0_34bnyqoxsac45lgkbz54epaynm: resolution: {integrity: sha512-wp652EogZlKmQoMS5hAvWqRKplXvkuOnNzZSE0PVvsKjpexd/XznRVHAtrfHFYmqaJz0DFkjlDsGYC9OXw+OhQ==} @@ -478,7 +483,6 @@ packages: transitivePeerDependencies: - supports-color - typescript - dev: true /@typescript-eslint/visitor-keys/6.1.0: resolution: {integrity: sha512-yQeh+EXhquh119Eis4k0kYhj9vmFzNpbhM3LftWQVwqVjipCkwHBQOZutcYW+JVkjtTG9k8nrZU1UoNedPDd1A==} @@ -486,7 +490,6 @@ packages: dependencies: '@typescript-eslint/types': 6.1.0 eslint-visitor-keys: 3.4.1 - dev: true /acorn-jsx/5.3.2_acorn@8.10.0: resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==} @@ -555,7 +558,6 @@ packages: /array-union/2.1.0: resolution: {integrity: sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==} engines: {node: '>=8'} - dev: true /astral-regex/2.0.0: resolution: {integrity: sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==} @@ -835,7 +837,6 @@ packages: engines: {node: '>=8'} dependencies: path-type: 4.0.0 - dev: true /doctrine/3.0.0: resolution: {integrity: sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==} @@ -1253,7 +1254,6 @@ packages: ignore: 5.2.4 merge2: 1.4.1 slash: 3.0.0 - dev: true /got/9.6.0: resolution: {integrity: sha512-R7eWptXuGYxwijs0eV+v3o6+XH1IqVK8dJOEecQfTmkncw9AV4dcw/Dhxi8MdlqPthxxpZyizMzyg8RTmEsG+Q==} @@ -1563,7 +1563,6 @@ packages: engines: {node: '>=10'} dependencies: yallist: 4.0.0 - dev: true /matcher/3.0.0: resolution: {integrity: sha512-OkeDaAZ/bQCxeFAozM55PKcKU0yJMPGifLwV4Qgjitu+5MoAfSQN4lsLJeXZ1b8w0x+/Emda6MZgXS1jvsapng==} @@ -1638,7 +1637,6 @@ packages: /natural-compare-lite/1.4.0: resolution: {integrity: sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==} - dev: true /natural-compare/1.4.0: resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==} @@ -1774,7 +1772,6 @@ packages: /path-type/4.0.0: resolution: {integrity: sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==} engines: {node: '>=8'} - dev: true /pend/1.2.0: resolution: {integrity: sha1-elfrVQpng/kRUzH89GY9XI4AelA=} @@ -1973,7 +1970,6 @@ packages: hasBin: true dependencies: lru-cache: 6.0.0 - dev: true /serialize-error/7.0.1: resolution: {integrity: sha512-8I8TjW5KMOKsZQTvoxjuSIa7foAwPWGOts+6o7sgjz41/qMD9VQHEDxi6PBvK2l0MXUmqZyNpUK+T2tQaaElvw==} @@ -2008,7 +2004,6 @@ packages: /slash/3.0.0: resolution: {integrity: sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==} engines: {node: '>=8'} - dev: true /slice-ansi/3.0.0: resolution: {integrity: sha512-pSyv7bSTC7ig9Dcgbw9AuRNUb5k5V6oDudjZoMBSr13qpLBG7tB+zgCkARjq7xIUgdz5P1Qe8u+rSGdouOOIyQ==} @@ -2169,7 +2164,6 @@ packages: typescript: '>=4.2.0' dependencies: typescript: 4.5.4 - dev: true /tslib/2.3.1: resolution: {integrity: sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==} @@ -2213,7 +2207,6 @@ packages: resolution: {integrity: sha512-VgYs2A2QIRuGphtzFV7aQJduJ2gyfTljngLzjpfW9FoYZF6xuw1W0vW9ghCKLfcWrCFxK81CSGRAvS1pn4fIUg==} engines: {node: '>=4.2.0'} hasBin: true - dev: true /universalify/0.1.2: resolution: {integrity: sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==} @@ -2280,7 +2273,6 @@ packages: /yallist/4.0.0: resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==} - dev: true /yaml/1.10.2: resolution: {integrity: sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==}