News for hackers. Stuff that matters.
Re:Catching bugs early with static analysis by phpdave11 on Monday August 12, 2019 @09:12AM (#20675058)
PHPStan is a great tool. In addition to PHPStan, I also use phpnsc (name space checker) to check for missing use statements, php-cs-fixer (code style fixer) to ensure the code adheres to my code style, phpcpd (copy paste detector) to detect duplicate code, and phpmd (mess detector) to find potential problems in the code. These are all set up in my CI pipeline so that my app will fail to build if any of these 5 tools detect a problem. It has saved me from deploying buggy code several times.
Re:Catching bugs early with static analysis by blowski on Monday August 12, 2019 @01:29PM (#20677709)
Here’s a GitHub repo and Docker image with lots more static analysis tools to play with:

https://github.com/jakzal/phpqa

Re:Catching bugs early with static analysis by king7532 on Monday August 12, 2019 @10:17AM (#20675594)
Great advice and thank you for sharing! Do you have a Dockerfile or CI config/recipe that you could share?
Re:Catching bugs early with static analysis by phpdave11 on Monday August 12, 2019 @10:33AM (#20675741)
Here's the bash script I use to do the code validation. It's called from within my Dockerfile.

https://gist.github.com/phpdave11/412893f8366cab0afa85e81a7a...

Re:Catching bugs early with static analysis by andreascreten on Monday August 12, 2019 @09:13AM (#20675064)
Makes sense, thanks for sharing!
Re:Catching bugs early with static analysis by baybal2 on Monday August 12, 2019 @09:16AM (#20675100)
Very helpful in the JS world, but I am afraid there is not standalone standard for static checks in JS.

There is typescript, but that's an entire new language to just partially cover the type checks.

Re:Catching bugs early with static analysis by bcherny on Monday August 12, 2019 @09:55AM (#20675409)
If you compile your code with TypeScript and set allowJs=true, you’ll get a lot of checking for free with no changes at all to your existing JS code. TS will catch things like dead code, missing return statements, type mismatches and so on for free.
Re:Catching bugs early with static analysis by baybal2 on Monday August 12, 2019 @10:24AM (#20675663)
It will be nice if the use case of TS only being used as a static checker be supported better, but then there will be no point in TS as a language
Re:Catching bugs early with static analysis by oakesm9 on Monday August 12, 2019 @10:27AM (#20675699)
If that's the use case you have, then Facebook's Flow is a better fit.
Re:Catching bugs early with static analysis by bcherny on Monday August 12, 2019 @11:51AM (#20676541)
What kind of additional support do you wish TS had, that it doesn’t have already?
Re:Catching bugs early with static analysis by tru3_power on Monday August 12, 2019 @11:44AM (#20676472)
Fortify SCA supports js and typescript. I’ve been writing custom rules for it lately at work and have had great success with it. Expensive but powerful tool.
Re:Catching bugs early with static analysis by xenorplxx on Monday August 12, 2019 @10:24AM (#20675668)
alternative to typescript would be facebook's flow.js, which works with 'normal' JS code