nextjs/no-script-component-in-head Correctness
它的作用
阻止在 next/head 组件中使用 next/script。
为什么这不好?
next/script 组件不应在 next/head 组件中使用。 请将 <Script /> 组件移到 <Head> 外部。
示例
以下是此规则的错误代码示例:
jsx
import Script from "next/script";
import Head from "next/head";
export default function Index() {
return (
<Head>
<title>Next.js</title>
<Script src="/my-script.js" />
</Head>
);
}以下是此规则的正确代码示例:
jsx
import Script from "next/script";
import Head from "next/head";
export default function Index() {
return (
<>
<Head>
<title>Next.js</title>
</Head>
<Script src="/my-script.js" />
</>
);
}如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["nextjs"],
"rules": {
"nextjs/no-script-component-in-head": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["nextjs"],
rules: {
"nextjs/no-script-component-in-head": "error",
},
});bash
oxlint --deny nextjs/no-script-component-in-head --nextjs-plugin版本
此规则在 v0.2.0 中添加。
