本文档介绍如何编写分析器生成的注释,并给出相关指南。
分析器注释的内容以 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 通用化的进展情况(如果有的话)。