Skip to content

chore: sort imports in our typescript code #12417

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

Merged
merged 13 commits into from
Mar 5, 2024
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
32 changes: 22 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -382,32 +382,44 @@ install: build/coder_$(VERSION)_$(GOOS)_$(GOARCH)$(GOOS_BIN_EXT)
cp "$<" "$$output_file"
.PHONY: install

fmt: fmt/prettier fmt/terraform fmt/shfmt fmt/go
BOLD := $(shell tput bold)
GREEN := $(shell tput setaf 2)
RESET := $(shell tput sgr0)

fmt: fmt/eslint fmt/prettier fmt/terraform fmt/shfmt fmt/go
.PHONY: fmt

fmt/go:
echo "$(GREEN)==>$(RESET) $(BOLD)fmt/go$(RESET)"
# VS Code users should check out
# https://github.com/mvdan/gofumpt#visual-studio-code
go run mvdan.cc/gofumpt@v0.4.0 -w -l .
.PHONY: fmt/go

fmt/eslint:
echo "$(GREEN)==>$(RESET) $(BOLD)fmt/eslint$(RESET)"
cd site
pnpm run lint:fix
.PHONY: fmt/eslint

fmt/prettier:
echo "--- prettier"
echo "$(GREEN)==>$(RESET) $(BOLD)fmt/prettier$(RESET)"
cd site
# Avoid writing files in CI to reduce file write activity
ifdef CI
pnpm run format:check
else
pnpm run format:write
pnpm run format
endif
.PHONY: fmt/prettier

fmt/terraform: $(wildcard *.tf)
echo "$(GREEN)==>$(RESET) $(BOLD)fmt/terraform$(RESET)"
terraform fmt -recursive
.PHONY: fmt/terraform

fmt/shfmt: $(SHELL_SRC_FILES)
echo "--- shfmt"
echo "$(GREEN)==>$(RESET) $(BOLD)fmt/shfmt$(RESET)"
# Only do diff check in CI, errors on diff.
ifdef CI
shfmt -d $(SHELL_SRC_FILES)
Expand Down Expand Up @@ -574,7 +586,7 @@ provisionerd/proto/provisionerd.pb.go: provisionerd/proto/provisionerd.proto

site/src/api/typesGenerated.ts: $(wildcard scripts/apitypings/*) $(shell find ./codersdk $(FIND_EXCLUSIONS) -type f -name '*.go')
go run ./scripts/apitypings/ > $@
pnpm run format:write:only "$@"
pnpm exec prettier --write "$@"

site/e2e/provisionerGenerated.ts: provisionerd/proto/provisionerd.pb.go provisionersdk/proto/provisioner.pb.go
cd site
Expand All @@ -583,7 +595,7 @@ site/e2e/provisionerGenerated.ts: provisionerd/proto/provisionerd.pb.go provisio

site/src/theme/icons.json: $(wildcard scripts/gensite/*) $(wildcard site/static/icon/*)
go run ./scripts/gensite/ -icons "$@"
pnpm run format:write:only "$@"
pnpm exec prettier --write "$@"

examples/examples.gen.json: scripts/examplegen/main.go examples/examples.go $(shell find ./examples/templates)
go run ./scripts/examplegen/main.go > examples/examples.gen.json
Expand All @@ -593,19 +605,19 @@ coderd/rbac/object_gen.go: scripts/rbacgen/main.go coderd/rbac/object.go

docs/admin/prometheus.md: scripts/metricsdocgen/main.go scripts/metricsdocgen/metrics
go run scripts/metricsdocgen/main.go
pnpm run format:write:only ./docs/admin/prometheus.md
pnpm exec prettier --write ./docs/admin/prometheus.md

docs/cli.md: scripts/clidocgen/main.go examples/examples.gen.json $(GO_SRC_FILES)
CI=true BASE_PATH="." go run ./scripts/clidocgen
pnpm run format:write:only ./docs/cli.md ./docs/cli/*.md ./docs/manifest.json
pnpm exec prettier --write ./docs/cli.md ./docs/cli/*.md ./docs/manifest.json

docs/admin/audit-logs.md: coderd/database/querier.go scripts/auditdocgen/main.go enterprise/audit/table.go coderd/rbac/object_gen.go
go run scripts/auditdocgen/main.go
pnpm run format:write:only ./docs/admin/audit-logs.md
pnpm exec prettier --write ./docs/admin/audit-logs.md

coderd/apidoc/swagger.json: $(shell find ./scripts/apidocgen $(FIND_EXCLUSIONS) -type f) $(wildcard coderd/*.go) $(wildcard enterprise/coderd/*.go) $(wildcard codersdk/*.go) $(wildcard enterprise/wsproxy/wsproxysdk/*.go) $(DB_GEN_FILES) .swaggo docs/manifest.json coderd/rbac/object_gen.go
./scripts/apidocgen/generate.sh
pnpm run format:write:only ./docs/api ./docs/manifest.json ./coderd/apidoc/swagger.json
pnpm exec prettier --write ./docs/api ./docs/manifest.json ./coderd/apidoc/swagger.json

update-golden-files: \
cli/testdata/.gen-golden \
Expand Down
11 changes: 5 additions & 6 deletions offlinedocs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
"private": true,
"scripts": {
"dev": "pnpm copy-images && next dev",
"build": "pnpm exec next build",
"start": "pnpm exec next start",
"build": "next build",
"start": "next start",
"export": "pnpm copy-images && next build",
"copy-images": "sh ./scripts/copyImages.sh",
"lint": "pnpm run lint:types",
"lint:fix": "FIX=true pnpm lint",
"lint:types": "pnpm exec tsc --noEmit",
"format:check": "pnpm exec prettier --cache --check './**/*.{css,html,js,json,jsx,md,ts,tsx,yaml,yml}'",
"format:write": "pnpm exec prettier --cache --write './**/*.{css,html,js,json,jsx,md,ts,tsx,yaml,yml}'"
"lint:types": "tsc --noEmit",
"format": "prettier --cache --write './**/*.{css,html,js,json,jsx,md,ts,tsx,yaml,yml}'",
"format:check": "prettier --cache --check './**/*.{css,html,js,json,jsx,md,ts,tsx,yaml,yml}'"
},
"dependencies": {
"@chakra-ui/react": "2.8.0",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"name": "coder",
"version": "0.0.0",
"scripts": {
"format:write:only": "prettier --cache --write"
"format": "prettier --cache --write",
"storybook": "pnpm run -C site/ storybook"
},
"devDependencies": {
"prettier": "3.0.0"
Expand Down
18 changes: 15 additions & 3 deletions site/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ overrides:
testing-library/prefer-screen-queries: "off"
root: true
rules:
"@typescript-eslint/brace-style":
["error", "1tbs", { "allowSingleLine": false }]
"@typescript-eslint/method-signature-style": ["error", "property"]
# TODO: Investigate whether to enable this rule & fix and/or disable all its complaints
"@typescript-eslint/no-misused-promises": "off"
# TODO: Investigate whether to enable this rule & fix and/or disable all its complaints
Expand All @@ -75,6 +72,14 @@ rules:
"@typescript-eslint/restrict-template-expressions": "off"
# TODO: Investigate whether to enable this rule & fix and/or disable all its complaints
"@typescript-eslint/unbound-method": "off"

"@typescript-eslint/brace-style":
["error", "1tbs", { "allowSingleLine": false }]
"@typescript-eslint/consistent-type-imports":
- error
- fixStyle: inline-type-imports
"@typescript-eslint/method-signature-style": ["error", "property"]
"@typescript-eslint/no-import-type-side-effects": "error"
# We're disabling the `no-namespace` rule to use a pattern of defining an interface,
# and then defining functions that operate on that data via namespace. This is helpful for
# dealing with immutable objects. This is a common pattern that shows up in some other
Expand Down Expand Up @@ -104,6 +109,13 @@ rules:
import/no-named-as-default: "off"
import/no-named-as-default-member: "off"
import/prefer-default-export: "off"
import/order:
- error
- groups: [["builtin", "external"], "internal", "parent"]
newlines-between: never
alphabetize:
order: asc
caseInsensitive: true
jest/no-focused-tests: "error"
jsx-a11y/label-has-for: "off"
jsx-a11y/no-autofocus: "off"
Expand Down
2 changes: 1 addition & 1 deletion site/e2e/global.setup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from "@playwright/test";
import { Language } from "pages/CreateUserPage/CreateUserForm";
import * as constants from "./constants";
import { STORAGE_STATE } from "./playwright.config";
import { Language } from "pages/CreateUserPage/CreateUserForm";

test("setup first user", async ({ page }) => {
await page.goto("/", { waitUntil: "domcontentloaded" });
Expand Down
38 changes: 19 additions & 19 deletions site/e2e/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import { expect, Page } from "@playwright/test";
import { ChildProcess, exec, spawn } from "child_process";
import { expect, type Page } from "@playwright/test";
import axios from "axios";
import { type ChildProcess, exec, spawn } from "child_process";
import { randomUUID } from "crypto";
import path from "path";
import express from "express";
import capitalize from "lodash/capitalize";
import path from "path";
import * as ssh from "ssh2";
import { Duplex } from "stream";
import type {
WorkspaceBuildParameter,
UpdateTemplateMeta,
} from "api/typesGenerated";
import { TarWriter } from "utils/tar";
import { prometheusPort, agentPProfPort } from "./constants";
import { port } from "./playwright.config";
import {
Agent,
App,
type App,
AppSharingLevel,
type ParseComplete,
type PlanComplete,
type ApplyComplete,
type Resource,
Response,
ParseComplete,
PlanComplete,
ApplyComplete,
Resource,
RichParameter,
type RichParameter,
} from "./provisionerGenerated";
import { prometheusPort, agentPProfPort } from "./constants";
import { port } from "./playwright.config";
import * as ssh from "ssh2";
import { Duplex } from "stream";
import {
WorkspaceBuildParameter,
UpdateTemplateMeta,
} from "api/typesGenerated";
import axios from "axios";
import capitalize from "lodash/capitalize";

// createWorkspace creates a workspace for a template.
// It does not wait for it to be running, but it does navigate to the page.
Expand Down
2 changes: 1 addition & 1 deletion site/e2e/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Page } from "@playwright/test";
import type { Page } from "@playwright/test";

export const beforeCoderTest = async (page: Page) => {
// eslint-disable-next-line no-console -- Show everything that was printed with console.log()
Expand Down
2 changes: 1 addition & 1 deletion site/e2e/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RichParameter } from "./provisionerGenerated";
import type { RichParameter } from "./provisionerGenerated";

// Rich parameters

Expand Down
2 changes: 1 addition & 1 deletion site/e2e/pom/BasePom.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Page } from "@playwright/test";
import type { Page } from "@playwright/test";

export abstract class BasePom {
protected readonly baseURL: string | undefined;
Expand Down
2 changes: 1 addition & 1 deletion site/e2e/pom/SignInPage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Page } from "@playwright/test";
import type { Page } from "@playwright/test";
import { BasePom } from "./BasePom";

export class SignInPage extends BasePom {
Expand Down
2 changes: 1 addition & 1 deletion site/e2e/pom/WorkspacesPage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Page } from "@playwright/test";
import type { Page } from "@playwright/test";
import { BasePom } from "./BasePom";

export class WorkspacesPage extends BasePom {
Expand Down
2 changes: 1 addition & 1 deletion site/e2e/reporter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable no-console -- Logging is sort of the whole point here */
import * as fs from "fs/promises";
import type {
FullConfig,
Suite,
Expand All @@ -10,6 +9,7 @@ import type {
TestError,
} from "@playwright/test/reporter";
import axios from "axios";
import * as fs from "fs/promises";
import type { Writable } from "stream";

class CoderReporter implements Reporter {
Expand Down
5 changes: 2 additions & 3 deletions site/e2e/tests/createWorkspace.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
echoResponsesWithParameters,
verifyParameters,
} from "../helpers";

import { beforeCoderTest } from "../hooks";
import {
secondParameter,
fourthParameter,
Expand All @@ -16,8 +16,7 @@ import {
sixthParameter,
randParamName,
} from "../parameters";
import { RichParameter } from "../provisionerGenerated";
import { beforeCoderTest } from "../hooks";
import type { RichParameter } from "../provisionerGenerated";

test.beforeEach(async ({ page }) => await beforeCoderTest(page));

Expand Down
4 changes: 2 additions & 2 deletions site/e2e/tests/externalAuth.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Endpoints } from "@octokit/types";
import { test } from "@playwright/test";
import type { ExternalAuthDevice } from "api/typesGenerated";
import { gitAuth } from "../constants";
import { Endpoints } from "@octokit/types";
import { ExternalAuthDevice } from "api/typesGenerated";
import { Awaiter, createServer } from "../helpers";
import { beforeCoderTest } from "../hooks";

Expand Down
5 changes: 2 additions & 3 deletions site/e2e/tests/restartWorkspace.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import {
echoResponsesWithParameters,
verifyParameters,
} from "../helpers";

import { firstBuildOption, secondBuildOption } from "../parameters";
import { RichParameter } from "../provisionerGenerated";
import { beforeCoderTest } from "../hooks";
import { firstBuildOption, secondBuildOption } from "../parameters";
import type { RichParameter } from "../provisionerGenerated";

test.beforeEach(async ({ page }) => await beforeCoderTest(page));

Expand Down
3 changes: 1 addition & 2 deletions site/e2e/tests/startWorkspace.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import {
stopWorkspace,
verifyParameters,
} from "../helpers";

import { firstBuildOption, secondBuildOption } from "../parameters";
import { RichParameter } from "../provisionerGenerated";
import type { RichParameter } from "../provisionerGenerated";

test("start workspace with ephemeral parameters", async ({ page }) => {
const richParameters: RichParameter[] = [firstBuildOption, secondBuildOption];
Expand Down
6 changes: 2 additions & 4 deletions site/e2e/tests/updateWorkspace.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { test } from "@playwright/test";

import {
createTemplate,
createWorkspace,
Expand All @@ -9,16 +8,15 @@ import {
updateWorkspaceParameters,
verifyParameters,
} from "../helpers";

import { beforeCoderTest } from "../hooks";
import {
fifthParameter,
firstParameter,
secondParameter,
sixthParameter,
secondBuildOption,
} from "../parameters";
import { RichParameter } from "../provisionerGenerated";
import { beforeCoderTest } from "../hooks";
import type { RichParameter } from "../provisionerGenerated";

test.beforeEach(async ({ page }) => await beforeCoderTest(page));

Expand Down
2 changes: 1 addition & 1 deletion site/e2e/tests/webTerminal.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { test } from "@playwright/test";
import { randomUUID } from "crypto";
import {
createTemplate,
createWorkspace,
startAgent,
stopAgent,
} from "../helpers";
import { randomUUID } from "crypto";
import { beforeCoderTest } from "../hooks";

test.beforeEach(async ({ page }) => await beforeCoderTest(page));
Expand Down
12 changes: 6 additions & 6 deletions site/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import "@testing-library/jest-dom";
import { cleanup } from "@testing-library/react";
import crypto from "crypto";
import { server } from "testHelpers/server";
import "jest-location-mock";
import { TextEncoder, TextDecoder } from "util";
import { cleanup } from "@testing-library/react";
import { Blob } from "buffer";
import crypto from "crypto";
import jestFetchMock from "jest-fetch-mock";
import { ProxyLatencyReport } from "contexts/useProxyLatency";
import { Region } from "api/typesGenerated";
import { useMemo } from "react";
import { TextEncoder, TextDecoder } from "util";
import type { Region } from "api/typesGenerated";
import type { ProxyLatencyReport } from "contexts/useProxyLatency";
import { server } from "testHelpers/server";

jestFetchMock.enableMocks();

Expand Down
7 changes: 3 additions & 4 deletions site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
"check:all": "pnpm format:check && pnpm lint && pnpm test",
"chromatic": "chromatic",
"dev": "vite",
"format": "prettier --cache --write '../**/*.{css,html,js,json,jsx,md,ts,tsx,yaml,yml}'",
"format:check": "prettier --cache --check '../**/*.{css,html,js,json,jsx,md,ts,tsx,yaml,yml}'",
"format:write": "prettier --cache --write '../**/*.{css,html,js,json,jsx,md,ts,tsx,yaml,yml}'",
"format:write:only": "prettier --cache --write",
"lint": "pnpm run lint:types && pnpm exec jest --selectProjects lint",
"lint:fix": "FIX=true pnpm lint",
"lint": "pnpm run lint:types && jest --selectProjects lint",
"lint:fix": "eslint --fix e2e/ src/",
"lint:types": "tsc -p .",
"playwright:install": "playwright install --with-deps chromium",
"playwright:test": "playwright test --config=e2e/playwright.config.ts",
Expand Down
4 changes: 2 additions & 2 deletions site/src/@types/storybook.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as _storybook_types from "@storybook/react";
import { Experiments, FeatureName } from "api/typesGenerated";
import { QueryKey } from "react-query";
import type { QueryKey } from "react-query";
import type { Experiments, FeatureName } from "api/typesGenerated";

declare module "@storybook/react" {
interface Parameters {
Expand Down
Loading