DEV Community

Ryota Murakami
Ryota Murakami

Posted on

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!

Top comments (0)