> For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt.

# prefer-arrow-callback

[Added in v0.6.5](https://github.com/web-infra-dev/rslint/releases/tag/v0.6.5)
## Configuration


```ts title=rslint.config.ts
import { defineConfig, js } from '@rslint/core';

export default defineConfig([
  js.configs.recommended,
  {
    rules: {
      'prefer-arrow-callback': 'error',
    },
  },
]);
```

## Rule Details

Requires using arrow functions for callbacks when the function expression can be
replaced without changing `this`, `super`, `arguments`, or `new.target`
semantics.

Examples of **incorrect** code for this rule:

```javascript
foo(function (value) {
  return value;
});

foo(function () {
  return this.value;
}.bind(this));
```

Examples of **correct** code for this rule:

```javascript
foo((value) => {
  return value;
});

foo(() => {
  return this.value;
});

foo(function () {
  return this.value;
});
```

## Options

This rule accepts an options object with the following properties:

- `allowNamedFunctions` defaults to `false`. When `true`, named function
  expressions are allowed.
- `allowUnboundThis` defaults to `true`. When `false`, callbacks that reference
  their own `this` are still reported, but they are not automatically fixed.

Examples of **correct** code for this rule with `{ "allowNamedFunctions": true }`:

```json
{ "prefer-arrow-callback": ["error", { "allowNamedFunctions": true }] }
```

```javascript
foo(function namedCallback() {});
```

Examples of **incorrect** code for this rule with `{ "allowUnboundThis": false }`:

```json
{ "prefer-arrow-callback": ["error", { "allowUnboundThis": false }] }
```

```javascript
foo(function () {
  return this.value;
});
```

## Original Documentation

- [ESLint: prefer-arrow-callback](https://eslint.org/docs/latest/rules/prefer-arrow-callback)
- [Source code](https://github.com/eslint/eslint/blob/v10.8.1/lib/rules/prefer-arrow-callback.js)
