dfinity / eslint-config-oisy-wallet

Shared ESLint configurations from the Oisy Wallet team
Apache License 2.0
2 stars 0 forks source link

feat: add new rule explicit-non-void-return-type #23

Closed AntonioVentilii-DFINITY closed 1 month ago

AntonioVentilii-DFINITY commented 1 month ago

Motivation

We want to introduce a new custom rule that enforces the declaration of non-void return types

Incorrect

function foo() { 
  return 42; 
}

const foo = function() { 
  return "hello"; 
}

const foo = () => { 
  return true; 
}

const bar = async function() { 
  return 42; 
}

async function bar() { 
  return true; 
}

Correct

function foo(): number { 
  return 42; 
}

const foo = function(): string { 
  return "hello"; 
}

const foo = (): boolean => true;

const bar = async function(): Promise<number> { 
  return Promise.resolve(42); 
}

async function bar(): Promise<boolean> { 
  return Promise.resolve(true); 
}

function foo() { 
  // No return value
}

const foo = function() { 
  // No return value
}

const foo = () => { 
  // No return value
}

const bar = async function() { 
  // No return value
}

async function bar() { 
  // No return value
}