Skip to content

Commit 728e8f0

Browse files
hittytPangjiping
authored andcommitted
docs: document coding standards enforcement
1 parent 55a0bef commit 728e8f0

7 files changed

Lines changed: 119 additions & 9 deletions

File tree

.github/workflows/egress-test.yaml.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ jobs:
2626
with:
2727
go-version: '1.25.9'
2828

29+
- name: Check gofmt
30+
working-directory: components/egress
31+
run: |
32+
files="$(gofmt -l . ../internal)"
33+
if [ -n "$files" ]; then
34+
echo "$files"
35+
exit 1
36+
fi
37+
2938
- name: Run Build
3039
working-directory: components/egress
3140
run: |

.github/workflows/execd-test.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ jobs:
2626
with:
2727
go-version: '1.25.9'
2828

29+
- name: Check gofmt
30+
working-directory: components/execd
31+
run: |
32+
files="$(gofmt -l . ../internal)"
33+
if [ -n "$files" ]; then
34+
echo "$files"
35+
exit 1
36+
fi
37+
2938
- name: Run golint
3039
working-directory: components/execd
3140
run: |

.github/workflows/ingress-test.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ jobs:
2525
with:
2626
go-version: '1.25.9'
2727

28+
- name: Check gofmt
29+
working-directory: components/ingress
30+
run: |
31+
files="$(gofmt -l . ../internal)"
32+
if [ -n "$files" ]; then
33+
echo "$files"
34+
exit 1
35+
fi
36+
2837
- name: Run golint
2938
working-directory: components/ingress
3039
run: |

.github/workflows/kubernetes-test.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ jobs:
4949
with:
5050
go-version: '1.24.0'
5151

52+
- name: Check gofmt
53+
working-directory: kubernetes
54+
run: |
55+
files="$(gofmt -l .)"
56+
if [ -n "$files" ]; then
57+
echo "$files"
58+
exit 1
59+
fi
60+
5261
- name: Run golint
5362
working-directory: kubernetes
5463
run: |
@@ -63,4 +72,4 @@ jobs:
6372
- name: Run tests
6473
working-directory: kubernetes
6574
run: |
66-
make test
75+
make test

.github/workflows/sdk-tests.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,15 @@ jobs:
375375
with:
376376
go-version: "1.20"
377377

378+
- name: Check gofmt
379+
working-directory: sdks/sandbox/go
380+
run: |
381+
files="$(gofmt -l .)"
382+
if [ -n "$files" ]; then
383+
echo "$files"
384+
exit 1
385+
fi
386+
378387
- name: Run go vet
379388
working-directory: sdks/sandbox/go
380389
run: |

CONTRIBUTING.md

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,37 @@ refactor(sdk): simplify filesystem API
226226

227227
## Coding Standards
228228

229-
### Python (Server, Python SDKs)
230-
231-
- **Style Guide**: Follow [PEP 8](https://pep8.org/)
232-
- **Formatter**: Use `ruff` for formatting and linting
229+
Contributions are required to generally comply with the coding standards for
230+
the language and component they touch. Generated files are excluded where the
231+
local tool configuration excludes them; update the source specification or
232+
generator and regenerate those files instead of hand-editing generated output.
233+
234+
### Required Style Guides
235+
236+
| Area | Primary language | Required style guide |
237+
| --- | --- | --- |
238+
| Server, CLI, Python SDKs, Python tests | Python | [PEP 8](https://peps.python.org/pep-0008/) plus Google-style docstrings for public APIs |
239+
| Go components, Kubernetes controller, Go SDK | Go | [Effective Go](https://go.dev/doc/effective_go) and [Go Code Review Comments](https://go.dev/wiki/CodeReviewComments) |
240+
| JavaScript/TypeScript SDKs | JavaScript/TypeScript | [TypeScript ESLint recommended and stylistic rule sets](https://typescript-eslint.io/users/configs/) |
241+
| Kotlin SDKs | Kotlin | [Kotlin Coding Conventions](https://kotlinlang.org/docs/coding-conventions.html) |
242+
| C# SDKs | C# | [Microsoft C# coding conventions](https://learn.microsoft.com/dotnet/csharp/fundamentals/coding-style/coding-conventions) |
243+
244+
### Automated Enforcement
245+
246+
| Area | Tooling and CI entry point |
247+
| --- | --- |
248+
| Server | `server/pyproject.toml`; `.github/workflows/server-test.yml` runs `uv run ruff check` |
249+
| CLI and Python SDKs | package `pyproject.toml` files; `.github/workflows/sdk-tests.yml` runs `uv run ruff check` and `uv run pyright` |
250+
| Go components and Kubernetes | `gofmt`, `go vet`, and `golangci-lint` where configured; component workflows run format, lint, build, and test checks |
251+
| Go SDK | `.github/workflows/sdk-tests.yml` runs `gofmt`, `go vet`, and tests |
252+
| JavaScript/TypeScript SDKs | `sdks/eslint.base.mjs` and package `eslint.config.mjs`; `.github/workflows/sdk-tests.yml` runs `pnpm run lint` and `pnpm run typecheck` |
253+
| Kotlin SDKs | Gradle Spotless with ktlint; `.github/workflows/sdk-tests.yml` runs `./gradlew spotlessCheck ...` |
254+
| C# SDKs | `.editorconfig`, `Directory.Build.props`, and .NET analyzers; `.github/workflows/sdk-tests.yml` runs `dotnet build ... /warnaserror` |
255+
256+
### Python (Server, CLI, Python SDKs)
257+
258+
- **Style Guide**: Follow [PEP 8](https://peps.python.org/pep-0008/)
259+
- **Linter/Formatter**: Use `ruff` for linting and formatting
233260
- **Type Hints**: Always use type hints for function signatures
234261
- **Docstrings**: Use Google-style docstrings for public APIs
235262

@@ -259,13 +286,13 @@ def create_sandbox(
259286

260287
```bash
261288
cd server
262-
uv run ruff check src tests
263-
uv run ruff format src tests
289+
uv run ruff check
290+
uv run ruff format opensandbox_server tests
264291
```
265292

266-
### Go (execd)
293+
### Go (components, Kubernetes, Go SDK)
267294

268-
- **Style Guide**: Follow [Effective Go](https://golang.org/doc/effective_go)
295+
- **Style Guide**: Follow [Effective Go](https://go.dev/doc/effective_go)
269296
- **Formatter**: Use `gofmt` for formatting
270297
- **Imports**: Organize in three groups (stdlib, third-party, internal)
271298
- **Error Handling**: Always handle errors explicitly
@@ -291,6 +318,20 @@ gofmt -w .
291318
make fmt
292319
```
293320

321+
### JavaScript/TypeScript (SDKs)
322+
323+
- **Style Guide**: Follow the TypeScript ESLint recommended and stylistic rule sets configured in `sdks/eslint.base.mjs`
324+
- **Linter**: Use `eslint` for JavaScript/TypeScript linting
325+
- **Type Checking**: Run `tsc` with the package `tsconfig.json`
326+
327+
**Running Checks:**
328+
329+
```bash
330+
cd sdks
331+
pnpm run lint:js
332+
pnpm run typecheck:js
333+
```
334+
294335
### Java/Kotlin (Java/Kotlin SDKs)
295336

296337
- **Style Guide**: Follow [Kotlin Coding Conventions](https://kotlinlang.org/docs/coding-conventions.html)
@@ -307,6 +348,22 @@ suspend fun createSandbox(
307348
}
308349
```
309350

351+
### C# (C# SDKs)
352+
353+
- **Style Guide**: Follow [Microsoft C# coding conventions](https://learn.microsoft.com/dotnet/csharp/fundamentals/coding-style/coding-conventions)
354+
- **Formatting**: Follow the SDK `.editorconfig` files
355+
- **Analyzers**: Keep .NET analyzers enabled and treat build warnings as errors in CI
356+
357+
**Running Checks:**
358+
359+
```bash
360+
cd sdks/sandbox/csharp
361+
dotnet build OpenSandbox.sln --configuration Release /warnaserror
362+
363+
cd ../../code-interpreter/csharp
364+
dotnet build OpenSandbox.CodeInterpreter.sln --configuration Release /warnaserror
365+
```
366+
310367
### General Guidelines
311368

312369
- **Naming Conventions**:
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
root = true
2+
3+
[*.cs]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4

0 commit comments

Comments
 (0)