Back to Biomejs

noDeprecatedImports

src/content/docs/linter/rules/no-deprecated-imports.mdx

latest3.9 KB
Original Source

import { Tabs, TabItem } from '@astrojs/starlight/components';

<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> :::note This rule belongs to the project domain. This means that its activation will activate the Biome Scanner to scan the files of your project. Read more about it in the [documentation page](/linter/domains#project) ::: ## Summary - Rule available since: `v2.2.5` - Diagnostic Category: [`lint/suspicious/noDeprecatedImports`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule doesn't have a fix. - The default severity of this rule is [**warning**](/reference/diagnostics#warning). - This rule belongs to the following domains: - [`project`](/linter/domains#project) - Sources: - Inspired from [`@typescript-eslint/no-deprecated`](https://typescript-eslint.io/rules/no-deprecated) - Inspired from [`import/no-deprecated`](https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-deprecated.md)

How to configure

json
{
	"linter": {
		"rules": {
			"suspicious": {
				"noDeprecatedImports": "error"
			}
		}
	}
}

Description

Restrict imports of deprecated exports.

This rule flags any imports for symbols (such as types, functions, or anything else that can be imported), that are documented with a JSDoc comment that contains an "@deprecated" annotation.

Examples

Invalid

js
import { oldUtility } from "./utils.js";
<pre class="language-text"><code class="language-text"><a href="file:///foo.js">/foo.js</a>:1:10 <a href="https://biomejs.dev/linter/rules/no-deprecated-imports">lint/suspicious/noDeprecatedImports</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">Deprecated import.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>import &#123; oldUtility &#125; from &quot;./utils.js&quot;; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong>2 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">An </span><span style="color: lightgreen;"><strong>@deprecated</strong></span><span style="color: lightgreen;"> annotation indicates the author doesn't want you to rely on this import anymore.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">You should probably import a different symbol instead.</span> </code></pre>
js
/**
 * @deprecated
 */
export function oldUtility() {}

Valid

js
import { newUtility, oldUtility } from "./utils.js";
js
export function newUtility() {}

// @deprecated (this is not a JSDoc comment)
export function oldUtility() {}
</TabItem> </Tabs>