feat(lint): add too_many_instance_attributes rule

This commit is contained in:
GreasySlug 2024-05-27 01:00:36 +09:00
parent 2282d12a92
commit 1a0daed8a4
2 changed files with 57 additions and 2 deletions

View file

@ -1,5 +1,6 @@
use erg_common::error::{ErrorCore, ErrorKind, Location, SubMessage};
use erg_common::io::Input;
use erg_common::switch_lang;
use erg_common::traits::NoTypeDisplay;
use erg_compiler::error::CompileWarning;
use erg_compiler::hir::Expr;
@ -18,6 +19,38 @@ pub(crate) fn too_many_params(input: Input, caused_by: String, loc: Location) ->
)
}
pub(crate) fn too_many_instance_attributes(
input: Input,
caused_by: String,
loc: Location,
) -> CompileWarning {
let msg = switch_lang!(
"japanese" => "インスタンス属性が多すぎます",
"simplified_chinese" => "实例属性过多",
"traditional_chinese" => "實例屬性過多",
"english" => "too many instance attributes",
)
.to_string();
let hint = switch_lang!(
"japanese" => "サブクラスやデータクラスを活用してください",
"simplified_chinese" => "利用子类和数据类",
"traditional_chinese" => "利用子類和資料類",
"english" => "take advantage of subclasses and data classes",
)
.to_string();
CompileWarning::new(
ErrorCore::new(
vec![SubMessage::ambiguous_new(loc, vec![], Some(hint))],
msg,
0,
ErrorKind::AttributeWarning,
loc,
),
input,
caused_by,
)
}
pub(crate) fn true_comparison(
expr: &Expr,
input: Input,