Skip to content

Commit

Permalink
reduce nesting a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
todor-a committed May 19, 2024
1 parent f53a37b commit 5a07354
Showing 1 changed file with 43 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,55 +150,59 @@ impl Rule for ConsistentIndexedObjectStyle {
}
}
TSType::TSTypeLiteral(lit) => {
if lit.members.len() == 1 {
if let TSSignature::TSIndexSignature(sig) = &lit.members[0] {
match &sig.type_annotation.type_annotation {
TSType::TSUnionType(uni) => {
for t in &uni.types {
if let TSType::TSTypeReference(re) = t {
if let TSTypeName::IdentifierReference(i) =
&re.type_name
{
if i.name == al.id.name && self.is_index_signature {
ctx.diagnostic(
ConsistentIndexedObjectStyleDiagnostic(
"index signature",
"record",
re.span,
),
);
}
if lit.members.len() != 1 {
return;
}

if let TSSignature::TSIndexSignature(sig) = &lit.members[0] {
match &sig.type_annotation.type_annotation {
TSType::TSUnionType(uni) => {
if !self.is_index_signature {
return;
}

for t in &uni.types {
if let TSType::TSTypeReference(re) = t {
if let TSTypeName::IdentifierReference(i) = &re.type_name {
if i.name == al.id.name {
ctx.diagnostic(
ConsistentIndexedObjectStyleDiagnostic(
"index signature",
"record",
re.span,
),
);
}
}
}
}
TSType::TSTypeReference(tref) => match &tref.type_name {
TSTypeName::IdentifierReference(i) => {
if i.name != al.id.name {
ctx.diagnostic(ConsistentIndexedObjectStyleDiagnostic(
"record",
"index signature",
tref.span,
));
}
}
TSTypeName::QualifiedName(_) => {
ctx.diagnostic(ConsistentIndexedObjectStyleDiagnostic(
"record",
"index signature",
sig.span,
));
}
},
_ => {
if !self.is_index_signature {
}
TSType::TSTypeReference(tref) => match &tref.type_name {
TSTypeName::IdentifierReference(i) => {
if i.name != al.id.name {
ctx.diagnostic(ConsistentIndexedObjectStyleDiagnostic(
"record",
"index signature",
sig.span,
tref.span,
));
}
}
TSTypeName::QualifiedName(_) => {
ctx.diagnostic(ConsistentIndexedObjectStyleDiagnostic(
"record",
"index signature",
sig.span,
));
}
},
_ => {
if !self.is_index_signature {
ctx.diagnostic(ConsistentIndexedObjectStyleDiagnostic(
"record",
"index signature",
sig.span,
));
}
}
}
}
Expand Down

0 comments on commit 5a07354

Please sign in to comment.