本文件提供如何撰寫分析器所產生之註解的相關資訊與準則。
分析器註解的內容以 Markdown 文件的形式,存放在 exercism/website-copy 儲存庫中。
註解會包含一個指標字串,格式為<track-slug>.<exercise-slug>.<comment-slug>,指向 website-copy 儲存庫中特定的 Markdown 文件。
例如,ruby.two-fer.string-interpolation 指向 https://github.com/exercism/website-copy/blob/main/analyzer-comments/ruby/two-fer/string_interpolation.md。
如果某則註解是特定於某種語言,而_不_是特定於某個練習,請把<exercise-slug>替換成general。
例如ruby.general.string-explicit_return
在軌道最初的幾個練習中,以下幾點_格外_重要:
在 JavaScript 中,有位學生用let寫了一個頂層常數。
<!-- not following these guidelines -->
As you know, everyone uses const, you shouldn't use let or var.
這則註解沒有遵循這些準則,原因如下:
<!-- better -->
Prefer `const` and `let` over `var`. The `const` declaration stops a variable
from being accidentally reassigned, which provides safety, and reduces
cognitive load for someone reading the code. [This article](https://medium.com/javascript-scene/javascript-es6-var-let-or-const-ba58b8dcde75)
explains the difference between the three.
在 Go 中,有位學生建立了自訂錯誤,而沒有使用內建的錯誤:
<!-- not following these guidelines -->
I see you are creating a custom `error`. This is perfectly fine! If you did not
know about `errors.New` and `fmt.Errorf` have a look at them as they are much
simpler ways to create an error. Custom errors are helpful if you want to check
if an error is of a certain type later.
這則註解沒有遵循這些準則,原因如下:
<!-- better -->
A custom `error` is typically used to provide custom behavior, or to distinguish
on type later. For simpler cases, it's more common to rely on `errors.New` or
`fmt.Errorf`. This [in-depth article](https://golangbot.com/custom-errors/) about
custom errors might be interesting.
由於註解與分析器並不在同一個儲存庫中,每個分析器都應該有 CI,用來檢查該分析器所使用的註解(也就是那些可能成為輸出的註解),是否都是 exercism/website-copy 儲存庫 main 分支上的註解。
撰寫本文時,這個 issue 記錄了這套 CI 通用化(如果真有)的進展狀態。