alpm_lint/lint_rules/source_info/
no_architecture.rs1use std::collections::BTreeMap;
7
8use documented::Documented;
9
10use crate::{
11 Level,
12 internal_prelude::*,
13 issue::SourceInfoIssue,
14 lint_rules::source_info::source_info_from_resource,
15};
16
17#[derive(Clone, Debug, Documented)]
46pub struct NoArchitecture {}
47
48impl NoArchitecture {
49 pub fn new_boxed(_: &LintRuleConfiguration) -> Box<dyn LintRule> {
51 Box::new(Self {})
52 }
53}
54
55impl LintRule for NoArchitecture {
56 fn name(&self) -> &'static str {
57 "no_architecture"
58 }
59
60 fn scope(&self) -> LintScope {
61 LintScope::SourceInfo
62 }
63
64 fn level(&self) -> Level {
65 Level::Error
66 }
67
68 fn documentation(&self) -> String {
69 NoArchitecture::DOCS.into()
70 }
71
72 fn help_text(&self) -> String {
73 r#"An Architecture must be specified.
74
75Make sure to add an 'arch' field to specify the supported architectures for your package.
76"#
77 .into()
78 }
79
80 fn run(&self, resources: &Resources, issues: &mut Vec<LintIssue>) -> Result<(), Error> {
81 let source_info = source_info_from_resource(resources, self.scoped_name())?;
83
84 if source_info.base.architectures.is_empty() {
86 issues.push(LintIssue::from_rule(
87 self,
88 SourceInfoIssue::MissingField {
89 field_name: "arch".to_string(),
90 }
91 .into(),
92 ));
93 }
94
95 Ok(())
96 }
97
98 fn extra_links(&self) -> Option<BTreeMap<String, String>> {
99 let mut links = BTreeMap::new();
100 links.insert(
101 "SRCINFO specification".to_string(),
102 "https://alpm.archlinux.page/specifications/SRCINFO.5.html".to_string(),
103 );
104 links.insert(
105 "alpm-architecture specification".to_string(),
106 "https://alpm.archlinux.page/specifications/alpm-architecture.7.html".to_string(),
107 );
108
109 Some(links)
110 }
111}