From b17fece525c4ae6fd4bbab793a61af2d60a3b61e Mon Sep 17 00:00:00 2001 From: dpilafian Date: Wed, 14 Aug 2024 00:10:55 -0700 Subject: [PATCH] Convert to new flat config for eslint --- bin/cli.js | 2 +- copy-file.ts | 6 +++--- eslint.config.js | 22 ++++++++++++++++++++++ package.json | 35 ++++++++--------------------------- tsconfig.json | 6 +++--- 5 files changed, 37 insertions(+), 34 deletions(-) create mode 100644 eslint.config.js diff --git a/bin/cli.js b/bin/cli.js index af5ff6e..589e976 100644 --- a/bin/cli.js +++ b/bin/cli.js @@ -46,7 +46,7 @@ const error = !target ? 'Missing target file.' : null; if (error) - throw Error('[copy-file-util] ' + error); + throw new Error('[copy-file-util] ' + error); const targetKey = cli.flagOn.folder ? 'targetFolder' : 'targetFile'; const templateVariables = /{{[^{}]*}}/g; //example match: "{{package.version}}" const options = { diff --git a/copy-file.ts b/copy-file.ts index b11a12e..a85a7cc 100644 --- a/copy-file.ts +++ b/copy-file.ts @@ -48,7 +48,7 @@ const copyFile = { const sourceFilename = sourceIsFile ? path.basename(source) : null; const targetPath = settings.targetFile ? path.dirname(settings.targetFile) : settings.targetFolder; const targetFolder = targetPath ? normalize(startFolder + targetPath) : null; - const targetFile = settings.targetFile ?? settings.targetFolder + '/' + sourceFilename; + const targetFile = settings.targetFile ?? `${settings.targetFolder}/${sourceFilename}`; const target = normalize(startFolder + targetFile); const targetExists = !missingTarget && fs.existsSync(target); const skip = targetExists && !settings.overwrite; @@ -62,10 +62,10 @@ const copyFile = { !sourceIsFile ? 'Source is not a file: ' + source : missingTarget ? 'Must specify a target file or folder.' : ambiguousTarget ? 'Target cannot be both a file and a folder.' : - badTargetFolder ? 'Target folder cannot be written to: ' + targetFolder : + badTargetFolder ? 'Target folder cannot be written to: ' + String(targetFolder) : null; if (errorMessage) - throw Error('[copy-file-util] ' + errorMessage); + throw new Error('[copy-file-util] ' + errorMessage); if (!skip && settings.move) fs.renameSync(source, target); else if (!skip) diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..76686d1 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,22 @@ +// @ts-check + +import eslint from '@eslint/js'; +import tseslint from 'typescript-eslint'; + +export default [ + eslint.configs.recommended, + ...tseslint.configs.strictTypeChecked, + { ignores: ['**/*.js'] }, + { + languageOptions: { parserOptions: { projectService: true } }, + rules: { + '@typescript-eslint/no-confusing-void-expression': 'off', //prefer minimal arrow functions + '@typescript-eslint/no-floating-promises': 'off', //annimations may be fire-and-forget + '@typescript-eslint/no-misused-promises': 'off', //annimations may be fire-and-forget + '@typescript-eslint/no-non-null-assertion': 'off', //ts cannot always know value exists + '@typescript-eslint/restrict-template-expressions': 'off', //numbers in templates are natural + '@typescript-eslint/unbound-method': 'off', //safer to not use 'this' + '@typescript-eslint/use-unknown-in-catch-callback-variable': 'off', //clarity over theoretical exceptions + }, + }, + ]; diff --git a/package.json b/package.json index 9578c2c..91c6942 100644 --- a/package.json +++ b/package.json @@ -40,32 +40,13 @@ "node": true, "mocha": true }, - "eslintConfig": { - "ignorePatterns": [ - "build", - "dist", - "node_modules" - ], - "root": true, - "parser": "@typescript-eslint/parser", - "plugins": [ - "@typescript-eslint" - ], - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/recommended" - ], - "rules": { - "@typescript-eslint/no-non-null-assertion": "off" - } - }, "runScriptsConfig": { "clean": [ "rimraf build dist spec/fixtures/target" ], "lint": [ "jshint . --exclude-path .gitignore", - "eslint --max-warnings 0 . --ext .ts" + "eslint --max-warnings 0" ], "build": [ "tsc", @@ -84,17 +65,17 @@ "slash": "~5.1" }, "devDependencies": { - "@eslint/js": "~9.5", + "@eslint/js": "~9.9", "@types/fancy-log": "~2.0", - "@types/node": "~20.14", + "@types/node": "~22.2", "add-dist-header": "~1.4", "assert-deep-strict-equal": "~1.2", - "eslint": "8.57.0", + "eslint": "~9.9", "jshint": "~2.13", - "mocha": "~10.5", - "rimraf": "~5.0", - "run-scripts-util": "~1.2", + "mocha": "~10.7", + "rimraf": "~6.0", + "run-scripts-util": "~1.3", "typescript": "~5.5", - "typescript-eslint": "~7.14" + "typescript-eslint": "~8.1" } } diff --git a/tsconfig.json b/tsconfig.json index 1618182..05caa62 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,13 +3,14 @@ "target": "ES2021", "module": "ES2020", "moduleResolution": "node", + "esModuleInterop": true, "declaration": true, "outDir": "build", "newLine": "lf", + "removeComments": true, "strict": true, "allowSyntheticDefaultImports": true, "alwaysStrict": true, - "esModuleInterop": true, "exactOptionalPropertyTypes": true, "forceConsistentCasingInFileNames": true, "noFallthroughCasesInSwitch": true, @@ -17,7 +18,6 @@ "noImplicitReturns": true, "noImplicitThis": true, "noUncheckedIndexedAccess": true, - "noUnusedLocals": true, - "removeComments": true + "noUnusedLocals": true } }