tag:crieit.net,2005:https://crieit.net/tags/marked/feed
「marked」の記事 - Crieit
Crieitでタグ「marked」に投稿された最近の記事
2022-03-05T23:05:27+09:00
https://crieit.net/tags/marked/feed
tag:crieit.net,2005:PublicArticle/18135
2022-03-05T23:05:27+09:00
2022-03-05T23:05:27+09:00
https://crieit.net/posts/stylelint-adjust-rgb-and-scss-20220305
stylelint 周りのアップデート (Scss対応、 rgb 指定)
<p>久々にパッケージガーデニングしたら stylelint から Scss 関連や <code>rgb</code> の指定で怒られるようになってしまったので対処。</p>
<h2 id="現象"><a href="#%E7%8F%BE%E8%B1%A1">現象</a></h2>
<pre><code class="bash">$ stylelint ./src/scss/**/*.scss
src/scss/global/_scssVariables.scss
19:19 ✖ Unexpected unknown function "color.scale" function-no-unknown
21:19 ✖ Unexpected unknown function "color.adjust" function-no-unknown
22:17 ✖ Unexpected unknown function "color.adjust" function-no-unknown
23:19 ✖ Unexpected unknown function "color.scale" function-no-unknown
24:20 ✖ Unexpected unknown function "color.scale" function-no-unknown
src/scss/object/component/_c-button.scss
19:31 ✖ Expected modern color-function notation color-function-notation
src/scss/_plugins/articlesns/_articlesns.scss
40:16 ✖ Unexpected unknown function "color.scale" function-no-unknown
53:31 ✖ Unexpected unknown function "map.get" function-no-unknown
57:35 ✖ Unexpected unknown function "color.scale" function-no-unknown
57:47 ✖ Unexpected unknown function "map.get" function-no-unknown
57:81 ✖ Unexpected unknown function "map.get" function-no-unknown
</code></pre>
<p>npmパッケージをアップデートした際に stylelint やそれに関連するパッケージ等をアップデートしたところ、いくつかの項目で怒られるようになってしまいました。</p>
<p>この中で特に気になったのが <code>Expected modern color-function notation color-function-notation</code> のエラー。</p>
<p><a target="_blank" rel="nofollow noopener" href="https://twitter.com/kaji2/status/1451433868863553536">かじさんはTwitterを使っています 「stylelint-config-standard の 23.0.0 アップデートで、 color-function-notation が 'modern' で追加された。 従来のコンマ区切りだったrgb()、rgba()をスペース区切りに揃えるもの。ついでにrgbaをrgbに揃えている。 https:\/\/t.co\/yHFngFOS8J」 \/ Twitter</a></p>
<p>検索したところ、このツイートがヒット。</p>
<p><code>stylelint-config-standard</code> のアップデートで色指定が引っかかるようになったようです。これは css level 4 の構文に対応したもののようです。</p>
<ul>
<li><a target="_blank" rel="nofollow noopener" href="https://triple-underscore.github.io/css-color-ja.html#rgb-functions">CSS Color Module Level 4 (日本語訳)</a></li>
</ul>
<p>構文としては次のように変更になります。</p>
<pre><code class="css">/* 旧来 */
.hoge {
background-color: rgba(48, 48, 48, 0.5);
}
/* 新 */
.hoge {
background-color: rgb(48 48 48 / 50%);
}
</code></pre>
<ul>
<li><code>rgb()</code> と <code>rgba()</code> から <code>rgb()</code> へ統一</li>
<li>RGB値はカンマ区切りからスペース区切りへ</li>
<li>RGB値とアルファ値の区切りはカンマからスラッシュへ</li>
</ul>
<p>一方、 Scss でも独自に <code>rgb()</code> が存在しています。このおかげで、 Scss で次のように色の指定でRGB値ではなく16進数や変数を使用しても問題が発生しないわけですね。</p>
<pre><code class="scss">$black: #333;
.hoge {
background-color: rgba($black, 0.5);
}
</code></pre>
<p>ただ、 Scss 側ではまだカンマ区切りしか対応していなさそうです。そのため、仮に css level 4 の構文を使用して Scss のトランスパイルを走らせると、次のようにエラーになってしまいます。</p>
<pre><code class="bash">[hh:ii:ss] gulp-notify: [sass] Error: src\scss\object\component\_c-newscards.scss
Error: Missing element $blue.
╷
128 │ box-shadow: inset 2px 2px 5px 0 rgb(g.$us-main-color 0.5);
│ ^^^^^^^^^^^^^^^^^^^^^^^^^
╵
src\scss\object\component\_c-newscards.scss 128:37 @use
src\scss\contents.scss 36:1 root stylesheet
19:31 ✖ Expected modern color-function notation color-function-notation
</code></pre>
<p>Scss の構文にすると stylelint でコケて、 stylelint のデオフォルトに従って css level 4 の構文にすると Scss のトランスパイルが通らない、と。</p>
<h2 id="対処"><a href="#%E5%AF%BE%E5%87%A6">対処</a></h2>
<p>仕方ないので、上述引用のツイートと同様に <code>color-function-notation</code> のパラメータを <code>legacy</code> にすることで回避することにしました。</p>
<h3 id=".stylelint.json"><a href="#.stylelint.json">.stylelint.json</a></h3>
<pre><code class="json"> "rules": {
// 略
"color-function-notation": "legacy",
// 略
}
</code></pre>
<h2 id="余談"><a href="#%E4%BD%99%E8%AB%87">余談</a></h2>
<p>上述対処の前に他の回避方法がないか試す中で、一通りパッケージをアップデートしたりしましたがかえって Scss の関数等のエラーが出てしまったのは冒頭の通り。</p>
<p>そこでそれらへの対応として次のようにしました。</p>
<h3 id="package.json"><a href="#package.json">package.json</a></h3>
<pre><code class="json"> "devDependencies": {
// 略
"stylelint-config-standard-scss": "3.0.0", // 追加
// 略
}
</code></pre>
<h3 id=".stylelint.json"><a href="#.stylelint.json">.stylelint.json</a></h3>
<pre><code class="json"> "extends": [
"stylelint-config-standard",
"stylelint-config-standard-scss", // 追加
"stylelint-config-recommended-scss",
"stylelint-config-prettier"
],
</code></pre>
<p>まず <code>stylelint-config-standard-scss</code> を追加。</p>
<h3 id=".stylelint.json"><a href="#.stylelint.json">.stylelint.json</a></h3>
<pre><code class="json"> "rules": {
// 略
"at-rule-no-unknown": null, // Scss関数は stylelint-config-standard-scss に任せるようにしたため独自で追加していた設定は削除
"function-no-unknown": [
true, // map.get や color.scale 等 Dart Sass の関数は引っかかってしまうのでルールを追加
{
"ignoreFunctions": [
"/^map\\..+/",
"/^color\\..+/"
]
}
],
"scss/at-rule-no-unknown": true, // Scssのデフォルト関数以外は引っかかるようにする
"scss/dollar-variable-pattern": "^(([a-z][a-zA-Z0-9_]+)|([a-z][a-z0-9]*)(-[a-zA-Z0-9_]+)*)$", // 互換性のためケバブケース強制は除去
"scss/at-mixin-pattern": "^(([a-z][a-zA-Z0-9_]+)|([a-z][a-z0-9]*)(-[a-zA-Z0-9_]+)*)$", // 互換性のためケバブケース強制は除去
"scss/at-mixin-argumentless-call-parentheses": "always" // 互換性のため引数なしのmixin呼び出しの際は括弧強制
"stylelint-config-standard-scss": "3.0.0", // 追加
// 略
}
</code></pre>
<p>その上で <code>.stylelint.json</code> のルールをいくつか変更しました。</p>
<p>これで stylelint を走らせてエラーが出なくなったことを確認。</p>
<h2 id="参考"><a href="#%E5%8F%82%E8%80%83">参考</a></h2>
<h3 id="color-function-notation"><a href="#color-function-notation">color-function-notation</a></h3>
<ul>
<li><a target="_blank" rel="nofollow noopener" href="https://stylelint.io/user-guide/rules/list/color-function-notation/">color-function-notation | Stylelint</a></li>
<li><a target="_blank" rel="nofollow noopener" href="https://twitter.com/kaji2/status/1451433868863553536">かじさんはTwitterを使っています 「stylelint-config-standard の 23.0.0 アップデートで、 color-function-notation が 'modern' で追加された。 従来のコンマ区切りだったrgb()、rgba()をスペース区切りに揃えるもの。ついでにrgbaをrgbに揃えている。 https:\/\/t.co\/yHFngFOS8J」 \/ Twitter</a></li>
</ul>
<h3 id="css level 4"><a href="#css+level+4">css level 4</a></h3>
<ul>
<li><a target="_blank" rel="nofollow noopener" href="https://triple-underscore.github.io/css-color-ja.html#rgb-functions">CSS Color Module Level 4 (日本語訳)</a></li>
<li><a target="_blank" rel="nofollow noopener" href="https://stackoverflow.com/questions/66825515/getting-error-in-css-with-rgb0-0-0-15">Getting error in CSS with <code>rgb\(0 0 0 \/ 15%\)</code> - Stack Overflow</a>
<ul>
<li>似たようなケース</li>
</ul></li>
</ul>
<h3 id="Scss 周りへの対応"><a href="#Scss+%E5%91%A8%E3%82%8A%E3%81%B8%E3%81%AE%E5%AF%BE%E5%BF%9C">Scss 周りへの対応</a></h3>
<ul>
<li><a target="_blank" rel="nofollow noopener" href="https://qiita.com/taqumo/items/2ed2cd7e35301d4aed8e">Stylelint 14.0.0 で Sass ファイルを lint させる方法 - Qiita</a></li>
<li><a target="_blank" rel="nofollow noopener" href="https://github.com/stylelint-scss/stylelint-config-standard-scss">GitHub - stylelint-scss\/stylelint-config-standard-scss: The standard shareable SCSS config for Stylelint.</a></li>
<li><a target="_blank" rel="nofollow noopener" href="https://stylelint.io/user-guide/rules/list/at-rule-no-unknown/">at-rule-no-unknown | Stylelint</a></li>
<li><a target="_blank" rel="nofollow noopener" href="https://stylelint.io/user-guide/rules/list/function-no-unknown/">function-no-unknown | Stylelint</a></li>
<li><a target="_blank" rel="nofollow noopener" href="https://github.com/stylelint-scss/stylelint-scss/blob/master/src/rules/at-mixin-pattern/README.md">stylelint-scss\/README.md at master · stylelint-scss\/stylelint-scss · GitHub</a></li>
<li><a target="_blank" rel="nofollow noopener" href="https://qiita.com/shigemaruu/items/2e64fe0a425946a2e4a1">stylelint-config-sass-guidelinesの内容をメモする - Qiita</a></li>
<li><a target="_blank" rel="nofollow noopener" href="https://github.com/stylelint-scss/stylelint-scss/blob/master/src/rules/at-mixin-argumentless-call-parentheses/README.md">stylelint-scss\/README.md at master · stylelint-scss\/stylelint-scss · GitHub</a></li>
</ul>
<h3 id="marked"><a href="#marked">marked</a></h3>
<ul>
<li><a target="_blank" rel="nofollow noopener" href="https://marked.js.org/">Marked Documentation</a></li>
</ul>
<p>パースする関数が <code>marked</code> から <code>marked.parse</code> メソッドに変更になっていた。</p>
arm-band