Skip to content

Commit c9aa9e3

Browse files
authored
chore: ci & dev environment improvements (#13)
* chore: dev environment * ci: improved ci * feat: update go version to 1.22 for flake * docs: added coverage status badge * fix: minor code refactors
1 parent ff315d0 commit c9aa9e3

13 files changed

+165
-33
lines changed

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.github/workflows/ci.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
branches: "**"
6+
pull_request:
7+
branches: "**"
8+
workflow_dispatch:
9+
10+
jobs:
11+
test:
12+
strategy:
13+
matrix:
14+
go-version: [1.21.x, 1.22.x]
15+
os: [ubuntu-latest]
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
- name: Set up Go
21+
uses: actions/setup-go@v5
22+
with:
23+
go-version: ${{ matrix.go-version }}
24+
# - name: Set up Make
25+
# run: sudo apt-get install make
26+
- name: Run tests
27+
#run: make test
28+
run: go test ./...
29+
golangci:
30+
name: lint
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v4
34+
- uses: actions/setup-go@v5
35+
with:
36+
go-version: 1.22.x
37+
- name: golangci-lint
38+
uses: golangci/golangci-lint-action@v4
39+
with:
40+
version: latest

.github/workflows/test.yaml

Lines changed: 0 additions & 20 deletions
This file was deleted.

.github/workflows/testCoverage.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Coverage
2+
3+
on:
4+
push:
5+
branches: [master]
6+
workflow_dispatch:
7+
8+
jobs:
9+
coverage:
10+
strategy:
11+
matrix:
12+
go-version: [1.21.x, 1.22.x]
13+
os: [ubuntu-latest, macos-latest, windows-latest]
14+
runs-on: ${{ matrix.os }}
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Install Go
20+
uses: actions/setup-go@v5
21+
with:
22+
go-version: ${{ matrix.go-version }}
23+
24+
- name: Test
25+
run: go test -race -covermode=atomic -coverprofile="profile.cov" ./...
26+
27+
- name: Send Coverage
28+
if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.22.x'
29+
uses: shogo82148/actions-goveralls@v1
30+
with:
31+
path-to-profile: profile.cov

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
tailwind-merge/
2+
playground
3+
.idea
4+
.direnv
5+
*.cov
6+
*.out

.goignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
assets/
2+
*.md
3+
docs/

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
1+
test-watch:
2+
@gotestsum --format=short-verbose --watch
23

34
test:
4-
go test -v -cover ./pkg/twmerge...
5+
@gotestsum --format=short-verbose
6+
7+
test-cover:
8+
@CGO_ENABLED=1 gotestsum -- -race -covermode=atomic -coverprofile="profile.cov" ./... && go tool cover -func=profile.cov | grep -v "100.0%"
9+
10+
lint:
11+
@go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<a href="https://pkg.go.dev/github.com/Oudwins/tailwind-merge-go"><img src="https://pkg.go.dev/badge/github.com//github.com/Oudwins/tailwind-merge-go.svg" alt="Go Reference" /></a>
1111
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
1212
[![Go Report Card](https://goreportcard.com/badge/Oudwins/tailwind-merge-go)](https://goreportcard.com/report/github.com/Oudwins/tailwind-merge-go)
13+
[![Coverage Status](https://coveralls.io/repos/github/Oudwins/tailwind-merge-go/badge.svg?branch=master)](https://coveralls.io/github/Oudwins/tailwind-merge-go?branch=master)
1314

1415
Utility function to efficiently merge Tailwind CSS classes in Golang without style conflicts. This library aims to be as close as possible to a 1:1 copy of the original [dcastil/tailwind-merge](https://github.com/dcastil/tailwind-merge/) library written in javascript.
1516

flake.lock

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
description = "A Nix-flake-based Go 1.22 development environment";
3+
4+
inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.*.tar.gz";
5+
6+
outputs = { self, nixpkgs }:
7+
let
8+
goVersion = 22; # Change this to update the whole stack
9+
10+
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
11+
forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f {
12+
pkgs = import nixpkgs {
13+
inherit system;
14+
overlays = [ self.overlays.default ];
15+
};
16+
});
17+
in
18+
{
19+
overlays.default = final: prev: {
20+
go = final."go_1_${toString goVersion}";
21+
};
22+
23+
devShells = forEachSupportedSystem ({ pkgs }: {
24+
default = pkgs.mkShell {
25+
packages = with pkgs; [
26+
# go (version is specified by overlay)
27+
go
28+
29+
# goimports, godoc, etc.
30+
gotools
31+
32+
# https://github.com/golangci/golangci-lint
33+
golangci-lint
34+
35+
# Tests summaries
36+
gotestsum
37+
];
38+
shellHook = ''
39+
export CGO_ENABLED="0" # disables cgo. Not sure why this fixes debugger on tests in vscode
40+
'';
41+
};
42+
});
43+
};
44+
}

pkg/twmerge/class-utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func MakeGetClassGroupId(conf *TwMergeConfig) GetClassGroupIdfn {
2626
}
2727
}
2828

29-
if classMap.Validators != nil && len(classMap.Validators) > 0 {
29+
if len(classMap.Validators) > 0 {
3030
remainingClass := strings.Join(classParts[i:], string(conf.ClassSeparator))
3131

3232
for _, validator := range classMap.Validators {

pkg/twmerge/create-tailwind-merge_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,9 +528,9 @@ func TestTailwindMerge(t *testing.T) {
528528
got := Merge(tc.in)
529529
if areStringsEqual(got, tc.out) == false {
530530
t.Errorf("twMerge failed -> | in: %v | %v != %v", tc.in, got, tc.out)
531-
} else {
531+
} /* else {
532532
// t.Log("twMerge passed -> | in: ", tc.in, " | out: ", got, " | expected: ", tc.out)
533-
}
533+
} */
534534
}
535535
}
536536

pkg/twmerge/validators.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,12 @@ func IsNumber(val string) bool {
9696

9797
func IsInteger(val string) bool {
9898
_, err := strconv.Atoi(val)
99-
if err != nil {
100-
return false
101-
}
102-
return true
99+
return err == nil
103100
}
104101

105102
func IsFloat(val string) bool {
106103
_, err := strconv.ParseFloat(val, 64)
107-
if err != nil {
108-
return false
109-
}
110-
return true
104+
return err == nil
111105
}
112106

113107
func IsLengthOnly(val string) bool {

0 commit comments

Comments
 (0)