Skip to content

Commit

Permalink
Merge branch 'main' into feat/add-html-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
mohkale authored Apr 22, 2023
2 parents 7cbf89b + 568862d commit 4860478
Show file tree
Hide file tree
Showing 23 changed files with 440 additions and 1 deletion.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,30 @@ The format is based on [Keep a Changelog].
### Formatters

* [purs-tidy](https://github.com/natefaubion/purescript-tidy) for PureScript ([#182]).
* [`jq`](https://stedolan.github.io/jq/) for
[JSON](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/JSON)
([#174]).
* [`gawk`](https://www.gnu.org/software/gawk/) for
[awk](https://en.wikipedia.org/wiki/AWK) ([#187]).
* [`asmfmt`](https://github.com/klauspost/asmfmt) for assembly ([#168]).
* [`astyle`](https://github.com/steinwurf/astyle) for C ([#169]).
* [`beautysh`](https://github.com/lovesegfault/beautysh) for shell
scripts ([#170])
* [`buildifier`](https://github.com/bazelbuild/buildtools)
for [Bazel Build](https://bazel.build/) ([#171]).
* [`cmake-format`](https://github.com/cheshirekow/cmake_format)
for [CMake](https://cmake.org/) ([#172]).
* [`html-tidy`](https://www.html-tidy.org/) for HTML/XML ([#173]).

[#168]: https://github.com/radian-software/apheleia/pull/168
[#169]: https://github.com/radian-software/apheleia/pull/169
[#170]: https://github.com/radian-software/apheleia/pull/170
[#171]: https://github.com/radian-software/apheleia/pull/171
[#172]: https://github.com/radian-software/apheleia/pull/172
[#173]: https://github.com/radian-software/apheleia/pull/173
[#174]: https://github.com/radian-software/apheleia/pull/174
[#182]: https://github.com/radian-software/apheleia/pull/182
[#187]: https://github.com/radian-software/apheleia/pull/187

## 3.2 (released 2023-02-25)
### Features
Expand Down
20 changes: 19 additions & 1 deletion apheleia.el
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,32 @@
:link '(emacs-commentary-link :tag "Commentary" "apheleia"))

(defcustom apheleia-formatters
'((bean-format . ("bean-format"))
'((astyle . ("astyle" (apheleia-formatters-locate-file
"--options" ".astylerc")))
(asmfmt . ("asmfmt"))
(bean-format . ("bean-format"))
(beautysh . ("beautysh"
(apheleia-formatters-indent
"--tab" "--indent-size" 'sh-basic-offset)
"-"))
(black . ("black"
(when (apheleia-formatters-extension-p "pyi") "--pyi")
(apheleia-formatters-fill-column "--line-length")
"-"))
(brittany . ("brittany"))
(buildifier . ("buildifier"))
(caddyfmt . ("caddy" "fmt" "-"))
(clang-format . ("clang-format"
"-assume-filename"
(or (buffer-file-name)
(apheleia-formatters-mode-extension)
".c")))
(cmake-format . ("cmake-format" "-"))
(crystal-tool-format . ("crystal" "tool" "format" "-"))
(dart-format . ("dart" "format"))
(elm-format . ("elm-format" "--yes" "--stdin"))
(fish-indent . ("fish_indent"))
(gawk . ("gawk" "-f" "-" "--pretty-print=-"))
(gofmt . ("gofmt"))
(gofumpt . ("gofumpt"))
(goimports . ("goimports"))
Expand All @@ -69,6 +79,8 @@
'web-mode-indent-style)))
(apheleia-formatters-fill-column "-wrap"))
(isort . ("isort" "-"))
(jq "jq" "."
(apheleia-formatters-js-indent "--tab" "--indent"))
(lisp-indent . apheleia-indent-lisp-buffer)
(ktlint . ("ktlint" "--log-level=none" "--stdin" "-F" "-"))
(latexindent . ("latexindent" "--logfile=/dev/null"))
Expand Down Expand Up @@ -202,7 +214,10 @@ rather than using this system."
(json-mode . prettier-json)
(json-ts-mode . prettier-json)
;; rest are alphabetical
(asm-mode . asmfmt)
(awk-mode . gawk)
(bash-ts-mode . shfmt)
(bazel-mode . buildifier)
(beancount-mode . bean-format)
(c++-ts-mode . clang-format)
(caddyfile-mode . caddyfmt)
Expand All @@ -211,6 +226,8 @@ rather than using this system."
(c-ts-mode . clang-format)
(c++-mode . clang-format)
(caml-mode . ocamlformat)
(cmake-mode . cmake-format)
(cmake-ts-mode . cmake-format)
(common-lisp-mode . lisp-indent)
(crystal-mode . crystal-tool-format)
(css-mode . prettier-css)
Expand All @@ -236,6 +253,7 @@ rather than using this system."
(LaTeX-mode . latexindent)
(lua-mode . stylua)
(lisp-mode . lisp-indent)
(nasm-mode . asmfmt)
(nix-mode . nixfmt)
(purescript-mode . purs-tidy)
(python-mode . black)
Expand Down
6 changes: 6 additions & 0 deletions test/formatters/installers/asmfmt.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version=1.3.2

dest=$(mktemp -d)
curl -L "https://github.com/klauspost/asmfmt/releases/download/v$version/asmfmt-Linux_x86_64_$version.tar.gz" | tar -xvzC "$dest"
mv "$dest/asmfmt" /usr/local/bin/asmfmt
rm -rf "$dest"
1 change: 1 addition & 0 deletions test/formatters/installers/astyle.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apt-get install -y astyle
2 changes: 2 additions & 0 deletions test/formatters/installers/beautysh.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
apt-get install -y python3-pip
pip3 install beautysh
2 changes: 2 additions & 0 deletions test/formatters/installers/buildifier.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version=6.0.1
curl -L --output /usr/local/bin/buildifier "https://github.com/bazelbuild/buildtools/releases/download/$version/buildifier-linux-amd64" && chmod +x /usr/local/bin/buildifier
2 changes: 2 additions & 0 deletions test/formatters/installers/cmake-format.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
apt-get install -y python3-pip
pip3 install cmakelang
1 change: 1 addition & 0 deletions test/formatters/installers/gawk.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apt-get install -y gawk
1 change: 1 addition & 0 deletions test/formatters/installers/jq.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apt-get install -y jq
45 changes: 45 additions & 0 deletions test/formatters/samplecode/asmfmt/in.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Taken from https://files.klauspost.com/diff.html

#include "zasm_GOOS_GOARCH.h"
#include "funcdata.h"
#include "textflag.h"

TEXT runtime·rt0_go(SB),NOSPLIT,$0
// copy arguments forward on an even stack
MOVQ DI, AX // argc
MOVQ SI, BX // argv
SUBQ $(4*8+7), SP // 2args 2auto
ANDQ $~15, SP
MOVQ AX, 16(SP)
MOVQ BX, 24(SP)
// create istack out of the given (operating system) stack.
// _cgo_init may update stackguard.
MOVQ $runtime·g0(SB), DI
LEAQ (-64*1024+104)(SP), BX
MOVQ BX, g_stackguard0(DI)
MOVQ BX, g_stackguard1(DI)
MOVQ BX, (g_stack+stack_lo)(DI)
MOVQ SP, (g_stack+stack_hi)(DI)

// find out information about the processor we're on
MOVQ $0, AX
CPUID
CMPQ AX, $0
JE nocpuinfo
MOVQ $1, AX
CPUID
MOVL CX, runtime·cpuid_ecx(SB)
MOVL DX, runtime·cpuid_edx(SB)
nocpuinfo:
// if there is an _cgo_init, call it.
MOVQ _cgo_init(SB), AX
TESTQ AX, AX
JZ needtls
// g0 already in DI
MOVQ DI, CX // Win64 uses CX for first parameter
MOVQ $setg_gcc<>(SB), SI
CALL AX


46 changes: 46 additions & 0 deletions test/formatters/samplecode/asmfmt/out.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Taken from https: // files.klauspost.com/diff.html

#include "zasm_GOOS_GOARCH.h"
#include "funcdata.h"
#include "textflag.h"

TEXT runtime·rt0_go(SB), NOSPLIT, $0
// copy arguments forward on an even stack
MOVQ DI, AX // argc
MOVQ SI, BX // argv
SUBQ $(4*8+7), SP // 2args 2auto
ANDQ $~15, SP
MOVQ AX, 16(SP)
MOVQ BX, 24(SP)

// create istack out of the given (operating system) stack.
// _cgo_init may update stackguard.
MOVQ $runtime·g0(SB), DI
LEAQ (-64*1024+104)(SP), BX
MOVQ BX, g_stackguard0(DI)
MOVQ BX, g_stackguard1(DI)
MOVQ BX, (g_stack+stack_lo)(DI)
MOVQ SP, (g_stack+stack_hi)(DI)

// find out information about the processor we're on
MOVQ $0, AX
CPUID
CMPQ AX, $0
JE nocpuinfo
MOVQ $1, AX
CPUID
MOVL CX, runtime·cpuid_ecx(SB)
MOVL DX, runtime·cpuid_edx(SB)

nocpuinfo:

// if there is an _cgo_init, call it.
MOVQ _cgo_init(SB), AX
TESTQ AX, AX
JZ needtls

// g0 already in DI
MOVQ DI, CX // Win64 uses CX for first parameter
MOVQ $setg_gcc<>(SB), SI
CALL AX

1 change: 1 addition & 0 deletions test/formatters/samplecode/astyle/in.c
5 changes: 5 additions & 0 deletions test/formatters/samplecode/astyle/out.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// https://www.ioccc.org/2020/burton/prog.c
int main(int b,char**i) {
long long n=B,a=I^n,r=(a/b&a)>>4,y=atoi(*++i),_=(((a^n/b)*(y>>T)|y>>S)&r)|(a^r);
printf("%.8s\n",(char*)&_);
}
1 change: 1 addition & 0 deletions test/formatters/samplecode/beautysh/in.bash
2 changes: 2 additions & 0 deletions test/formatters/samplecode/beautysh/out.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
function f(){
thing;}
4 changes: 4 additions & 0 deletions test/formatters/samplecode/buildifier/in.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library");cc_library(
name="hello-greet",
srcs=["hello-greet.cc"],
hdrs=["hello-greet.h"]);cc_binary(name="hello-world", srcs=["hello-world.cc"], deps=[":hello-greet", "//lib:hello-time"])
8 changes: 8 additions & 0 deletions test/formatters/samplecode/buildifier/out.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")

cc_library(
name = "hello-greet",
srcs = ["hello-greet.cc"],
hdrs = ["hello-greet.h"],
)
cc_binary(name = "hello-world", srcs = ["hello-world.cc"], deps = [":hello-greet", "//lib:hello-time"])
97 changes: 97 additions & 0 deletions test/formatters/samplecode/cmake-format/in.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# The following multiple newlines should be collapsed into a single newline




cmake_minimum_required(VERSION 2.8.11)
project(cmakelang_test)

# This multiline-comment should be reflowed
# into a single comment
# on one line

# This comment should remain right before the command call.
# Furthermore, the command call should be formatted
# to a single line.
add_subdirectories(foo bar baz
foo2 bar2 baz2)

# This very long command should be wrapped
set(HEADERS very_long_header_name_a.h very_long_header_name_b.h very_long_header_name_c.h)

# This command should be split into one line per entry because it has a long argument list.
set(SOURCES source_a.cc source_b.cc source_d.cc source_e.cc source_f.cc source_g.cc source_h.cc)

# The string in this command should not be split
set_target_properties(foo bar baz PROPERTIES COMPILE_FLAGS "-std=c++11 -Wall -Wextra")

# This command has a very long argument and can't be aligned with the command
# end, so it should be moved to a new line with block indent + 1.
some_long_command_name("Some very long argument that really needs to be on the next line.")

# This situation is similar but the argument to a KWARG needs to be on a
# newline instead.
set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -Wno-sign-compare -Wno-unused-parameter -xx")

set(HEADERS header_a.h header_b.h # This comment should
# be preserved, moreover it should be split
# across two lines.
header_c.h header_d.h)


# This part of the comment should
# be formatted
# but...
# cmake-format: off
# This bunny should remain untouched:
# .   _ ∩
#   レヘヽ| |
#     (・x・)
#    c( uu}
# cmake-format: on
# while this part should
# be formatted again

# This is a paragraph
#
# This is a second paragraph
#
# This is a third paragraph

# This is a comment
# that should be joined

if(foo)
if(sbar)
# This comment is in-scope.
add_library(foo_bar_baz foo.cc bar.cc # this is a comment for arg2
# this is more comment for arg2, it should be joined with the first.
baz.cc) # This comment is part of add_library

other_command(some_long_argument some_long_argument) # this comment is very long and gets split across some lines

other_command(some_long_argument some_long_argument some_long_argument) # this comment is even longer and wouldn't make sense to pack at the end of the command so it gets it's own lines
endif()
endif()


# This very long command should be broken up along keyword arguments
foo(nonkwarg_a nonkwarg_b HEADERS a.h b.h c.h d.h e.h f.h SOURCES a.cc b.cc d.cc DEPENDS foo bar baz)

# This command uses a string with escaped quote chars
foo(some_arg some_arg "This is a \"string\" within a string")

# This command uses an empty string
foo(some_arg some_arg "")

# This command uses a multiline string
foo(some_arg some_arg "
This string is on multiple lines
")

# No, I really want this to look ugly
# cmake-format: off
add_library(a b.cc
c.cc d.cc
e.cc)
# cmake-format: on
Loading

0 comments on commit 4860478

Please sign in to comment.