Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into p/module-import
Browse files Browse the repository at this point in the history
  • Loading branch information
leaysgur committed Jan 22, 2025
2 parents 61faff7 + 5b3c412 commit e0e621b
Show file tree
Hide file tree
Showing 68 changed files with 1,466 additions and 1,063 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/oxlint/src/command/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ pub struct WarningOptions {
/// Output
#[derive(Debug, Clone, Bpaf)]
pub struct OutputOptions {
/// Use a specific output format (default, json, unix, checkstyle, github)
/// Use a specific output format (default, json, unix, checkstyle, github, stylish)
#[bpaf(long, short, fallback(OutputFormat::Default), hide_usage)]
pub format: OutputFormat,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_isolated_declarations/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ impl<'a> IsolatedDeclarations<'a> {
for element in &decl.body.body {
match element {
ClassElement::StaticBlock(_) => {}
ClassElement::MethodDefinition(ref method) => {
ClassElement::MethodDefinition(method) => {
if self.has_internal_annotation(method.span) {
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_isolated_declarations/src/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ impl<'a> IsolatedDeclarations<'a> {

if let Some(value) = &value {
let member_name = match &member.id {
TSEnumMemberName::Identifier(id) => &id.name,
TSEnumMemberName::String(str) => &str.value,
TSEnumMemberName::Identifier(id) => id.name,
TSEnumMemberName::String(str) => str.value,
};
prev_members.insert(*member_name, value.clone());
prev_members.insert(member_name, value.clone());
}

let member = self.ast.ts_enum_member(
Expand Down
28 changes: 13 additions & 15 deletions crates/oxc_isolated_declarations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl<'a> IsolatedDeclarations<'a> {
// 2. Transform export declarations
// 3. Collect all bindings / reference from module declarations
// 4. Collect transformed indexes
for stmt in &stmts {
for &stmt in &stmts {
match stmt {
match_declaration!(Statement) => {
if let Statement::TSModuleDeclaration(decl) = stmt {
Expand Down Expand Up @@ -433,9 +433,9 @@ impl<'a> IsolatedDeclarations<'a> {
let mut last_function_name: Option<Atom<'a>> = None;
let mut is_export_default_function_overloads = false;

stmts.retain(move |stmt| match stmt {
Statement::FunctionDeclaration(ref func) => {
let name = &func
stmts.retain(move |&stmt| match stmt {
Statement::FunctionDeclaration(func) => {
let name = func
.id
.as_ref()
.unwrap_or_else(|| {
Expand All @@ -446,17 +446,17 @@ impl<'a> IsolatedDeclarations<'a> {
.name;

if func.body.is_some() {
if last_function_name.as_ref().is_some_and(|last_name| last_name == name) {
if last_function_name.as_ref().is_some_and(|&last_name| last_name == name) {
return false;
}
} else {
last_function_name = Some(*name);
last_function_name = Some(name);
}
true
}
Statement::ExportNamedDeclaration(ref decl) => {
if let Some(Declaration::FunctionDeclaration(ref func)) = decl.declaration {
let name = &func
Statement::ExportNamedDeclaration(decl) => {
if let Some(Declaration::FunctionDeclaration(func)) = &decl.declaration {
let name = func
.id
.as_ref()
.unwrap_or_else(|| {
Expand All @@ -466,21 +466,19 @@ impl<'a> IsolatedDeclarations<'a> {
})
.name;
if func.body.is_some() {
if last_function_name.as_ref().is_some_and(|last_name| last_name == name) {
if last_function_name.as_ref().is_some_and(|&last_name| last_name == name) {
return false;
}
} else {
last_function_name = Some(*name);
last_function_name = Some(name);
}
true
} else {
true
}
}
Statement::ExportDefaultDeclaration(ref decl) => {
if let ExportDefaultDeclarationKind::FunctionDeclaration(ref func) =
decl.declaration
{
Statement::ExportDefaultDeclaration(decl) => {
if let ExportDefaultDeclarationKind::FunctionDeclaration(func) = &decl.declaration {
if is_export_default_function_overloads && func.body.is_some() {
is_export_default_function_overloads = false;
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl IsolatedLintHandler {
// a diagnostics connected from related_info to original diagnostic
let mut inverted_diagnostics = vec![];
for d in &diagnostics {
let Some(ref related_info) = d.diagnostic.related_information else {
let Some(related_info) = &d.diagnostic.related_information else {
continue;
};
let related_information = Some(vec![DiagnosticRelatedInformation {
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/fixer/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ impl<'a> CompositeFix<'a> {
let mut output = String::new();

for fix in fixes {
let Fix { ref content, span } = fix;
let Fix { content, span } = fix;
// negative range or overlapping ranges is invalid
if span.start > span.end {
debug_assert!(false, "Negative range is invalid: {span:?}");
Expand All @@ -513,7 +513,7 @@ impl<'a> CompositeFix<'a> {

output.reserve(before.len() + content.len());
output.push_str(before);
output.push_str(content);
output.push_str(&content);
last_pos = span.end;
}

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/getter_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ impl GetterReturn {
// If the signature of function supports the return of the `undefined` value,
// you do not need to check this rule
if let AstKind::Function(func) = node.kind() {
if let Some(ref ret) = func.return_type {
if let Some(ret) = &func.return_type {
if ret.type_annotation.is_maybe_undefined() {
break 'returns true;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/new_cap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ fn get_computed_member_name(computed_member: &ComputedMemberExpression) -> Optio
Expression::TemplateLiteral(lit) if lit.expressions.is_empty() && lit.quasis.len() == 1 => {
Some(lit.quasis[0].value.raw.as_ref().into())
}
Expression::RegExpLiteral(lit) => lit.raw.as_ref().map(|x| (*x).into_compact_str()),
Expression::RegExpLiteral(lit) => lit.raw.as_ref().map(|&x| x.into_compact_str()),
_ => None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/no_regex_spaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl<'a> Visit<'a> for ConsecutiveSpaceFinder {
if ch.value != u32::from(b' ') {
return;
}
if let Some(ref mut space_span) = self.last_space_span {
if let Some(space_span) = &mut self.last_space_span {
// If this is consecutive with the last space, extend it
if space_span.end == ch.span.start {
space_span.end = ch.span.end;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ where
IgnorePattern::Default => {
name.strip_prefix('_').map_or(".".into(), |name| format!(" to '{name}'."))
}
IgnorePattern::Some(ref r) => {
IgnorePattern::Some(r) => {
format!(" to match the pattern /{r}/.")
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl<R> IgnorePattern<R> {
match self {
Self::Default => IgnorePattern::Default,
Self::None => IgnorePattern::None,
Self::Some(ref r) => IgnorePattern::Some(r),
Self::Some(r) => IgnorePattern::Some(r),
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions crates/oxc_linter/src/rules/eslint/no_useless_rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,12 @@ impl Rule for NoUselessRename {
BindingPatternKind::AssignmentPattern(assignment_pattern) => {
match &assignment_pattern.left.kind {
BindingPatternKind::BindingIdentifier(binding_ident) => {
&binding_ident.name
binding_ident.name
}
_ => continue,
}
}

BindingPatternKind::BindingIdentifier(binding_ident) => &binding_ident.name,
BindingPatternKind::BindingIdentifier(binding_ident) => binding_ident.name,
_ => continue,
};

Expand All @@ -134,7 +133,7 @@ impl Rule for NoUselessRename {
let Some(key) = property.name.static_name() else {
continue;
};
let Some(renamed_key) = property.binding.identifier().map(|ident| &ident.name)
let Some(renamed_key) = property.binding.identifier().map(|ident| ident.name)
else {
continue;
};
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/sort_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl SortImports {
let specifiers: Vec<_> = specifiers
.iter()
.filter_map(|specifier| {
if let ImportDeclarationSpecifier::ImportSpecifier(ref specifier) = specifier {
if let ImportDeclarationSpecifier::ImportSpecifier(specifier) = specifier {
Some(specifier)
} else {
None
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/rules/import/first.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ impl Rule for First {

for statement in &program.body {
match statement {
Statement::TSImportEqualsDeclaration(decl) => match decl.module_reference {
TSModuleReference::ExternalModuleReference(ref mod_ref) => {
Statement::TSImportEqualsDeclaration(decl) => match &decl.module_reference {
TSModuleReference::ExternalModuleReference(mod_ref) => {
if matches!(self.absolute_first, AbsoluteFirst::AbsoluteFirst) {
if is_relative_path(mod_ref.expression.value.as_str()) {
any_relative = true;
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/import/no_amd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Rule for NoAmd {
return;
}
if let AstKind::CallExpression(call_expr) = node.kind() {
if let Expression::Identifier(ref identifier) = &call_expr.callee {
if let Expression::Identifier(identifier) = &call_expr.callee {
if identifier.name != "define" && identifier.name != "require" {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fn run<'a>(possible_jest_node: &PossibleJestNode<'a, '_>, ctx: &LintContext<'a>)
diagnostic(ctx, fn_expr.span, Message::UnexpectedDescribeArgument);
}

let Some(ref body) = fn_expr.body else {
let Some(body) = &fn_expr.body else {
return;
};
if let Some(span) = find_first_return_stmt_span(body) {
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/jsdoc/require_returns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl Rule for RequireReturns {
match parent_node.kind() {
AstKind::Function(_) | AstKind::ArrowFunctionExpression(_) => {
// Ignore `return;`
let Some(ref argument) = return_stmt.argument else {
let Some(argument) = &return_stmt.argument else {
continue 'visit_node;
};

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/nextjs/no_typos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl Rule for NoTypos {
if let AstKind::ModuleDeclaration(ModuleDeclaration::ExportNamedDeclaration(en_decl)) =
node.kind()
{
if let Some(ref decl) = en_decl.declaration {
if let Some(decl) = &en_decl.declaration {
match decl {
Declaration::VariableDeclaration(decl) => {
for decl in &decl.declarations {
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/oxc/no_accumulating_spread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl Rule for NoAccumulatingSpread {
let AstKind::SpreadElement(spread) = node.kind() else {
return;
};
let Expression::Identifier(ref ident) = spread.argument else {
let Expression::Identifier(ident) = &spread.argument else {
return;
};

Expand Down
11 changes: 5 additions & 6 deletions crates/oxc_linter/src/rules/react/exhaustive_deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ impl Rule for ExhaustiveDeps {
return false;
}

if !is_identifier_a_dependency(&dep.name, dep.reference_id, ctx, component_scope_id) {
if !is_identifier_a_dependency(dep.name, dep.reference_id, ctx, component_scope_id) {
return false;
};
true
Expand Down Expand Up @@ -764,7 +764,7 @@ fn concat_members<'a, 'b>(
}

fn is_identifier_a_dependency<'a>(
ident_name: &Atom<'a>,
ident_name: Atom<'a>,
ident_reference_id: ReferenceId,
ctx: &'_ LintContext<'a>,
component_scope_id: ScopeId,
Expand Down Expand Up @@ -824,7 +824,7 @@ fn is_identifier_a_dependency<'a>(
// https://github.com/facebook/react/blob/fee786a057774ab687aff765345dd86fce534ab2/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js#L164
fn is_stable_value<'a, 'b>(
node: &'b AstNode<'a>,
ident_name: &Atom<'a>,
ident_name: Atom<'a>,
ident_reference_id: ReferenceId,
ctx: &'b LintContext<'a>,
component_scope_id: ScopeId,
Expand Down Expand Up @@ -943,9 +943,8 @@ fn is_function_stable<'a, 'b>(
collector.found_dependencies
};

deps.iter().all(|dep| {
!is_identifier_a_dependency(&dep.name, dep.reference_id, ctx, component_scope_id)
})
deps.iter()
.all(|dep| !is_identifier_a_dependency(dep.name, dep.reference_id, ctx, component_scope_id))
}

// https://github.com/facebook/react/blob/fee786a057774ab687aff765345dd86fce534ab2/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js#L1742
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/react/jsx_no_undef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn get_resolvable_ident<'a>(node: &'a JSXElementName<'a>) -> Option<&'a Identifi
JSXElementName::Identifier(_)
| JSXElementName::NamespacedName(_)
| JSXElementName::ThisExpression(_) => None,
JSXElementName::IdentifierReference(ref ident) => Some(ident),
JSXElementName::IdentifierReference(ident) => Some(ident),
JSXElementName::MemberExpression(expr) => get_member_ident(expr),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ impl Rule for JsxPropsNoSpreadMulti {
let spread_attrs =
jsx_opening_el.attributes.iter().filter_map(JSXAttributeItem::as_spread);

let mut identifier_names: FxHashMap<&Atom, Span> = FxHashMap::default();
let mut identifier_names: FxHashMap<Atom, Span> = FxHashMap::default();
let mut member_expressions = Vec::new();
let mut duplicate_spreads: FxHashMap<&Atom, Vec<Span>> = FxHashMap::default();
let mut duplicate_spreads: FxHashMap<Atom, Vec<Span>> = FxHashMap::default();

for spread_attr in spread_attrs {
let argument_without_parenthesized = spread_attr.argument.without_parentheses();

if let Some(identifier_name) =
argument_without_parenthesized.get_identifier_reference().map(|arg| &arg.name)
argument_without_parenthesized.get_identifier_reference().map(|arg| arg.name)
{
identifier_names
.entry(identifier_name)
Expand All @@ -97,7 +97,7 @@ impl Rule for JsxPropsNoSpreadMulti {
ctx.diagnostic_with_fix(
jsx_props_no_spread_multiple_identifiers_diagnostic(
spans.clone(),
identifier_name,
&identifier_name,
),
|_fixer| {
spans
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/typescript/ban_ts_comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl Rule for BanTsComment {
));
}

if let DirectiveConfig::DescriptionFormat(Some(ref re)) = config {
if let DirectiveConfig::DescriptionFormat(Some(re)) = config {
if !re.is_match(description) {
ctx.diagnostic(comment_description_not_match_pattern(
directive,
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/rules/typescript/no_require_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ impl Rule for NoRequireImports {

ctx.diagnostic(no_require_imports_diagnostic(call_expr.span));
}
AstKind::TSImportEqualsDeclaration(decl) => match decl.module_reference {
TSModuleReference::ExternalModuleReference(ref mod_ref) => {
AstKind::TSImportEqualsDeclaration(decl) => match &decl.module_reference {
TSModuleReference::ExternalModuleReference(mod_ref) => {
if self.allow_as_import {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ impl Rule for TripleSlashReference {
if !refs_for_import.is_empty() {
for stmt in &program.body {
match stmt {
Statement::TSImportEqualsDeclaration(decl) => match decl.module_reference {
TSModuleReference::ExternalModuleReference(ref mod_ref) => {
Statement::TSImportEqualsDeclaration(decl) => match &decl.module_reference {
TSModuleReference::ExternalModuleReference(mod_ref) => {
if let Some(v) = refs_for_import.get(mod_ref.expression.value.as_str())
{
ctx.diagnostic(triple_slash_reference_diagnostic(
Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_linter/src/rules/unicorn/no_thenable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Rule for NoThenable {
}
AstKind::ModuleDeclaration(ModuleDeclaration::ExportNamedDeclaration(decl)) => {
// check declaration
if let Some(ref decl) = decl.declaration {
if let Some(decl) = &decl.declaration {
match decl {
Declaration::VariableDeclaration(decl) => {
for decl in &decl.declarations {
Expand Down Expand Up @@ -242,8 +242,8 @@ fn check_expression(expr: &Expression, ctx: &LintContext<'_>) -> Option<oxc_span
let decl = ctx.semantic().nodes().get_node(symbols.get_declaration(symbol_id));
let var_decl = decl.kind().as_variable_declarator()?;

match var_decl.init {
Some(Expression::StringLiteral(ref lit)) => {
match &var_decl.init {
Some(Expression::StringLiteral(lit)) => {
if lit.value == "then" {
Some(lit.span)
} else {
Expand Down
Loading

0 comments on commit e0e621b

Please sign in to comment.