Skip to content

Commit

Permalink
Convert to new flat config for eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilafian committed Aug 14, 2024
1 parent e2dabf1 commit b17fece
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 34 deletions.
2 changes: 1 addition & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
6 changes: 3 additions & 3 deletions copy-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -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
},
},
];
35 changes: 8 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
"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,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"removeComments": true
"noUnusedLocals": true
}
}

0 comments on commit b17fece

Please sign in to comment.