Skip to content

Commit 1f8720f

Browse files
committed
Hide lint behind a feature flag
1 parent 4796df7 commit 1f8720f

File tree

5 files changed

+35
-12
lines changed

5 files changed

+35
-12
lines changed

scarb/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ cairo-lang-starknet.workspace = true
3535
cairo-lang-syntax.workspace = true
3636
cairo-lang-test-plugin.workspace = true
3737
cairo-lang-utils.workspace = true
38-
cairo-lint-core.workspace = true
38+
cairo-lint-core = {workspace = true, optional = true }
3939
camino.workspace = true
4040
clap.workspace = true
4141
convert_case.workspace = true
@@ -125,3 +125,7 @@ fs_extra.workspace = true
125125
scarb-build-metadata = { path = "../utils/scarb-build-metadata" }
126126
toml.workspace = true
127127
zip.workspace = true
128+
129+
[features]
130+
default = ["scarb-lint"]
131+
scarb-lint = ["dep:cairo-lint-core"]

scarb/src/bin/scarb/commands/lint.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
use scarb::ops::{self, LintOptions};
2-
31
use crate::args::LintArgs;
42
use anyhow::Result;
53
use scarb::core::Config;
64

75
#[tracing::instrument(skip_all, level = "info")]
86
pub fn run(args: LintArgs, config: &Config) -> Result<()> {
7+
do_lint(args, config)
8+
}
9+
10+
#[cfg(feature = "scarb-lint")]
11+
fn do_lint(args: LintArgs, config: &Config) -> Result<()> {
12+
use scarb::ops::{self, LintOptions};
13+
914
let ws = ops::read_workspace(config.manifest_path(), config)?;
1015
let packages = args
1116
.packages_filter
1217
.match_many(&ws)?
1318
.into_iter()
1419
.collect::<Vec<_>>();
15-
1620
ops::lint(
1721
LintOptions {
1822
packages,
@@ -23,3 +27,8 @@ pub fn run(args: LintArgs, config: &Config) -> Result<()> {
2327
&ws,
2428
)
2529
}
30+
31+
#[cfg(not(feature = "scarb-lint"))]
32+
fn do_lint(_args: LintArgs, _config: &Config) -> Result<()> {
33+
panic!("scarb was not compiled with the `lint` command enabled")
34+
}

scarb/src/compiler/db.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ use cairo_lang_filesystem::ids::CrateLongId;
2020
use cairo_lang_semantic::db::PluginSuiteInput;
2121
use cairo_lang_semantic::plugin::PluginSuite;
2222
use cairo_lang_utils::ordered_hash_map::OrderedHashMap;
23-
use cairo_lint_core::plugin::CairoLintAllow;
2423
use smol_str::SmolStr;
2524
use std::collections::HashMap;
2625
use std::path::PathBuf;
2726
use std::sync::Arc;
2827
use tracing::trace;
2928

29+
#[cfg(feature = "scarb-lint")]
30+
use cairo_lint_core::plugin::CairoLintAllow;
31+
3032
pub struct ScarbDatabase {
3133
pub db: RootDatabase,
3234
pub proc_macros: Vec<Arc<ProcMacroHostPlugin>>,
@@ -47,10 +49,7 @@ pub(crate) fn build_scarb_root_database(
4749
proc_macros,
4850
} = PluginsForComponents::collect(ws, unit)?;
4951

50-
plugins
51-
.get_mut(&unit.main_component().id)
52-
.unwrap()
53-
.add_analyzer_plugin::<CairoLintAllow>();
52+
append_lint_plugin(plugins.get_mut(&unit.main_component().id).unwrap());
5453

5554
let main_component_suite = plugins
5655
.get_mut(&unit.main_component().id)
@@ -72,6 +71,14 @@ pub(crate) fn build_scarb_root_database(
7271
Ok(ScarbDatabase { db, proc_macros })
7372
}
7473

74+
#[cfg(feature = "scarb-lint")]
75+
fn append_lint_plugin(suite: &mut PluginSuite) {
76+
suite.add_analyzer_plugin::<CairoLintAllow>();
77+
}
78+
79+
#[cfg(not(feature = "scarb-lint"))]
80+
fn append_lint_plugin(_suite: &mut PluginSuite) {}
81+
7582
/// Sets the plugin suites for crates related to the library components
7683
/// according to the `plugins_for_components` mapping.
7784
fn apply_plugins(

scarb/src/ops/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ pub use clean::*;
77
pub use compile::*;
88
pub use expand::*;
99
pub use fmt::*;
10-
pub use lint::*;
1110
pub use manifest::*;
1211
pub use metadata::*;
1312
pub use new::*;
@@ -24,7 +23,6 @@ mod clean;
2423
mod compile;
2524
mod expand;
2625
mod fmt;
27-
mod lint;
2826
mod lockfile;
2927
mod manifest;
3028
mod metadata;
@@ -36,3 +34,8 @@ mod resolve;
3634
mod scripts;
3735
mod subcommands;
3836
mod workspace;
37+
38+
#[cfg(feature = "scarb-lint")]
39+
mod lint;
40+
#[cfg(feature = "scarb-lint")]
41+
pub use lint::*;

utils/scarb-test-support/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dunce.workspace = true
1515
hyper = "0.14"
1616
indoc.workspace = true
1717
itertools.workspace = true
18-
scarb = { path = "../../scarb" }
18+
scarb = { path = "../../scarb", default-features = false }
1919
scarb-build-metadata = { path = "../scarb-build-metadata" }
2020
scarb-proc-macro-server-types = { path = "../scarb-proc-macro-server-types" }
2121
scarb-ui = { path = "../scarb-ui" }

0 commit comments

Comments
 (0)