fmt: insert newline after last HashStmt (#8482)

pull/8495/head
Lukas Neubert 2021-02-01 14:50:41 +01:00 committed by GitHub
parent 53a5aad855
commit d660f2cc6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 32 additions and 13 deletions

View File

@ -1752,7 +1752,7 @@ Global variables are not allowed, so this can be really useful.
When naming constants, `snake_case` must be used. In order to distinguish consts
from local variables, the full path to consts must be specified. For example,
to access the PI const, full `math.pi` name must be used both outside the `math`
module, and inside it. That restriction is relaxed only for the `main` module
module, and inside it. That restriction is relaxed only for the `main` module
(the one containing your `fn main()`, where you can use the shorter name of the
constants too, i.e. just `println(numbers)`, not `println(main.numbers)` .
@ -3413,7 +3413,7 @@ single block. `customflag` should be a snake_case identifier, it can not
contain arbitrary characters (only lower case latin letters + numbers + `_`).
NB: a combinatorial `_d_customflag_linux.c.v` postfix will not work.
If you do need a custom flag file, that has platform dependent code, use the
postfix `_d_customflag.v`, and then use plaftorm dependent compile time
postfix `_d_customflag.v`, and then use plaftorm dependent compile time
conditional blocks inside it, i.e. `$if linux {}` etc.
## Compile time pseudo variables

View File

@ -4,6 +4,7 @@ module big
#flag -I @VROOT/thirdparty/bignum
#flag @VROOT/thirdparty/bignum/bn.o
#include "bn.h"
struct C.bn {
mut:
array [32]u32

View File

@ -2,6 +2,7 @@ module os
#include <sys/stat.h> // #include <signal.h>
#include <errno.h>
struct C.dirent {
d_name [256]char
}

View File

@ -4,6 +4,7 @@
module os
#include "@VROOT/vlib/os/os_darwin.m"
pub const (
sys_write = 4
sys_open = 5

View File

@ -6,6 +6,7 @@ import strings
#include <unistd.h>
#include <fcntl.h>
#include <sys/utsname.h>
pub const (
path_separator = '/'
path_delimiter = ':'

View File

@ -3,6 +3,7 @@ module os
import strings
#include <process.h>
pub const (
path_separator = '\\'
path_delimiter = ';'

View File

@ -4,6 +4,7 @@
module time
#include <time.h>
const (
days_string = 'MonTueWedThuFriSatSun'
month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

View File

@ -1,6 +1,7 @@
module time
#include <mach/mach_time.h>
const (
// start_time is needed on Darwin and Windows because of potential overflows
start_time = C.mach_absolute_time()

View File

@ -4,6 +4,7 @@
module time
#include <time.h>
struct C.tm {
tm_sec int
tm_min int

View File

@ -5,6 +5,7 @@ module time
#include <time.h>
// #include <sysinfoapi.h>
struct C.tm {
tm_year int
tm_mon int

View File

@ -7,6 +7,7 @@ import v.cflag
#flag windows -l shell32
#flag windows -l dbghelp
#flag windows -l advapi32
struct MsvcResult {
full_cl_exe_path string
exe_path string

View File

@ -295,6 +295,9 @@ pub fn (f Fmt) imp_stmt_str(imp ast.Import) string {
fn (mut f Fmt) should_insert_newline_before_stmt(stmt ast.Stmt, prev_stmt ast.Stmt) bool {
prev_line_nr := prev_stmt.position().last_line
if prev_stmt is ast.HashStmt && stmt !is ast.HashStmt && stmt !is ast.ExprStmt {
return true
}
// The stmt either has or shouldn't have a newline before
if stmt.position().line_nr - prev_line_nr <= 1 || f.out.last_n(2) == '\n\n' {
return false

View File

@ -0,0 +1,3 @@
#include "header.h"
struct Foo {}

View File

@ -0,0 +1,2 @@
#include "header.h"
struct Foo {}

View File

@ -0,0 +1,12 @@
// comment above HashStmt
#flag -I @VROOT/c
#flag @VROOT/c/implementation.o
#include "@VROOT/c/implementation.h"
// comment between with newlines around
#include "header.h"
// comment between without newlines
#include "sqlite3.h"
// comment directly after the HsahStmt

View File

@ -1,8 +0,0 @@
// comment above HashStmts
#flag linux -lsdl2
#include "stdio.h"
// comment between with newlines around
#include "header.h"
#include "sqlite3.h"

View File

@ -1,3 +0,0 @@
#flag -I @VROOT/c
#flag @VROOT/c/implementation.o
#include "@VROOT/c/implementation.h"