Skip to content

Commit 1efb2e2

Browse files
committed
Refactor strict configuration: rename doc_integer_const_match_int to doc_base_const_match_base_type .
1 parent e8856fe commit 1efb2e2

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

crates/emmylua_code_analysis/resources/schema.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@
159159
"strict": {
160160
"default": {
161161
"arrayIndex": true,
162-
"docIntegerConstMatchInt": true,
162+
"docBaseConstMatchBaseType": true,
163163
"metaOverrideFileDefine": true,
164164
"requirePath": false,
165165
"typeCall": false
@@ -925,8 +925,8 @@
925925
"default": true,
926926
"type": "boolean"
927927
},
928-
"docIntegerConstMatchInt": {
929-
"description": "`doc_integer_const` type can match `int` type.",
928+
"docBaseConstMatchBaseType": {
929+
"description": "Base constant types defined in doc can match base types, allowing int to match `---@alias id 1|2|3`, same for string.",
930930
"default": false,
931931
"type": "boolean"
932932
},

crates/emmylua_code_analysis/src/config/configs/strict.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ pub struct EmmyrcStrict {
2424
/// meta define overrides file define
2525
#[serde(default = "default_true")]
2626
pub meta_override_file_define: bool,
27-
/// `doc_integer_const` type can match `int` type.
27+
/// Base constant types defined in doc can match base types, allowing int to match `---@alias id 1|2|3`, same for string.
2828
#[serde(default = "default_false")]
29-
pub doc_integer_const_match_int: bool,
29+
pub doc_base_const_match_base_type: bool,
3030
}
3131

3232
impl Default for EmmyrcStrict {
@@ -36,7 +36,7 @@ impl Default for EmmyrcStrict {
3636
type_call: false,
3737
array_index: true,
3838
meta_override_file_define: true,
39-
doc_integer_const_match_int: true,
39+
doc_base_const_match_base_type: true,
4040
}
4141
}
4242
}

crates/emmylua_code_analysis/src/diagnostic/test/param_type_check_test.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ mod test {
10241024
fn test_int_to_alias() {
10251025
let mut ws = VirtualWorkspace::new();
10261026
let mut emmyrc = ws.analysis.get_emmyrc().deref().clone();
1027-
emmyrc.strict.doc_integer_const_match_int = true;
1027+
emmyrc.strict.doc_base_const_match_base_type = true;
10281028
ws.analysis.update_config(Arc::new(emmyrc));
10291029

10301030
assert!(ws.check_code_for(
@@ -1048,6 +1048,10 @@ mod test {
10481048
#[test]
10491049
fn test_enum_value_matching() {
10501050
let mut ws = VirtualWorkspace::new();
1051+
let mut emmyrc = ws.analysis.get_emmyrc().deref().clone();
1052+
emmyrc.strict.doc_base_const_match_base_type = true;
1053+
ws.analysis.update_config(Arc::new(emmyrc));
1054+
10511055
assert!(ws.check_code_for(
10521056
DiagnosticCode::ParamTypeNotMatch,
10531057
r#"

crates/emmylua_code_analysis/src/semantic/type_check/simple_type.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub fn check_simple_type_compact(
131131
return Err(TypeCheckFailReason::TypeNotMatch);
132132
}
133133
LuaType::Integer => {
134-
if db.get_emmyrc().strict.doc_integer_const_match_int {
134+
if db.get_emmyrc().strict.doc_base_const_match_base_type {
135135
return Ok(());
136136
}
137137
return Err(TypeCheckFailReason::TypeNotMatch);
@@ -144,10 +144,12 @@ pub fn check_simple_type_compact(
144144
return Err(TypeCheckFailReason::TypeNotMatch);
145145
}
146146
LuaType::Ref(_) => {
147-
match check_base_type_for_ref_compact(db, source, compact_type, check_guard) {
148-
Ok(_) => return Ok(()),
149-
Err(err) if err.is_type_not_match() => {}
150-
Err(err) => return Err(err),
147+
if db.get_emmyrc().strict.doc_base_const_match_base_type {
148+
match check_base_type_for_ref_compact(db, source, compact_type, check_guard) {
149+
Ok(_) => return Ok(()),
150+
Err(err) if err.is_type_not_match() => {}
151+
Err(err) => return Err(err),
152+
}
151153
}
152154
}
153155
_ => {}
@@ -169,10 +171,12 @@ pub fn check_simple_type_compact(
169171
return Err(TypeCheckFailReason::TypeNotMatch);
170172
}
171173
LuaType::Ref(_) => {
172-
match check_base_type_for_ref_compact(db, source, compact_type, check_guard) {
173-
Ok(_) => return Ok(()),
174-
Err(err) if err.is_type_not_match() => {}
175-
Err(err) => return Err(err),
174+
if db.get_emmyrc().strict.doc_base_const_match_base_type {
175+
match check_base_type_for_ref_compact(db, source, compact_type, check_guard) {
176+
Ok(_) => return Ok(()),
177+
Err(err) if err.is_type_not_match() => {}
178+
Err(err) => return Err(err),
179+
}
176180
}
177181
}
178182
_ => {}

0 commit comments

Comments
 (0)