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

Add pre-commit to repo #51

Merged
merged 13 commits into from
Oct 11, 2024
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dotenv
dotenv
5 changes: 0 additions & 5 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ jobs:
- name: generate templ files
run: templ generate

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest

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

Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: pre-commit

on:
push:
branches: [ "main" ]
pull_request:

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

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

- name: Install templ
run: go install github.com/a-h/templ/cmd/templ@latest

- name: generate templ files
run: templ generate

- uses: actions/setup-python@v3

- uses: pre-commit/[email protected]
23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
repos:
- repo: https://github.com/golangci/golangci-lint
rev: v1.61.0
hooks:
- id: golangci-lint-full
- id: golangci-lint-config-verify
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-illegal-windows-names
- id: check-merge-conflict
- id: check-yaml
- id: detect-private-key
- id: end-of-file-fixer
exclude: "internal/ui/assets/.*"
exclude_types:
- svg
- id: trailing-whitespace
exclude: "internal/ui/assets/.*"
exclude_types:
- svg
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ In order to run the app you'll need to have completed the following steps:
```

1. Install [mkcert](https://github.com/FiloSottile/mkcert)
1. Create your own self-signed certs for local development:
1. Create your own self-signed certs for local development:

```bash
cd tls
Expand Down Expand Up @@ -116,4 +116,11 @@ If you'd prefer to not rely on Docker and instead run PostgreSQL locally, you wi

### Linting

Pull requests to the `main` branch are required to pass linting checks. To run these locally, [install `golangci-lint`](https://golangci-lint.run/welcome/install/#local-installation). Then you can `golangci-lint run` from the project directory.
Pull requests to the `main` branch are required to pass linting checks. We use [`pre-commit`](https://pre-commit.com/) to run these checks. To run them locally, install `pre-commit` and then install the hooks to run before every commit.

```bash
pip install pre-commit
pre-commit install
```

You can also run the checks on demand using `pre-commit run` (staged files) or `pre-commit run --all-files` (entire repo).
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ services:
- db-data:/var/lib/postgresql/data
- ./:/app
volumes:
db-data:
db-data:
6 changes: 3 additions & 3 deletions internal/ui/components/breadcrumb.templ
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ templ Breadcrumb(currentPage string) {
<div>
if currentPage == "Home" {
<br>
} else {
} else {
<div class="cdc-breadcrumb">
<div class="cdc-breadcrumb__content cdc-page-offset">
<a href="/">PHIN VADS Home</a> <img src="/assets/img/usa-icons/chevron_right.svg" /> {currentPage}
</div>
</div>
}
}
</div>
}
}
6 changes: 3 additions & 3 deletions internal/ui/components/code_system_result.templ
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ templ CodeSystemResult(searchTerm string, searchResults *models.CodeSystemResult
<div role="rowgroup">
<div class="cdc-header top-header">
<div class="col search-results page-count">Showing {strconv.Itoa(searchResults.PageCount)} of {searchResults.CodeSystemsCount} Code Systems</div>
<div
<div
if searchResults.PageCount >=5 {
class="pagination"
} else {
Expand All @@ -36,7 +36,7 @@ templ CodeSystemResult(searchTerm string, searchResults *models.CodeSystemResult
<button disabled aria-disabled="true">
<img src="/assets/img/material-icons/file_download_off.svg">
Download Value Set
</button>
</button>
} else {
<button disabled aria-disabled="true">
<img src="/assets/img/material-icons/file_download_off.svg">
Expand All @@ -57,4 +57,4 @@ templ CodeSystemResult(searchTerm string, searchResults *models.CodeSystemResult
</div>
</div>
</div>
}
}
8 changes: 4 additions & 4 deletions internal/ui/components/code_system_result_row.templ
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package components
import "github.com/CDCgov/phinvads-go/internal/database/models/xo"

templ CodeSystemResultRow(alternate bool, result *xo.CodeSystem) {
<div
<div
if alternate == true {
class="row content-row" role="row"
} else {
Expand All @@ -12,8 +12,8 @@ templ CodeSystemResultRow(alternate bool, result *xo.CodeSystem) {
>
<div class="col check">
<div role="cell">
<input
type="checkbox"
<input
type="checkbox"
value={result.Codesystemcode}
>
</div>
Expand All @@ -34,4 +34,4 @@ templ CodeSystemResultRow(alternate bool, result *xo.CodeSystem) {
</div>
</div>
</div>
}
}
4 changes: 2 additions & 2 deletions internal/ui/components/code_system_table_header.templ
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ templ CodeSystemTableHeader() {
</div>
</div>
<div class="col">
<div role="cell">
<div role="cell">
<p>Code System Code</p>
</div>
</div>
Expand All @@ -23,4 +23,4 @@ templ CodeSystemTableHeader() {
</div>
</div>
</div>
}
}
4 changes: 2 additions & 2 deletions internal/ui/components/error.templ
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package components
package components

templ Error(currentPage, errorText string) {
@Base(currentPage) {
Expand All @@ -9,4 +9,4 @@ templ Error(currentPage, errorText string) {
<p>{errorText}</p>
<div><br></div>
}
}
}
6 changes: 3 additions & 3 deletions internal/ui/components/footer.templ
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ templ Footer() {
<img class="cdc-fa-angle-down" src="/assets/img/usa-icons-bg/expand_more--white.svg"/>
</a>
<a id="aboutCDC-btn" class="cdc-footer__nav-link" data-bs-toggle="collapse" href="#aboutCDC" role="button" aria-expanded="false" aria-controls="aboutCDC">
About CDC
About CDC
<img class="cdc-fa-angle-down" src="/assets/img/usa-icons-bg/expand_more--white.svg"/>
</a>
<a id="policies-btn" class="cdc-footer__nav-link" data-bs-toggle="collapse" href="#policies" role="button" aria-expanded="false" aria-controls="policies">
Policies
<img class="cdc-fa-angle-down" src="/assets/img/usa-icons-bg/expand_more--white.svg"/>
</a>
<a id="languages-btn" class="cdc-footer__nav-link" data-bs-toggle="collapse" href="#languages" role="button" aria-expanded="false" aria-controls="languages">
Languages
Languages
<img class="cdc-fa-angle-down" src="/assets/img/usa-icons-bg/expand_more--white.svg"/>
</a>
<a id="archive-btn" class="cdc-footer__nav-link" data-bs-toggle="collapse" href="#archive" role="button" aria-expanded="false" aria-controls="archive">
Archive
Archive
<img class="cdc-fa-angle-down" src="/assets/img/usa-icons-bg/expand_more--white.svg"/>
</a>
</div>
Expand Down
4 changes: 2 additions & 2 deletions internal/ui/components/home.templ
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ templ Home() {
<h1>PHIN VADS Home</h1>
@SearchBar()
<h2>Hot Topics</h2>
<div
<div
hx-trigger="load"
hx-get="/load-hot-topics"
class="usa-accordion usa-accordion--multiselectable"
class="usa-accordion usa-accordion--multiselectable"
data-allow-multiple
>
</div>
Expand Down
2 changes: 1 addition & 1 deletion internal/ui/components/hot-topic.templ
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ templ HotTopic(topic_name string, topic_description, sequence, topic_id string )
<div id={sequence} class="usa-accordion__content usa-prose" hidden>
<p>{topic_description}</p>
</div>
}
}
8 changes: 4 additions & 4 deletions internal/ui/components/navbar.templ
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ templ NavBar(currentPage string) {
<div class="header-nav grid-col flex-2">
<a href="#">Home</a>
<a href="#">
Documentation
Documentation
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img">
<use xlink:href="/assets/img/sprite.svg#arrow_drop_down"></use>
</svg>
</a>
<a href="#">
Browse
Browse
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img">
<use xlink:href="/assets/img/sprite.svg#arrow_drop_down"></use>
</svg>
Expand Down Expand Up @@ -78,13 +78,13 @@ templ NavBar(currentPage string) {
<div class="cdc-mobile-navbar__links" tabindex="-1">
<a href="#">Home</a>
<a href="#">
Documentation
Documentation
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img">
<use xlink:href="/assets/img/sprite.svg#arrow_drop_down"></use>
</svg>
</a>
<a href="#">
Browse
Browse
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img">
<use xlink:href="/assets/img/sprite.svg#arrow_drop_down"></use>
</svg>
Expand Down
10 changes: 4 additions & 6 deletions internal/ui/components/results-count.templ
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import "github.com/CDCgov/phinvads-go/internal/database/models"

templ CodeSystemResultsCount(result *models.CodeSystemResultRow) {
<div class="search-results__tabs">
<div
<div
if result.ValueSetsCount == "0" && result.CodeSystemsCount != "0" {
class="tab-item active"
} else {
class="tab-item"
}
>
Code Systems ({result.CodeSystemsCount})</div>
<div
<div
if result.ValueSetsCount == "0" && result.CodeSystemsCount == "0" && result.CodeSystemConceptsCount != "0"{
class="tab-item active"
} else {
class="tab-item"
}
>
Code System Concepts ({result.CodeSystemConceptsCount})</div>
<div
<div
if result.ValueSetsCount == "0" {
class="tab-item"
} else {
Expand All @@ -29,7 +29,5 @@ templ CodeSystemResultsCount(result *models.CodeSystemResultRow) {
>
Value Sets ({result.ValueSetsCount})</div>
</div>

}


}
6 changes: 3 additions & 3 deletions internal/ui/components/search_bar.templ
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ templ SearchBar() {
type="search"
name="search"
/>
<button
<button
hx-post="/api/search"
hx-target="#main-body"
hx-swap="innerHTML"
class="usa-button"
class="usa-button"
type="submit"
>
<span class="usa-search__submit-text">Search </span>
Expand All @@ -47,4 +47,4 @@ templ SearchBar() {
<p><a href="#">Advanced Search</a></p>
</div>
</div>
}
}
8 changes: 4 additions & 4 deletions internal/ui/components/search_result_row.templ
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package components

templ ResultRow(conceptCode, conceptName, prefName, codeSystem, valueSet string, alternate bool) {
<div
<div
if alternate == true {
class="row content-row" role="row"
} else {
Expand All @@ -10,8 +10,8 @@ templ ResultRow(conceptCode, conceptName, prefName, codeSystem, valueSet string,
>
<div class="col check">
<div role="cell">
<input
type="checkbox"
<input
type="checkbox"
value={conceptCode}
>
</div>
Expand Down Expand Up @@ -42,4 +42,4 @@ templ ResultRow(conceptCode, conceptName, prefName, codeSystem, valueSet string,
</div>
</div>
</div>
}
}
2 changes: 1 addition & 1 deletion internal/ui/components/search_results.templ
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ templ SearchResults(isDirect bool, currentPage, searchTerm string, searchResults
@CodeSystemResult(searchTerm, searchResults)
<div><br></div>
}
}
}
8 changes: 4 additions & 4 deletions internal/ui/components/usa-banner.templ
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ templ UsaBanner(action string) {
class="usa-banner__toggle usa-banner__header-action"
aria-controls="usa-accordion__content"
>
Here's how you know
Here's how you know
</button>
</span>
</div>
Expand All @@ -47,12 +47,12 @@ templ UsaBanner(action string) {
<div class="usa-banner__content-text">
<b>Secure .gov websites use HTTPS</b>
<p>
A
A
<strong>
lock
</strong>
(<span><img src="/assets/img/lock.svg" class="lock-img"/></span>)
or
(<span><img src="/assets/img/lock.svg" class="lock-img"/></span>)
or
<span>
<strong>
https://
Expand Down
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ refreshdb:
@echo "Running database refresh..."
docker compose exec -T $(DB_SERVICE) psql -U $(DB_USER) -c "DROP DATABASE IF EXISTS $(DB_NAME) WITH (FORCE)"
docker compose exec -T $(DB_SERVICE) psql -U $(DB_USER) -c 'CREATE DATABASE $(DB_NAME)'
$(MAKE) load
$(MAKE) load
Loading
Loading