johnsoncodehk / tsslint

🔋⚡️ The fastest and lightest TypeScript semantic linting solution
MIT License
287 stars 2 forks source link

[@typescript-eslint/require-await] not correct #15

Closed tjx666 closed 3 months ago

tjx666 commented 3 months ago

eslint playground

following code is pass under eslint:

const f = async (context, { queryClient, uid }) => {
  const getGenerationHistory = async () => { };

  const [] = await Promise.all([]);

  return {};
};

but not under tsslint:

image
Configs ```ts import { createRequire } from 'module'; import path from 'path'; import type { Plugin } from '@tsslint/config'; import { defineConfig } from '@tsslint/config'; import { convertRule } from '@tsslint/eslint'; type ESLintRules = Record; const suggestion = 0; const error = 1; /** * @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/recommended-type-checked.ts */ const rules: ESLintRules = { // 'ban-ts-comment': [error], // 'no-explicit-any': [error], // 'no-misused-promises': [error], // 'no-unsafe-argument': [error], // 'no-unsafe-assignment': [error], // 'no-unsafe-return': [error], // 'no-unused-vars': [error], // 'no-floating-promises': [suggestion], 'await-thenable': [error], 'ban-types': [error], 'consistent-type-exports': [error], 'no-array-constructor': [error], 'no-base-to-string': [error], 'no-duplicate-enum-values': [error], 'no-duplicate-type-constituents': [error], 'no-extra-non-null-assertion': [error], 'no-for-in-array': [error], 'no-implied-eval': [error], 'no-loss-of-precision': [error], 'no-misused-new': [error], 'no-namespace': [error], 'no-non-null-asserted-optional-chain': [error], 'no-redundant-type-constituents': [error], 'no-this-alias': [error], 'no-unnecessary-type-assertion': [error], 'no-unnecessary-type-constraint': [error], 'no-unsafe-call': [error], 'no-unsafe-declaration-merging': [error], 'no-unsafe-enum-comparison': [error], 'no-unsafe-member-access': [error], 'no-var-requires': [error], 'prefer-as-const': [error], 'prefer-optional-chain': [error], 'require-await': [suggestion], 'restrict-plus-operands': [error], 'restrict-template-expressions': [error], 'return-await': [error], 'triple-slash-reference': [error], 'unbound-method': [error], }; export default defineConfig({ plugins: [ createIgnorePlugin(/\/\/ tsslint-disable-next-line\n/g), createIgnorePlugin(/\/\/ eslint-disable-next-line\n/g), ], rules: await convertESLintRulesToTSSLint(rules), }); /** * @see https://github.com/johnsoncodehk/tsslint/issues/10#issuecomment-2169565542 */ async function convertESLintRulesToTSSLint(rules: ESLintRules) { const require = createRequire(import.meta.url); const rulesDir = path.dirname(require.resolve('@typescript-eslint/eslint-plugin/package.json')); return Object.fromEntries( await Promise.all( Object.entries(rules).map(async ([ruleName, [severity, ...options]]) => { const rulePath = path.join(rulesDir, 'dist', 'rules', `${ruleName}.js`); return [ruleName, convertRule((await import(rulePath)).default.default, options, severity)]; }), ), ); } function createIgnorePlugin(pattern: RegExp): Plugin { return ({ languageService }) => ({ resolveDiagnostics(fileName, results) { const sourceFile = languageService.getProgram()?.getSourceFile(fileName); if (!sourceFile) { return results; } const comments = [...sourceFile.text.matchAll(pattern)]; const lines = new Set( comments.map((comment) => sourceFile.getLineAndCharacterOfPosition(comment.index).line), ); return results.filter( (result) => !lines.has(sourceFile.getLineAndCharacterOfPosition(result.start).line - 1), ); }, }); } ```
johnsoncodehk commented 3 months ago

I can't reproduce the problem. Did you have update @tsslint/eslint and VSCode extension to the latest v1.0.13?

tjx666 commented 3 months ago

I can reproduce in my fork:

image
tjx666 commented 3 months ago

fixed by:

image