sea_core/parser/
lint.rs

1use std::collections::HashSet;
2use thiserror::Error;
3
4#[derive(Error, Debug, PartialEq)]
5pub enum LintError {
6    #[error("Keyword collision: '{name}' is a reserved keyword. Hint: {hint}")]
7    KeywordCollision { name: String, hint: String },
8}
9
10pub struct Linter {
11    keywords: HashSet<String>,
12}
13
14impl Default for Linter {
15    fn default() -> Self {
16        Self::new()
17    }
18}
19
20impl Linter {
21    pub fn new() -> Self {
22        Self {
23            keywords: ["Entity", "Resource", "Flow", "Policy", "Unit", "Dimension"]
24                .iter()
25                .map(|s| s.to_string())
26                .collect(),
27        }
28    }
29
30    pub fn check_identifier(&self, name: &str, quoted: bool) -> Result<(), LintError> {
31        if !quoted && self.keywords.contains(name) {
32            return Err(LintError::KeywordCollision {
33                name: name.to_string(),
34                hint: format!("Use quoted identifier: \"{}\"", name),
35            });
36        }
37        Ok(())
38    }
39}