# n/no-sync

> Disallow calls to functions with names that end in `Sync`

A function such as `fs.readFileSync()` blocks the thread until it's done. In a server, every other request waits for that one file to be read. The versions that return a promise or take a callback let other work run in the meantime.

The rule only goes by the name. It reports any call to a function or method with a name that ends in `Sync`. Mentioning the function without calling it isn't reported.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"n/no-sync" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"n/no-sync" = ["error", {
  allowAtRootLevel = false,
  ignores = [], # list of strings
}]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
function handle(request) {
  const page = fs.readFileSync("index.html", "utf8");
  return new Response(page);
}
```

Not reported:

{/* good */}
```js
async function handle(request) {
  const page = await fs.promises.readFile("index.html", "utf8");
  return new Response(page);
}
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `allowAtRootLevel` | `false` | Allow calls outside of any function, which run once when the file is loaded. |
| `ignores` | `[]` | Names of functions that are never reported. |

{/* good {"options": [{"allowAtRootLevel": true}]} */}
```js
const template = fs.readFileSync("index.html", "utf8");
```

{/* bad {"options": [{"allowAtRootLevel": true}]} */}
```js
function template() {
  return fs.readFileSync("index.html", "utf8");
}
```

{/* good {"options": [{"ignores": ["existsSync"]}]} */}
```js
function hasConfig() {
  return fs.existsSync("config.json");
}
```

## When not to use it

In scripts, build steps and command line tools, nothing else is waiting for the thread, and the synchronous calls are simpler.
