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 c83a8dc commit 3f19f75
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 37 deletions.
2 changes: 1 addition & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const error =
cli.paramsCount > 2 ? 'Extraneous parameter: ' + cli.params[2] :
null;
if (error)
throw Error('[recursive-exec] ' + error);
throw new Error('[recursive-exec] ' + error);
const options = {
echo: cli.flagOn.echo,
excludes: cli.flagMap.exclude?.split(',') ?? null,
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
},
},
];
41 changes: 11 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,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 @@ -82,26 +63,26 @@
"chalk": "~5.3",
"cli-argv-util": "~1.2",
"fancy-log": "~2.0",
"glob": "~10.4",
"glob": "~11.0",
"slash": "~5.1"
},
"devDependencies": {
"@eslint/js": "~9.3",
"@eslint/js": "~9.9",
"@types/fancy-log": "~2.0",
"@types/node": "~20.12",
"@types/node": "~22.2",
"add-dist-header": "~1.4",
"assert-deep-strict-equal": "~1.2",
"copy-file-util": "~1.2",
"csso-cli": "~4.0",
"eslint": "8.57.0",
"eslint": "~9.9",
"jshint": "~2.13",
"less": "~4.2",
"make-dir-cli": "~4.0",
"mocha": "~10.4",
"rimraf": "~5.0",
"run-scripts-util": "~1.2",
"typescript": "~5.4",
"typescript-eslint": "~7.11",
"uglify-js": "~3.17"
"mocha": "~10.7",
"rimraf": "~6.0",
"run-scripts-util": "~1.3",
"typescript": "~5.5",
"typescript-eslint": "~8.1",
"uglify-js": "~3.19"
}
}
6 changes: 3 additions & 3 deletions recursive-exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ const recursiveExec = {
!command ? 'Command template missing.' :
null;
if (errorMessage)
throw Error('[recursive-exec] ' + errorMessage);
throw new Error('[recursive-exec] ' + errorMessage);
const startTime = Date.now();
const source = slash(path.normalize(folder)).replace(/\/$/, '');
const logName = chalk.gray('recursive-exec');
const getExts = () => settings.extensions!.join('|');
const extensions = !settings.extensions ? '' : `@(${getExts()})`;
const files = globSync(source + '/**/*' + extensions, { ignore: '**/node_modules/**/*', nodir: true });
const excludes = settings?.excludes || [];
const excludes = settings.excludes || [];
const keep = (file: string) => !excludes.find(exclude => file.includes(exclude));
const toCamel = (token: string) => token.replace(/-./g, char => char[1]!.toUpperCase()); //ex: 'fetch-json' --> 'fetchJson'
if (!settings.quiet)
Expand Down Expand Up @@ -85,7 +85,7 @@ const recursiveExec = {
log(logName, chalk.blue.bold('command:'), chalk.cyanBright(result.command));
const task = spawnSync(result.command, { shell: true, stdio: 'inherit' });
if (task.status !== 0)
throw Error(`[recursive-exec] Status: ${task.status}\nCommand: ${result.command}`);
throw new Error(`[recursive-exec] Status: ${task.status}\nCommand: ${result.command}`);
};
results.forEach(settings.echo ? previewCommand : execCommand);
const summary = `(files: ${results.length}, ${Date.now() - startTime}ms)`;
Expand Down
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 3f19f75

Please sign in to comment.