Add section about documenting magic numbers

オープン
#73 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
1/5
見積もり時間
1〜3時間
初心者へのやさしさ
48/100
issue の種類
ドキュメント
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
css
領域
documentation

調査の方向性

リポジトリ内の CSS Guide を特定し、既存のセクション構成とスタイルを確認します。magic numbers、変数、custom properties、design tokens、説明的なコメントのドキュメント化に関して提供されたガイダンスを言い換えるセクションを追加します。関連のない内容を変更せず、ガイダンスが明確に統合されていれば完了です。

索引モデルが issue の本文から書いたものです。

説明

enhancement

@spaceninja wrote this in a PR comment thread about why we prefer to convert "magic numbers" into variables. We should add a section rephrasing this to the CSS Guide:

Magic numbers in CSS files are a mystery. Why is it this particular value? What happens if I change it? Does it match anything else?

Turning your magic numbers into variables or custom properties is a form of documentation and safety checks:

By naming your number, you help explain what it means. $touch-target-size tells you at a glance what the number means and opens the door to reuse elsewhere.

It's also a form of safety check — if you set this value here and then it also gets used somewhere else but both locations are hard-coded, then a future dev doesn't know they need to update both if we want those sizes to match.

Thus, as a general practice, unless we have good reason, we convert almost all values to variables, custom properties, or design tokens.

Sometimes you really do have a special one-off magic number. "The component is sized at 137px wide because that's the only size that looks good". In those cases, when you don't need to reuse the value, then a descriptive comment explaining the source of the magic number is sufficient.

But in general, coming across a magic number with an unclear meaning and source is a red flag in a CSS file.

In almost every instance, I have found that what felt arbitrary made more sense when converted to a standard design token that already exists, or by documenting it so it could be reused.

In this case, your magic number is a very good one that can and should be reused elsewhere — minimum touch target size! That's a great case for making a design token, or at least a variable.

主要言語
言語のデータがありません
スター
24
フォーク
1
平均マージ
3時間 48分
マージ済み PR(30日)
1

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

cloudfour/guides のほかの issue

cloudfour/guides の issue をすべて見る

似ている issue

Documentation の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。