# n/no-path-concat

> Disallow joining `__dirname` and `__filename` to a path with `+` or a template

When you glue a path together by hand, you hardcode the separator. On Windows, `__dirname + "/data.json"` gives `C:\app/data.json`, which isn't equal to the same path from `path.join()`. `path.join()` and `path.resolve()` use the platform's separator and clean up `..` and doubled separators.

The rule reports `__dirname` or `__filename` followed by text that starts with `/` or `\`, or by `path.sep`.

{/* 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-path-concat" = "error" # or "warn"
```

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

## Examples

Reported:

{/* bad {"count": 3} */}
```js
const config = __dirname + "/config.json";
const cache = `${__dirname}/cache/${name}`;
const logs = __dirname + path.sep + "logs";
```

Not reported:

{/* good */}
```js
const path = require("path");

const config = path.join(__dirname, "config.json");
const cache = path.resolve(__dirname, "cache", name);
```

Adding something that isn't a new path segment is fine:

{/* good */}
```js
const sourceMap = __filename + ".map";
```
