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
use clap::Parser;
use nexlint::{prelude::*, NexLintContext};
use nexlint_lints::{
content::*,
file_path::{AllowedPaths, DEFAULT_ALLOWED_PATHS_REGEX},
handle_lint_results,
package::*,
project::{DirectDepDups, DirectDepDupsConfig},
};
static LICENSE_HEADER: &str = "Copyright (c) 2022, Mysten Labs, Inc.\n\
SPDX-License-Identifier: Apache-2.0\n\
";
#[derive(Debug, Parser)]
pub struct Args {
#[clap(long)]
fail_fast: bool,
}
pub fn run(args: Args) -> crate::Result<()> {
let direct_dups_config = DirectDepDupsConfig { allow: vec![] };
let project_linters: &[&dyn ProjectLinter] = &[&DirectDepDups::new(&direct_dups_config)];
let package_linters: &[&dyn PackageLinter] = &[
&CrateNamesPaths,
&IrrelevantBuildDeps,
&PublishedPackagesDontDependOnUnpublishedPackages,
&OnlyPublishToCratesIo,
&CratesInCratesDirectory,
&CratesOnlyInCratesDirectory,
];
let file_path_linters: &[&dyn FilePathLinter] =
&[&AllowedPaths::new(DEFAULT_ALLOWED_PATHS_REGEX)?];
let whitespace_exceptions = build_exceptions(&[])?;
let content_linters: &[&dyn ContentLinter] = &[
&LicenseHeader::new(LICENSE_HEADER),
&RootToml,
&EofNewline::new(&whitespace_exceptions),
&TrailingWhitespace::new(&whitespace_exceptions),
];
let nexlint_context = NexLintContext::from_current_dir()?;
let engine = LintEngineConfig::new(&nexlint_context)
.with_project_linters(project_linters)
.with_package_linters(package_linters)
.with_file_path_linters(file_path_linters)
.with_content_linters(content_linters)
.fail_fast(args.fail_fast)
.build();
let results = engine.run()?;
handle_lint_results(results)
}