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

fmt: a regression was introduced in #22025 (vfmt struct init) #22026

Closed
larpon opened this issue Aug 11, 2024 · 3 comments · Fixed by #22232
Closed

fmt: a regression was introduced in #22025 (vfmt struct init) #22026

larpon opened this issue Aug 11, 2024 · 3 comments · Fixed by #22232
Labels
Bug This tag is applied to issues which reports bugs. Unit: vfmt Bugs/feature requests, that are related to the `vfmt`, the formatter for V.

Comments

@larpon
Copy link
Contributor

larpon commented Aug 11, 2024

Describe the bug

I'm not sure if the follwing vfmt struct init align changes in #22025 was intentional, but in vab a one-liner field: if {} else {} was "unrolled" resulting in a situation where I had to run v fmt -w . twice (See this diff https://github.com/vlang/vab/pull/287/files#diff-d7aec8d71af6b80eee9d9768f16fd94d842270b868b008bf268679456c13df84R520-R527)

The code in question went from:

	deploy_opt := android.DeployOptions{
		verbosity: opt.verbosity
		format: format
		// keystore: keystore
		activity_name: opt.activity_name
		work_dir: opt.work_dir
		v_flags: opt.v_flags
		device_id: opt.device_id
		deploy_file: opt.output
		kill_adb: os.getenv('VAB_KILL_ADB') != ''
		clear_device_log: opt.clear_device_log
		device_log: opt.device_log || opt.device_log_raw
		log_mode: if opt.device_log_raw { android.LogMode.raw } else { android.LogMode.filtered }
		log_tags: log_tags
		run: run
	}

to:

	deploy_opt := android.DeployOptions{
		verbosity: opt.verbosity
		format:    format
		// keystore: keystore
		activity_name:    opt.activity_name
		work_dir:         opt.work_dir
		v_flags:          opt.v_flags
		device_id:        opt.device_id
		deploy_file:      opt.output
		kill_adb:         os.getenv('VAB_KILL_ADB') != ''
		clear_device_log: opt.clear_device_log
		device_log:       opt.device_log || opt.device_log_raw
		log_mode:         if opt.device_log_raw {
			android.LogMode.raw
		} else {
			android.LogMode.filtered
		}
		log_tags: log_tags
		run:      run
	}

Reproduction Steps

It can be seen locally by checking out vlang/vab on master and run v fmt -w cli/options.v

Expected Behavior

I'd argue that the output is prettier if the if {} else {} was kept on one line. Alternatively if it should be "unrolled" it should not take two runs of v fmt -w ..

	deploy_opt := android.DeployOptions{
		verbosity: opt.verbosity
		format:    format
		// keystore: keystore
		activity_name:    opt.activity_name
		work_dir:         opt.work_dir
		v_flags:          opt.v_flags
		device_id:        opt.device_id
		deploy_file:      opt.output
		kill_adb:         os.getenv('VAB_KILL_ADB') != ''
		clear_device_log: opt.clear_device_log
		device_log:       opt.device_log || opt.device_log_raw
		log_mode:         if opt.device_log_raw { android.LogMode.raw } else { android.LogMode.filtered }
		log_tags:         log_tags
		run:              run
	}

Current Behavior

	deploy_opt := android.DeployOptions{
		verbosity: opt.verbosity
		format:    format
		// keystore: keystore
		activity_name:    opt.activity_name
		work_dir:         opt.work_dir
		v_flags:          opt.v_flags
		device_id:        opt.device_id
		deploy_file:      opt.output
		kill_adb:         os.getenv('VAB_KILL_ADB') != ''
		clear_device_log: opt.clear_device_log
		device_log:       opt.device_log || opt.device_log_raw
		log_mode:         if opt.device_log_raw {
			android.LogMode.raw
		} else {
			android.LogMode.filtered
		}
		log_tags: log_tags
		run:      run
	}

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.7 c51d30b

Environment details (OS name and version, etc.)

Linux

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@larpon larpon added the Bug This tag is applied to issues which reports bugs. label Aug 11, 2024
@larpon larpon changed the title fmt: maybe a regression was introduced in #22025 (vfmt string init) fmt: a regression was introduced in #22025 (vfmt string init) Aug 11, 2024
@JalonSolov
Copy link
Contributor

At the least, it would've looked "better" (subjectively, of course) if it had been formatted as

deploy_opt := android.DeployOptions{
		verbosity: opt.verbosity
		format:    format
		// keystore: keystore
		activity_name:    opt.activity_name
		work_dir:         opt.work_dir
		v_flags:          opt.v_flags
		device_id:        opt.device_id
		deploy_file:      opt.output
		kill_adb:         os.getenv('VAB_KILL_ADB') != ''
		clear_device_log: opt.clear_device_log
		device_log:       opt.device_log || opt.device_log_raw
		log_mode:         if opt.device_log_raw {
					android.LogMode.raw
				  } else {
					android.LogMode.filtered
				  }
		log_tags: log_tags
		run:      run
	}

In other words, choose the right-hand alignment point as the base for everything on the right side.

@larpon
Copy link
Contributor Author

larpon commented Aug 11, 2024

Agreed. No matter the style, it is a bug that vfmt needs to be run twice 🙂 (first run creates incorrect formatted code)

@spytheman
Copy link
Member

Yes, ideally, running vfmt should produce stable output, no matter what the source is.

@larpon larpon changed the title fmt: a regression was introduced in #22025 (vfmt string init) fmt: a regression was introduced in #22025 (vfmt struct init) Aug 13, 2024
@spytheman spytheman added the Unit: vfmt Bugs/feature requests, that are related to the `vfmt`, the formatter for V. label Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Unit: vfmt Bugs/feature requests, that are related to the `vfmt`, the formatter for V.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants