Skip to content

Commit b234294

Browse files
committed
feat: Add a workspace lint pass
1 parent 58852d4 commit b234294

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

src/cargo/core/workspace.rs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,10 +1200,17 @@ impl<'gctx> Workspace<'gctx> {
12001200

12011201
pub fn emit_warnings(&self) -> CargoResult<()> {
12021202
let mut first_emitted_error = None;
1203+
1204+
if self.gctx.cli_unstable().cargo_lints {
1205+
if let Err(e) = self.emit_ws_lints() {
1206+
first_emitted_error = Some(e);
1207+
}
1208+
}
1209+
12031210
for (path, maybe_pkg) in &self.packages.packages {
12041211
if let MaybePackage::Package(pkg) = maybe_pkg {
12051212
if self.gctx.cli_unstable().cargo_lints {
1206-
if let Err(e) = self.emit_lints(pkg, &path)
1213+
if let Err(e) = self.emit_pkg_lints(pkg, &path)
12071214
&& first_emitted_error.is_none()
12081215
{
12091216
first_emitted_error = Some(e);
@@ -1242,7 +1249,7 @@ impl<'gctx> Workspace<'gctx> {
12421249
}
12431250
}
12441251

1245-
pub fn emit_lints(&self, pkg: &Package, path: &Path) -> CargoResult<()> {
1252+
pub fn emit_pkg_lints(&self, pkg: &Package, path: &Path) -> CargoResult<()> {
12461253
let mut error_count = 0;
12471254
let toml_lints = pkg
12481255
.manifest()
@@ -1270,6 +1277,41 @@ impl<'gctx> Workspace<'gctx> {
12701277
self.gctx,
12711278
)?;
12721279
check_im_a_teapot(pkg, &path, &cargo_lints, &mut error_count, self.gctx)?;
1280+
1281+
if error_count > 0 {
1282+
Err(crate::util::errors::AlreadyPrintedError::new(anyhow!(
1283+
"encountered {error_count} errors(s) while running lints"
1284+
))
1285+
.into())
1286+
} else {
1287+
Ok(())
1288+
}
1289+
}
1290+
1291+
pub fn emit_ws_lints(&self) -> CargoResult<()> {
1292+
let error_count = 0;
1293+
1294+
let _cargo_lints = match self.root_maybe() {
1295+
MaybePackage::Package(pkg) => {
1296+
let toml = pkg.manifest().normalized_toml();
1297+
if let Some(ws) = &toml.workspace {
1298+
ws.lints.as_ref()
1299+
} else {
1300+
toml.lints.as_ref().map(|l| &l.lints)
1301+
}
1302+
}
1303+
MaybePackage::Virtual(vm) => vm
1304+
.normalized_toml()
1305+
.workspace
1306+
.as_ref()
1307+
.unwrap()
1308+
.lints
1309+
.as_ref(),
1310+
}
1311+
.and_then(|t| t.get("cargo"))
1312+
.cloned()
1313+
.unwrap_or(manifest::TomlToolLints::default());
1314+
12731315
if error_count > 0 {
12741316
Err(crate::util::errors::AlreadyPrintedError::new(anyhow!(
12751317
"encountered {error_count} errors(s) while running lints"

0 commit comments

Comments
 (0)