DEV Community

Ryota Murakami
Ryota Murakami

Posted on

1

Update eslint-config-ts-prefixer@v0.23.3

Here is original post

I've published eslint-config-ts-prefixer@v0.23.3.

eslint-config-ts-prefixer is ESLint rule set that integrated prettier as one of ESLint rule and specialized fixable rule set.
And

  • 📦 Zero extend for explicit rules.
  • 💅 Prettier integration, specialized fixable import rules.
  • ✅ Meamingful rules code behavior.

I added these new rules this update.
One of my favorite rule is @typescript-eslint/promise-function-async.\
This is available --fix so auto adding async keyword property position.

1. @typescript-eslint/no-misused-new

This rule enforces that constructors within classes are marked with the new keyword.

// Bad
interface Foo {
  new (): Foo;
}

// Good
class Foo {
  constructor() {}
}
Enter fullscreen mode Exit fullscreen mode

2. @typescript-eslint/no-misused-promises

This rule avoids using promises in places not designed to handle them.

// Bad
addEventListener('click', async () => {
  await doSomethingAsync();
});

// Good
addEventListener('click', () => {
  doSomethingAsync();
});
Enter fullscreen mode Exit fullscreen mode

3. @typescript-eslint/promise-function-async

This rule requires any function or method that returns a Promise to be marked async.

// Bad
function foo(): Promise<void> {
  return Promise.resolve();
}

// Good
async function foo(): Promise<void> {
  return;
}
Enter fullscreen mode Exit fullscreen mode

4. no-await-in-loop

This rule disallows await inside of loops.

// Bad
for (let i = 0; i < 10; i++) {
  await asyncFunction()
}

// Good
const promises = []
for (let i = 0; i < 10; i++) {
  promises.push(asyncFunction())
}
await Promise.all(promises)
Enter fullscreen mode Exit fullscreen mode

5. no-return-await

This rule disallows unnecessary return await.

// Bad
async function foo() {
  return await bar()
}

// Good
async function foo() {
  return bar()
}
Enter fullscreen mode Exit fullscreen mode

6. prefer-promise-reject-errors

This rule requires using Error objects as Promise rejection reasons.

// Bad
Promise.reject('something went wrong')

// Good
Promise.reject(new Error('something went wrong'))
Enter fullscreen mode Exit fullscreen mode

7. require-atomic-updates

This rule disallows assignments that can lead to race conditions due to usage of await or yield.

// Bad
async function foo() {
  c = a + b
  await somethingAsync()
  c = c + 1 // This might be an outdated value of c
}

// Good
async function foo() {
  const temp = a + b
  await somethingAsync()
  c = temp + 1
}
Enter fullscreen mode Exit fullscreen mode

Thank you for all yours.
Really welcome ESLint & TS setting improvement feedback!

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay