Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): Explicitly turn on tree shaking plugin by default, add option to disable #7057

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions apps/oxlint/src/command/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,14 @@ pub struct EnablePlugins {
)]
pub typescript_plugin: OverrideToggle,

/// Disable tree shaking plugin, which is turned on by default
#[bpaf(
long("disable-tree-shaking-plugin"),
flag(OverrideToggle::Disable, OverrideToggle::NotSet),
hide_usage
)]
pub tree_shaking_plugin: OverrideToggle,

/// Enable the experimental import plugin and detect ESM problems.
/// It is recommended to use along side with the `--tsconfig` option.
#[bpaf(flag(OverrideToggle::Enable, OverrideToggle::NotSet), hide_usage)]
Expand Down Expand Up @@ -361,6 +369,7 @@ impl EnablePlugins {
self.promise_plugin.inspect(|yes| plugins.set(LintPlugins::PROMISE, yes));
self.node_plugin.inspect(|yes| plugins.set(LintPlugins::NODE, yes));
self.security_plugin.inspect(|yes| plugins.set(LintPlugins::SECURITY, yes));
self.tree_shaking_plugin.inspect(|yes| plugins.set(LintPlugins::TREE_SHAKING, yes));

// Without this, jest plugins adapted to vitest will not be enabled.
if self.vitest_plugin.is_enabled() && self.jest_plugin.is_not_set() {
Expand Down
14 changes: 13 additions & 1 deletion crates/oxc_linter/src/config/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ bitflags! {
const NODE = 1 << 12;
/// Custom security rules made by the Oxc team
const SECURITY = 1 << 13;
/// `eslint-plugin-tree-shaking`
const TREE_SHAKING = 1 << 14;
}
}
impl Default for LintPlugins {
#[inline]
fn default() -> Self {
LintPlugins::REACT | LintPlugins::UNICORN | LintPlugins::TYPESCRIPT | LintPlugins::OXC
LintPlugins::REACT | LintPlugins::UNICORN | LintPlugins::TYPESCRIPT | LintPlugins::OXC | LintPlugins::TREE_SHAKING
}
}

Expand All @@ -66,6 +68,7 @@ impl From<LintPluginOptions> for LintPlugins {
plugins.set(LintPlugins::PROMISE, options.promise);
plugins.set(LintPlugins::NODE, options.node);
plugins.set(LintPlugins::SECURITY, options.security);
plugins.set(LintPlugins::TREE_SHAKING, options.tree_shaking);
plugins
}
}
Expand Down Expand Up @@ -116,6 +119,7 @@ impl From<&str> for LintPlugins {
"promise" => LintPlugins::PROMISE,
"node" => LintPlugins::NODE,
"security" | "oxc-security" => LintPlugins::SECURITY,
"tree-shaking" | "tree_shaking" => LintPlugins::TREE_SHAKING,
// "eslint" is not really a plugin, so it's 'empty'. This has the added benefit of
// making it the default value.
_ => LintPlugins::empty(),
Expand All @@ -140,6 +144,7 @@ impl From<LintPlugins> for &'static str {
LintPlugins::PROMISE => "promise",
LintPlugins::NODE => "node",
LintPlugins::SECURITY => "security",
LintPlugins::TREE_SHAKING => "tree-shaking",
_ => "",
}
}
Expand Down Expand Up @@ -230,6 +235,7 @@ pub struct LintPluginOptions {
pub promise: bool,
pub node: bool,
pub security: bool,
pub tree_shaking: bool,
}

impl Default for LintPluginOptions {
Expand All @@ -249,6 +255,7 @@ impl Default for LintPluginOptions {
promise: false,
node: false,
security: false,
tree_shaking: true,
}
}
}
Expand All @@ -272,6 +279,7 @@ impl LintPluginOptions {
promise: false,
node: false,
security: false,
tree_shaking: false,
}
}

Expand All @@ -293,6 +301,7 @@ impl LintPluginOptions {
promise: true,
node: true,
security: true,
tree_shaking: true,
}
}
}
Expand All @@ -317,6 +326,7 @@ impl<S: AsRef<str>> FromIterator<(S, bool)> for LintPluginOptions {
LintPlugins::PROMISE => options.promise = enabled,
LintPlugins::NODE => options.node = enabled,
LintPlugins::SECURITY => options.security = enabled,
LintPlugins::TREE_SHAKING => options.tree_shaking = enabled,
_ => {} // ignored
}
}
Expand Down Expand Up @@ -350,6 +360,7 @@ mod test {
&& self.promise == other.promise
&& self.node == other.node
&& self.security == other.security
&& self.tree_shaking == other.tree_shaking
}
}

Expand Down Expand Up @@ -390,6 +401,7 @@ mod test {
promise: false,
node: false,
security: false,
tree_shaking: true,
};
assert_eq!(plugins, expected);
}
Expand Down
Loading