Skip to content

Commit 9492e8e

Browse files
committed
Merge master
2 parents 3e8069b + 4183a4e commit 9492e8e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+4461
-327
lines changed

.eslintrc.yaml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
---
2+
env:
3+
browser: true
4+
commonjs: true
5+
es6: true
6+
jest: true
7+
node: true
8+
extends:
9+
- eslint:recommended
10+
- plugin:@typescript-eslint/recommended
11+
- plugin:import/recommended
12+
- plugin:import/typescript
13+
- plugin:react/recommended
14+
- plugin:jsx-a11y/strict
15+
- plugin:compat/recommended
16+
- prettier
17+
parser: "@typescript-eslint/parser"
18+
parserOptions:
19+
ecmaVersion: 2018
20+
project:
21+
- "./tsconfig.json"
22+
- "./site/tsconfig.json"
23+
sourceType: module
24+
ecmaFeatures:
25+
jsx: true
26+
tsconfigRootDir: "./"
27+
plugins:
28+
- "@typescript-eslint"
29+
- import
30+
- react-hooks
31+
- jest
32+
- no-storage
33+
root: true
34+
rules:
35+
"@typescript-eslint/brace-style":
36+
["error", "1tbs", { "allowSingleLine": false }]
37+
"@typescript-eslint/camelcase": "off"
38+
"@typescript-eslint/explicit-function-return-type": "off"
39+
"@typescript-eslint/explicit-module-boundary-types": "error"
40+
"@typescript-eslint/method-signature-style": ["error", "property"]
41+
"@typescript-eslint/no-invalid-void-type": error
42+
# We're disabling the `no-namespace` rule to use a pattern of defining an interface,
43+
# and then defining functions that operate on that data via namespace. This is helpful for
44+
# dealing with immutable objects. This is a common pattern that shows up in some other
45+
# large TypeScript projects, like VSCode.
46+
# More details: https://github.com/coder/m/pull/9720#discussion_r697609528
47+
"@typescript-eslint/no-namespace": "off"
48+
"@typescript-eslint/no-unnecessary-boolean-literal-compare": error
49+
"@typescript-eslint/no-unnecessary-condition": warn
50+
"@typescript-eslint/no-unnecessary-type-assertion": warn
51+
"@typescript-eslint/no-unused-vars":
52+
- error
53+
- argsIgnorePattern: "^_"
54+
varsIgnorePattern: "^_"
55+
"@typescript-eslint/no-use-before-define": "off"
56+
"@typescript-eslint/object-curly-spacing": ["error", "always"]
57+
"@typescript-eslint/triple-slash-reference": "off"
58+
"brace-style": "off"
59+
"curly": ["error", "all"]
60+
eqeqeq: error
61+
import/default: "off"
62+
import/namespace: "off"
63+
import/newline-after-import:
64+
- error
65+
- count: 1
66+
import/no-named-as-default: "off"
67+
import/no-named-as-default-member: "off"
68+
import/prefer-default-export: "off"
69+
jest/no-focused-tests: "error"
70+
jsx-a11y/label-has-for: "off"
71+
jsx-a11y/no-autofocus: "off"
72+
no-console:
73+
- warn
74+
- allow:
75+
- warn
76+
- error
77+
- info
78+
- debug
79+
no-dupe-class-members: "off"
80+
no-restricted-imports:
81+
- error
82+
- paths:
83+
- name: "@material-ui/core"
84+
message:
85+
"Use path imports to avoid pulling in unused modules. See:
86+
https://material-ui.com/guides/minimizing-bundle-size/"
87+
- name: "@material-ui/icons"
88+
message:
89+
"Use path imports to avoid pulling in unused modules. See:
90+
https://material-ui.com/guides/minimizing-bundle-size/"
91+
- name: "@material-ui/styles"
92+
message:
93+
"Use path imports to avoid pulling in unused modules. See:
94+
https://material-ui.com/guides/minimizing-bundle-size/"
95+
- name: "@material-ui/core/Tooltip"
96+
message: "Use the custom Tooltip on componens/Tooltip"
97+
no-storage/no-browser-storage: error
98+
no-unused-vars: "off"
99+
"object-curly-spacing": "off"
100+
react-hooks/exhaustive-deps: warn
101+
react-hooks/rules-of-hooks: error
102+
react/jsx-no-script-url:
103+
- error
104+
- - name: Link
105+
props:
106+
- to
107+
- name: Button
108+
props:
109+
- href
110+
- name: IconButton
111+
props:
112+
- href
113+
react/prop-types: "off"
114+
react/jsx-boolean-value: ["error", "never"]
115+
react/jsx-curly-brace-presence:
116+
- error
117+
- children: ignore
118+
settings:
119+
react:
120+
version: detect
121+
import/resolver:
122+
typescript: {}

.github/workflows/coder.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,28 @@ jobs:
3838
with:
3939
version: latest
4040

41+
style-lint-typescript:
42+
name: "style/lint/typescript"
43+
runs-on: ubuntu-latest
44+
steps:
45+
- name: Checkout
46+
uses: actions/checkout@v2
47+
48+
- name: Cache Node
49+
id: cache-node
50+
uses: actions/cache@v2
51+
with:
52+
path: |
53+
**/node_modules
54+
.eslintcache
55+
key: js-${{ runner.os }}-test-${{ hashFiles('**/yarn.lock') }}
56+
57+
- name: Install node_modules
58+
run: yarn install
59+
60+
- name: "yarn lint"
61+
run: yarn lint
62+
4163
gen:
4264
name: "style/gen"
4365
runs-on: ubuntu-latest

.golangci.yml

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ linters-settings:
100100
# - whyNoLint
101101
# - wrapperFunc
102102
# - yodaStyleExpr
103-
settings:
104-
ruleguard:
105-
failOn: all
106-
rules: "${configDir}/lib/go/lintrules/*.go"
107103

108104
goimports:
109105
local-prefixes: coder.com,cdr.dev,go.coder.com,github.com/cdr,github.com/coder
@@ -113,24 +109,6 @@ linters-settings:
113109

114110
importas:
115111
no-unaliased: true
116-
alias:
117-
- pkg: k8s.io/api/(\w+)/(v[\w\d]+)
118-
alias: ${1}${2}
119-
120-
- pkg: k8s.io/apimachinery/pkg/apis/meta/(v[\w\d]+)
121-
alias: meta${1}
122-
123-
- pkg: k8s.io/client-go/kubernetes/typed/(\w+)/(v[\w\d]+)
124-
alias: ${1}${2}client
125-
126-
- pkg: k8s.io/metrics/pkg/apis/metrics/(v[\w\d]+)
127-
alias: metrics${1}
128-
129-
- pkg: github.com/docker/docker/api/types
130-
alias: dockertypes
131-
132-
- pkg: github.com/docker/docker/client
133-
alias: dockerclient
134112

135113
misspell:
136114
locale: US
@@ -195,6 +173,20 @@ linters-settings:
195173
- name: var-declaration
196174
- name: var-naming
197175
- name: waitgroup-by-value
176+
varnamelen:
177+
ignore-names:
178+
- err
179+
- rw
180+
- r
181+
- i
182+
- db
183+
# Optional list of variable declarations that should be ignored completely. (defaults to empty list)
184+
# Entries must be in the form of "<variable name> <type>" or "<variable name> *<type>" for
185+
# variables, or "const <name>" for constants.
186+
ignore-decls:
187+
- rw http.ResponseWriter
188+
- r *http.Request
189+
- t testing.T
198190

199191
issues:
200192
# Rules listed here: https://github.com/securego/gosec#available-rules
@@ -222,7 +214,6 @@ linters:
222214
- asciicheck
223215
- bidichk
224216
- bodyclose
225-
- contextcheck
226217
- deadcode
227218
- dogsled
228219
- errcheck
@@ -239,7 +230,6 @@ linters:
239230
- govet
240231
- importas
241232
- ineffassign
242-
# - ireturn
243233
- makezero
244234
- misspell
245235
- nilnil

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ else
2727
endif
2828
.PHONY: fmt/prettier
2929

30-
fmt: fmt/prettier
30+
fmt/sql:
31+
npx sql-formatter \
32+
--language postgresql \
33+
--lines-between-queries 2 \
34+
./database/query.sql \
35+
--output ./database/query.sql
36+
37+
fmt: fmt/prettier fmt/sql
3138
.PHONY: fmt
3239

3340
gen: database/generate peerbroker/proto provisionersdk/proto

_jest/setupTests.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Global setup for our Jest tests
3+
*/
4+
5+
// Set up 'next-router-mock' to with our front-end tests:
6+
// https://github.com/scottrippey/next-router-mock#quick-start
7+
jest.mock("next/router", () => require("next-router-mock"))

cmd/coder/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ package main
33
import "fmt"
44

55
func main() {
6-
fmt.Println("Hello World!")
6+
_, _ = fmt.Println("Hello World!")
77
}

codecov.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@ coverage:
2121

2222
ignore:
2323
# This is generated code.
24+
- database/models.go
25+
- database/query.sql.go
2426
- peerbroker/proto
2527
- provisionersdk/proto

coderd/cmd/root.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import (
55
"net/http"
66
"os"
77

8+
"github.com/spf13/cobra"
9+
"golang.org/x/xerrors"
10+
811
"cdr.dev/slog"
912
"cdr.dev/slog/sloggers/sloghuman"
1013
"github.com/coder/coder/coderd"
11-
"github.com/coder/coder/database"
12-
"github.com/spf13/cobra"
13-
"golang.org/x/xerrors"
14+
"github.com/coder/coder/database/databasefake"
1415
)
1516

1617
func Root() *cobra.Command {
@@ -22,7 +23,7 @@ func Root() *cobra.Command {
2223
RunE: func(cmd *cobra.Command, args []string) error {
2324
handler := coderd.New(&coderd.Options{
2425
Logger: slog.Make(sloghuman.Sink(os.Stderr)),
25-
Database: database.NewInMemory(),
26+
Database: databasefake.New(),
2627
})
2728

2829
listener, err := net.Listen("tcp", address)

coderd/cmd/root_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import (
44
"context"
55
"testing"
66

7-
"github.com/coder/coder/coderd/cmd"
87
"github.com/stretchr/testify/require"
8+
9+
"github.com/coder/coder/coderd/cmd"
910
)
1011

1112
func TestRoot(t *testing.T) {

coderd/coderd.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package coderd
33
import (
44
"net/http"
55

6+
"github.com/go-chi/chi"
7+
68
"cdr.dev/slog"
79
"github.com/coder/coder/database"
10+
"github.com/coder/coder/httpapi"
11+
"github.com/coder/coder/httpmw"
812
"github.com/coder/coder/site"
9-
"github.com/go-chi/chi"
10-
"github.com/go-chi/render"
1113
)
1214

1315
// Options are requires parameters for Coder to start.
@@ -18,15 +20,27 @@ type Options struct {
1820

1921
// New constructs the Coder API into an HTTP handler.
2022
func New(options *Options) http.Handler {
23+
users := &users{
24+
Database: options.Database,
25+
}
26+
2127
r := chi.NewRouter()
2228
r.Route("/api/v2", func(r chi.Router) {
2329
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
24-
render.JSON(w, r, struct {
25-
Message string `json:"message"`
26-
}{
30+
httpapi.Write(w, http.StatusOK, httpapi.Response{
2731
Message: "👋",
2832
})
2933
})
34+
r.Post("/user", users.createInitialUser)
35+
r.Post("/login", users.loginWithPassword)
36+
// Require an API key and authenticated user for this group.
37+
r.Group(func(r chi.Router) {
38+
r.Use(
39+
httpmw.ExtractAPIKey(options.Database, nil),
40+
httpmw.ExtractUser(options.Database),
41+
)
42+
r.Get("/user", users.authenticatedUser)
43+
})
3044
})
3145
r.NotFound(site.Handler().ServeHTTP)
3246
return r

0 commit comments

Comments
 (0)