1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use crate::{prelude::*, LintContext};
use camino::{Utf8Path, Utf8PathBuf};
use guppy::graph::PackageGraph;
use hakari::Hakari;
use x_core::{WorkspaceSubset, XCoreContext};
pub trait ProjectLinter: Linter {
#[allow(clippy::trivially_copy_pass_by_ref)]
fn run<'l>(
&self,
ctx: &ProjectContext<'l>,
out: &mut LintFormatter<'l, '_>,
) -> Result<RunStatus<'l>>;
}
#[derive(Debug)]
pub struct ProjectContext<'l> {
core: &'l XCoreContext,
}
impl<'l> ProjectContext<'l> {
pub fn new(core: &'l XCoreContext) -> Self {
Self { core }
}
pub fn core(&self) -> &'l XCoreContext {
self.core
}
pub fn project_root(&self) -> &'l Utf8Path {
self.core.project_root()
}
pub fn package_graph(&self) -> Result<&'l PackageGraph> {
self.core.package_graph()
}
pub fn full_path(&self, path: impl AsRef<Utf8Path>) -> Utf8PathBuf {
self.core.project_root().join(path.as_ref())
}
pub fn default_members(&self) -> Result<&WorkspaceSubset> {
Ok(self.core.subsets()?.default_members())
}
pub fn hakari(&self) -> Result<Hakari<'l>> {
Ok(self.core.hakari_builder()?.compute())
}
}
impl<'l> LintContext<'l> for ProjectContext<'l> {
fn kind(&self) -> LintKind<'l> {
LintKind::Project
}
}