Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use go modules, analysis package and add test #8

Merged
merged 7 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: Build and test
on:
push:
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ Whitespace is a linter that checks for unnecessary newlines at the start and end

## Installation guide

Whitespace is included in [golangci-lint](https://github.com/golangci/golangci-lint/). Install it and enable whitespace.
To install as a standalone linter, run `go install github.com/ultraware/whitespace`.

Whitespace is also included in [golangci-lint](https://github.com/golangci/golangci-lint/). Install it and enable whitespace.
10 changes: 10 additions & 0 deletions cmd/whitespace/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

import (
"github.com/ultraware/whitespace"
"golang.org/x/tools/go/analysis/singlechecker"
)

func main() {
singlechecker.Main(whitespace.NewAnalyzer(nil))
}
10 changes: 10 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/ultraware/whitespace

go 1.20

require golang.org/x/tools v0.12.0

require (
golang.org/x/mod v0.12.0 // indirect
golang.org/x/sys v0.11.0 // indirect
)
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/tools v0.11.0 h1:EMCa6U9S2LtZXLAMoWiR/R8dAQFRqbAitmbJ2UKhoi8=
golang.org/x/tools v0.11.0/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8=
golang.org/x/tools v0.12.0 h1:YW6HUoUmYBpwSgyaGaZq1fHjrBjX1rlpZ54T6mu2kss=
golang.org/x/tools v0.12.0/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM=
162 changes: 0 additions & 162 deletions main.go

This file was deleted.

85 changes: 85 additions & 0 deletions testdata/src/whitespace_multiline/multiline.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package whitespace

import "fmt"

// No comments, only whitespace.
func fn1() { // want "unnecessary leading newline"

fmt.Println("Hello, World")

} // want "unnecessary trailing newline"

// Whitespace before leading and after trailing comment.
func fn2() { // want "unnecessary leading newline"

// Some leading comments - this should yield error.
fmt.Println("Hello, World")
// And some trailing comments as well!

} // want "unnecessary trailing newline"

// Whitespace after leading and before trailing comment - no diagnostic.
func fn3() {
// This is fine, newline is after comment

fmt.Println("Hello, World")

// This is fine, newline before comment
}

// MultiFunc (FuncDecl), MultiIf and MultiFunc(FuncLit) without newlinew.
func fn4(
arg1 int,
arg2 int,
) { // want "multi-line statement should be followed by a newline"
fmt.Println("Hello, World")

if true &&
false { // want "multi-line statement should be followed by a newline"
fmt.Println("Hello, World")
}

_ = func(
arg1 int,
arg2 int,
) { // want "multi-line statement should be followed by a newline"
fmt.Println("Hello, World")
}

_ = func(
arg1 int,
arg2 int,
) { // want "multi-line statement should be followed by a newline"
_ = func(
arg1 int,
arg2 int,
) { // want "multi-line statement should be followed by a newline"
fmt.Println("Hello, World")
}
}
}


// MultiFunc (FuncDecl), MultiIf and MultiFunc(FuncLit) with comments counting
// as newlines.
func fn5(
arg1 int,
arg2 int,
) {
// Comment count as newline.
fmt.Println("Hello, World")

if true &&
false {
// Comment count as newline.
fmt.Println("Hello, World")
}

_ = func(
arg1 int,
arg2 int,
) {
// Comment count as newline.
fmt.Println("Hello, World")
}
}
85 changes: 85 additions & 0 deletions testdata/src/whitespace_multiline/multiline.go.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package whitespace

import "fmt"

// No comments, only whitespace.
func fn1() { // want "unnecessary leading newline"
fmt.Println("Hello, World")
} // want "unnecessary trailing newline"

// Whitespace before leading and after trailing comment.
func fn2() { // want "unnecessary leading newline"
// Some leading comments - this should yield error.
fmt.Println("Hello, World")
// And some trailing comments as well!
} // want "unnecessary trailing newline"

// Whitespace after leading and before trailing comment - no diagnostic.
func fn3() {
// This is fine, newline is after comment

fmt.Println("Hello, World")

// This is fine, newline before comment
}

// MultiFunc (FuncDecl), MultiIf and MultiFunc(FuncLit) without newlinew.
func fn4(
arg1 int,
arg2 int,
) { // want "multi-line statement should be followed by a newline"

fmt.Println("Hello, World")

if true &&
false { // want "multi-line statement should be followed by a newline"

fmt.Println("Hello, World")
}

_ = func(
arg1 int,
arg2 int,
) { // want "multi-line statement should be followed by a newline"

fmt.Println("Hello, World")
}

_ = func(
arg1 int,
arg2 int,
) { // want "multi-line statement should be followed by a newline"

_ = func(
arg1 int,
arg2 int,
) { // want "multi-line statement should be followed by a newline"

fmt.Println("Hello, World")
}
}
}

// MultiFunc (FuncDecl), MultiIf and MultiFunc(FuncLit) with comments counting
// as newlines.
func fn5(
arg1 int,
arg2 int,
) {
// Comment count as newline.
fmt.Println("Hello, World")

if true &&
false {
// Comment count as newline.
fmt.Println("Hello, World")
}

_ = func(
arg1 int,
arg2 int,
) {
// Comment count as newline.
fmt.Println("Hello, World")
}
}
Loading