-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce the idea of "package linters" -- linters that run once for every crate in the workspace. Implement a couple of linters: * a project linter which ensures that there are no banned direct dependencies * a package linter which ensures that license and authors are set correctly for every crate. Also implement the logic for running project and package linters. Closes: diem#3364 Approved by: bmwill
- Loading branch information
1 parent
4df38fa
commit d6031e4
Showing
11 changed files
with
339 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) The Libra Core Contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::{prelude::*, LintContext}; | ||
use guppy::{ | ||
graph::{PackageGraph, PackageMetadata}, | ||
PackageId, | ||
}; | ||
use std::path::Path; | ||
|
||
/// Represents a linter that runs once per package. | ||
pub trait PackageLinter: Linter { | ||
fn run<'l>( | ||
&self, | ||
ctx: &PackageContext<'l>, | ||
out: &mut LintFormatter<'l, '_>, | ||
) -> Result<RunStatus<'l>>; | ||
} | ||
|
||
/// Lint context for an individual package. | ||
#[derive(Copy, Clone, Debug)] | ||
pub struct PackageContext<'l> { | ||
project_ctx: ProjectContext<'l>, | ||
workspace_path: &'l Path, | ||
metadata: &'l PackageMetadata, | ||
} | ||
|
||
impl<'l> PackageContext<'l> { | ||
pub fn new( | ||
project_ctx: ProjectContext<'l>, | ||
package_graph: &'l PackageGraph, | ||
workspace_path: &'l Path, | ||
id: &PackageId, | ||
) -> Self { | ||
Self { | ||
project_ctx, | ||
workspace_path, | ||
metadata: package_graph.metadata(id).expect("package id is valid"), | ||
} | ||
} | ||
|
||
/// Returns the relative path for this package in the workspace. | ||
pub fn workspace_path(&self) -> &'l Path { | ||
self.workspace_path | ||
} | ||
|
||
/// Returns the metadata for this package. | ||
pub fn metadata(&self) -> &'l PackageMetadata { | ||
self.metadata | ||
} | ||
} | ||
|
||
impl<'l> LintContext<'l> for PackageContext<'l> { | ||
fn kind(&self) -> LintKind<'l> { | ||
LintKind::Package { | ||
name: self.metadata.name(), | ||
workspace_path: self.workspace_path, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.