Documentation
¶
Overview ¶
Package rules は verify の検証ルール群を実装する。 各ルールは Context を受け取り、指摘(Issue)の一覧を返す純粋な関数。
Index ¶
Constants ¶
const DefaultSectionsFile = "sections.yaml"
DefaultSectionsFile は必須セクション定義の既定のファイル名。
Variables ¶
This section is empty.
Functions ¶
func LoadSections ¶
func LoadSections(path string) (map[string]SectionSpec, error)
LoadSections は sections.yaml を読み込む。
未存在はエラーにする。読めなかったぶんを黙って空として扱うと、 定義ファイルを消したり綴りを誤ったりしたときに検査が素通りする。
func MarshalSections ¶
func MarshalSections(sections map[string]SectionSpec) ([]byte, error)
MarshalSections は必須セクション定義を YAML へ整形する。
Types ¶
type Context ¶
type Context struct {
Cfg *config.Config
Docs []*parser.Document
Sections map[string]SectionSpec
Config Settings
// contains filtered or unexported fields
}
Context はルールが参照する解析済みデータ。 組み立ては NewContext だけが行う。
func NewContext ¶
func NewContext(cfg *config.Config, docs []*parser.Document, sections map[string]SectionSpec, settings Settings) *Context
NewContext はルールが参照する文脈を組み立てる。
定義の索引をここで作るのは、別の手順に分けると呼び忘れが起きるためである。 呼び忘れると索引が空になり、ref_integrity が全参照を「未定義」と報告する。
func (*Context) Definition ¶
Definition は ID の定義位置を返す。
type Issue ¶
type Issue struct {
Rule string `json:"rule"`
Kind Kind `json:"kind"`
File string `json:"file"`
Line int `json:"line"`
Message string `json:"message"`
Expected string `json:"expected,omitempty"`
Severity Severity `json:"severity"`
}
Issue は検証結果の指摘 1 件。
func DepOrder ¶
DepOrder は依存関係(要件→設計→実装)の順序を検証する。
- depends_on に挙げたファイルが存在するか
- depends_on のまとめ指定(glob)が実ファイルに 1 件でも一致するか(警告)
- 参照先 ID が、依存関係として宣言済みの文書で定義されているか
- ファイル依存に循環が無いか(警告)
未宣言の文書は判定材料が無いため対象外とする。 chain に載らない文書タイプ(用語集など)で定義された ID も対象外とする。 どこからでも引かれる補助文書なので、参照のたびに depends_on を書かせない。
func IDHierarchy ¶
IDHierarchy は階層識別子(R-1.2 のようにドットで繋いだ ID)の名前上の親が、 構造上の親(直近の ID 付き祖先見出し)と一致するかを検証する。
関係(含有辺)を作るのは見出しの入れ子だけで、ドットは名前でしかない。 名前と構造が食い違うと、名前が示す親子と実際に辿られる親子が別物になる。 ドットを含まない ID は階層を主張していないので、対象にしない。
func RequiredSections ¶
RequiredSections は文書タイプごとの必須セクションを検証する。
ID 付き見出しがある文書では主レベル(parser.PrimaryLevels)の ID セクションの直下を、 ID が無い文書では文書全体を検査対象とする。深いレベルの ID は主要素の細目であり、 必須セクションを備える単位ではないため対象にしない。
func TermConsistency ¶
TermConsistency は用語集との一貫性を検証する。
検査するのは 1 つだけ。用語集が別表記として挙げている語が、正式な用語の 代わりに使われていないか。用語集が「FR = 機能要件 (Functional Requirement)」と 定めている以上、文書側は FR を使うべきなので、別表記の出現は指摘する。
探す語は用語集から与えられるので、判定は照合であって推測ではない。 日本語でも確実に効くので、深刻度は error にしてある。
用語集に無い語を推測して指摘することはしない。手がかりが英大文字の略語と 強調しか無く、語の区切りが無い言語では原理的に効かない。目安にしかならない 指摘で文書を埋めるより、何を用語とするかの判断は人に委ねる。
type Kind ¶
type Kind string
Kind は指摘の種類。メッセージの文言に依らず指摘を機械で識別する鍵で、 1 つのルールが複数の種類を発行することがある。
const ( // KindRefUndefined は未定義 ID への参照。 KindRefUndefined Kind = "ref_undefined" // KindTermAlias は正式な用語の代わりに使われた別表記。 KindTermAlias Kind = "term_alias" // KindSectionEmpty は中身の無い必須セクション。 KindSectionEmpty Kind = "section_empty" // KindSectionMissing は必須セクションの欠落。 KindSectionMissing Kind = "section_missing" // KindSectionOrder は必須セクションの順序違反。 KindSectionOrder Kind = "section_order" // KindIDDuplicate は ID の重複定義。 KindIDDuplicate Kind = "id_duplicate" // KindIDGap は連番の欠番。 KindIDGap Kind = "id_gap" // KindDepMissing は存在しないファイルへの依存宣言。 KindDepMissing Kind = "dep_missing" // KindDepGlobEmpty はどのファイルにも一致しない依存のまとめ指定。 KindDepGlobEmpty Kind = "dep_glob_empty" // KindDepUndeclared は依存関係に無いファイルで定義された ID への参照。 KindDepUndeclared Kind = "dep_undeclared" // KindDepInverted は下流で定義された ID への参照(依存順序違反)。 KindDepInverted Kind = "dep_inverted" // KindDepCycle はファイル依存の循環。 KindDepCycle Kind = "dep_cycle" // KindHierarchyMismatch は階層 ID と構造上の親の不一致(親の不在を含む)。 KindHierarchyMismatch Kind = "hierarchy_mismatch" )
type SectionSpec ¶
SectionSpec は文書タイプごとの必須セクション定義(sections.yaml)。
type Settings ¶
type Settings struct {
RefIntegrity struct {
Enabled *bool `yaml:"enabled"`
} `yaml:"ref_integrity"`
TermConsistency struct {
Enabled *bool `yaml:"enabled"`
// GlossaryType は厳密デコードが glossary_type を既知のキーとして
// 受けるための宣言。値の解決は cfg.GlossaryType の 1 経路に寄せて
// あるので、ルール実装はこのフィールドを読まないこと(読むと
// 経路によって答えが割れる状態へ逆戻りする)
GlossaryType string `yaml:"glossary_type"`
} `yaml:"term_consistency"`
RequiredSections struct {
Enabled *bool `yaml:"enabled"`
Config string `yaml:"config"`
} `yaml:"required_sections"`
IDUniqueness struct {
Enabled *bool `yaml:"enabled"`
CheckSequence bool `yaml:"check_sequence"`
} `yaml:"id_uniqueness"`
DepOrder struct {
Enabled *bool `yaml:"enabled"`
} `yaml:"dep_order"`
IDHierarchy struct {
Enabled *bool `yaml:"enabled"`
} `yaml:"id_hierarchy"`
}
Settings は設定ファイルの rules セクション。