mirror of
https://github.com/swc-project/swc.git
synced 2024-12-23 13:51:19 +03:00
chore(clippy): Improve config (#3691)
This commit is contained in:
parent
1198b04f27
commit
e35d73adf4
@ -1,2 +1,3 @@
|
||||
blacklisted-names = ["bool", "char", "str", "f32", "f64", "i8", "i16", "i32", "i64", "u8", "u16", "u32", "u64", "isize", "usize"]
|
||||
cognitive-complexity-threshold = 50
|
||||
type-complexity-threshold = 25000
|
||||
|
@ -78,8 +78,8 @@ where
|
||||
let mut dq = 0;
|
||||
let mut sq = 0;
|
||||
|
||||
for char in text.chars() {
|
||||
match char {
|
||||
for c in text.chars() {
|
||||
match c {
|
||||
// If the character is NULL (U+0000), then the REPLACEMENT CHARACTER (U+FFFD).
|
||||
'\0' => {
|
||||
new_string.push('\u{FFFD}');
|
||||
@ -91,7 +91,7 @@ where
|
||||
|
||||
let b3;
|
||||
let b4;
|
||||
let char_as_u8 = char as u8;
|
||||
let char_as_u8 = c as u8;
|
||||
|
||||
let bytes = if char_as_u8 > 0x0f {
|
||||
let high = (char_as_u8 >> 4) as usize;
|
||||
@ -101,7 +101,7 @@ where
|
||||
|
||||
&b4[..]
|
||||
} else {
|
||||
b3 = [b'\\', HEX_DIGITS[char as usize], b' '];
|
||||
b3 = [b'\\', HEX_DIGITS[c as usize], b' '];
|
||||
|
||||
&b3[..]
|
||||
};
|
||||
@ -117,16 +117,16 @@ where
|
||||
'"' => {
|
||||
dq += 1;
|
||||
|
||||
new_string.push(char);
|
||||
new_string.push(c);
|
||||
}
|
||||
'\'' => {
|
||||
sq += 1;
|
||||
|
||||
new_string.push(char);
|
||||
new_string.push(c);
|
||||
}
|
||||
// Otherwise, the character itself.
|
||||
_ => {
|
||||
new_string.push(char);
|
||||
new_string.push(c);
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -145,8 +145,8 @@ where
|
||||
}
|
||||
|
||||
fn write_raw(&mut self, span: Option<Span>, text: &str) -> Result {
|
||||
for char in text.chars() {
|
||||
self.write_raw_char(span, char)?;
|
||||
for c in text.chars() {
|
||||
self.write_raw_char(span, c)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -254,8 +254,8 @@ impl VisitMut for CompressSelector {
|
||||
let chars = value.chars();
|
||||
let mut starts_with_hyphen = false;
|
||||
|
||||
for (idx, char) in chars.enumerate() {
|
||||
match char {
|
||||
for (idx, c) in chars.enumerate() {
|
||||
match c {
|
||||
'0'..='9' if idx == 0 || (starts_with_hyphen && idx == 1) => {
|
||||
return;
|
||||
}
|
||||
@ -264,7 +264,7 @@ impl VisitMut for CompressSelector {
|
||||
starts_with_hyphen = true;
|
||||
}
|
||||
}
|
||||
_ if !matches!(char, '-' | '_' | 'a'..='z' | 'A'..='Z' | '0'..='9' | '\u{00a0}'..='\u{10FFFF}') =>
|
||||
_ if !matches!(c, '-' | '_' | 'a'..='z' | 'A'..='Z' | '0'..='9' | '\u{00a0}'..='\u{10FFFF}') =>
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
#![recursion_limit = "1024"]
|
||||
#![deny(clippy::all)]
|
||||
#![allow(clippy::match_like_matches_macro)]
|
||||
#![allow(clippy::nonminimal_bool)]
|
||||
#![allow(unused_variables)]
|
||||
@ -1058,7 +1059,7 @@ where
|
||||
}
|
||||
|
||||
#[emitter]
|
||||
fn emit_class_memeber(&mut self, node: &ClassMember) -> Result {
|
||||
fn emit_class_member(&mut self, node: &ClassMember) -> Result {
|
||||
match *node {
|
||||
ClassMember::Constructor(ref n) => emit!(n),
|
||||
ClassMember::ClassProp(ref n) => emit!(n),
|
||||
@ -1123,7 +1124,7 @@ where
|
||||
fn emit_class_method(&mut self, n: &ClassMethod) -> Result {
|
||||
self.emit_leading_comments_of_span(n.span(), false)?;
|
||||
|
||||
self.emit_accesibility(n.accessibility)?;
|
||||
self.emit_accessibility(n.accessibility)?;
|
||||
|
||||
if n.is_static {
|
||||
keyword!("static");
|
||||
@ -1216,7 +1217,7 @@ where
|
||||
|
||||
self.emit_list(n.span, Some(&n.decorators), ListFormat::Decorators)?;
|
||||
|
||||
self.emit_accesibility(n.accessibility)?;
|
||||
self.emit_accessibility(n.accessibility)?;
|
||||
|
||||
if n.is_static {
|
||||
keyword!("static");
|
||||
@ -1257,7 +1258,7 @@ where
|
||||
self.emit_leading_comments_of_span(n.span(), false)?;
|
||||
|
||||
if n.accessibility != Some(Accessibility::Public) {
|
||||
self.emit_accesibility(n.accessibility)?;
|
||||
self.emit_accessibility(n.accessibility)?;
|
||||
}
|
||||
|
||||
if n.is_static {
|
||||
@ -1295,7 +1296,7 @@ where
|
||||
semi!();
|
||||
}
|
||||
|
||||
fn emit_accesibility(&mut self, n: Option<Accessibility>) -> Result {
|
||||
fn emit_accessibility(&mut self, n: Option<Accessibility>) -> Result {
|
||||
if let Some(a) = n {
|
||||
match a {
|
||||
Accessibility::Public => keyword!(self, "public"),
|
||||
@ -1312,7 +1313,7 @@ where
|
||||
fn emit_class_constructor(&mut self, n: &Constructor) -> Result {
|
||||
self.emit_leading_comments_of_span(n.span(), false)?;
|
||||
|
||||
self.emit_accesibility(n.accessibility)?;
|
||||
self.emit_accessibility(n.accessibility)?;
|
||||
|
||||
keyword!("constructor");
|
||||
punct!("(");
|
||||
@ -2844,7 +2845,7 @@ where
|
||||
pub fn emit_module_export_name(&mut self, node: &ModuleExportName) -> Result {
|
||||
match *node {
|
||||
ModuleExportName::Ident(ref ident) => emit!(ident),
|
||||
ModuleExportName::Str(ref str) => emit!(str),
|
||||
ModuleExportName::Str(ref s) => emit!(s),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -636,7 +636,7 @@ where
|
||||
fn emit_ts_param_prop(&mut self, n: &TsParamProp) -> Result {
|
||||
self.emit_leading_comments_of_span(n.span(), false)?;
|
||||
|
||||
self.emit_accesibility(n.accessibility)?;
|
||||
self.emit_accessibility(n.accessibility)?;
|
||||
|
||||
if n.is_override {
|
||||
keyword!("override");
|
||||
|
@ -24,16 +24,16 @@ where
|
||||
match e {
|
||||
Expr::Member(MemberExpr { prop, .. }) => {
|
||||
if let MemberProp::Computed(c) = prop {
|
||||
if let Expr::Lit(Lit::Str(str)) = &mut *c.expr {
|
||||
if !str.value.starts_with(|c: char| c.is_ascii_alphabetic()) {
|
||||
if let Expr::Lit(Lit::Str(s)) = &mut *c.expr {
|
||||
if !s.value.starts_with(|c: char| c.is_ascii_alphabetic()) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.changed = true;
|
||||
tracing::debug!("arguments: Optimizing computed access to arguments");
|
||||
*prop = MemberProp::Ident(Ident {
|
||||
span: str.span,
|
||||
sym: str.take().value,
|
||||
span: s.span,
|
||||
sym: s.take().value,
|
||||
optional: false,
|
||||
})
|
||||
}
|
||||
@ -42,16 +42,16 @@ where
|
||||
|
||||
Expr::SuperProp(SuperPropExpr { prop, .. }) => {
|
||||
if let SuperProp::Computed(c) = prop {
|
||||
if let Expr::Lit(Lit::Str(str)) = &mut *c.expr {
|
||||
if !str.value.starts_with(|c: char| c.is_ascii_alphabetic()) {
|
||||
if let Expr::Lit(Lit::Str(s)) = &mut *c.expr {
|
||||
if !s.value.starts_with(|c: char| c.is_ascii_alphabetic()) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.changed = true;
|
||||
tracing::debug!("arguments: Optimizing computed access to arguments");
|
||||
*prop = SuperProp::Ident(Ident {
|
||||
span: str.span,
|
||||
sym: str.take().value,
|
||||
span: s.span,
|
||||
sym: s.take().value,
|
||||
optional: false,
|
||||
})
|
||||
}
|
||||
|
@ -473,10 +473,10 @@ impl SyntaxError {
|
||||
|
||||
SyntaxError::GeneratorConstructor => "A constructor cannot be generator".into(),
|
||||
|
||||
SyntaxError::ImportBindingIsString(str) => format!(
|
||||
SyntaxError::ImportBindingIsString(s) => format!(
|
||||
"A string literal cannot be used as an imported binding.\n- Did you mean `import \
|
||||
{{ \"{}\" as foo }}`?",
|
||||
str
|
||||
s
|
||||
)
|
||||
.into(),
|
||||
|
||||
|
@ -116,6 +116,7 @@
|
||||
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||
#![cfg_attr(test, feature(bench_black_box))]
|
||||
#![cfg_attr(test, feature(test))]
|
||||
#![deny(clippy::all)]
|
||||
#![deny(unused)]
|
||||
#![allow(clippy::nonminimal_bool)]
|
||||
#![allow(clippy::too_many_arguments)]
|
||||
|
@ -166,8 +166,8 @@ impl Visit for UsageVisitor {
|
||||
if e.op == op!("in") {
|
||||
// 'entries' in Object
|
||||
// 'entries' in [1, 2, 3]
|
||||
if let Expr::Lit(Lit::Str(str)) = &*e.left {
|
||||
self.add_property_deps(&e.right, &str.value);
|
||||
if let Expr::Lit(Lit::Str(s)) = &*e.left {
|
||||
self.add_property_deps(&e.right, &s.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -215,8 +215,8 @@ impl Visit for UsageVisitor {
|
||||
fn visit_member_expr(&mut self, e: &MemberExpr) {
|
||||
e.obj.visit_with(self);
|
||||
if let MemberProp::Computed(c) = &e.prop {
|
||||
if let Expr::Lit(Lit::Str(str)) = &*c.expr {
|
||||
self.add_property_deps(&e.obj, &str.value);
|
||||
if let Expr::Lit(Lit::Str(s)) = &*c.expr {
|
||||
self.add_property_deps(&e.obj, &s.value);
|
||||
}
|
||||
c.visit_with(self);
|
||||
}
|
||||
|
@ -213,8 +213,8 @@ impl VisitMut for TemplateLiteral {
|
||||
let len = args.len();
|
||||
for arg in args {
|
||||
// for `${asd}a`
|
||||
if let Expr::Lit(Lit::Str(str)) = obj.as_ref() {
|
||||
if str.value.len() == 0 && len == 2 {
|
||||
if let Expr::Lit(Lit::Str(s)) = obj.as_ref() {
|
||||
if s.value.len() == 0 && len == 2 {
|
||||
obj = arg;
|
||||
continue;
|
||||
}
|
||||
|
@ -463,7 +463,7 @@ impl ClassProperties {
|
||||
},
|
||||
}))),
|
||||
PropName::Num(num) => Box::new(Expr::from(num)),
|
||||
PropName::Str(str) => Box::new(Expr::from(str)),
|
||||
PropName::Str(s) => Box::new(Expr::from(s)),
|
||||
PropName::BigInt(big_int) => Box::new(Expr::from(big_int)),
|
||||
|
||||
PropName::Computed(mut key) => {
|
||||
@ -551,7 +551,7 @@ impl ClassProperties {
|
||||
let ident = Ident::new(
|
||||
format!("_{}", prop.key.id.sym).into(),
|
||||
// We use `self.mark` for private variables.
|
||||
prop.key.span.apply_mark(self.private.curr_mark()),
|
||||
prop.key.span.apply_mark(self.private.cur_mark()),
|
||||
);
|
||||
|
||||
if let Some(value) = &mut prop.value {
|
||||
@ -653,7 +653,7 @@ impl ClassProperties {
|
||||
method
|
||||
.span
|
||||
.with_ctxt(SyntaxContext::empty())
|
||||
.apply_mark(self.private.curr_mark()),
|
||||
.apply_mark(self.private.cur_mark()),
|
||||
);
|
||||
|
||||
let should_use_map =
|
||||
@ -664,7 +664,7 @@ impl ClassProperties {
|
||||
let weak_coll_var = Ident::new(
|
||||
format!("_{}", method.key.id.sym).into(),
|
||||
// We use `self.mark` for private variables.
|
||||
method.key.span.apply_mark(self.private.curr_mark()),
|
||||
method.key.span.apply_mark(self.private.cur_mark()),
|
||||
);
|
||||
method.function.visit_with(&mut UsedNameCollector {
|
||||
used_names: &mut used_names,
|
||||
|
@ -30,7 +30,7 @@ impl PrivateRecord {
|
||||
&self.0.last().unwrap().class_name
|
||||
}
|
||||
|
||||
pub fn curr_mark(&self) -> Mark {
|
||||
pub fn cur_mark(&self) -> Mark {
|
||||
self.0.last().unwrap().mark
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
//! New-generation javascript to old-javascript compiler.
|
||||
#![deny(clippy::all)]
|
||||
#![allow(clippy::vec_box)]
|
||||
|
||||
pub use self::{
|
||||
|
@ -452,8 +452,8 @@ where
|
||||
})
|
||||
}
|
||||
PropName::Ident(id) => MemberProp::Ident(id),
|
||||
PropName::Str(str) => MemberProp::Computed(ComputedPropName {
|
||||
expr: Box::new(Expr::Lit(Lit::Str(str))),
|
||||
PropName::Str(s) => MemberProp::Computed(ComputedPropName {
|
||||
expr: Box::new(Expr::Lit(Lit::Str(s))),
|
||||
span: DUMMY_SP,
|
||||
}),
|
||||
PropName::Num(num) => MemberProp::Computed(ComputedPropName {
|
||||
@ -510,8 +510,8 @@ where
|
||||
})
|
||||
}
|
||||
PropName::Ident(id) => MemberProp::Ident(id),
|
||||
PropName::Str(str) => MemberProp::Computed(ComputedPropName {
|
||||
expr: Box::new(Expr::Lit(Lit::Str(str))),
|
||||
PropName::Str(s) => MemberProp::Computed(ComputedPropName {
|
||||
expr: Box::new(Expr::Lit(Lit::Str(s))),
|
||||
span: DUMMY_SP,
|
||||
}),
|
||||
PropName::Num(num) => MemberProp::Computed(ComputedPropName {
|
||||
|
@ -655,7 +655,7 @@ impl Swcify for swc_estree_ast::ModuleExportNameType {
|
||||
swc_estree_ast::ModuleExportNameType::Ident(ident) => {
|
||||
swc_ecma_ast::ModuleExportName::Ident(ident.swcify(ctx).id)
|
||||
}
|
||||
swc_estree_ast::ModuleExportNameType::Str(str) => str.swcify(ctx).into(),
|
||||
swc_estree_ast::ModuleExportNameType::Str(s) => s.swcify(ctx).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user