Skip to content

Commit 5fc648f

Browse files
authored
Add JuliaFormatter (#39)
1 parent c0b48fc commit 5fc648f

File tree

15 files changed

+851
-273
lines changed

15 files changed

+851
-273
lines changed

.JuliaFormatter.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Configuration file for JuliaFormatter.jl
2+
# For more information, see: https://domluna.github.io/JuliaFormatter.jl/stable/config/
3+
4+
always_for_in = true
5+
always_use_return = true
6+
margin = 80
7+
remove_extra_newlines = true
8+
separate_kwargs_with_semicolon = true
9+
short_to_long_function_def = true

.github/workflows/format_check.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: format-check
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- release-*
7+
pull_request:
8+
types: [opened, synchronize, reopened]
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: julia-actions/setup-julia@latest
14+
with:
15+
version: '1'
16+
- uses: actions/checkout@v1
17+
- name: Format check
18+
shell: julia --color=yes {0}
19+
run: |
20+
using Pkg
21+
Pkg.add(PackageSpec(name="JuliaFormatter", version="1"))
22+
using JuliaFormatter
23+
format(".", verbose=true)
24+
out = String(read(Cmd(`git diff`)))
25+
if isempty(out)
26+
exit(0)
27+
end
28+
@error "Some files have not been formatted !!!"
29+
write(stdout, out)
30+
exit(1)

src/DSDP.jl

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ macro dsdp_ccall(f, args...)
1313
quote
1414
# QuoteNode prevents the interpretion of the symbol
1515
# and leave it as a symbol
16-
info = ccall(($(QuoteNode(f)), DSDP_jll.libdsdp), Cint, $(esc.(args)...))
16+
info =
17+
ccall(($(QuoteNode(f)), DSDP_jll.libdsdp), Cint, $(esc.(args)...))
1718
if !iszero(info)
1819
error("DSDP call $($(QuoteNode(f))) returned nonzero status $info.")
1920
end
@@ -29,33 +30,51 @@ include("lpcone.jl")
2930
function CreateLPCone(dsdp::DSDPT)
3031
lpcone = Ref{LPCone.LPConeT}()
3132
@dsdp_ccall DSDPCreateLPCone (DSDPT, Ref{LPCone.LPConeT}) dsdp lpcone
32-
lpcone[]
33+
return lpcone[]
3334
end
3435

3536
include("sdpcone.jl")
3637
function CreateSDPCone(dsdp::DSDPT, n::Integer)
3738
sdpcone = Ref{SDPCone.SDPConeT}()
3839
@dsdp_ccall DSDPCreateSDPCone (DSDPT, Cint, Ref{SDPCone.SDPConeT}) dsdp n sdpcone
39-
sdpcone[]
40+
return sdpcone[]
4041
end
4142

4243
include("bcone.jl")
4344
function CreateBCone(dsdp::DSDPT)
4445
bcone = Ref{BCone.BConeT}()
4546
@dsdp_ccall DSDPCreateBCone (DSDPT, Ref{BCone.BConeT}) dsdp bcone
46-
bcone[]
47+
return bcone[]
4748
end
4849

4950
# Writes to `input.sdpa`
50-
function PrintData(dsdp::DSDPT, sdpcone::SDPCone.SDPConeT, lpcone::LPCone.LPConeT)
51+
function PrintData(
52+
dsdp::DSDPT,
53+
sdpcone::SDPCone.SDPConeT,
54+
lpcone::LPCone.LPConeT,
55+
)
5156
@dsdp_ccall DSDPPrintData (DSDPT, SDPCone.SDPConeT, LPCone.LPConeT) dsdp sdpcone lpcone
5257
end
5358

54-
function PrintSolution(fp::Libc.FILE,dsdp::DSDPT,sdpcone::SDPCone.SDPConeT,lpcone::LPCone.LPConeT)
55-
@dsdp_ccall DSDPPrintSolution (Ptr{Cvoid}, DSDPT, SDPCone.SDPConeT, LPCone.LPConeT) fp dsdp sdpcone lpcone
59+
function PrintSolution(
60+
fp::Libc.FILE,
61+
dsdp::DSDPT,
62+
sdpcone::SDPCone.SDPConeT,
63+
lpcone::LPCone.LPConeT,
64+
)
65+
@dsdp_ccall DSDPPrintSolution (
66+
Ptr{Cvoid},
67+
DSDPT,
68+
SDPCone.SDPConeT,
69+
LPCone.LPConeT,
70+
) fp dsdp sdpcone lpcone
5671
end
5772

58-
function PrintSolution(dsdp::DSDPT,sdpcone::SDPCone.SDPConeT,lpcone::LPCone.LPConeT)
73+
function PrintSolution(
74+
dsdp::DSDPT,
75+
sdpcone::SDPCone.SDPConeT,
76+
lpcone::LPCone.LPConeT,
77+
)
5978
# See https://discourse.julialang.org/t/access-c-stdout-in-julia/24187/2
6079
stdout = Libc.FILE(Libc.RawFD(1), "w")
6180
return PrintSolution(stdout, dsdp, sdpcone, lpcone)

0 commit comments

Comments
 (0)