mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
chore: fix clippy warnings (#2519)
This commit is contained in:
parent
570ca68b1e
commit
46e779194a
22 changed files with 38 additions and 65 deletions
|
|
@ -79,10 +79,7 @@ fn diagnostic_assign_expr<'a>(expr: &'a AssignmentExpression<'a>, ctx: &LintCont
|
|||
SimpleAssignmentTarget::MemberAssignmentTarget(member_expr),
|
||||
) = &expr.left
|
||||
{
|
||||
let (span, property_name) = match get_jasmine_property_name(member_expr) {
|
||||
Some(value) => value,
|
||||
None => return,
|
||||
};
|
||||
let Some((span, property_name)) = get_jasmine_property_name(member_expr) else { return };
|
||||
|
||||
if property_name == "DEFAULT_TIMEOUT_INTERVAL" {
|
||||
// `jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000` we can fix it to `jest.setTimeout(5000)`
|
||||
|
|
@ -104,10 +101,7 @@ fn diagnostic_assign_expr<'a>(expr: &'a AssignmentExpression<'a>, ctx: &LintCont
|
|||
|
||||
fn diagnostic_call_expr<'a>(expr: &'a CallExpression<'a>, ctx: &LintContext) {
|
||||
if let Expression::MemberExpression(member_expr) = &expr.callee {
|
||||
let (span, property_name) = match get_jasmine_property_name(member_expr) {
|
||||
Some(value) => value,
|
||||
None => return,
|
||||
};
|
||||
let Some((span, property_name)) = get_jasmine_property_name(member_expr) else { return };
|
||||
|
||||
JasmineProperty::from_str(property_name).map_or_else(
|
||||
|| {
|
||||
|
|
|
|||
|
|
@ -187,17 +187,15 @@ impl Rule for AutocompleteValid {
|
|||
return;
|
||||
}
|
||||
|
||||
let autocomplete_prop = match has_jsx_prop_lowercase(jsx_el, "autocomplete") {
|
||||
Some(autocomplete_prop) => autocomplete_prop,
|
||||
None => return,
|
||||
let Some(autocomplete_prop) = has_jsx_prop_lowercase(jsx_el, "autocomplete") else {
|
||||
return;
|
||||
};
|
||||
let attr = match autocomplete_prop {
|
||||
JSXAttributeItem::Attribute(attr) => attr,
|
||||
JSXAttributeItem::SpreadAttribute(_) => return,
|
||||
};
|
||||
let autocomplete_values = match &attr.value {
|
||||
Some(JSXAttributeValue::StringLiteral(autocomplete_values)) => autocomplete_values,
|
||||
_ => return,
|
||||
let Some(JSXAttributeValue::StringLiteral(autocomplete_values)) = &attr.value else {
|
||||
return;
|
||||
};
|
||||
let value = autocomplete_values.value.to_string();
|
||||
if !is_valid_autocomplete_value(&value) {
|
||||
|
|
|
|||
|
|
@ -77,9 +77,7 @@ impl Rule for IframeHasTitle {
|
|||
return;
|
||||
}
|
||||
|
||||
let alt_prop = if let Some(prop) = has_jsx_prop_lowercase(jsx_el, "title") {
|
||||
prop
|
||||
} else {
|
||||
let Some(alt_prop) = has_jsx_prop_lowercase(jsx_el, "title") else {
|
||||
ctx.diagnostic(IframeHasTitleDiagnostic(iden.span));
|
||||
return;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -121,18 +121,12 @@ impl Rule for ImgRedundantAlt {
|
|||
return;
|
||||
}
|
||||
|
||||
let alt_prop = match has_jsx_prop_lowercase(jsx_el, "alt") {
|
||||
Some(v) => v,
|
||||
None => {
|
||||
return;
|
||||
}
|
||||
let Some(alt_prop) = has_jsx_prop_lowercase(jsx_el, "alt") else {
|
||||
return;
|
||||
};
|
||||
|
||||
let alt_attribute = match get_prop_value(alt_prop) {
|
||||
Some(v) => v,
|
||||
None => {
|
||||
return;
|
||||
}
|
||||
let Some(alt_attribute) = get_prop_value(alt_prop) else {
|
||||
return;
|
||||
};
|
||||
|
||||
let alt_attribute_name = match alt_prop {
|
||||
|
|
|
|||
|
|
@ -66,10 +66,7 @@ impl Rule for NoCssTags {
|
|||
}
|
||||
}
|
||||
|
||||
let (rel_attr, href_attr) = match (rel_attr, href_attr) {
|
||||
(Some(rel_attr), Some(href_attr)) => (rel_attr, href_attr),
|
||||
_ => return,
|
||||
};
|
||||
let (Some(rel_attr), Some(href_attr)) = (rel_attr, href_attr) else { return };
|
||||
|
||||
let Some(rel_prop_value) = get_string_literal_prop_value(rel_attr) else { return };
|
||||
let Some(href_prop_value) = get_string_literal_prop_value(href_attr) else { return };
|
||||
|
|
@ -88,7 +85,7 @@ fn test() {
|
|||
|
||||
let pass = vec![
|
||||
r"import {Head} from 'next/document';
|
||||
|
||||
|
||||
export class Blah extends Head {
|
||||
render() {
|
||||
return (
|
||||
|
|
@ -136,7 +133,7 @@ fn test() {
|
|||
let fail = vec![
|
||||
r#"
|
||||
import {Head} from 'next/document';
|
||||
|
||||
|
||||
export class Blah extends Head {
|
||||
render() {
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -84,14 +84,11 @@ impl Rule for ErrorMessage {
|
|||
|
||||
let message_argument = args.get(message_argument_idx);
|
||||
|
||||
let arg = match message_argument {
|
||||
Some(v) => v,
|
||||
None => {
|
||||
return ctx.diagnostic(ErrorMessageDiagnostic::MissingMessage(
|
||||
constructor_name.to_compact_string(),
|
||||
span,
|
||||
))
|
||||
}
|
||||
let Some(arg) = message_argument else {
|
||||
return ctx.diagnostic(ErrorMessageDiagnostic::MissingMessage(
|
||||
constructor_name.to_compact_string(),
|
||||
span,
|
||||
));
|
||||
};
|
||||
|
||||
let arg = match arg {
|
||||
|
|
|
|||
|
|
@ -51,10 +51,7 @@ declare_oxc_lint!(
|
|||
|
||||
impl Rule for NoConsoleSpaces {
|
||||
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
|
||||
let call_expr = match node.kind() {
|
||||
AstKind::CallExpression(call_expr) => call_expr,
|
||||
_ => return,
|
||||
};
|
||||
let AstKind::CallExpression(call_expr) = node.kind() else { return };
|
||||
|
||||
if !is_method_call(
|
||||
call_expr,
|
||||
|
|
|
|||
|
|
@ -295,9 +295,7 @@ impl<'a> Lexer<'a> {
|
|||
let offset = self.offset();
|
||||
self.token.start = offset;
|
||||
|
||||
let byte = if let Some(byte) = self.source.peek_byte() {
|
||||
byte
|
||||
} else {
|
||||
let Some(byte) = self.source.peek_byte() else {
|
||||
return Kind::Eof;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -60,9 +60,7 @@ impl<'a> Lexer<'a> {
|
|||
|
||||
while let Some(ch @ ('$' | '_' | 'a'..='z' | 'A'..='Z' | '0'..='9')) = self.peek() {
|
||||
self.consume_char();
|
||||
let flag = if let Ok(flag) = RegExpFlags::try_from(ch) {
|
||||
flag
|
||||
} else {
|
||||
let Ok(flag) = RegExpFlags::try_from(ch) else {
|
||||
self.error(diagnostics::RegExpFlag(ch, self.current_offset()));
|
||||
continue;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ impl<'a> Lexer<'a> {
|
|||
if !has_escape {
|
||||
return;
|
||||
}
|
||||
self.escaped_templates.insert(self.token.start, is_valid_escape_sequence.then(|| s));
|
||||
self.escaped_templates.insert(self.token.start, is_valid_escape_sequence.then_some(s));
|
||||
self.token.escaped = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ workspace = true
|
|||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
miette = { workspace = true }
|
||||
compact_str = { version = "0.7.1" }
|
||||
miette = { workspace = true }
|
||||
compact_str = { version = "0.7.1" }
|
||||
|
||||
tsify = { workspace = true, optional = true }
|
||||
wasm-bindgen = { workspace = true, optional = true }
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ pub struct DuplicateKeys<'a> {
|
|||
|
||||
impl<'a> DuplicateKeys<'a> {
|
||||
pub fn new(ast: Rc<AstBuilder<'a>>, options: &TransformOptions) -> Option<Self> {
|
||||
(options.target < TransformTarget::ES2015 || options.duplicate_keys).then(|| Self { ast })
|
||||
(options.target < TransformTarget::ES2015 || options.duplicate_keys).then_some(Self { ast })
|
||||
}
|
||||
|
||||
pub fn transform_object_expression<'b>(&mut self, obj_expr: &'b mut ObjectExpression<'a>) {
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ impl<'a> FunctionName<'a> {
|
|||
ctx: TransformerCtx<'a>,
|
||||
options: &TransformOptions,
|
||||
) -> Option<Self> {
|
||||
(options.target < TransformTarget::ES2015 || options.function_name).then(|| Self {
|
||||
(options.target < TransformTarget::ES2015 || options.function_name).then_some(Self {
|
||||
_ast: ast,
|
||||
ctx,
|
||||
// TODO hook up the plugin
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@ impl<'a> Instanceof<'a> {
|
|||
ctx: TransformerCtx<'a>,
|
||||
options: &TransformOptions,
|
||||
) -> Option<Self> {
|
||||
(options.target < TransformTarget::ES2015 || options.instanceof).then(|| Self { ast, ctx })
|
||||
(options.target < TransformTarget::ES2015 || options.instanceof)
|
||||
.then_some(Self { ast, ctx })
|
||||
}
|
||||
|
||||
pub fn transform_expression(&mut self, expr: &mut Expression<'a>) {
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ impl<'a> NewTarget<'a> {
|
|||
options: &TransformOptions,
|
||||
) -> Option<Self> {
|
||||
let kinds = ast.new_vec();
|
||||
(options.target < TransformTarget::ES2015 || options.new_target).then(|| Self {
|
||||
(options.target < TransformTarget::ES2015 || options.new_target).then_some(Self {
|
||||
ast,
|
||||
ctx,
|
||||
kinds,
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ pub struct ShorthandProperties<'a> {
|
|||
impl<'a> ShorthandProperties<'a> {
|
||||
pub fn new(ast: Rc<AstBuilder<'a>>, options: &TransformOptions) -> Option<Self> {
|
||||
(options.target < TransformTarget::ES2015 || options.shorthand_properties)
|
||||
.then(|| Self { ast })
|
||||
.then_some(Self { ast })
|
||||
}
|
||||
|
||||
pub fn transform_object_property<'b>(&mut self, obj_prop: &'b mut ObjectProperty<'a>) {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ pub struct TemplateLiterals<'a> {
|
|||
impl<'a> TemplateLiterals<'a> {
|
||||
pub fn new(ast: Rc<AstBuilder<'a>>, options: &TransformOptions) -> Option<Self> {
|
||||
(options.target < TransformTarget::ES2015 || options.template_literals)
|
||||
.then(|| Self { ast })
|
||||
.then_some(Self { ast })
|
||||
}
|
||||
|
||||
pub fn transform_expression<'b>(&mut self, expr: &'b mut Expression<'a>) {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ pub struct JsonStrings<'a> {
|
|||
|
||||
impl<'a> JsonStrings<'a> {
|
||||
pub fn new(ast: Rc<AstBuilder<'a>>, options: &TransformOptions) -> Option<Self> {
|
||||
(options.target < TransformTarget::ES2019 || options.json_strings).then(|| Self { ast })
|
||||
(options.target < TransformTarget::ES2019 || options.json_strings).then_some(Self { ast })
|
||||
}
|
||||
|
||||
// Allow `U+2028` and `U+2029` in string literals
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ pub struct OptionalCatchBinding<'a> {
|
|||
impl<'a> OptionalCatchBinding<'a> {
|
||||
pub fn new(ast: Rc<AstBuilder<'a>>, options: &TransformOptions) -> Option<Self> {
|
||||
(options.target < TransformTarget::ES2019 || options.optional_catch_binding)
|
||||
.then(|| Self { ast })
|
||||
.then_some(Self { ast })
|
||||
}
|
||||
|
||||
pub fn transform_catch_clause<'b>(&mut self, clause: &'b mut CatchClause<'a>) {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ pub struct ClassStaticBlock<'a> {
|
|||
impl<'a> ClassStaticBlock<'a> {
|
||||
pub fn new(ast: Rc<AstBuilder<'a>>, options: &TransformOptions) -> Option<Self> {
|
||||
(options.target < TransformTarget::ES2022 || options.class_static_block)
|
||||
.then(|| Self { ast })
|
||||
.then_some(Self { ast })
|
||||
}
|
||||
|
||||
pub fn transform_class_body<'b>(&mut self, class_body: &'b mut ClassBody<'a>) {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ pub struct PropertyLiteral<'a> {
|
|||
|
||||
impl<'a> PropertyLiteral<'a> {
|
||||
pub fn new(ast: Rc<AstBuilder<'a>>, options: &TransformOptions) -> Option<Self> {
|
||||
(options.target <= TransformTarget::ES3 || options.property_literals).then(|| Self { ast })
|
||||
(options.target <= TransformTarget::ES3 || options.property_literals)
|
||||
.then_some(Self { ast })
|
||||
}
|
||||
|
||||
pub fn transform_object_property<'b>(&mut self, expr: &'b mut ObjectProperty<'a>) {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ pub struct RegexpFlags<'a> {
|
|||
impl<'a> RegexpFlags<'a> {
|
||||
pub fn new(ast: Rc<AstBuilder<'a>>, options: &TransformOptions) -> Option<Self> {
|
||||
let transform_flags = Self::from_transform_target(options);
|
||||
(!transform_flags.is_empty()).then(|| Self { ast, transform_flags })
|
||||
(!transform_flags.is_empty()).then_some(Self { ast, transform_flags })
|
||||
}
|
||||
|
||||
fn from_transform_target(options: &TransformOptions) -> RegExpFlags {
|
||||
|
|
|
|||
Loading…
Reference in a new issue