---
title: Oxlint eslint-plugin rule implementation
tags: 
author: [藤谷想楽](https://www.docswell.com/user/8723788)
site: [Docswell](https://www.docswell.com/)
thumbnail: https://bcdn.docswell.com/page/4EMYL6WNEW.jpg?width=480
description: Oxlint eslint-plugin rule implementation by 藤谷想楽
published: June 20, 26
canonical: https://www.docswell.com/s/8723788/5MQ6MN-slide-oxlint-test-toolchain-summary
---
# Page. 1

![Page Image](https://bcdn.docswell.com/page/4EMYL6WNEW.jpg)

Oxlint eslint-plugin rule implementation
TSKaigi 2026事後勉強会 / #tskaigi_smarthr / fujitani sora


# Page. 2

![Page Image](https://bcdn.docswell.com/page/PER9KPY4J9.jpg)

fujitani sora
2001 (25)
toridori inc engineer
x.com/sorafujitani
github.com/sorafujitani
sorafujitani.me
TSKaigi2026 振り返りレポート


# Page. 3

![Page Image](https://bcdn.docswell.com/page/P7XQL3GZEX.jpg)

Oxlint は TypeScript / JavaScript の lint を高速に実行するツール。
既存の ESLint plugin の rule と同じ名前・同じ挙動に寄せて実装される rule群 とその
移行計画がある
Linter Product Plan and Progress
node/prefer-global-console も、eslint-plugin-n の n/prefer-global/console
相当の rule
Issue: https://github.com/oxc-project/oxc/issues/493
PR: https://github.com/oxc-project/oxc/pull/23610


# Page. 4

![Page Image](https://bcdn.docswell.com/page/37K9LY4V7D.jpg)

node/prefer-global-console
は console の使い方を揃える rule。
グローバル console
1
//
2
console.log(&quot;hello&quot;)
3
から import
4
// console module
5
import console from &quot;node:console&quot;
6
console.log(&quot;hello&quot;)
Node.js では console はグローバルにも module にもある。


# Page. 5

![Page Image](https://bcdn.docswell.com/page/LJ3W39DQJ5.jpg)

&quot;always&quot;
では、console module からの import / require を避ける。
1
// NG
2
import console from &quot;node:console&quot;
3
console.log(&quot;hello&quot;)
4
5
// OK
6
console.log(&quot;hello&quot;)
CommonJS でも同じ。
1
// NG
2
const console = require(&quot;console&quot;)


# Page. 6

![Page Image](https://bcdn.docswell.com/page/8JDK4GPWEG.jpg)

.oxlintrc.json
1
から有効化する。
{
2
&quot;plugins&quot;: [&quot;node&quot;],
3
&quot;rules&quot;: {
4
&quot;node/prefer-global-console&quot;: [&quot;warn&quot;, &quot;always&quot;]
5
6
}
}
&quot;always&quot;
はグローバル console 、 &quot;never&quot; は module 側を使う設定。


# Page. 7

![Page Image](https://bcdn.docswell.com/page/VEPKM3NX78.jpg)

PR #23610 で追加されたもの。
rule 本体、診断、検出ロジック、テストを実装する
prefer_global_console.rs
rule を Oxlint の実行経路に登録する
rules_enum.rs / rule_runner_impls.rs
.oxlintrc.json から設定できるようにする
configuration_schema.json / config.generated.ts


# Page. 8

![Page Image](https://bcdn.docswell.com/page/27VV94K37Q.jpg)

.oxlintrc.json
生成コマンド
から読める schema と型定義。
cargo lintgen &amp;&amp; just linter-schema-json &amp;&amp; just linter-config-ts
生成されるもの
: TS 側の rule 名と option 型
configuration_schema.json : JSON schema 側の rule 名と option 型
config.generated.ts
1
// apps/oxlint/src-js/package/config.generated.ts:1227
2
&quot;node/prefer-global-console&quot;?: RuleNoConfig | [
3
AllowWarnDeny,
4
PreferGlobalConsoleMode,
5
];
6
7
// npm/oxlint/configuration_schema.json:5758
8
&quot;node/prefer-global-console&quot;: { ... }


# Page. 9

![Page Image](https://bcdn.docswell.com/page/5JGLZ1QY7L.jpg)

module 経由の console を見つける
変数宣言を見る
const console = require(&quot;console&quot;)
const console = require(&quot;node:console&quot;)
import 宣言を見る
import console from &quot;node:console&quot;
import * as console from &quot;node:console&quot;


# Page. 10

![Page Image](https://bcdn.docswell.com/page/47QYLDK6EP.jpg)

crates/oxc_linter/src/rules/node/prefer_global_console.rs:90-102
のときだけ module 経由の console を検出
前のページの「変数宣言」と「import 宣言」を分岐して見る
Always
1
PreferGlobalConsoleMode::Always =&gt; match node.kind() {
2
AstKind::VariableDeclarator(var_decl) =&gt; {
3
if let Some(span) = module_console_binding_span(var_decl) {
4
ctx.diagnostic(prefer_global_diagnostic(span));
5
}
6
}
7
AstKind::ImportDeclaration(import_decl) =&gt; {
8
if let Some(span) = imported_console_span(import_decl) {
9
ctx.diagnostic(prefer_global_diagnostic(span));
10
}
11
}
12
_ =&gt; {}
13
},


# Page. 11

![Page Image](https://bcdn.docswell.com/page/KE4WDZPMJ1.jpg)

PR本文の test plan。
rule の pass / fail case を確認する
cargo test -p oxc_linter --lib prefer_global_console
schema と型定義の更新漏れを確認する
cargo lintgen &amp;&amp; just linter-schema-json &amp;&amp; just linter-config-ts
&amp;&amp; git diff --exit-code
formatting を確認する
just fmt


# Page. 12

![Page Image](https://bcdn.docswell.com/page/L71YZR9YJG.jpg)

rule 本体を実装する
実行経路と schema も更新する
test plan では rule、schema / 型定義、formatting を確認する


# Page. 13

![Page Image](https://bcdn.docswell.com/page/G7WG91Q1E2.jpg)

see you later 👋


