开发者

Emulating compile-time checks for scripting languages (PHP and JS)

开发者 https://www.devze.com 2023-03-10 06:32 出处:网络
For compiled languages like Java or C, compilation is at the forefront of testing your code. It handles misspellings and enforces interfaces. It has other neat fetures like Java\'s @Deprecated and @Ov

For compiled languages like Java or C, compilation is at the forefront of testing your code. It handles misspellings and enforces interfaces. It has other neat fetures like Java's @Deprecated and @Override to mention a few.

Is there a tool wh开发者_运维技巧ich checks your code in similar fashion for interpreted languages like PHP or JavaScript?

I'm well aware that JS does not have interfaces, but many meta-information could be fed to the tool thru Javadoc style comments for example.


For some of your required use cases like syntax checking, naming errors, etc this can be done through static code analysis tools, which can also enforce coding conventions (line length, naming conventions, use of deprecated functions, etc). For JavaScript there's JSLint (also check out jslint4java, which can be used from command-line or IDEs). There are similar tools for most scripting languages. I'm not familiar with such tools for PHP, but you might find something good in this related question.

Also, when you use unit tests to ensure the quality of your code, the code will be executed all the time and syntax errors etc. will be identified quickly anyway. While tools like jslint can find you some of the same problems without the need to write test code, unit testing will find much more. A combination of unit testing and one or more code checkers should always be use IMHO.

0

精彩评论

暂无评论...
验证码 换一张
取 消