Skip to content

Instantly share code, notes, and snippets.

@sanemat
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanemat/68bf1d9013d4b6a98a17 to your computer and use it in GitHub Desktop.
Save sanemat/68bf1d9013d4b6a98a17 to your computer and use it in GitHub Desktop.
Visualize php lint tools

静的解析をPull Request上に可視化する

あまり詳しくないのでおしえてください! 気になるところがあったらどんどん止めて。 あと、こんなことやってるので誰か手伝って!

今使ってる lintなど静的解析のコマンド、web サービスなど

  • PHP CodeSniffer
    • CodeSniffer is a tool which checks if your code is compliant with a general ruleset or your own custom ruleset.
  • PHP MD
    • MD stands for Mess Detector

言語ごとの特色

  • php
    • 知りたい
  • javascript
    • eslint, jscsなどがある
    • これらを使っているプロジェクトの場合、そもそもこれらが npm test の中などに組み込んであることが多い
    • gulpでwatchしてたりして、手元で保存して怒られて直す
    • 静的解析とかASTいじるとかtranspilerとか全盛
    • 片手間javascriptの場合、viewにjavascript片が うわー
  • golang
    • gofmt, gorename など? golint 全然知らない
  • python
    • pep8, flake8
  • ruby
    • rubocop, brakeman, ruby組み込みのcheck warning などがある
    • test には組み込んでいないところが多い testはtestのみ
    • HoundCI, pronto といったソリューション(pull requestにreview commentとして載せる)

エディタのサポート

エディタなりIDEなりの手元でガンガン支援受けて直すのが一番いい

Pull Request Review Comment

全員がlint済みのものをpushしてくれるか? というと疑問 低い方に合わせる jenkinsのログに、カバレッジと一緒に眠ってるよ 必要無いならそれでいい、無駄に可視化すると埋もれる

おもにrubyプロジェクトの場合 HoundCI, pronto 言語ごとに実装してるのマヌケっぽい

example

# TravisCIやCircleCIの after testの中で(travisCI用語でafter_script, CircleCI用語でpost test)
git diff --name-only origin/master \
  | grep ".*.php$" \
  | xargs phpcs --report=checkstyle \
  | checkstyle_filter-git diff origin/master \
  | saddler report \
      --require saddler/reporter/github \
      --reporter Saddler::Reporter::Github::PullRequestReviewComment

途中出力

git diff --name-only origin/master \
  | grep ".*.php$" \
  | xargs phpcs --report=checkstyle

<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="1.0.0">
 <file name="/path/to/code/myfile.php">
  <error line="2" column="1" severity="error" message="Missing file doc comment" source="PEAR.Commenting.FileComment"/>
  <error line="20" column="43" severity="error" message="PHP keywords must be lowercase; expected &quot;false&quot; but found &quot;FALSE&quot;" source="Generic.PHP.LowerCaseConstant"/>
  <error line="47" column="1" severity="error" message="Line not indented correctly; expected 4 spaces but found 1" source="PEAR.WhiteSpace.ScopeIndent"/>
  <error line="47" column="20" severity="warning" message="Equals sign not aligned with surrounding assignments" source="Generic.Formatting.MultipleStatementAlignment"/>
  <error line="51" column="4" severity="error" message="Missing function doc comment" source="PEAR.Commenting.FunctionComment"/>
 </file>
</checkstyle>

と、たぶんなるはずなんだけど、手元にいい感じにsetupしたphpプロジェクト無いので、誰か手伝ってほしい。

参照

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment