Skip to content

Commit

Permalink
fmt: fix formating a file in an oscillating manner (fix #22223, fix #…
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 authored Sep 17, 2024
1 parent c004d0c commit acf6b34
Show file tree
Hide file tree
Showing 99 changed files with 681 additions and 655 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/v_apps_and_modules_compile_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,18 @@ jobs:
echo "Build v-analyzer release"
v build.vsh release
- name: Format vlang/v-analyzer
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: |
cd /tmp/v-analyzer
set +e
v fmt -c .
exit_code=$?
if [[ $exit_code -ne 0 && $exit_code -ne 5 ]]; then
# Don't fail if there are only internal errors (exit code 5).
v fmt -diff .
exit 1
fi
# - name: Format vlang/v-analyzer
# if: ${{ !cancelled() && steps.build.outcome == 'success' }}
# run: |
# cd /tmp/v-analyzer
# set +e
# v fmt -c .
# exit_code=$?
# if [[ $exit_code -ne 0 && $exit_code -ne 5 ]]; then
# # Don't fail if there are only internal errors (exit code 5).
# v fmt -diff .
# exit 1
# fi

- name: Build vlang/go2v
if: ${{ !cancelled() && steps.build.outcome == 'success' && matrix.os != 'macos-14' }}
Expand Down
8 changes: 4 additions & 4 deletions cmd/tools/measure/fmt_speed.v
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ fn process_files(files []string) ! {

fn new_parser(path string, comments_mode scanner.CommentsMode, table &ast.Table, pref_ &pref.Preferences) &parser.Parser {
mut p := &parser.Parser{
scanner: scanner.new_scanner_file(path, comments_mode, pref_) or { panic(err) }
table: table
pref: pref_
scope: &ast.Scope{
scanner: scanner.new_scanner_file(path, comments_mode, pref_) or { panic(err) }
table: table
pref: pref_
scope: &ast.Scope{
start_pos: 0
parent: table.global_scope
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/tools/measure/parser_speed.v
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ fn process_files(files []string) ! {

fn new_parser(path string, comments_mode scanner.CommentsMode, table &ast.Table, pref_ &pref.Preferences) &parser.Parser {
mut p := &parser.Parser{
scanner: scanner.new_scanner_file(path, comments_mode, pref_) or { panic(err) }
table: table
pref: pref_
scope: &ast.Scope{
scanner: scanner.new_scanner_file(path, comments_mode, pref_) or { panic(err) }
table: table
pref: pref_
scope: &ast.Scope{
start_pos: 0
parent: table.global_scope
}
Expand Down
16 changes: 8 additions & 8 deletions cmd/tools/vbump_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ struct BumpTestCase {

const test_cases = [
BumpTestCase{
file_name: 'v.mod'
contents: "Module {
file_name: 'v.mod'
contents: "Module {
name: 'Sample'
description: 'Sample project'
version: '1.2.6'
Expand All @@ -38,8 +38,8 @@ const test_cases = [
expected_major: " version: '2.0.0'"
},
BumpTestCase{
file_name: 'random_versions.vv'
contents: "
file_name: 'random_versions.vv'
contents: "
1.1.2
1.2.5
3.21.73
Expand All @@ -52,8 +52,8 @@ version = '1.5.1'
expected_major: "version = '2.0.0'"
},
BumpTestCase{
file_name: 'sample_tool.v'
contents: "// Module comment and copyright information
file_name: 'sample_tool.v'
contents: "// Module comment and copyright information
import os
import flag
Expand Down Expand Up @@ -110,8 +110,8 @@ struct SkipTestCase {

const skip_test_cases = [
SkipTestCase{
file_name: 'CITATION.cff'
contents: 'abstract: A sample CLI tool made in V that prints geometric shapes to the screen.
file_name: 'CITATION.cff'
contents: 'abstract: A sample CLI tool made in V that prints geometric shapes to the screen.
authors:
- alias: hungrybluedev
family-names: Haldar
Expand Down
6 changes: 3 additions & 3 deletions cmd/tools/vcreate/vcreate.v
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn main() {
},
]
mut cmd := Command{
flags: [
flags: [
Flag{
flag: .bool
name: 'help'
Expand All @@ -70,7 +70,7 @@ fn main() {
'The <project_name> argument can be omitted and entered in the prompts dialog.',
'If git is installed, `git init` will be performed during the setup.',
].join_lines()
parent: &Command{
parent: &Command{
name: 'v'
}
posix_mode: true
Expand All @@ -87,7 +87,7 @@ fn main() {
'If no `.v` file exists, a project template is generated. If the current directory is not a',
'git project and git is installed, `git init` will be performed during the setup.',
].join_lines()
parent: &Command{
parent: &Command{
name: 'v'
}
posix_mode: true
Expand Down
2 changes: 1 addition & 1 deletion cmd/tools/vdoc/files.v
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mut:
// Default ignore patterns.
'': ['testdata', 'tests', '*_test.v']
}
paths map[string]bool
paths map[string]bool
}

fn get_modules(path string) []string {
Expand Down
2 changes: 1 addition & 1 deletion cmd/tools/vdoc/html.v
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ fn (mut vd VDoc) create_search_results(mod string, dn doc.DocNode, out Output) {
dn_description := trim_doc_node_description(dn.name, comments)
vd.search_index << dn.name
vd.search_data << SearchResult{
prefix: if dn.parent_name != '' {
prefix: if dn.parent_name != '' {
'${dn.kind} (${dn.parent_name})'
} else {
'${dn.kind} '
Expand Down
2 changes: 1 addition & 1 deletion cmd/tools/vdoc/vdoc.v
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ fn (mut vd VDoc) generate_docs_from_file() {
println(markdown.to_plain(readme_contents))
} else if out.typ == .html && cfg.is_multi {
vd.docs << doc.Doc{
head: doc.DocNode{
head: doc.DocNode{
name: 'README'
comments: [comment]
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/tools/vrepl.v
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn new_repl(folder string) Repl {
vstartup_source := os.read_file(vstartup) or { '' }.trim_right('\n\r').split_into_lines()
os.mkdir_all(folder) or {}
return Repl{
readline: readline.Readline{
readline: readline.Readline{
skip_empty: true
}
folder: folder
Expand Down
8 changes: 4 additions & 4 deletions examples/2048/2048.v
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ fn on_event(e &gg.Event, mut app App) {
if e.num_touches > 0 {
t := e.touches[0]
app.touch.start = Touch{
pos: Pos{
pos: Pos{
x: int(t.pos_x / app.ui.dpi_scale)
y: int(t.pos_y / app.ui.dpi_scale)
}
Expand All @@ -839,7 +839,7 @@ fn on_event(e &gg.Event, mut app App) {
if e.num_touches > 0 {
t := e.touches[0]
app.touch.end = Touch{
pos: Pos{
pos: Pos{
x: int(t.pos_x / app.ui.dpi_scale)
y: int(t.pos_y / app.ui.dpi_scale)
}
Expand All @@ -850,7 +850,7 @@ fn on_event(e &gg.Event, mut app App) {
}
.mouse_down {
app.touch.start = Touch{
pos: Pos{
pos: Pos{
x: int(e.mouse_x / app.ui.dpi_scale)
y: int(e.mouse_y / app.ui.dpi_scale)
}
Expand All @@ -859,7 +859,7 @@ fn on_event(e &gg.Event, mut app App) {
}
.mouse_up {
app.touch.end = Touch{
pos: Pos{
pos: Pos{
x: int(e.mouse_x / app.ui.dpi_scale)
y: int(e.mouse_y / app.ui.dpi_scale)
}
Expand Down
8 changes: 4 additions & 4 deletions examples/clock/clock.v
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ const second_hand_color = gx.red
struct App {
minutes_tic []f32 = [f32(center - tw), tp, center + tw, tp, center + tw, tp, center + tw,
tp + 1 * th, center - tw, tp + 1 * th]
hours_tic []f32 = [f32(center - tw), tp, center + tw, tp, center + tw, tp, center + tw, tp + 2 * th,
center - tw, tp + 2 * th]
hours3_tic []f32 = [f32(center - tw), tp, center + tw, tp, center + tw, tp, center + tw, tp + 3 * th,
center - tw, tp + 3 * th]
hours_tic []f32 = [f32(center - tw), tp, center + tw, tp, center + tw, tp, center + tw,
tp + 2 * th, center - tw, tp + 2 * th]
hours3_tic []f32 = [f32(center - tw), tp, center + tw, tp, center + tw, tp, center + tw,
tp + 3 * th, center - tw, tp + 3 * th]

hour_hand []f32 = [f32(329), 161, 350, 140, 371, 161, 371, 413, 329, 413]
minute_hand []f32 = [f32(334.25), 40.25, 350, 24.5, 365.75, 40.25, 365.75, 427, 334.25, 427]
Expand Down
2 changes: 1 addition & 1 deletion examples/fireworks/modules/objects/rocket.v
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn new_rocket() Rocket {
pos: Vector{
x: rand.f32_in_range(50, get_params().width - 50) or { 50 }
}
vel: Vector{
vel: Vector{
x: rand.f32_in_range(-1.5, 1.5) or { -1.5 }
y: rand.f32_in_range(5, 7) or { 5 }
}
Expand Down
4 changes: 2 additions & 2 deletions examples/flag/animated_help_text.v
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ fn frame(mut app App) {
description: 'Hello! This should show an *animated* example application description.
We are at frame ${app.frame}.
Press ESCAPE or Ctrl+C to exit'
footer: '
footer: '
Press ESCAPE or Ctrl+C to exit'
fields: {
fields: {
'level': 'Level of lorem ipsum\nand more\nmany many many more.\nNotice how user newlines/format is kept since\ninput lines are all less or within\nthe default layout.description_padding\nand max width'
'example': 'Looong example text without newlines or anything else and lorem ipsum and more and many many many more. Should be auto fitted'
'multi': 'This flag can be repeated'
Expand Down
8 changes: 4 additions & 4 deletions examples/flag/flag_layout_editor.v
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@ Editing property: ${app.edit}, value: ${value}')
help_text := flag.to_doc[DocTest](
description: 'Simple DocLayout editor.
Press ESCAPE or Ctrl+C to exit and print layout code'
footer: '
footer: '
Press ESCAPE or Ctrl+C to exit and print layout code'
fields: unsafe { field_docs }
layout: app.layout
options: app.options
fields: unsafe { field_docs }
layout: app.layout
options: app.options
) or { '' }

app.tui.draw_text(0, 5, '${help_text}')
Expand Down
24 changes: 12 additions & 12 deletions examples/gg/additive.v
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ pub fn (mut window Window) draw(_ voidptr) {
x: myconfig.img_rect.x + f32(math.sin(f32(window.ctx.frame) / 10.0) * 60)
y: myconfig.img_rect.y + f32(math.cos(f32(window.ctx.frame) / 10.0) * 60)
}
color: gx.Color{255, 0, 0, 255}
effect: .add
color: gx.Color{255, 0, 0, 255}
effect: .add
})

// Green
Expand All @@ -54,8 +54,8 @@ pub fn (mut window Window) draw(_ voidptr) {
x: myconfig.img_rect.x + f32(math.sin(f32(window.ctx.frame) / 10.0) * 80)
y: myconfig.img_rect.y + f32(math.cos(f32(window.ctx.frame) / 10.0) * 80)
}
color: gx.Color{0, 255, 0, 255}
effect: .add
color: gx.Color{0, 255, 0, 255}
effect: .add
})

// Blue
Expand All @@ -66,8 +66,8 @@ pub fn (mut window Window) draw(_ voidptr) {
x: myconfig.img_rect.x + f32(math.sin(f32(window.ctx.frame) / 10.0) * 100)
y: myconfig.img_rect.y + f32(math.cos(f32(window.ctx.frame) / 10.0) * 100)
}
color: gx.Color{0, 0, 255, 255}
effect: .add
color: gx.Color{0, 0, 255, 255}
effect: .add
})

// More examples
Expand All @@ -78,8 +78,8 @@ pub fn (mut window Window) draw(_ voidptr) {
x: 50
y: 0
}
color: gx.Color{255, 0, 0, 255}
effect: .add
color: gx.Color{255, 0, 0, 255}
effect: .add
})

window.ctx.draw_image_with_config(gg.DrawImageConfig{
Expand All @@ -89,8 +89,8 @@ pub fn (mut window Window) draw(_ voidptr) {
x: 50
y: 50
}
color: gx.Color{0, 255, 0, 255}
effect: .add
color: gx.Color{0, 255, 0, 255}
effect: .add
})

window.ctx.draw_image_with_config(gg.DrawImageConfig{
Expand All @@ -100,8 +100,8 @@ pub fn (mut window Window) draw(_ voidptr) {
x: 50
y: 100
}
color: gx.Color{0, 0, 255, 255}
effect: .add
color: gx.Color{0, 0, 255, 255}
effect: .add
})

window.ctx.end()
Expand Down
6 changes: 3 additions & 3 deletions examples/gg/digital_rain.v
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn rain(mut app App) {
init_fn: fn (mut app App) {
gg.toggle_fullscreen()
}
event_fn: fn (event &gg.Event, mut app App) {
event_fn: fn (event &gg.Event, mut app App) {
vprintln('event.typ: ${event.typ} | event.char_code: ${event.char_code}')
if event.typ == .resized {
app.should_calc = true
Expand All @@ -63,7 +63,7 @@ fn rain(mut app App) {
app.delay = if new_delay > 0 { new_delay } else { 0 }
}
}
frame_fn: frame
frame_fn: frame
)
app.ctx.run()
}
Expand Down Expand Up @@ -146,7 +146,7 @@ fn draw_rain_column(rc RainColumn, app App) {
b: if at_head { u8(255) } else { 0 }
a: alpha
}
mono: true
mono: true
}
if i < rc.drops.len {
app.ctx.draw_text(x, y, rc.drops[i].ascii_str(), cfg)
Expand Down
2 changes: 1 addition & 1 deletion examples/gg/path_finding_algorithm_visualizer/aStar.v
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ fn astar_path_finding(mut app App, mut grid [][]Cell, start Point, end Point) {
x: start.x
y: start.y
}
count: 0
count: 0
})

for priority_queue.len() > 0 {
Expand Down
2 changes: 1 addition & 1 deletion examples/macos_tray/tray.v
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn main() {
}

my_app.tray_info = C.tray_app_init(TrayParams{
items: [TrayMenuItem{
items: [TrayMenuItem{
id: 'hello'
text: 'Hello'
}, TrayMenuItem{
Expand Down
2 changes: 1 addition & 1 deletion examples/pendulum-simulation/modules/sim/params_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const params_test_mock_state = SimState{
y: -12.559375680227724
z: -105.91539687686381
)
accel: vector(
accel: vector(
x: -8.337034766251843e-11
y: -2.842170943040401e-10
z: 1.2126596023639044e-10
Expand Down
2 changes: 1 addition & 1 deletion examples/pendulum-simulation/modules/sim/sim_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const sim_test_mock_state = SimState{
y: -12.559375680227724
z: -105.91539687686381
)
accel: vector(
accel: vector(
x: -8.337034766251843e-11
y: -2.842170943040401e-10
z: 1.2126596023639044e-10
Expand Down
Loading

0 comments on commit acf6b34

Please sign in to comment.