# function-return-type

Rule `sonarjs/function-return-type`. Functions should always return the same type

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: yes
- Autofix: no
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1218 by reach, #519 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/function-return-type` | yes | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-3800/) |

## Code examples

### Incorrect: the rule reports this

```js
function foo(a) {  // Noncompliant
  if (a === 1) {
    return true;
  }
  return 3;
}
```

### Correct: the rule accepts this

```js
function foo(a) {
  if (a === 1) {
    return true;
  }
  return false;
}
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "sonarjs/function-return-type": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [sonarjs/function-inside-loop](https://lintradar.dev/rules/sonarjs/function-inside-loop.md): Functions should not be defined inside loops
- [sonarjs/future-reserved-words](https://lintradar.dev/rules/sonarjs/future-reserved-words.md): Future reserved words should not be used as identifiers
- [sonarjs/for-loop-increment-sign](https://lintradar.dev/rules/sonarjs/for-loop-increment-sign.md): A "for" loop update clause should move the counter in the right direction
- [sonarjs/generator-without-yield](https://lintradar.dev/rules/sonarjs/generator-without-yield.md): Generators should explicitly "yield" a value
- [sonarjs/fixme-tag](https://lintradar.dev/rules/sonarjs/fixme-tag.md): Track uses of "FIXME" tags
- [sonarjs/hardcoded-secret-signatures](https://lintradar.dev/rules/sonarjs/hardcoded-secret-signatures.md): Credentials should not be hard-coded

---

Web page: https://lintradar.dev/rules/sonarjs/function-return-type. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
