私のやっていることは、GitHub - discourse/discourse-plugin-skeleton: Template for Discourse plugins と GitHub - discourse/discourse-theme-skeleton: Template for Discourse themes からワークフローを盲目的にコピーすることです。(ダッシュボードプラグインがストライププラグインに依存しているため、プラグインのものを少し調整する必要があります)。これで、リンティングは十分に行えるはずだと信じています。
しかし、私が望むのは、コミットする前にVSCodeでリンティングを行うことです。以前は機能していましたが、停止してしまい、Emacsを20年前に知っていたようなVSCodeの知識がある人が、「Control-Pと入力し、フォーマットツールをインストールする操作を行い、設定ファイルを編集して正しいことをするようにする」といったことを言えるのではないかと思っています。そうすれば、Control-Sと入力するだけで、Handlebars、JavaScript、その他のものがきれいにフォーマットされ、定義したものの使っていない変数などもすべて見つけられるようになります。
近づいてきた
さて、これを実行しました。
npm install --global yarn
yarn add prettier
そして、discourse-prettier ができました。
#!/usr/bin/env bash
if [ -n "$(find assets -type f \( -name "*.scss" -or -name "*.js" -or -name "*.es6" -or -name "*.hbs" \) 2>/dev/null)" ]; then
yarn prettier --write "assets/**/*.{scss,js,es6,hbs}"
fi
if [ -n "$(find admin/assets -type f \( -name "*.scss" -or -name "*.js" -or -name "*.es6" -or -name "*.hbs" \) 2>/dev/null)" ]; then
yarn prettier --write "admin/assets/**/*.{scss,js,es6,hbs}"
fi
if [ 0 -lt $(find test -type f \( -name "*.js" -or -name "*.es6" \) 2> /dev/null | wc -l) ]; then
yarn prettier --write "test/**/*.{js,es6}"
fi
if [ -n "$(find assets -type f \( -name "*.scss" -or -name "*.js" -or -name "*.es6" -or -name "*.hbs" \) 2>/dev/null)" ]; then
yarn prettier --list-different "assets/**/*.{scss,js,es6,hbs}"
fi
if [ -n "$(find admin/assets -type f \( -name "*.scss" -or -name "*.js" -or -name "*.es6" -or -name "*.hbs" \) 2>/dev/null)" ]; then
yarn prettier --list-different "admin/assets/**/*.{scss,js,es6,hbs}"
fi
if [ 0 -lt $(find test -type f \( -name "*.js" -or -name "*.es6" \) 2> /dev/null | wc -l) ]; then
yarn prettier --list-different "test/**/*.{js,es6}"
fi
これで問題の一部は解決したので、少なくともコマンドラインからprettierを実行できるようになりました。しかし、VSCodeに私の面倒な作業をしてもらうために、まだお金を払う価値はあると思っています。保存時に、eslint(またはrubopなど)を実行し、修正するか、修正できないことを教えてほしいです。エディタにコードを書かせるほどではないと思いますが、フォーマットさせないほどではないと思っています。
以前、誰かが使用しているVSCodeプラグインを提案していたトピックがあり、それが多少役立ちましたが、今は見当たりません。