mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
chore: upgrade rustc toolchain to stable 1.75.0 (#1853)
ref: https://blog.rust-lang.org/2023/12/28/Rust-1.75.0.html
This commit is contained in:
parent
a743d06207
commit
4bbc977971
34 changed files with 50 additions and 46 deletions
|
|
@ -134,9 +134,9 @@ impl GraphicalReportHandler {
|
||||||
/// Render a [`Diagnostic`]. This function is mostly internal and meant to
|
/// Render a [`Diagnostic`]. This function is mostly internal and meant to
|
||||||
/// be called by the toplevel [`ReportHandler`] handler, but is made public
|
/// be called by the toplevel [`ReportHandler`] handler, but is made public
|
||||||
/// to make it easier (possible) to test in isolation from global state.
|
/// to make it easier (possible) to test in isolation from global state.
|
||||||
pub fn render_report(
|
pub fn render_report<T: fmt::Write>(
|
||||||
&self,
|
&self,
|
||||||
f: &mut impl fmt::Write,
|
f: &mut T,
|
||||||
diagnostic: &(dyn Diagnostic),
|
diagnostic: &(dyn Diagnostic),
|
||||||
) -> fmt::Result {
|
) -> fmt::Result {
|
||||||
self.render_header(f, diagnostic)?;
|
self.render_header(f, diagnostic)?;
|
||||||
|
|
|
||||||
|
|
@ -244,7 +244,7 @@ fn resolve_rule_value(value: &serde_json::Value) -> Result<(AllowWarnDeny, Optio
|
||||||
config.push(item.clone());
|
config.push(item.clone());
|
||||||
}
|
}
|
||||||
let config = if config.is_empty() { None } else { Some(Value::Array(config)) };
|
let config = if config.is_empty() { None } else { Some(Value::Array(config)) };
|
||||||
if let Some(v_idx_0) = v.get(0) {
|
if let Some(v_idx_0) = v.first() {
|
||||||
return Ok((AllowWarnDeny::try_from(v_idx_0)?, config));
|
return Ok((AllowWarnDeny::try_from(v_idx_0)?, config));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ impl Rule for BadArrayMethodOnArguments {
|
||||||
// only check template string like "arguments[`METHOD_NAME`]" for Deepscan compatible
|
// only check template string like "arguments[`METHOD_NAME`]" for Deepscan compatible
|
||||||
if template.expressions.is_empty() && template.quasis.len() == 1 {
|
if template.expressions.is_empty() && template.quasis.len() == 1 {
|
||||||
if let Some(name) =
|
if let Some(name) =
|
||||||
template.quasis.get(0).and_then(|template_element| {
|
template.quasis.first().and_then(|template_element| {
|
||||||
template_element.value.cooked.as_deref()
|
template_element.value.cooked.as_deref()
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ impl Rule for UninvokedArrayCallback {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if !matches!(
|
if !matches!(
|
||||||
new_expr.arguments.get(0),
|
new_expr.arguments.first(),
|
||||||
Some(Argument::Expression(Expression::NumberLiteral(_)))
|
Some(Argument::Expression(Expression::NumberLiteral(_)))
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -69,7 +69,7 @@ impl Rule for UninvokedArrayCallback {
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
if !matches!(call_expr.arguments.get(0), Some(Argument::Expression(arg_expr)) if arg_expr.is_function())
|
if !matches!(call_expr.arguments.first(), Some(Argument::Expression(arg_expr)) if arg_expr.is_function())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ impl NoRegexSpaces {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(Argument::Expression(Expression::StringLiteral(pattern))) = args.get(0) {
|
if let Some(Argument::Expression(Expression::StringLiteral(pattern))) = args.first() {
|
||||||
if Self::has_exempted_char_class(&pattern.value) {
|
if Self::has_exempted_char_class(&pattern.value) {
|
||||||
return None; // skip spaces inside char class, e.g. RegExp('[ ]')
|
return None; // skip spaces inside char class, e.g. RegExp('[ ]')
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -176,7 +176,7 @@ fn find_argument_of_callback<'a>(
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches!(kind, JestFnKind::General(JestGeneralFnKind::Hook)) {
|
if matches!(kind, JestFnKind::General(JestGeneralFnKind::Hook)) {
|
||||||
return call_expr.arguments.get(0);
|
return call_expr.arguments.first();
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches!(kind, JestFnKind::General(JestGeneralFnKind::Test)) {
|
if matches!(kind, JestFnKind::General(JestGeneralFnKind::Test)) {
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ fn filter_and_process_jest_result<'a>(
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
|
|
||||||
match call_expr.arguments.get(0) {
|
match call_expr.arguments.first() {
|
||||||
Some(Argument::Expression(Expression::StringLiteral(string_lit))) => {
|
Some(Argument::Expression(Expression::StringLiteral(string_lit))) => {
|
||||||
Some((string_lit.span, &string_lit.value, kind, parent_id))
|
Some((string_lit.span, &string_lit.value, kind, parent_id))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ impl Rule for NoMocksImport {
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(Argument::Expression(Expression::StringLiteral(string_literal))) =
|
let Some(Argument::Expression(Expression::StringLiteral(string_literal))) =
|
||||||
call_expr.arguments.get(0)
|
call_expr.arguments.first()
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ impl ValidTitle {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let Some(Argument::Expression(expr)) = call_expr.arguments.get(0) else {
|
let Some(Argument::Expression(expr)) = call_expr.arguments.first() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -263,7 +263,7 @@ fn compile_matcher_pattern(pattern: MatcherPattern) -> Option<CompiledMatcherAnd
|
||||||
Some((reg, None))
|
Some((reg, None))
|
||||||
}
|
}
|
||||||
MatcherPattern::Vec(pattern) => {
|
MatcherPattern::Vec(pattern) => {
|
||||||
let reg_str = pattern.get(0).and_then(|v| v.as_str()).map(|v| format!("(?u){v}"))?;
|
let reg_str = pattern.first().and_then(|v| v.as_str()).map(|v| format!("(?u){v}"))?;
|
||||||
let reg = Regex::new(®_str).ok()?;
|
let reg = Regex::new(®_str).ok()?;
|
||||||
let message = pattern.get(1).map(std::string::ToString::to_string);
|
let message = pattern.get(1).map(std::string::ToString::to_string);
|
||||||
Some((reg, message))
|
Some((reg, message))
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ impl Rule for NoAccumulatingSpread {
|
||||||
// We're only looking for the first parameter, since that's where acc is.
|
// We're only looking for the first parameter, since that's where acc is.
|
||||||
// Skip non-parameter or non-first-parameter declarations.
|
// Skip non-parameter or non-first-parameter declarations.
|
||||||
let first_param_symbol_id =
|
let first_param_symbol_id =
|
||||||
params.items.get(0).and_then(|item| get_identifier_symbol_id(&item.pattern.kind));
|
params.items.first().and_then(|item| get_identifier_symbol_id(&item.pattern.kind));
|
||||||
if !first_param_symbol_id.is_some_and(|id| id == referenced_symbol_id) {
|
if !first_param_symbol_id.is_some_and(|id| id == referenced_symbol_id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ impl Rule for ButtonHasType {
|
||||||
AstKind::CallExpression(call_expr) => {
|
AstKind::CallExpression(call_expr) => {
|
||||||
if is_create_element_call(call_expr) {
|
if is_create_element_call(call_expr) {
|
||||||
let Some(Argument::Expression(Expression::StringLiteral(str))) =
|
let Some(Argument::Expression(Expression::StringLiteral(str))) =
|
||||||
call_expr.arguments.get(0)
|
call_expr.arguments.first()
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
@ -144,7 +144,7 @@ impl Rule for ButtonHasType {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_configuration(value: serde_json::Value) -> Self {
|
fn from_configuration(value: serde_json::Value) -> Self {
|
||||||
let value = value.as_array().and_then(|arr| arr.get(0)).and_then(|val| val.as_object());
|
let value = value.as_array().and_then(|arr| arr.first()).and_then(|val| val.as_object());
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
button: value
|
button: value
|
||||||
|
|
|
||||||
|
|
@ -198,7 +198,7 @@ fn is_fragment_with_only_text_and_is_not_child<'a>(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(JSXChild::Text(_)) = node.get(0) {
|
if let Some(JSXChild::Text(_)) = node.first() {
|
||||||
let Some(parent) = ctx.nodes().parent_kind(id) else { return false };
|
let Some(parent) = ctx.nodes().parent_kind(id) else { return false };
|
||||||
return !matches!(parent, AstKind::JSXElement(_) | AstKind::JSXFragment(_));
|
return !matches!(parent, AstKind::JSXElement(_) | AstKind::JSXFragment(_));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@ impl Rule for CatchErrorName {
|
||||||
if let AstKind::CallExpression(call_expr) = node.kind() {
|
if let AstKind::CallExpression(call_expr) = node.kind() {
|
||||||
if let Expression::MemberExpression(member_expr) = &call_expr.callee {
|
if let Expression::MemberExpression(member_expr) = &call_expr.callee {
|
||||||
if member_expr.static_property_name() == Some("catch") {
|
if member_expr.static_property_name() == Some("catch") {
|
||||||
if let Some(arg0) = call_expr.arguments.get(0) {
|
if let Some(arg0) = call_expr.arguments.first() {
|
||||||
if let Some(diagnostic) = self.check_function_arguments(arg0, ctx) {
|
if let Some(diagnostic) = self.check_function_arguments(arg0, ctx) {
|
||||||
ctx.diagnostic(diagnostic);
|
ctx.diagnostic(diagnostic);
|
||||||
}
|
}
|
||||||
|
|
@ -149,7 +149,7 @@ impl CatchErrorName {
|
||||||
let expr = expr.without_parenthesized();
|
let expr = expr.without_parenthesized();
|
||||||
|
|
||||||
if let Expression::ArrowExpression(arrow_expr) = expr {
|
if let Expression::ArrowExpression(arrow_expr) = expr {
|
||||||
if let Some(arg0) = arrow_expr.params.items.get(0) {
|
if let Some(arg0) = arrow_expr.params.items.first() {
|
||||||
if let BindingPatternKind::BindingIdentifier(v) = &arg0.pattern.kind {
|
if let BindingPatternKind::BindingIdentifier(v) = &arg0.pattern.kind {
|
||||||
if self.is_name_allowed(&v.name) {
|
if self.is_name_allowed(&v.name) {
|
||||||
return None;
|
return None;
|
||||||
|
|
@ -177,7 +177,7 @@ impl CatchErrorName {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Expression::FunctionExpression(fn_expr) = expr {
|
if let Expression::FunctionExpression(fn_expr) = expr {
|
||||||
if let Some(arg0) = fn_expr.params.items.get(0) {
|
if let Some(arg0) = fn_expr.params.items.first() {
|
||||||
if let BindingPatternKind::BindingIdentifier(binding_ident) = &arg0.pattern.kind {
|
if let BindingPatternKind::BindingIdentifier(binding_ident) = &arg0.pattern.kind {
|
||||||
if self.is_name_allowed(&binding_ident.name) {
|
if self.is_name_allowed(&binding_ident.name) {
|
||||||
return None;
|
return None;
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ declare_oxc_lint!(
|
||||||
);
|
);
|
||||||
|
|
||||||
fn is_hex_char(c: char) -> bool {
|
fn is_hex_char(c: char) -> bool {
|
||||||
matches!(c, '0'..='9' | 'a'..='f' | 'A'..='F')
|
c.is_ascii_hexdigit()
|
||||||
}
|
}
|
||||||
fn is_hex(iter: &Chars, count: i32) -> bool {
|
fn is_hex(iter: &Chars, count: i32) -> bool {
|
||||||
let mut iter = iter.clone();
|
let mut iter = iter.clone();
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ use crate::{context::LintContext, rule::Rule};
|
||||||
struct FilenameCaseDiagnostic(#[label] pub Span, &'static str);
|
struct FilenameCaseDiagnostic(#[label] pub Span, &'static str);
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
#[allow(clippy::struct_field_names)]
|
||||||
pub struct FilenameCase {
|
pub struct FilenameCase {
|
||||||
kebab_case: bool,
|
kebab_case: bool,
|
||||||
camel_case: bool,
|
camel_case: bool,
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ impl Rule for NoArrayReduce {
|
||||||
};
|
};
|
||||||
|
|
||||||
if is_method_call(call_expr, None, Some(&["reduce", "reduceRight"]), Some(1), Some(2))
|
if is_method_call(call_expr, None, Some(&["reduce", "reduceRight"]), Some(1), Some(2))
|
||||||
&& !matches!(call_expr.arguments.get(0), Some(Argument::SpreadElement(_)))
|
&& !matches!(call_expr.arguments.first(), Some(Argument::SpreadElement(_)))
|
||||||
&& !call_expr.optional
|
&& !call_expr.optional
|
||||||
&& !member_expr.is_computed()
|
&& !member_expr.is_computed()
|
||||||
{
|
{
|
||||||
|
|
@ -99,7 +99,7 @@ impl Rule for NoArrayReduce {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_simple_operation(node: &CallExpression) -> bool {
|
fn is_simple_operation(node: &CallExpression) -> bool {
|
||||||
let Some(Argument::Expression(callback_arg)) = node.arguments.get(0) else {
|
let Some(Argument::Expression(callback_arg)) = node.arguments.first() else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
let function_body = match callback_arg {
|
let function_body = match callback_arg {
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ impl Rule for NoInvalidRemoveEventListener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches!(call_expr.arguments.get(0), Some(Argument::SpreadElement(_))) {
|
if matches!(call_expr.arguments.first(), Some(Argument::SpreadElement(_))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ fn check_array_flat_map_case<'a>(call_expr: &CallExpression<'a>, ctx: &LintConte
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let Argument::Expression(first_argument) = call_expr.arguments.get(0).unwrap() else {
|
let Argument::Expression(first_argument) = call_expr.arguments.first().unwrap() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -113,7 +113,7 @@ fn check_array_reduce_case<'a>(call_expr: &CallExpression<'a>, ctx: &LintContext
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let Argument::Expression(Expression::ArrowExpression(first_argument)) =
|
let Argument::Expression(Expression::ArrowExpression(first_argument)) =
|
||||||
call_expr.arguments.get(0).unwrap()
|
call_expr.arguments.first().unwrap()
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
@ -144,7 +144,7 @@ fn check_array_reduce_case<'a>(call_expr: &CallExpression<'a>, ctx: &LintContext
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(Statement::ExpressionStatement(expr_stmt)) = first_argument.body.statements.get(0)
|
let Some(Statement::ExpressionStatement(expr_stmt)) = first_argument.body.statements.first()
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ impl Rule for PreferDateNow {
|
||||||
if matches!(ident.name.as_str(), "Number" | "BigInt")
|
if matches!(ident.name.as_str(), "Number" | "BigInt")
|
||||||
&& call_expr.arguments.len() == 1
|
&& call_expr.arguments.len() == 1
|
||||||
{
|
{
|
||||||
if let Some(Argument::Expression(expr)) = call_expr.arguments.get(0) {
|
if let Some(Argument::Expression(expr)) = call_expr.arguments.first() {
|
||||||
if is_new_date(expr.without_parenthesized()) {
|
if is_new_date(expr.without_parenthesized()) {
|
||||||
ctx.diagnostic(
|
ctx.diagnostic(
|
||||||
PreferDateNowDiagnostic::PreferDateNowOverNumberDateObject(
|
PreferDateNowDiagnostic::PreferDateNowOverNumberDateObject(
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ impl Rule for PreferNativeCoercionFunctions {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_first_parameter_name<'a>(arg: &'a FormalParameters) -> Option<&'a str> {
|
fn get_first_parameter_name<'a>(arg: &'a FormalParameters) -> Option<&'a str> {
|
||||||
let first_func_param = arg.items.get(0)?;
|
let first_func_param = arg.items.first()?;
|
||||||
let BindingPatternKind::BindingIdentifier(first_func_param) = &first_func_param.pattern.kind
|
let BindingPatternKind::BindingIdentifier(first_func_param) = &first_func_param.pattern.kind
|
||||||
else {
|
else {
|
||||||
return None;
|
return None;
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ impl Rule for PreferQuerySelector {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let Argument::Expression(argument_expr) = call_expr.arguments.get(0).unwrap() else {
|
let Argument::Expression(argument_expr) = call_expr.arguments.first().unwrap() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -97,7 +97,7 @@ impl Rule for PreferQuerySelector {
|
||||||
Expression::StringLiteral(literal) => Some(literal.value.trim()),
|
Expression::StringLiteral(literal) => Some(literal.value.trim()),
|
||||||
Expression::TemplateLiteral(literal) => {
|
Expression::TemplateLiteral(literal) => {
|
||||||
if literal.expressions.len() == 0 {
|
if literal.expressions.len() == 0 {
|
||||||
literal.quasis.get(0).unwrap().value.cooked.as_deref().map(str::trim)
|
literal.quasis.first().unwrap().value.cooked.as_deref().map(str::trim)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ impl Rule for PreferSpread {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(first_arg) = call_expr.arguments.get(0) {
|
if let Some(first_arg) = call_expr.arguments.first() {
|
||||||
let Argument::Expression(first_arg) = first_arg else { return };
|
let Argument::Expression(first_arg) = first_arg else { return };
|
||||||
if let Expression::NumberLiteral(num_lit) = first_arg.without_parenthesized() {
|
if let Expression::NumberLiteral(num_lit) = first_arg.without_parenthesized() {
|
||||||
if num_lit.value != 0.0 {
|
if num_lit.value != 0.0 {
|
||||||
|
|
|
||||||
|
|
@ -196,7 +196,7 @@ pub fn parse_jsx_value(value: &JSXAttributeValue) -> Result<f64, ()> {
|
||||||
}) => match expression {
|
}) => match expression {
|
||||||
Expression::StringLiteral(str) => str.value.parse().or(Err(())),
|
Expression::StringLiteral(str) => str.value.parse().or(Err(())),
|
||||||
Expression::TemplateLiteral(tmpl) => {
|
Expression::TemplateLiteral(tmpl) => {
|
||||||
tmpl.quasis.get(0).unwrap().value.raw.parse().or(Err(()))
|
tmpl.quasis.first().unwrap().value.raw.parse().or(Err(()))
|
||||||
}
|
}
|
||||||
Expression::NumberLiteral(num) => Ok(num.value),
|
Expression::NumberLiteral(num) => Ok(num.value),
|
||||||
_ => Err(()),
|
_ => Err(()),
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ pub fn is_logical_expression(node: &AstNode) -> bool {
|
||||||
|
|
||||||
// gets the name of the first parameter of a function
|
// gets the name of the first parameter of a function
|
||||||
pub fn get_first_parameter_name<'a>(arg: &'a FormalParameters) -> Option<&'a str> {
|
pub fn get_first_parameter_name<'a>(arg: &'a FormalParameters) -> Option<&'a str> {
|
||||||
let first_func_param = arg.items.get(0)?;
|
let first_func_param = arg.items.first()?;
|
||||||
let BindingPatternKind::BindingIdentifier(first_func_param) = &first_func_param.pattern.kind
|
let BindingPatternKind::BindingIdentifier(first_func_param) = &first_func_param.pattern.kind
|
||||||
else {
|
else {
|
||||||
return None;
|
return None;
|
||||||
|
|
@ -117,9 +117,9 @@ pub fn get_first_parameter_name<'a>(arg: &'a FormalParameters) -> Option<&'a str
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_return_identifier_name<'a>(body: &'a FunctionBody<'_>) -> Option<&'a str> {
|
pub fn get_return_identifier_name<'a>(body: &'a FunctionBody<'_>) -> Option<&'a str> {
|
||||||
match body.statements.get(0)? {
|
match body.statements.first()? {
|
||||||
Statement::BlockStatement(block_stmt) => {
|
Statement::BlockStatement(block_stmt) => {
|
||||||
let Statement::ReturnStatement(return_stmt) = block_stmt.body.get(0)? else {
|
let Statement::ReturnStatement(return_stmt) = block_stmt.body.first()? else {
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -457,7 +457,7 @@ pub fn get_boolean_value(expr: &Expression) -> Option<bool> {
|
||||||
// only for ``
|
// only for ``
|
||||||
template_literal
|
template_literal
|
||||||
.quasis
|
.quasis
|
||||||
.get(0)
|
.first()
|
||||||
.filter(|quasi| quasi.tail)
|
.filter(|quasi| quasi.tail)
|
||||||
.and_then(|quasi| quasi.value.cooked.as_ref())
|
.and_then(|quasi| quasi.value.cooked.as_ref())
|
||||||
.map(|cooked| !cooked.is_empty())
|
.map(|cooked| !cooked.is_empty())
|
||||||
|
|
@ -550,7 +550,7 @@ pub fn get_string_value<'a>(expr: &'a Expression) -> Option<Cow<'a, str>> {
|
||||||
// Closure-compiler do more: [case TEMPLATELIT](https://github.com/google/closure-compiler/blob/e13f5cd0a5d3d35f2db1e6c03fdf67ef02946009/src/com/google/javascript/jscomp/NodeUtil.java#L241-L256).
|
// Closure-compiler do more: [case TEMPLATELIT](https://github.com/google/closure-compiler/blob/e13f5cd0a5d3d35f2db1e6c03fdf67ef02946009/src/com/google/javascript/jscomp/NodeUtil.java#L241-L256).
|
||||||
template_literal
|
template_literal
|
||||||
.quasis
|
.quasis
|
||||||
.get(0)
|
.first()
|
||||||
.filter(|quasi| quasi.tail)
|
.filter(|quasi| quasi.tail)
|
||||||
.and_then(|quasi| quasi.value.cooked.as_ref())
|
.and_then(|quasi| quasi.value.cooked.as_ref())
|
||||||
.map(|cooked| Cow::Borrowed(cooked.as_str()))
|
.map(|cooked| Cow::Borrowed(cooked.as_str()))
|
||||||
|
|
|
||||||
|
|
@ -1110,6 +1110,7 @@ impl<'a> Parser<'a> {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::unnecessary_fallible_conversions)]
|
||||||
if let Ok(modifier_flag) = self.cur_kind().try_into() {
|
if let Ok(modifier_flag) = self.cur_kind().try_into() {
|
||||||
flags.set(modifier_flag, true);
|
flags.set(modifier_flag, true);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ fn choose_layout<'a>(
|
||||||
return Layout::Chain;
|
return Layout::Chain;
|
||||||
} else if let Expression::ArrowExpression(arrow_expr) = right_expr {
|
} else if let Expression::ArrowExpression(arrow_expr) = right_expr {
|
||||||
if let Some(Statement::ExpressionStatement(expr_stmt)) =
|
if let Some(Statement::ExpressionStatement(expr_stmt)) =
|
||||||
arrow_expr.body.statements.get(0)
|
arrow_expr.body.statements.first()
|
||||||
{
|
{
|
||||||
if let Expression::ArrowExpression(_) = expr_stmt.expression {
|
if let Expression::ArrowExpression(_) = expr_stmt.expression {
|
||||||
return Layout::ChainTailArrowChain;
|
return Layout::ChainTailArrowChain;
|
||||||
|
|
|
||||||
|
|
@ -993,7 +993,7 @@ impl<'a> Format<'a> for ImportDeclaration<'a> {
|
||||||
parts.push(ss!(" type"));
|
parts.push(ss!(" type"));
|
||||||
}
|
}
|
||||||
if let Some(specifiers) = &self.specifiers {
|
if let Some(specifiers) = &self.specifiers {
|
||||||
let is_default = specifiers.get(0).is_some_and(|x| {
|
let is_default = specifiers.first().is_some_and(|x| {
|
||||||
matches!(x, ImportDeclarationSpecifier::ImportDefaultSpecifier(_))
|
matches!(x, ImportDeclarationSpecifier::ImportDefaultSpecifier(_))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -1001,7 +1001,7 @@ impl<'a> Format<'a> for ImportDeclaration<'a> {
|
||||||
matches!(x, ImportDeclarationSpecifier::ImportNamespaceSpecifier(_))
|
matches!(x, ImportDeclarationSpecifier::ImportNamespaceSpecifier(_))
|
||||||
};
|
};
|
||||||
|
|
||||||
let is_namespace = specifiers.get(0).is_some_and(validate_namespace)
|
let is_namespace = specifiers.first().is_some_and(validate_namespace)
|
||||||
|| specifiers.get(1).is_some_and(validate_namespace);
|
|| specifiers.get(1).is_some_and(validate_namespace);
|
||||||
|
|
||||||
parts.push(module::print_module_specifiers(p, specifiers, is_default, is_namespace));
|
parts.push(module::print_module_specifiers(p, specifiers, is_default, is_namespace));
|
||||||
|
|
|
||||||
|
|
@ -642,7 +642,7 @@ impl<'a> Prettier<'a> {
|
||||||
}
|
}
|
||||||
Expression::SequenceExpression(e) => e
|
Expression::SequenceExpression(e) => e
|
||||||
.expressions
|
.expressions
|
||||||
.get(0)
|
.first()
|
||||||
.map_or(false, |e| Self::starts_with_no_lookahead_token(e, span)),
|
.map_or(false, |e| Self::starts_with_no_lookahead_token(e, span)),
|
||||||
Expression::ChainExpression(e) => match &e.expression {
|
Expression::ChainExpression(e) => match &e.expression {
|
||||||
ChainElement::CallExpression(e) => {
|
ChainElement::CallExpression(e) => {
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ impl ModuleRecordBuilder {
|
||||||
};
|
};
|
||||||
if ident.name == "require" {
|
if ident.name == "require" {
|
||||||
let Some(Argument::Expression(Expression::StringLiteral(module))) =
|
let Some(Argument::Expression(Expression::StringLiteral(module))) =
|
||||||
call.arguments.get(0)
|
call.arguments.first()
|
||||||
else {
|
else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,7 @@ impl SemanticTester {
|
||||||
///
|
///
|
||||||
/// ## Fails
|
/// ## Fails
|
||||||
/// If no class with the given name exists.
|
/// If no class with the given name exists.
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn has_class(&self, name: &str) -> ClassTester {
|
pub fn has_class(&self, name: &str) -> ClassTester {
|
||||||
ClassTester::has_class(self.build(), name)
|
ClassTester::has_class(self.build(), name)
|
||||||
}
|
}
|
||||||
|
|
@ -124,6 +125,7 @@ impl SemanticTester {
|
||||||
/// 1. No symbol with the given name exists,
|
/// 1. No symbol with the given name exists,
|
||||||
/// 2. More than one symbol with the given name exists, so a symbol cannot
|
/// 2. More than one symbol with the given name exists, so a symbol cannot
|
||||||
/// be uniquely obtained.
|
/// be uniquely obtained.
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn has_some_symbol(&self, name: &str) -> SymbolTester {
|
pub fn has_some_symbol(&self, name: &str) -> SymbolTester {
|
||||||
SymbolTester::new_unique(self, self.build(), name)
|
SymbolTester::new_unique(self, self.build(), name)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ impl<'a> TemplateLiterals<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure the first node is a string
|
// make sure the first node is a string
|
||||||
if !matches!(nodes.get(0), Some(Expression::StringLiteral(_))) {
|
if !matches!(nodes.first(), Some(Expression::StringLiteral(_))) {
|
||||||
let literal = StringLiteral::new(SPAN, Atom::from(""));
|
let literal = StringLiteral::new(SPAN, Atom::from(""));
|
||||||
let string_literal = self.ast.literal_string_expression(literal);
|
let string_literal = self.ast.literal_string_expression(literal);
|
||||||
nodes.insert(0, string_literal);
|
nodes.insert(0, string_literal);
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
[toolchain]
|
[toolchain]
|
||||||
channel = "1.74.0"
|
channel = "1.75.0"
|
||||||
profile = "default"
|
profile = "default"
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ impl BabelOptions {
|
||||||
|
|
||||||
pub fn is_typescript_definition(&self) -> bool {
|
pub fn is_typescript_definition(&self) -> bool {
|
||||||
self.plugins.iter().filter_map(Value::as_array).any(|p| {
|
self.plugins.iter().filter_map(Value::as_array).any(|p| {
|
||||||
let typescript = p.get(0).and_then(Value::as_str).is_some_and(|s| s == "typescript");
|
let typescript = p.first().and_then(Value::as_str).is_some_and(|s| s == "typescript");
|
||||||
let dts = p
|
let dts = p
|
||||||
.get(1)
|
.get(1)
|
||||||
.and_then(Value::as_object)
|
.and_then(Value::as_object)
|
||||||
|
|
@ -91,7 +91,7 @@ impl BabelOptions {
|
||||||
pub fn get_plugin(&self, name: &str) -> Option<Option<Value>> {
|
pub fn get_plugin(&self, name: &str) -> Option<Option<Value>> {
|
||||||
self.plugins.iter().find_map(|v| match v {
|
self.plugins.iter().find_map(|v| match v {
|
||||||
Value::String(s) if s == name => Some(None),
|
Value::String(s) if s == name => Some(None),
|
||||||
Value::Array(a) if a.get(0).and_then(Value::as_str).is_some_and(|s| s == name) => {
|
Value::Array(a) if a.first().and_then(Value::as_str).is_some_and(|s| s == name) => {
|
||||||
Some(a.get(1).cloned())
|
Some(a.get(1).cloned())
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue