Skip to content

Commit

Permalink
Lint Go code
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmeuli committed Apr 28, 2020
1 parent 46bc931 commit 81f2f02
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 5 deletions.
30 changes: 29 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- pull_request

jobs:
lint:
lint-swift:
name: Lint
runs-on: macos-latest

Expand All @@ -31,3 +31,31 @@ jobs:
run: |
mint run swiftlint --quiet --strict
mint run swiftformat --lint .
lint-go:
name: Lint
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./HTMLConverter/

steps:
- name: Check out Git repository
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.14

- name: Restore Go Modules cache
id: go-mod-cache
uses: actions/cache@v1
with:
path: ~/go/pkg/mod/
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-mod-
- name: Run linters
run: docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.25.1 golangci-lint run
25 changes: 25 additions & 0 deletions HTMLConverter/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
output:
print-issued-lines: false

linters:
enable-all: true
disable:
- funlen
- gochecknoglobals
- gocognit
- gomnd
- maligned
- testpackage
- wsl

linters-settings:
lll:
max-length: 100
tab-width: 2

issues:
max-issues-per-linter: 0
max-same-issues: 0
exclude-use-default: false
exclude:
- "Line contains TODO/BUG/FIXME"
Binary file modified HTMLConverter/htmlconverter.a
Binary file not shown.
8 changes: 7 additions & 1 deletion HTMLConverter/htmlconverter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"C"
"bytes"
"fmt"
"regexp"

"github.com/Depado/bfchroma"
"github.com/alecthomas/chroma"
htmlFormatter "github.com/alecthomas/chroma/formatters/html"
Expand All @@ -12,7 +14,6 @@ import (
"github.com/microcosm-cc/bluemonday"
"github.com/samuelmeuli/nbtohtml"
"gopkg.in/russross/blackfriday.v2"
"regexp"
)

// Regex for YAML front matter in a Markdown document
Expand All @@ -33,6 +34,8 @@ func convertToGoString(cString *C.char) string {
// start with "error: ".

//export convertCodeToHTML
// convertCodeToHTML converts the provided source code string to HTML. Classes for syntax
// highlighting are generated using Chroma.
func convertCodeToHTML(source *C.char, lexer *C.char) *C.char {
sourceString := convertToGoString(source)
lexerString := convertToGoString(lexer)
Expand Down Expand Up @@ -72,6 +75,8 @@ func convertCodeToHTML(source *C.char, lexer *C.char) *C.char {
}

//export convertMarkdownToHTML
// convertMarkdownToHTML converts the provided Markdown string to HTML using Blackfriday. Classes
// for syntax highlighting inside code blocks are generated using Chroma.
func convertMarkdownToHTML(source *C.char) *C.char {
sourceString := convertToGoString(source)

Expand All @@ -96,6 +101,7 @@ func convertMarkdownToHTML(source *C.char) *C.char {
}

//export convertNotebookToHTML
// convertNotebookToHTML converts the provided Jupyter Notebook JSON to HTML using `nbtohtml`.
func convertNotebookToHTML(source *C.char) *C.char {
sourceString := convertToGoString(source)

Expand Down
8 changes: 8 additions & 0 deletions HTMLConverter/htmlconverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,18 @@ extern "C" {
#endif


// convertCodeToHTML converts the provided source code string to HTML. Classes for syntax
// highlighting are generated using Chroma.

extern char* convertCodeToHTML(char* p0, char* p1);

// convertMarkdownToHTML converts the provided Markdown string to HTML using Blackfriday. Classes
// for syntax highlighting inside code blocks are generated using Chroma.

extern char* convertMarkdownToHTML(char* p0);

// convertNotebookToHTML converts the provided Jupyter Notebook JSON to HTML using `nbtohtml`.

extern char* convertNotebookToHTML(char* p0);

#ifdef __cplusplus
Expand Down
7 changes: 4 additions & 3 deletions HTMLConverter/htmlconverter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package main

import (
"fmt"
"strings"
"testing"

"github.com/stretchr/testify/assert"
"github.com/tdewolff/minify/v2"
"github.com/tdewolff/minify/v2/html"
"strings"
"testing"
)

var minifier *minify.M
Expand Down Expand Up @@ -58,7 +59,7 @@ Text`
}

func TestConvertNotebookToHTML(t *testing.T) {
source := `{"cells":[{"cell_type":"code","execution_count":1,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["Hello world\n"]}],"source":["print(\"Hello world\")"]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.8.2"}},"nbformat":4,"nbformat_minor":4}`
source := `{"cells":[{"cell_type":"code","execution_count":1,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["Hello world\n"]}],"source":["print(\"Hello world\")"]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.8.2"}},"nbformat":4,"nbformat_minor":4}` // nolint:lll
actual := convertToGoString(convertNotebookToHTML(convertToCString(source)))
actualTrimmed := strings.TrimSpace(actual)
assert.True(t, strings.HasPrefix(actualTrimmed, `<div class="notebook">`))
Expand Down

0 comments on commit 81f2f02

Please sign in to comment.