# prefer-import-meta-properties

Rule `unicorn/prefer-import-meta-properties`. Prefer `import.meta.{dirname,filename}` over legacy techniques for getting file paths.

- Source: unicorn
- Technologies: JavaScript
- Kind: suspicious
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 2.1M weekly downloads of presets that enable it
- Trend: +151.7% last quarter
- Rank: #1524 by reach, #28 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/prefer-import-meta-properties` | no | safe | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/prefer-import-meta-properties.md) |
| Oxlint | `unicorn/prefer-import-meta-properties` | no | safe | plugin `unicorn`, category pedantic | [docs](https://oxc.rs/docs/guide/usage/linter/rules/unicorn/prefer-import-meta-properties.html) |

## Code examples

### Incorrect: the rule reports this

```js
const filename = fileURLToPath(import.meta.url);
```

```js
const dirname = path.dirname(fileURLToPath(import.meta.url));
```

### Correct: the rule accepts this

```js
const filename = import.meta.filename;
```

```js
const dirname = import.meta.dirname;
```

Examples from the ESLint documentation.

## Enable it

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

```js
import unicorn from "eslint-plugin-unicorn";

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/prefer-import-meta-properties": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "unicorn/prefer-import-meta-properties": "error"
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Ultracite for Oxlint](https://lintradar.dev/presets/ultracite-oxlint.md) | Oxlint | `ultracite` | 475 | 2.1M | +151.7% |

## Related rules

- [unicorn/require-post-message-target-origin](https://lintradar.dev/rules/unicorn/require-post-message-target-origin.md): Enforce using the `targetOrigin` argument with `window.postMessage()`.
- [unicorn/custom-error-definition](https://lintradar.dev/rules/unicorn/custom-error-definition.md): Enforce correct `Error` subclassing.
- [unicorn/no-array-for-each](https://lintradar.dev/rules/unicorn/no-array-for-each.md): Forbids the use of `Array#forEach` in favor of a for loop.
- [unicorn/no-invalid-file-input-accept](https://lintradar.dev/rules/unicorn/no-invalid-file-input-accept.md): Disallow invalid `accept` values on file inputs.
- [unicorn/no-empty-link-text](https://lintradar.dev/rules/unicorn/no-empty-link-text.md): Disallow empty link text in Markdown.
- [unicorn/no-javascript-url](https://lintradar.dev/rules/unicorn/no-javascript-url.md): Disallow `javascript:` URLs in Markdown.

---

Web page: https://lintradar.dev/rules/unicorn/prefer-import-meta-properties. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
