Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add convert_luau_numbers rule #257

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jiwonz
Copy link
Contributor

@jiwonz jiwonz commented Jan 29, 2025

Closes #256

Changes

  • Add a rule convert_luau_numbers that converts luau's number literal syntax.
  • Add a simple tests for a rule convert_luau_numbers.

Copy link
Contributor

@jeparlefrancais jeparlefrancais left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Thanks for submitting the PR

Before merging this, I'd like to see these:

  • change the rule name to convert_luau_numbers
  • convert only binary numbers to decimal numbers because those are the compatibility issue
  • for each kind of number, if they have a token, remove the token if it contains any underscores (_)

src/rules/mod.rs Outdated
@@ -235,6 +237,7 @@ pub fn get_default_rules() -> Vec<Box<dyn Rule>> {
Box::<RemoveNilDeclaration>::default(),
Box::<RenameVariables>::default(),
Box::<RemoveFunctionCallParens>::default(),
Box::<RemoveNumberLiterals>::default(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would not put this rule in the default rules, at least for now

struct Processor {}

impl NodeProcessor for Processor {
fn process_expression(&mut self, exp: &mut Expression) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a function for number expressions you can use directly:

Suggested change
fn process_expression(&mut self, exp: &mut Expression) {
fn process_number_expression(&mut self, number: &mut NumberExpression) {

@ewd3v
Copy link

ewd3v commented Feb 3, 2025

I can't see a reason why you would want this, but it might be cool to atleast have an option for it to convert all number literals (so even hex literals like 0xFFFFFFF, like it's doing right now), instead of it only converting binary literals and removing underscores.

… changed to convert_luau_numbers and only converts binary to decimal and removes underscores from token)
@jiwonz jiwonz changed the title Add remove_number_literals rule Add convert_luau_numbers rule Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A way of converting number literals to decimals
3 participants