User:Sumit.iitp/static analysis tools

Static Analysis tools for mediawiki
This is a GSoC project proposal to create tools for checking the integrity of code submitted to mediawiki repositories against its set of code conventions.

Phabricator report:

Profile Information:

 * Name: Sumit Asthana
 * Email: asthana.sumit23@gmail.com
 * IRC nick: codezee
 * Location: India
 * Typical working hours: 6PM to 2AM before 26th April, 2PM to 12AM after 26th April(Indian Standard Time)

Synopsis
Presently, the mediawiki code is checked jenkins tests for potential errors, as well as violations of spaces. However it does not check if the code conventions of mediawiki are being properly followed. E.g if a user gives a space before a php open tag, its not an error in itself, and hence not flagged as one, but its a potential code style error. Thus, phpcs [code sniffer] has been introduced to check for errors. The project mainly consists of developing phpcs sniffs with respect to mediawiki code conventions

Workflow
The following sniffs have been proposed to be introduced:

General Sniffs

 * 1) Usage of $dbr->query directly instead of the $dbr->select wrapper
 * 2) Using wfMessage when $this->msg is usable
 * 3) Using globals ($wgUser, $wgRequest) when their context equivalents could be used instead ($this->getUser, $this->getRequest)
 * 4) Modifying certain globals ($wgUser, $wgResourceModules, etc) inside a $wgExtensionFunction where it is either too early or late to do so
 * 5) Sniff to check indent of multiline statements,except switch cases
 * 6) Space after if,while,foreach,for,switch
 * 7) Disallow multiline ternary operator
 * 8) Disallow 'endif syntax for if conditional
 * 9) Sniff to give preference to use of ! over empty
 * 10) Enforce use of === over ==
 * 11) Sniff to detect documentation of parameters for functions using parameters
 * 12) Sniff to suppress use of $_GET, $_POST, over $request->get(...)
 * 13) Sniff to disallow the use of @ in PHP for suppressing errors
 * 14) Sniff to detect inadequate spacing
 * 15) Sniff to enforce use of MWException over generic Exception

Class Sniffs

 * 1) Sniff to validate class name(can be modified and ported from SquizLabs)

Comments

 * 1) Sniff to check space after inline comments
 * 2) Sniff to validate doc comments as per D-oxygen standards
 * 3) Sniff to disallow doc comments except for funtion,class,interface documentation

Files

 * 1) Sniff to enforce new line at the end of file (GenericSniffs EndFileNewLineSniff from SquizLabs)

Formatting

 * 1) Sniff for alignment of multiline statements, especially when function,array parameters span more than one line
 * 2) Sniff to restrict space after cast(Generic Sniffs NoSpaceAfterCastSniff from SquizLabs)

Naming COnventions

 * 1) Camel Case function name sniff(from SquizLabs GenericSniffs)
 * 2) Constructor Name Sniff
 * 3) UpperConstantNameSniff

Strings

 * 1) Unnecessary String concat sniff

WhiteSpace

 * 1) Disallow SpaceIndentSniff

Existing sniffs that can be ported from Squizlabs

 * 1) [GenericSniffs Whitespace DisallowSpaceIndentSniff]
 * 2) Generic_Sniffs_ControlStructures_InlineControlStructureSniff.
 * 3) DocCommentSniff for vlidating doc comments
 * 4) GenericSniffs EndFileNewLineSniff
 * 5) GenericSniffs LowerCaseFileNameSniff
 * 6) GenericSniffs DisallowMultipleStatementsSniff