mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
refactor(rust): apply cllippy::nursery rules (#9232)
This commit is contained in:
1 parent
63bb214555
commit
9f361819b9
56 files changed
+119
-111
No files matched your search
+13
@@ -68,15 +68,28 @@ wildcard_imports = "allow"
|
||||
# used_underscore_binding= "allow"
|
||||
doc_markdown = "allow"
|
||||
# nursery
|
||||
nursery = { level = "warn", priority = -1 }
|
||||
# `const` functions do not make sense for our project because this is not a `const` library.
|
||||
# This rule also confuses newcomers and forces them to add `const` blindlessly without any reason.
|
||||
missing_const_for_fn = "allow"
|
||||
option_if_let_else = "allow"
|
||||
or_fun_call = "allow"
|
||||
cognitive_complexity = "allow"
|
||||
non_send_fields_in_send_ty = "allow"
|
||||
use_self = "allow"
|
||||
significant_drop_tightening = "allow"
|
||||
branches_sharing_code = "allow"
|
||||
fallible_impl_from = "allow"
|
||||
useless_let_if_seq = "allow"
|
||||
significant_drop_in_scrutinee = "warn"
|
||||
iter_on_single_items = "warn"
|
||||
unused_peekable = "warn"
|
||||
too_long_first_doc_paragraph = "warn"
|
||||
suspicious_operation_groupings = "warn"
|
||||
redundant_clone = "warn"
|
||||
redundant_pub_crate = "allow" # FIXME
|
||||
debug_assert_with_mut_call = "allow" # FIXME
|
||||
needless_pass_by_ref_mut = "allow" # FIXME
|
||||
# cargo
|
||||
cargo = { level = "warn", priority = -1 }
|
||||
multiple_crate_versions = "allow"
|
||||
|
||||
@@ -209,7 +209,7 @@ impl Runner for LintRunner {
|
||||
|
||||
if fs::write(Self::DEFAULT_OXLINTRC, configuration).is_ok() {
|
||||
stdout
|
||||
.write_all("Configuration file created\n".as_bytes())
|
||||
.write_all(b"Configuration file created\n")
|
||||
.or_else(Self::check_for_writer_error)
|
||||
.unwrap();
|
||||
stdout.flush().unwrap();
|
||||
|
||||
@@ -53,7 +53,7 @@ fn format_junit(diagnostics: &[Error]) -> String {
|
||||
let rule = diagnostic.code().map_or_else(String::new, |code| code.to_string());
|
||||
let Info { message, start, .. } = Info::new(diagnostic);
|
||||
|
||||
let severity = if let Some(Severity::Error) = diagnostic.severity() {
|
||||
let severity = if diagnostic.severity() == Some(Severity::Error) {
|
||||
total_errors += 1;
|
||||
error += 1;
|
||||
"error"
|
||||
|
||||
@@ -53,17 +53,17 @@ impl Tester {
|
||||
let options = lint_command().run_inner(*args).unwrap();
|
||||
let args_string = args.join(" ");
|
||||
|
||||
output.extend_from_slice("########## \n".as_bytes());
|
||||
output.extend_from_slice(b"########## \n");
|
||||
output.extend_from_slice(format!("arguments: {args_string}\n").as_bytes());
|
||||
output.extend_from_slice(
|
||||
format!("working directory: {}\n", relative_dir.to_str().unwrap()).as_bytes(),
|
||||
);
|
||||
output.extend_from_slice("----------\n".as_bytes());
|
||||
output.extend_from_slice(b"----------\n");
|
||||
let result = LintRunner::new(options).with_cwd(self.cwd.clone()).run(&mut output);
|
||||
|
||||
output.extend_from_slice("----------\n".as_bytes());
|
||||
output.extend_from_slice(b"----------\n");
|
||||
output.extend_from_slice(format!("CLI result: {result:?}\n").as_bytes());
|
||||
output.extend_from_slice("----------\n".as_bytes());
|
||||
output.extend_from_slice(b"----------\n");
|
||||
|
||||
output.push(b'\n');
|
||||
}
|
||||
|
||||
@@ -205,15 +205,19 @@ impl ControlFlowGraph {
|
||||
|
||||
// if there is exactly one and it is a condition instruction we are in a loop so we
|
||||
// check the condition to infer if it is always true.
|
||||
if let EvalConstConditionResult::Eval(true) = try_eval_const_condition(only_instruction) {
|
||||
if matches!(
|
||||
try_eval_const_condition(only_instruction),
|
||||
EvalConstConditionResult::Eval(true)
|
||||
) {
|
||||
get_jump_target(&self.graph, node).map(|it| (it, node))
|
||||
} else if let EvalConstConditionResult::Eval(true) = self
|
||||
.basic_block(backedge.source())
|
||||
.instructions()
|
||||
.iter()
|
||||
.exactly_one()
|
||||
.map_or_else(|_| EvalConstConditionResult::NotFound, try_eval_const_condition)
|
||||
{
|
||||
} else if matches!(
|
||||
self.basic_block(backedge.source())
|
||||
.instructions()
|
||||
.iter()
|
||||
.exactly_one()
|
||||
.map_or_else(|_| EvalConstConditionResult::NotFound, try_eval_const_condition),
|
||||
EvalConstConditionResult::Eval(true)
|
||||
) {
|
||||
get_jump_target(&self.graph, node).map(|it| (node, it))
|
||||
} else {
|
||||
None
|
||||
|
||||
@@ -12,7 +12,7 @@ use oxc_syntax::{
|
||||
use crate::{gen::GenExpr, Codegen, Context, Operator};
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub(crate) enum Binaryish<'a> {
|
||||
pub enum Binaryish<'a> {
|
||||
Binary(&'a BinaryExpression<'a>),
|
||||
Logical(&'a LogicalExpression<'a>),
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use oxc_syntax::identifier::is_line_terminator;
|
||||
|
||||
use crate::{Codegen, LegalComment};
|
||||
|
||||
pub(crate) type CommentsMap = FxHashMap</* attached_to */ u32, Vec<Comment>>;
|
||||
pub type CommentsMap = FxHashMap</* attached_to */ u32, Vec<Comment>>;
|
||||
|
||||
impl Codegen<'_> {
|
||||
pub(crate) fn build_comments(&mut self, comments: &[Comment]) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use oxc_syntax::operator::{BinaryOperator, UnaryOperator, UpdateOperator};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub(crate) enum Operator {
|
||||
pub enum Operator {
|
||||
Binary(BinaryOperator),
|
||||
Unary(UnaryOperator),
|
||||
Update(UpdateOperator),
|
||||
|
||||
@@ -537,7 +537,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn add_source_mapping_for_name() {
|
||||
let output = "ac".as_bytes();
|
||||
let output = b"ac";
|
||||
let mut builder = SourcemapBuilder::new(Path::new("x.js"), "ab");
|
||||
builder.add_source_mapping_for_name(output, Span::new(0, 1), "a");
|
||||
builder.add_source_mapping_for_name(output, Span::new(1, 2), "c");
|
||||
@@ -556,7 +556,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn add_source_mapping_for_unordered_position() {
|
||||
let output = "".as_bytes();
|
||||
let output = b"";
|
||||
let mut builder = SourcemapBuilder::new(Path::new("x.js"), "ab");
|
||||
builder.add_source_mapping(output, 1, None);
|
||||
builder.add_source_mapping(output, 0, None);
|
||||
|
||||
@@ -81,7 +81,7 @@ impl ToPrimitive<'_> for Expression<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn maybe_object_with_to_primitive_related_properties_overridden(
|
||||
pub fn maybe_object_with_to_primitive_related_properties_overridden(
|
||||
obj: &ObjectExpression<'_>,
|
||||
) -> bool {
|
||||
obj.properties.iter().any(|prop| match prop {
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::{rules::RULES, RuleWithSeverity};
|
||||
|
||||
// TODO: support `categories` et. al. in overrides.
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct ResolvedLinterState {
|
||||
pub struct ResolvedLinterState {
|
||||
// TODO: Arc + Vec -> SyncVec? It would save a pointer dereference.
|
||||
pub rules: Arc<[RuleWithSeverity]>,
|
||||
pub config: Arc<LintConfig>,
|
||||
|
||||
@@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize};
|
||||
/// list of
|
||||
/// environments](https://eslint.org/docs/v8.x/use/configure/language-options#specifying-environments)
|
||||
/// for what environments are available and what each one provides.
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, JsonSchema)]
|
||||
pub struct OxlintEnv(FxHashMap<String, bool>);
|
||||
|
||||
impl FromIterator<String> for OxlintEnv {
|
||||
|
||||
@@ -30,7 +30,7 @@ use serde::{de::Visitor, Deserialize, Serialize};
|
||||
/// You may also use `"readable"` or `false` to represent `"readonly"`, and
|
||||
/// `"writeable"` or `true` to represent `"writable"`.
|
||||
// <https://eslint.org/docs/v8.x/use/configure/language-options#using-configuration-files-1>
|
||||
#[derive(Debug, Default, PartialEq, Deserialize, Serialize, JsonSchema, Clone)]
|
||||
#[derive(Debug, Default, PartialEq, Eq, Deserialize, Serialize, JsonSchema, Clone)]
|
||||
pub struct OxlintGlobals(FxHashMap<String, GlobalValue>);
|
||||
|
||||
impl Deref for OxlintGlobals {
|
||||
|
||||
@@ -12,7 +12,7 @@ mod rules;
|
||||
mod settings;
|
||||
pub use config_builder::{ConfigBuilderError, ConfigStoreBuilder};
|
||||
pub use config_store::ConfigStore;
|
||||
pub(crate) use config_store::ResolvedLinterState;
|
||||
pub use config_store::ResolvedLinterState;
|
||||
pub use env::OxlintEnv;
|
||||
pub use globals::{GlobalValue, OxlintGlobals};
|
||||
pub use overrides::OxlintOverrides;
|
||||
|
||||
@@ -8,7 +8,7 @@ use serde::{
|
||||
|
||||
bitflags! {
|
||||
// NOTE: may be increased to a u32 if needed
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Hash)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct LintPlugins: u16 {
|
||||
/// Not really a plugin. Included for completeness.
|
||||
const ESLINT = 0;
|
||||
|
||||
@@ -23,8 +23,7 @@ type RuleSet = FxHashSet<RuleWithSeverity>;
|
||||
// - type RuleConf = SeverityConf | [SeverityConf, ...any[]];
|
||||
// <https://github.com/eslint/eslint/blob/ce838adc3b673e52a151f36da0eedf5876977514/lib/shared/types.js#L12>
|
||||
// Note: when update document comment, also update `DummyRuleMap`'s description in this file.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
#[cfg_attr(test, derive(PartialEq))]
|
||||
#[derive(Debug, Clone, Default, Eq, PartialEq)]
|
||||
pub struct OxlintRules {
|
||||
/// List of all configured rules
|
||||
pub(crate) rules: Vec<ESLintRule>,
|
||||
@@ -46,8 +45,7 @@ impl OxlintRules {
|
||||
/// e.g. `eslint/no-console` or `react/rule-of-hooks`.
|
||||
/// Includes the plugin name, the rule name, and the configuration for the rule (if any).
|
||||
/// This does not imply the rule is known to the linter as that, only that it is configured.
|
||||
#[derive(Debug, Clone)]
|
||||
#[cfg_attr(test, derive(PartialEq))]
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct ESLintRule {
|
||||
/// Name of the plugin: `eslint`, `react`, etc.
|
||||
pub plugin_name: String,
|
||||
|
||||
@@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
|
||||
/// [eslint-plugin-jsx-a11y](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y#configurations)'s
|
||||
/// configuration for a full reference.
|
||||
#[derive(Debug, Clone, Deserialize, Default, Serialize, JsonSchema)]
|
||||
#[cfg_attr(test, derive(PartialEq))]
|
||||
#[cfg_attr(test, derive(PartialEq, Eq))]
|
||||
pub struct JSXA11yPluginSettings {
|
||||
/// An optional setting that define the prop your code uses to create polymorphic components.
|
||||
/// This setting will be used to determine the element type in rules that
|
||||
|
||||
@@ -35,7 +35,7 @@ use super::{plugin_name_to_prefix, LintContext};
|
||||
/// - [Flyweight Pattern](https://en.wikipedia.org/wiki/Flyweight_pattern)
|
||||
#[must_use]
|
||||
#[non_exhaustive]
|
||||
pub(crate) struct ContextHost<'a> {
|
||||
pub struct ContextHost<'a> {
|
||||
/// Shared semantic information about the file being linted, which includes scopes, symbols
|
||||
/// and AST nodes. See [`Semantic`].
|
||||
pub(super) semantic: Rc<Semantic<'a>>,
|
||||
@@ -106,7 +106,6 @@ impl<'a> ContextHost<'a> {
|
||||
|
||||
/// Set the linter configuration for this context.
|
||||
#[inline]
|
||||
#[expect(dead_code)] // will be used in up-stack PR
|
||||
pub fn with_config(mut self, config: &Arc<LintConfig>) -> Self {
|
||||
let plugins = config.plugins;
|
||||
self.config = Arc::clone(config);
|
||||
|
||||
@@ -19,7 +19,7 @@ use crate::{
|
||||
};
|
||||
|
||||
mod host;
|
||||
pub(crate) use host::ContextHost;
|
||||
pub use host::ContextHost;
|
||||
|
||||
/// Contains all of the state and context specific to this lint rule.
|
||||
///
|
||||
|
||||
@@ -72,7 +72,7 @@ impl FrameworkFlags {
|
||||
}
|
||||
|
||||
/// <https://jestjs.io/docs/configuration#testmatch-arraystring>
|
||||
pub(crate) fn is_jestlike_file(path: &Path) -> bool {
|
||||
pub fn is_jestlike_file(path: &Path) -> bool {
|
||||
use std::ffi::OsStr;
|
||||
|
||||
if path.components().any(|c| match c {
|
||||
@@ -88,10 +88,10 @@ pub(crate) fn is_jestlike_file(path: &Path) -> bool {
|
||||
.is_some_and(|name_or_first_ext| name_or_first_ext == "test" || name_or_first_ext == "spec")
|
||||
}
|
||||
|
||||
pub(crate) fn has_vitest_imports(module_record: &ModuleRecord) -> bool {
|
||||
pub fn has_vitest_imports(module_record: &ModuleRecord) -> bool {
|
||||
module_record.import_entries.iter().any(|entry| entry.module_request.name() == "vitest")
|
||||
}
|
||||
|
||||
pub(crate) fn has_jest_imports(module_record: &ModuleRecord) -> bool {
|
||||
pub fn has_jest_imports(module_record: &ModuleRecord) -> bool {
|
||||
module_record.import_entries.iter().any(|entry| entry.module_request.name() == "@jest/globals")
|
||||
}
|
||||
@@ -74,7 +74,7 @@ impl<'a> AstroPartialLoader<'a> {
|
||||
break;
|
||||
};
|
||||
// check for the / of a self closing script tag
|
||||
if let Some('/') = self.source_text.chars().nth(js_start - 2) {
|
||||
if self.source_text.chars().nth(js_start - 2) == Some('/') {
|
||||
js_end = pointer;
|
||||
// find "</script>" if no self closing tag was found
|
||||
} else if let Some(offset) =
|
||||
|
||||
@@ -11,8 +11,7 @@ use super::AllowWarnDeny;
|
||||
/// 2. Filter an entire category: `correctness`
|
||||
/// 3. Some unknow filter. This is a fallback used when parsing a filter string,
|
||||
/// and is interpreted uniquely by the linter.
|
||||
#[derive(Debug, Clone)]
|
||||
#[cfg_attr(test, derive(PartialEq))]
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct LintFilter {
|
||||
severity: AllowWarnDeny,
|
||||
kind: LintFilterKind,
|
||||
@@ -77,8 +76,7 @@ impl<'a> From<&'a LintFilter> for (AllowWarnDeny, &'a LintFilterKind) {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[cfg_attr(test, derive(PartialEq))]
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub enum LintFilterKind {
|
||||
Generic(Cow<'static, str>),
|
||||
/// e.g. `no-const-assign` or `eslint/no-const-assign`
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::{fixer::FixKind, FrameworkFlags};
|
||||
|
||||
/// Subset of options used directly by the linter.
|
||||
#[derive(Debug, Default, Clone, Copy)]
|
||||
#[cfg_attr(test, derive(PartialEq))]
|
||||
#[cfg_attr(test, derive(PartialEq, Eq))]
|
||||
pub struct LintOptions {
|
||||
pub fix: FixKind,
|
||||
pub framework_hints: FrameworkFlags,
|
||||
|
||||
@@ -130,9 +130,9 @@ impl Rule for ForDirection {
|
||||
span.end = update.argument.span().start;
|
||||
}
|
||||
|
||||
if let UpdateOperator::Increment = update.operator {
|
||||
if update.operator == UpdateOperator::Increment {
|
||||
new_operator_str = "--";
|
||||
} else if let UpdateOperator::Decrement = update.operator {
|
||||
} else if update.operator == UpdateOperator::Decrement {
|
||||
new_operator_str = "++";
|
||||
}
|
||||
}
|
||||
@@ -140,9 +140,9 @@ impl Rule for ForDirection {
|
||||
span.start = update.left.span().end;
|
||||
span.end = update.right.span().start;
|
||||
|
||||
if let AssignmentOperator::Addition = update.operator {
|
||||
if update.operator == AssignmentOperator::Addition {
|
||||
new_operator_str = "-=";
|
||||
} else if let AssignmentOperator::Subtraction = update.operator {
|
||||
} else if update.operator == AssignmentOperator::Subtraction {
|
||||
new_operator_str = "+=";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,10 +251,10 @@ impl Rule for FuncStyle {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(NamedExports::Expression) = self.named_exports {
|
||||
if matches!(parent.kind(), AstKind::ExportNamedDeclaration(_)) {
|
||||
ctx.diagnostic(func_style_diagnostic(func.span, self.style));
|
||||
}
|
||||
if self.named_exports == Some(NamedExports::Expression)
|
||||
&& matches!(parent.kind(), AstKind::ExportNamedDeclaration(_))
|
||||
{
|
||||
ctx.diagnostic(func_style_diagnostic(func.span, self.style));
|
||||
}
|
||||
}
|
||||
FunctionType::FunctionExpression => {
|
||||
@@ -266,12 +266,10 @@ impl Rule for FuncStyle {
|
||||
ctx.diagnostic(func_style_diagnostic(decl.span, self.style));
|
||||
}
|
||||
|
||||
if let Some(NamedExports::Declaration) = self.named_exports {
|
||||
if is_ancestor_export {
|
||||
ctx.diagnostic(func_style_diagnostic(
|
||||
decl.span, self.style,
|
||||
));
|
||||
}
|
||||
if self.named_exports == Some(NamedExports::Declaration)
|
||||
&& is_ancestor_export
|
||||
{
|
||||
ctx.diagnostic(func_style_diagnostic(decl.span, self.style));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -310,10 +308,8 @@ impl Rule for FuncStyle {
|
||||
ctx.diagnostic(func_style_diagnostic(decl.span, self.style));
|
||||
}
|
||||
|
||||
if let Some(NamedExports::Declaration) = self.named_exports {
|
||||
if is_ancestor_export {
|
||||
ctx.diagnostic(func_style_diagnostic(decl.span, self.style));
|
||||
}
|
||||
if self.named_exports == Some(NamedExports::Declaration) && is_ancestor_export {
|
||||
ctx.diagnostic(func_style_diagnostic(decl.span, self.style));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,10 +271,10 @@ impl GetterReturn {
|
||||
});
|
||||
|
||||
let does_return = return_instruction.is_some_and(|ret| {
|
||||
!matches! { ret.kind,
|
||||
!matches!( ret.kind,
|
||||
InstructionKind::Return(ReturnInstructionKind::ImplicitUndefined)
|
||||
if !self.allow_implicit
|
||||
}
|
||||
)
|
||||
});
|
||||
|
||||
// Return true as the second argument to signify we should
|
||||
|
||||
@@ -171,7 +171,7 @@ impl Rule for InitDeclarations {
|
||||
));
|
||||
}
|
||||
Mode::Never if is_initialized && !self.ignore_for_loop_init => {
|
||||
if let VariableDeclarationKind::Const = &v.kind {
|
||||
if matches!(&v.kind, VariableDeclarationKind::Const) {
|
||||
continue;
|
||||
}
|
||||
ctx.diagnostic(init_declarations_diagnostic(
|
||||
|
||||
@@ -157,11 +157,11 @@ impl Rule for NoUnreachable {
|
||||
continue;
|
||||
}
|
||||
|
||||
if matches! {
|
||||
if matches!(
|
||||
node.kind(),
|
||||
AstKind::VariableDeclaration(decl)
|
||||
if matches!(decl.kind, VariableDeclarationKind::Var) && !decl.has_init()
|
||||
} {
|
||||
) {
|
||||
// Skip `var` declarations without any initialization,
|
||||
// These work because of the JavaScript hoisting rules.
|
||||
continue;
|
||||
|
||||
@@ -167,7 +167,7 @@ impl Rule for NoLargeSnapshots {
|
||||
});
|
||||
|
||||
if is_snap {
|
||||
for node in ctx.nodes().iter().collect::<Vec<_>>() {
|
||||
for node in ctx.nodes().iter() {
|
||||
if let AstKind::ExpressionStatement(expr_stmt) = node.kind() {
|
||||
self.report_in_expr_stmt(expr_stmt, ctx);
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ fn check_interface_declaration(
|
||||
allow_interfaces: AllowInterfaces,
|
||||
allow_with_name: &str,
|
||||
) {
|
||||
if let AllowInterfaces::Always = allow_interfaces {
|
||||
if matches!(allow_interfaces, AllowInterfaces::Always) {
|
||||
return;
|
||||
};
|
||||
if interface.id.name.as_str() == allow_with_name {
|
||||
@@ -190,7 +190,7 @@ fn check_type_literal(
|
||||
allow_object_types: AllowObjectTypes,
|
||||
allow_with_name: &str,
|
||||
) {
|
||||
if let AllowObjectTypes::Always = allow_object_types {
|
||||
if matches!(allow_object_types, AllowObjectTypes::Always) {
|
||||
return;
|
||||
};
|
||||
let Some(parent_node) = ctx.nodes().parent_node(node_id) else {
|
||||
|
||||
@@ -224,7 +224,7 @@ fn get_replacement(right: &Expression, operator: BinaryOperator) -> Option<GetRe
|
||||
|
||||
fn is_negative_one(expression: &Expression) -> bool {
|
||||
if let Expression::UnaryExpression(unary_expression) = expression {
|
||||
if let UnaryOperator::UnaryNegation = unary_expression.operator {
|
||||
if unary_expression.operator == UnaryOperator::UnaryNegation {
|
||||
if let Expression::NumericLiteral(value) =
|
||||
&unary_expression.argument.get_inner_expression()
|
||||
{
|
||||
|
||||
@@ -132,7 +132,7 @@ impl Rule for PreferSetHas {
|
||||
return;
|
||||
};
|
||||
|
||||
if let VariableDeclarationKind::Var = declarator.kind {
|
||||
if declarator.kind == VariableDeclarationKind::Var {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -330,10 +330,10 @@ pub fn is_react_function_call(call: &CallExpression, expected_call: &str) -> boo
|
||||
}
|
||||
|
||||
if let Some(member) = call.callee.as_member_expression() {
|
||||
matches! {
|
||||
matches!(
|
||||
member.object().get_identifier_reference(),
|
||||
Some(ident) if ident.name.as_str() == PRAGMA
|
||||
}
|
||||
)
|
||||
} else {
|
||||
true
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ fn react_perf_reference_diagnostic(
|
||||
diagnostic.and_label(attr_span.label("And used here"))
|
||||
}
|
||||
|
||||
pub(crate) trait ReactPerfRule: Sized + Default + fmt::Debug {
|
||||
pub trait ReactPerfRule: Sized + Default + fmt::Debug {
|
||||
const MESSAGE: &'static str;
|
||||
|
||||
/// Check if an [`Expression`] violates a react perf rule. If it does,
|
||||
|
||||
@@ -55,7 +55,7 @@ impl Parse for LintRuleMeta {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn rule_name_converter() -> Converter {
|
||||
pub fn rule_name_converter() -> Converter {
|
||||
Converter::new().remove_boundary(Boundary::LOWER_DIGIT).to_case(Case::Kebab)
|
||||
}
|
||||
|
||||
|
||||
@@ -464,7 +464,7 @@ impl<'a> PeepholeOptimizations {
|
||||
// In Rust, when facing `.5`, it may follow `half-away-from-zero` instead of round to upper bound.
|
||||
// So we need to handle it manually.
|
||||
let frac_part = arg_val.fract();
|
||||
let epsilon = 2f64.powf(-52f64);
|
||||
let epsilon = 2f64.powi(-52);
|
||||
if (frac_part.abs() - 0.5).abs() < epsilon {
|
||||
// We should ceil it.
|
||||
arg_val.ceil()
|
||||
@@ -831,7 +831,7 @@ impl<'a> PeepholeOptimizations {
|
||||
"NaN" => num(span, f64::NAN),
|
||||
"MAX_SAFE_INTEGER" => {
|
||||
if self.target < ESTarget::ES2016 {
|
||||
num(span, 2.0f64.powf(53.0) - 1.0)
|
||||
num(span, 2.0f64.powi(53) - 1.0)
|
||||
} else {
|
||||
// 2**53 - 1
|
||||
pow_with_expr(span, 2.0, 53.0, BinaryOperator::Subtraction, 1.0)
|
||||
@@ -839,7 +839,7 @@ impl<'a> PeepholeOptimizations {
|
||||
}
|
||||
"MIN_SAFE_INTEGER" => {
|
||||
if self.target < ESTarget::ES2016 {
|
||||
num(span, -(2.0f64.powf(53.0) - 1.0))
|
||||
num(span, -(2.0f64.powi(53) - 1.0))
|
||||
} else {
|
||||
// -(2**53 - 1)
|
||||
ctx.ast.expression_unary(
|
||||
|
||||
@@ -268,7 +268,7 @@ mod parser_parse {
|
||||
///
|
||||
/// `UniquePromise::new_for_tests_and_benchmarks` is a backdoor for tests/benchmarks, so they can
|
||||
/// create a `ParserImpl` or `Lexer`, and manipulate it directly, for testing/benchmarking purposes.
|
||||
pub(crate) struct UniquePromise(());
|
||||
pub struct UniquePromise(());
|
||||
|
||||
impl UniquePromise {
|
||||
#[inline]
|
||||
|
||||
@@ -83,7 +83,7 @@ pub struct BoundaryAssertion {
|
||||
}
|
||||
|
||||
#[ast]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[generate_derive(CloneIn, ContentEq, ESTree)]
|
||||
pub enum BoundaryAssertionKind {
|
||||
Start = 0,
|
||||
@@ -104,7 +104,7 @@ pub struct LookAroundAssertion<'a> {
|
||||
}
|
||||
|
||||
#[ast]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[generate_derive(CloneIn, ContentEq, ESTree)]
|
||||
pub enum LookAroundAssertionKind {
|
||||
Lookahead = 0,
|
||||
@@ -140,7 +140,7 @@ pub struct Character {
|
||||
}
|
||||
|
||||
#[ast]
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[generate_derive(CloneIn, ContentEq, ESTree)]
|
||||
pub enum CharacterKind {
|
||||
ControlLetter = 0,
|
||||
@@ -167,7 +167,7 @@ pub struct CharacterClassEscape {
|
||||
}
|
||||
|
||||
#[ast]
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[generate_derive(CloneIn, ContentEq, ESTree)]
|
||||
pub enum CharacterClassEscapeKind {
|
||||
D = 0,
|
||||
@@ -217,7 +217,7 @@ pub struct CharacterClass<'a> {
|
||||
}
|
||||
|
||||
#[ast]
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[generate_derive(CloneIn, ContentEq, ESTree)]
|
||||
pub enum CharacterClassContentsKind {
|
||||
Union = 0,
|
||||
|
||||
@@ -9,7 +9,7 @@ pub struct StringLiteral {
|
||||
pub body: Vec<CodePoint>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum StringLiteralKind {
|
||||
Double,
|
||||
Single,
|
||||
|
||||
@@ -12,7 +12,7 @@ use oxc_syntax::{
|
||||
|
||||
use crate::SemanticBuilder;
|
||||
|
||||
pub(crate) trait Binder<'a> {
|
||||
pub trait Binder<'a> {
|
||||
#[expect(unused_variables)]
|
||||
fn bind(&self, builder: &mut SemanticBuilder<'a>) {}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ use oxc_syntax::{
|
||||
|
||||
use crate::SymbolTable;
|
||||
|
||||
pub(crate) type Bindings<'a> = ArenaHashMap<'a, &'a str, SymbolId>;
|
||||
pub type Bindings<'a> = ArenaHashMap<'a, &'a str, SymbolId>;
|
||||
pub type UnresolvedReferences<'a> = ArenaHashMap<'a, &'a str, ArenaVec<'a, ReferenceId>>;
|
||||
|
||||
/// Scope Tree
|
||||
@@ -69,7 +69,7 @@ self_cell::self_cell!(
|
||||
}
|
||||
);
|
||||
|
||||
pub(crate) struct ScopeTreeInner<'cell> {
|
||||
pub struct ScopeTreeInner<'cell> {
|
||||
/// Symbol bindings in a scope.
|
||||
///
|
||||
/// A binding is a mapping from an identifier name to its [`SymbolId`]
|
||||
|
||||
@@ -13,7 +13,7 @@ type TempUnresolvedReferences<'a> = FxHashMap<Atom<'a>, Vec<ReferenceId>>;
|
||||
// to reduce allocations, so the stack grows to maximum scope depth, but never shrinks.
|
||||
// See: <https://github.com/oxc-project/oxc/issues/4169>
|
||||
// This stack abstraction uses the invariant that stack only grows to avoid bounds checks.
|
||||
pub(crate) struct UnresolvedReferencesStack<'a> {
|
||||
pub struct UnresolvedReferencesStack<'a> {
|
||||
stack: Vec<TempUnresolvedReferences<'a>>,
|
||||
/// Current scope depth.
|
||||
/// 0 is global scope. 1 is `Program`.
|
||||
|
||||
@@ -11,7 +11,7 @@ define_index_type! {
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd)]
|
||||
pub struct ElementKind: u8 {
|
||||
const Accessor = 1 << 0;
|
||||
const Method = 1 << 1;
|
||||
|
||||
@@ -65,7 +65,7 @@ export type ScopeId = number;
|
||||
"#;
|
||||
|
||||
bitflags! {
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct ScopeFlags: u16 {
|
||||
const StrictMode = 1 << 0;
|
||||
const Top = 1 << 1;
|
||||
|
||||
@@ -16,7 +16,7 @@ use crate::{JsxOptions, JsxRuntime, TransformCtx, TypeScriptOptions};
|
||||
/// otherwise `JSDoc` could be used instead.
|
||||
///
|
||||
/// This behavior is aligned with Babel.
|
||||
pub(crate) fn update_options_with_comments(
|
||||
pub fn update_options_with_comments(
|
||||
comments: &[Comment],
|
||||
typescript: &mut TypeScriptOptions,
|
||||
jsx: &mut JsxOptions,
|
||||
|
||||
@@ -11,7 +11,7 @@ mod jsx_self;
|
||||
mod jsx_source;
|
||||
mod options;
|
||||
mod refresh;
|
||||
pub(crate) use comments::update_options_with_comments;
|
||||
pub use comments::update_options_with_comments;
|
||||
use display_name::ReactDisplayName;
|
||||
use jsx_impl::JsxImpl;
|
||||
use jsx_self::JsxSelf;
|
||||
|
||||
@@ -8,8 +8,8 @@ mod env;
|
||||
mod plugins;
|
||||
mod presets;
|
||||
pub use env::{BabelEnvOptions, BabelModule, BabelTargets};
|
||||
pub(crate) use plugins::BabelPlugins;
|
||||
pub(crate) use presets::BabelPresets;
|
||||
pub use plugins::BabelPlugins;
|
||||
pub use presets::BabelPresets;
|
||||
|
||||
/// Babel options
|
||||
///
|
||||
|
||||
@@ -5,7 +5,7 @@ use oxc_span::{GetSpan, SPAN};
|
||||
use oxc_traverse::TraverseCtx;
|
||||
|
||||
/// `object` -> `object.call`.
|
||||
pub(crate) fn create_member_callee<'a>(
|
||||
pub fn create_member_callee<'a>(
|
||||
object: Expression<'a>,
|
||||
property: &'static str,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
@@ -15,7 +15,7 @@ pub(crate) fn create_member_callee<'a>(
|
||||
}
|
||||
|
||||
/// `object` -> `object.bind(this)`.
|
||||
pub(crate) fn create_bind_call<'a>(
|
||||
pub fn create_bind_call<'a>(
|
||||
callee: Expression<'a>,
|
||||
this: Expression<'a>,
|
||||
span: Span,
|
||||
@@ -27,7 +27,7 @@ pub(crate) fn create_bind_call<'a>(
|
||||
}
|
||||
|
||||
/// `object` -> `object.call(...arguments)`.
|
||||
pub(crate) fn create_call_call<'a>(
|
||||
pub fn create_call_call<'a>(
|
||||
callee: Expression<'a>,
|
||||
this: Expression<'a>,
|
||||
span: Span,
|
||||
@@ -42,7 +42,7 @@ pub(crate) fn create_call_call<'a>(
|
||||
/// with a body block.
|
||||
///
|
||||
/// `expr` -> `(() => { return expr; })()`
|
||||
pub(crate) fn wrap_expression_in_arrow_function_iife<'a>(
|
||||
pub fn wrap_expression_in_arrow_function_iife<'a>(
|
||||
expr: Expression<'a>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) -> Expression<'a> {
|
||||
@@ -56,7 +56,7 @@ pub(crate) fn wrap_expression_in_arrow_function_iife<'a>(
|
||||
/// Wrap statements in an IIFE (immediately invoked function expression).
|
||||
///
|
||||
/// `x; y; z;` -> `(() => { x; y; z; })()`
|
||||
pub(crate) fn wrap_statements_in_arrow_function_iife<'a>(
|
||||
pub fn wrap_statements_in_arrow_function_iife<'a>(
|
||||
stmts: ArenaVec<'a, Statement<'a>>,
|
||||
scope_id: ScopeId,
|
||||
span: Span,
|
||||
@@ -73,7 +73,7 @@ pub(crate) fn wrap_statements_in_arrow_function_iife<'a>(
|
||||
}
|
||||
|
||||
/// `object` -> `object.prototype`.
|
||||
pub(crate) fn create_prototype_member<'a>(
|
||||
pub fn create_prototype_member<'a>(
|
||||
object: Expression<'a>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) -> Expression<'a> {
|
||||
@@ -83,7 +83,7 @@ pub(crate) fn create_prototype_member<'a>(
|
||||
}
|
||||
|
||||
/// `object` -> `object.a`.
|
||||
pub(crate) fn create_property_access<'a>(
|
||||
pub fn create_property_access<'a>(
|
||||
object: Expression<'a>,
|
||||
property: &str,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
|
||||
@@ -1 +1 @@
|
||||
pub(crate) mod ast_builder;
|
||||
pub mod ast_builder;
|
||||
@@ -11,7 +11,7 @@ use oxc_transformer::{InjectGlobalVariables, InjectGlobalVariablesConfig, Inject
|
||||
|
||||
use crate::codegen;
|
||||
|
||||
pub(crate) fn test(source_text: &str, expected: &str, config: InjectGlobalVariablesConfig) {
|
||||
pub fn test(source_text: &str, expected: &str, config: InjectGlobalVariablesConfig) {
|
||||
let source_type = SourceType::default();
|
||||
let allocator = Allocator::default();
|
||||
let ret = Parser::new(&allocator, source_text, source_type).parse();
|
||||
|
||||
@@ -8,7 +8,7 @@ use oxc_transformer::{ReplaceGlobalDefines, ReplaceGlobalDefinesConfig};
|
||||
|
||||
use crate::codegen;
|
||||
|
||||
pub(crate) fn test(source_text: &str, expected: &str, config: ReplaceGlobalDefinesConfig) {
|
||||
pub fn test(source_text: &str, expected: &str, config: ReplaceGlobalDefinesConfig) {
|
||||
let source_type = SourceType::default();
|
||||
let allocator = Allocator::default();
|
||||
let ret = Parser::new(&allocator, source_text, source_type).parse();
|
||||
|
||||
@@ -203,4 +203,4 @@ impl<'a> TraverseAncestry<'a> {
|
||||
/// It is not `Clone` or `Copy`, so no way to obtain one except in this file.
|
||||
/// Only method which generates a `PopToken` is `push_stack`, and `pop_stack` consumes one,
|
||||
/// which guarantees you can't have more pops than pushes.
|
||||
pub(crate) struct PopToken(());
|
||||
pub struct PopToken(());
|
||||
@@ -75,9 +75,9 @@ pub use context::{
|
||||
|
||||
mod generated {
|
||||
pub mod ancestor;
|
||||
pub(super) mod scopes_collector;
|
||||
pub mod scopes_collector;
|
||||
pub mod traverse;
|
||||
pub(super) mod walk;
|
||||
pub mod walk;
|
||||
}
|
||||
pub use generated::{ancestor, ancestor::Ancestor, traverse::Traverse};
|
||||
use generated::{scopes_collector, walk::walk_ast};
|
||||
|
||||
@@ -3,11 +3,11 @@ use std::sync::OnceLock;
|
||||
static LOG: OnceLock<bool> = OnceLock::new();
|
||||
|
||||
/// Disable logging.
|
||||
pub(super) fn quiet() {
|
||||
pub fn quiet() {
|
||||
LOG.set(false).expect("Failed to disable logger");
|
||||
}
|
||||
|
||||
pub(super) fn __internal_log_enable() -> bool {
|
||||
pub fn __internal_log_enable() -> bool {
|
||||
*LOG.get_or_init(|| true)
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ use walkdir::WalkDir;
|
||||
|
||||
use crate::{snap_root, workspace_root, AppArgs, Driver};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum TestResult {
|
||||
ToBeRun,
|
||||
Passed,
|
||||
|
||||
@@ -6,7 +6,7 @@ use std::{
|
||||
};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub(crate) struct HtmlWriter {
|
||||
pub struct HtmlWriter {
|
||||
inner: RefCell<String>,
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user