From 867d8d2eeb2ec76573991813d66cc99a0575db1b Mon Sep 17 00:00:00 2001 From: Francis Gulotta Date: Tue, 24 Dec 2024 15:13:44 -0500 Subject: [PATCH] fix: linting (#2966) Eslint9 and stylistic mean we can ditch prettier, typscript specific rules, and a can revisit the whole eslint config. --- .prettierignore | 7 - .prettierrc | 7 - eslint.config.mjs | 70 +---- package-lock.json | 267 +++++------------- package.json | 17 +- packages/list/lib/index.ts | 3 +- packages/list/tsconfig-build.json | 2 +- packages/list/tsconfig.json | 2 +- packages/parser-packet-length/lib/index.ts | 2 +- packages/parser-slip-encoder/lib/decoder.ts | 2 +- packages/parser-spacepacket/lib/index.test.ts | 3 +- packages/repl/lib/index.ts | 2 +- packages/stream/lib/index.ts | 14 +- packages/terminal/lib/index.ts | 5 +- packages/terminal/tsconfig-build.json | 2 +- packages/terminal/tsconfig.json | 2 +- test/assert.ts | 3 +- 17 files changed, 108 insertions(+), 302 deletions(-) delete mode 100644 .prettierignore delete mode 100644 .prettierrc diff --git a/.prettierignore b/.prettierignore deleted file mode 100644 index 941b8e0e3..000000000 --- a/.prettierignore +++ /dev/null @@ -1,7 +0,0 @@ -/.nyc_output -/coverage -/packages/**/dist -tsconfig-build.tsbuildinfo -tsconfig.tsbuildinfo -package-lock.json -/packages/**/package-lock.json diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index d7d6ffb07..000000000 --- a/.prettierrc +++ /dev/null @@ -1,7 +0,0 @@ -{ - "singleQuote": true, - "semi": false, - "printWidth": 150, - "tabWidth": 2, - "arrowParens": "avoid" -} diff --git a/eslint.config.mjs b/eslint.config.mjs index 5dc1ec830..6b276e29d 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,68 +1,28 @@ -import nodePlugin from 'eslint-plugin-n' -import mocha from 'eslint-plugin-mocha' import globals from 'globals' -import js from '@eslint/js' -import eslintConfigPrettier from 'eslint-config-prettier' -import eslint from '@eslint/js' -import typescriptEslint from 'typescript-eslint' +import pluginJs from '@eslint/js' +import tseslint from 'typescript-eslint' +import mocha from 'eslint-plugin-mocha' +import stylistic from '@stylistic/eslint-plugin' +/** @type {import('eslint').Linter.Config[]} */ export default [ { - ignores: ['packages/*/node_modules', '**/docs', 'packages/*/dist/*'], + ignores: ['**/dist/', '**/*.js'], }, - js.configs.recommended, - nodePlugin.configs['flat/recommended-script'], + { languageOptions: { globals: globals.node } }, + pluginJs.configs.recommended, + ...tseslint.configs.recommended, mocha.configs['flat'].recommended, - ...typescriptEslint.configs.recommended, - eslintConfigPrettier, + stylistic.configs['recommended-flat'], { - languageOptions: { - globals: { - ...globals.node, - ...globals.mocha, - assert: false, - makeTestFeature: false, - shouldReject: false, - }, - ecmaVersion: 12, - sourceType: 'commonjs', - }, - rules: { - 'no-extra-semi': 'off', - '@typescript-eslint/no-extra-semi': 'off', - 'n/no-process-exit': 'off', - 'no-var': 'error', - - 'n/no-extraneous-import': [ - 'error', - { - allowModules: ['sinon', 'chai'], - }, - ], - - 'n/no-missing-import': 'off', - 'n/no-missing-require': 'off', - 'n/no-unpublished-import': 'off', - 'n/no-unpublished-require': 'off', - 'n/no-unsupported-features/es-builtins': 'error', - 'n/no-unsupported-features/es-syntax': 'off', - 'n/no-unsupported-features/node-builtins': 'error', - 'n/hashbang': 'off', - 'object-shorthand': 'error', - 'prefer-arrow-callback': 'error', - 'prefer-const': 'error', - 'prefer-template': 'error', - 'mocha/no-exclusive-tests': 'error', - 'mocha/no-hooks-for-single-case': 'off', 'mocha/no-mocha-arrows': 'off', - 'mocha/no-pending-tests': 'error', 'mocha/no-setup-in-describe': 'off', - strict: ['error', 'never'], - 'valid-jsdoc': 'off', - '@typescript-eslint/no-var-requires': 'off', - '@typescript-eslint/no-empty-function': 'off', - '@typescript-eslint/no-require-imports': 'off', + 'mocha/no-exclusive-tests': 'error', + '@stylistic/arrow-parens': ['error', 'as-needed'], + '@stylistic/brace-style': ['error', '1tbs', { allowSingleLine: true }], + '@stylistic/quotes': ['error', 'single', { avoidEscape: true }], + 'object-shorthand': ['error', 'always', { avoidQuotes: true }], }, }, ] diff --git a/package-lock.json b/package-lock.json index 7e00f66f7..651907d7c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,30 +14,25 @@ "devDependencies": { "@eslint/js": "9.17.0", "@serialport/bindings-cpp": "13.0.0", + "@stylistic/eslint-plugin": "2.12.1", "@tsconfig/node18": "18.2.1", "@types/chai": "5.0.1", "@types/chai-subset": "1.3.5", "@types/debug": "4.1.12", - "@types/eslint__js": "8.42.3", "@types/mocha": "10.0.10", "@types/node": "22.8.2", "@types/sinon": "17.0.3", - "@typescript-eslint/eslint-plugin": "8.18.2", - "@typescript-eslint/parser": "8.18.2", "chai": "5.1.2", "chai-subset": "1.6.0", "esbuild": "0.24.2", "esbuild-register": "3.6.0", "eslint": "9.17.0", - "eslint-config-prettier": "9.1.0", "eslint-plugin-mocha": "10.5.0", - "eslint-plugin-n": "17.15.1", - "eslint-plugin-promise": "7.2.1", + "globals": "15.14.0", "lerna": "7.2.0", "lerna-changelog": "2.2.0", "mocha": "11.0.1", "nyc": "17.1.0", - "prettier": "3.0.3", "sinon": "19.0.2", "typescript": "5.2.2", "typescript-eslint": "8.18.2" @@ -888,6 +883,19 @@ "concat-map": "0.0.1" } }, + "node_modules/@eslint/eslintrc/node_modules/globals": { + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", + "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/@eslint/eslintrc/node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -2634,6 +2642,52 @@ "dev": true, "license": "(Unlicense OR Apache-2.0)" }, + "node_modules/@stylistic/eslint-plugin": { + "version": "2.12.1", + "resolved": "https://registry.npmjs.org/@stylistic/eslint-plugin/-/eslint-plugin-2.12.1.tgz", + "integrity": "sha512-fubZKIHSPuo07FgRTn6S4Nl0uXPRPYVNpyZzIDGfp7Fny6JjNus6kReLD7NI380JXi4HtUTSOZ34LBuNPO1XLQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/utils": "^8.13.0", + "eslint-visitor-keys": "^4.2.0", + "espree": "^10.3.0", + "estraverse": "^5.3.0", + "picomatch": "^4.0.2" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "peerDependencies": { + "eslint": ">=8.40.0" + } + }, + "node_modules/@stylistic/eslint-plugin/node_modules/eslint-visitor-keys": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.2.0.tgz", + "integrity": "sha512-UyLnSehNt62FFhSwjZlHmeokpRK59rcz29j+F1/aDgbkbRTk7wIc9XzdoasMUbRNKDM0qQt/+BJ4BrpFeABemw==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/@stylistic/eslint-plugin/node_modules/picomatch": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz", + "integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, "node_modules/@tootallnate/once": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-1.1.2.tgz", @@ -2712,27 +2766,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@types/eslint": { - "version": "9.6.1", - "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-9.6.1.tgz", - "integrity": "sha512-FXx2pKgId/WyYo2jXw63kk7/+TY7u7AziEJxJAnSFzHlqTAS3Ync6SvgYAN/k4/PQpnnVuzoMuVnByKK2qp0ag==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/estree": "*", - "@types/json-schema": "*" - } - }, - "node_modules/@types/eslint__js": { - "version": "8.42.3", - "resolved": "https://registry.npmjs.org/@types/eslint__js/-/eslint__js-8.42.3.tgz", - "integrity": "sha512-alfG737uhmPdnvkrLdZLcEKJ/B8s9Y4hrZ+YAdzUeoArBlSUERA2E87ROfOaS4jd/C45fzOoZzidLc1IPwLqOw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/eslint": "*" - } - }, "node_modules/@types/estree": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.6.tgz", @@ -4563,20 +4596,6 @@ "once": "^1.4.0" } }, - "node_modules/enhanced-resolve": { - "version": "5.18.0", - "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.18.0.tgz", - "integrity": "sha512-0/r0MySGYG8YqlayBZ6MuCfECmHFdJ5qyPh8s8wa5Hnm6SaFLSK1VYCbj+NKp090Nm1caZhD+QTnmxO7esYGyQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "graceful-fs": "^4.2.4", - "tapable": "^2.2.0" - }, - "engines": { - "node": ">=10.13.0" - } - }, "node_modules/enquirer": { "version": "2.3.6", "resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.3.6.tgz", @@ -4774,57 +4793,6 @@ } } }, - "node_modules/eslint-compat-utils": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/eslint-compat-utils/-/eslint-compat-utils-0.5.1.tgz", - "integrity": "sha512-3z3vFexKIEnjHE3zCMRo6fn/e44U7T1khUjg+Hp0ZQMCigh28rALD0nPFBcGZuiLC5rLZa2ubQHDRln09JfU2Q==", - "dev": true, - "license": "MIT", - "dependencies": { - "semver": "^7.5.4" - }, - "engines": { - "node": ">=12" - }, - "peerDependencies": { - "eslint": ">=6.0.0" - } - }, - "node_modules/eslint-config-prettier": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz", - "integrity": "sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw==", - "dev": true, - "license": "MIT", - "bin": { - "eslint-config-prettier": "bin/cli.js" - }, - "peerDependencies": { - "eslint": ">=7.0.0" - } - }, - "node_modules/eslint-plugin-es-x": { - "version": "7.8.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-es-x/-/eslint-plugin-es-x-7.8.0.tgz", - "integrity": "sha512-7Ds8+wAAoV3T+LAKeu39Y5BzXCrGKrcISfgKEqTS4BDN8SFEDQd0S43jiQ8vIa3wUKD07qitZdfzlenSi8/0qQ==", - "dev": true, - "funding": [ - "https://github.com/sponsors/ota-meshi", - "https://opencollective.com/eslint" - ], - "license": "MIT", - "dependencies": { - "@eslint-community/eslint-utils": "^4.1.2", - "@eslint-community/regexpp": "^4.11.0", - "eslint-compat-utils": "^0.5.1" - }, - "engines": { - "node": "^14.18.0 || >=16.0.0" - }, - "peerDependencies": { - "eslint": ">=8" - } - }, "node_modules/eslint-plugin-mocha": { "version": "10.5.0", "resolved": "https://registry.npmjs.org/eslint-plugin-mocha/-/eslint-plugin-mocha-10.5.0.tgz", @@ -4872,64 +4840,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/eslint-plugin-n": { - "version": "17.15.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-n/-/eslint-plugin-n-17.15.1.tgz", - "integrity": "sha512-KFw7x02hZZkBdbZEFQduRGH4VkIH4MW97ClsbAM4Y4E6KguBJWGfWG1P4HEIpZk2bkoWf0bojpnjNAhYQP8beA==", - "dev": true, - "license": "MIT", - "dependencies": { - "@eslint-community/eslint-utils": "^4.4.1", - "enhanced-resolve": "^5.17.1", - "eslint-plugin-es-x": "^7.8.0", - "get-tsconfig": "^4.8.1", - "globals": "^15.11.0", - "ignore": "^5.3.2", - "minimatch": "^9.0.5", - "semver": "^7.6.3" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" - }, - "peerDependencies": { - "eslint": ">=8.23.0" - } - }, - "node_modules/eslint-plugin-n/node_modules/globals": { - "version": "15.14.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-15.14.0.tgz", - "integrity": "sha512-OkToC372DtlQeje9/zHIo5CT8lRP/FUgEOKBEhU4e0abL7J7CD24fD9ohiLN5hagG/kWCYj4K5oaxxtj2Z0Dig==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=18" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/eslint-plugin-promise": { - "version": "7.2.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-7.2.1.tgz", - "integrity": "sha512-SWKjd+EuvWkYaS+uN2csvj0KoP43YTu7+phKQ5v+xw6+A0gutVX2yqCeCkC3uLCJFiPfR2dD8Es5L7yUsmvEaA==", - "dev": true, - "license": "ISC", - "dependencies": { - "@eslint-community/eslint-utils": "^4.4.0" - }, - "engines": { - "node": "^18.18.0 || ^20.9.0 || >=21.1.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" - }, - "peerDependencies": { - "eslint": "^7.0.0 || ^8.0.0 || ^9.0.0" - } - }, "node_modules/eslint-scope": { "version": "8.2.0", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.2.0.tgz", @@ -5635,19 +5545,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/get-tsconfig": { - "version": "4.8.1", - "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.8.1.tgz", - "integrity": "sha512-k9PN+cFBmaLWtVz29SkUoqU5O0slLuHJXt/2P+tMVFT+phsSGXGkp9t3rQIqdz0e+06EHNGs3oM6ZX1s2zHxRg==", - "dev": true, - "license": "MIT", - "dependencies": { - "resolve-pkg-maps": "^1.0.0" - }, - "funding": { - "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1" - } - }, "node_modules/git-raw-commits": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/git-raw-commits/-/git-raw-commits-3.0.0.tgz", @@ -5798,9 +5695,9 @@ } }, "node_modules/globals": { - "version": "14.0.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", - "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", + "version": "15.14.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-15.14.0.tgz", + "integrity": "sha512-OkToC372DtlQeje9/zHIo5CT8lRP/FUgEOKBEhU4e0abL7J7CD24fD9ohiLN5hagG/kWCYj4K5oaxxtj2Z0Dig==", "dev": true, "license": "MIT", "engines": { @@ -10297,22 +10194,6 @@ "node": ">= 0.8.0" } }, - "node_modules/prettier": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz", - "integrity": "sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==", - "dev": true, - "license": "MIT", - "bin": { - "prettier": "bin/prettier.cjs" - }, - "engines": { - "node": ">=14" - }, - "funding": { - "url": "https://github.com/prettier/prettier?sponsor=1" - } - }, "node_modules/pretty-format": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", @@ -11024,16 +10905,6 @@ "node": ">=4" } }, - "node_modules/resolve-pkg-maps": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", - "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==", - "dev": true, - "license": "MIT", - "funding": { - "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" - } - }, "node_modules/restore-cursor": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-3.1.0.tgz", @@ -11955,16 +11826,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/tapable": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.1.tgz", - "integrity": "sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=6" - } - }, "node_modules/tar": { "version": "6.1.11", "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.11.tgz", diff --git a/package.json b/package.json index eadc61868..a01246e92 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,8 @@ "license": "MIT", "scripts": { "build": "lerna run build", - "format": "npx prettier --write . && eslint packages test --fix", - "lint": "eslint packages test && npx prettier --check .", + "format": "eslint --fix", + "lint": "eslint", "outdated": "lerna exec --no-bail npm outdated && npm outdated", "publish": "lerna publish --exact", "test:arduino": "TEST_PORT=$(./bin/find-arduino.ts) npm test", @@ -28,33 +28,28 @@ "devDependencies": { "@eslint/js": "9.17.0", "@serialport/bindings-cpp": "13.0.0", + "@stylistic/eslint-plugin": "2.12.1", "@tsconfig/node18": "18.2.1", "@types/chai": "5.0.1", "@types/chai-subset": "1.3.5", "@types/debug": "4.1.12", - "@types/eslint__js": "8.42.3", "@types/mocha": "10.0.10", "@types/node": "22.8.2", "@types/sinon": "17.0.3", - "@typescript-eslint/eslint-plugin": "8.18.2", - "@typescript-eslint/parser": "8.18.2", "chai": "5.1.2", "chai-subset": "1.6.0", "esbuild": "0.24.2", "esbuild-register": "3.6.0", "eslint": "9.17.0", - "eslint-config-prettier": "9.1.0", "eslint-plugin-mocha": "10.5.0", - "eslint-plugin-n": "17.15.1", - "eslint-plugin-promise": "7.2.1", + "globals": "15.14.0", "lerna": "7.2.0", "lerna-changelog": "2.2.0", "mocha": "11.0.1", "nyc": "17.1.0", - "prettier": "3.0.3", - "typescript-eslint": "8.18.2", "sinon": "19.0.2", - "typescript": "5.2.2" + "typescript": "5.2.2", + "typescript-eslint": "8.18.2" }, "funding": "https://opencollective.com/serialport/donate", "changelog": { diff --git a/packages/list/lib/index.ts b/packages/list/lib/index.ts index 422a1fefd..955bf9a1e 100644 --- a/packages/list/lib/index.ts +++ b/packages/list/lib/index.ts @@ -2,8 +2,9 @@ import { autoDetect, PortInfo } from '@serialport/bindings-cpp' import { program, Option } from 'commander' +import { readFileSync } from 'node:fs' -const { version } = require('../package.json') +const { version } = JSON.parse(readFileSync('../package.json', 'utf8')) const formatOption = new Option('-f, --format ', 'Format the output').choices(['text', 'json', 'jsonline', 'jsonl']).default('text') diff --git a/packages/list/tsconfig-build.json b/packages/list/tsconfig-build.json index 14eb29056..1e4143937 100644 --- a/packages/list/tsconfig-build.json +++ b/packages/list/tsconfig-build.json @@ -2,7 +2,7 @@ "extends": "../../tsconfig-build.json", "compilerOptions": { "rootDir": "lib", - "outDir": "dist" + "outDir": "dist", }, "exclude": ["node_modules", "**/*.test.ts", "dist"] } diff --git a/packages/list/tsconfig.json b/packages/list/tsconfig.json index 4082f16a5..6f83eb665 100644 --- a/packages/list/tsconfig.json +++ b/packages/list/tsconfig.json @@ -1,3 +1,3 @@ { - "extends": "../../tsconfig.json" + "extends": "../../tsconfig.json", } diff --git a/packages/parser-packet-length/lib/index.ts b/packages/parser-packet-length/lib/index.ts index bb362bcf3..7d0874d56 100644 --- a/packages/parser-packet-length/lib/index.ts +++ b/packages/parser-packet-length/lib/index.ts @@ -29,7 +29,7 @@ export interface PacketLengthOptions extends TransformOptions { export class PacketLengthParser extends Transform { buffer: Buffer start: boolean - opts: { delimiter: number; packetOverhead: number; lengthBytes: number; lengthOffset: number; maxLen: number } + opts: { delimiter: number, packetOverhead: number, lengthBytes: number, lengthOffset: number, maxLen: number } constructor(options: PacketLengthOptions = {}) { super(options) diff --git a/packages/parser-slip-encoder/lib/decoder.ts b/packages/parser-slip-encoder/lib/decoder.ts index 80c5eb744..95f5a340a 100644 --- a/packages/parser-slip-encoder/lib/decoder.ts +++ b/packages/parser-slip-encoder/lib/decoder.ts @@ -22,7 +22,7 @@ export interface SlipDecoderOptions extends TransformOptions { * Runs in O(n) time, stripping out slip encoding and emitting decoded data. Optionally custom slip escape and delimiters can be provided. */ export class SlipDecoder extends Transform { - opts: { START: number | undefined; ESC: number; END: number; ESC_START: number | undefined; ESC_END: number; ESC_ESC: number } + opts: { START: number | undefined, ESC: number, END: number, ESC_START: number | undefined, ESC_END: number, ESC_ESC: number } buffer: Buffer escape: boolean start: boolean diff --git a/packages/parser-spacepacket/lib/index.test.ts b/packages/parser-spacepacket/lib/index.test.ts index 11dfc9a3f..7f342db76 100644 --- a/packages/parser-spacepacket/lib/index.test.ts +++ b/packages/parser-spacepacket/lib/index.test.ts @@ -1,4 +1,5 @@ -import { expect } from 'chai' +// eslint-disable-next-line @typescript-eslint/no-require-imports +const { expect } = require('chai') import sinon from 'sinon' import { SpacePacketParser } from './' diff --git a/packages/repl/lib/index.ts b/packages/repl/lib/index.ts index 2b631a36b..ef87c44ef 100644 --- a/packages/repl/lib/index.ts +++ b/packages/repl/lib/index.ts @@ -24,7 +24,7 @@ async function findArduino() { } findArduino() - .then(({ path, baudRate }: { path: string; baudRate: number }) => { + .then(({ path, baudRate }: { path: string, baudRate: number }) => { console.log(`DEBUG=${process.env.DEBUG || ''} # enable debugging with DEBUG=serialport*`) console.log(`port = SerialPort({ path: "${path}", baudRate: ${baudRate}, autoOpen: false })`) console.log('globals { SerialPort, SerialPortMock, path, port }') diff --git a/packages/stream/lib/index.ts b/packages/stream/lib/index.ts index d47ad185c..6272499c2 100644 --- a/packages/stream/lib/index.ts +++ b/packages/stream/lib/index.ts @@ -40,7 +40,7 @@ function allocNewReadPool(poolSize: number): PoolBuffer { */ export type ErrorCallback = (err: Error | null) => void -export type ModemBitsCallback = (err: Error | null, options?: { cts: boolean; dsr: boolean; dcd: boolean }) => void +export type ModemBitsCallback = (err: Error | null, options?: { cts: boolean, dsr: boolean, dcd: boolean }) => void export type OpenOptions = StreamOptions & OpenOptionsFromBinding @@ -53,7 +53,7 @@ export interface StreamOptions { */ binding: T - /** Automatically opens the port defaults to true*/ + /** Automatically opens the port defaults to true */ autoOpen?: boolean /** @@ -269,10 +269,10 @@ export class SerialPortStream ext ) } - _writev(data: Array<{ chunk: Buffer; encoding: BufferEncoding }>, callback: ErrorCallback) { + _writev(data: Array<{ chunk: Buffer, encoding: BufferEncoding }>, callback: ErrorCallback) { debug('_writev', `${data.length} chunks of data`) const dataV = data.map(write => write.chunk) - this._write(Buffer.concat(dataV), undefined, callback) + this._write(Buffer.concat(dataV), 'binary', callback) } _read(bytesToRead: number) { @@ -298,10 +298,10 @@ export class SerialPortStream ext const start = pool.used // the actual read. - debug('_read', `reading`, { start, toRead }) + debug('_read', 'reading', { start, toRead }) this.port.read(pool, start, toRead).then( ({ bytesRead }) => { - debug('binding.read', `finished`, { bytesRead }) + debug('binding.read', 'finished', { bytesRead }) // zero bytes means read means we've hit EOF? Maybe this should be an error if (bytesRead === 0) { debug('binding.read', 'Zero bytes read closing readable stream') @@ -312,7 +312,7 @@ export class SerialPortStream ext this.push(pool.slice(start, start + bytesRead)) }, err => { - debug('binding.read', `error`, err) + debug('binding.read', 'error', err) if (!err.canceled) { this._disconnected(err) } diff --git a/packages/terminal/lib/index.ts b/packages/terminal/lib/index.ts index 283a07d53..10cb6ee11 100755 --- a/packages/terminal/lib/index.ts +++ b/packages/terminal/lib/index.ts @@ -5,8 +5,9 @@ import { program } from 'commander' import { SerialPortStream, OpenOptions } from '@serialport/stream' import { OutputTranslator } from './output-translator' import { autoDetect, AutoDetectTypes } from '@serialport/bindings-cpp' +import { readFileSync } from 'node:fs' -const { version } = require('../package.json') +const { version } = JSON.parse(readFileSync('../package.json', 'utf8')) const binding = autoDetect() const makeNumber = (input: string) => Number(input) @@ -81,7 +82,7 @@ const askForBaudRate = async () => { return baud } -const createPort = ({ path, baudRate }: { path: string; baudRate: number }) => { +const createPort = ({ path, baudRate }: { path: string, baudRate: number }) => { console.log(`Opening serial port: ${path} echo: ${args.echo}`) const openOptions: OpenOptions = { diff --git a/packages/terminal/tsconfig-build.json b/packages/terminal/tsconfig-build.json index 804a3b0aa..7b9570bf4 100644 --- a/packages/terminal/tsconfig-build.json +++ b/packages/terminal/tsconfig-build.json @@ -2,7 +2,7 @@ "extends": "../../tsconfig-build.json", "compilerOptions": { "outDir": "dist", - "rootDir": "lib" + "rootDir": "lib", }, "exclude": ["node_modules", "**/*.test.ts", "dist"], "references": [{ "path": "../parser-delimiter/tsconfig-build.json" }, { "path": "../stream/tsconfig-build.json" }] diff --git a/packages/terminal/tsconfig.json b/packages/terminal/tsconfig.json index 4082f16a5..6f83eb665 100644 --- a/packages/terminal/tsconfig.json +++ b/packages/terminal/tsconfig.json @@ -1,3 +1,3 @@ { - "extends": "../../tsconfig.json" + "extends": "../../tsconfig.json", } diff --git a/test/assert.ts b/test/assert.ts index be0a78e81..a0a0389c1 100644 --- a/test/assert.ts +++ b/test/assert.ts @@ -1,4 +1,5 @@ -import { assert, use } from 'chai' +// eslint-disable-next-line @typescript-eslint/no-require-imports +const { assert, use } = require('chai') import chaiSubset from 'chai-subset' use(chaiSubset)