Skip to content

Commit 8981bbd

Browse files
committed
feat: capture and log unknown fields using Serde flatten attribute
1 parent 2fd9558 commit 8981bbd

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/lint/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::fmt;
22
use std::fs;
33
use std::path::{Path, PathBuf};
4+
use std::collections::HashMap;
5+
use serde_json::Value;
46
use log::{debug, error, trace};
57
use serde::{Deserialize, Serialize};
68
use rules::{instantiate_rules, CurrentRules, RuleType};
@@ -31,6 +33,10 @@ pub fn parse_lint_cfg(path: PathBuf) -> Result<LintCfg, String> {
3133
pub fn maybe_parse_lint_cfg(path: PathBuf) -> Option<LintCfg> {
3234
match parse_lint_cfg(path) {
3335
Ok(mut cfg) => {
36+
if !cfg.unknown_fields.is_empty() {
37+
// Log the unknown fields as a comma-separated list
38+
error!("Unknown lint config fields: {}", cfg.unknown_fields.keys().cloned().collect::<Vec<_>>().join(", "));
39+
}
3440
setup_indentation_size(&mut cfg);
3541
Some(cfg)
3642
},
@@ -43,8 +49,9 @@ pub fn maybe_parse_lint_cfg(path: PathBuf) -> Option<LintCfg> {
4349

4450
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
4551
#[serde(default)]
46-
#[serde(deny_unknown_fields)]
4752
pub struct LintCfg {
53+
#[serde(flatten)]
54+
pub unknown_fields: HashMap<String, Value>,
4855
#[serde(default)]
4956
pub sp_brace: Option<SpBraceOptions>,
5057
#[serde(default)]
@@ -84,6 +91,7 @@ fn get_true() -> bool {
8491
impl Default for LintCfg {
8592
fn default() -> LintCfg {
8693
LintCfg {
94+
unknown_fields: HashMap::new(),
8795
sp_brace: Some(SpBraceOptions{}),
8896
sp_punct: Some(SpPunctOptions{}),
8997
nsp_funpar: Some(NspFunparOptions{}),

0 commit comments

Comments
 (0)