Beautify: Difference between revisions

From Freephile Wiki
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
Code is sometimes ugly.  You want to make it look pretty.  http://jsbeautifier.org/ is one such tool.
Code is sometimes ugly.  You want to make it look pretty.  [http://jsbeautifier.org/ JS-beautify] is one such tool.


For PHP, JavaScript and CSS, '''[https://github.com/PHPCSStandards/PHP_CodeSniffer PHP Code Sniffer]''' (phpcs) and its counterpart PHP Code Beautifier (phpcbf) work to ensure your code adheres to standards. For using phpcs in MediaWiki, see [[mw:Manual:Coding_conventions/PHP]]. PHPCS is enabled in ~89% of repositories hosted by WMF<ref>https://phpcs.toolforge.org/</ref>  '''[https://github.com/wikimedia/mediawiki-tools-codesniffer MediaWiki Code Sniffer]''' is the set of rules (or ruleset to be more precise) that defines the standards for the MediaWiki project.
For [[PHP]], [[JavaScript]] and [[CSS]], '''[https://github.com/PHPCSStandards/PHP_CodeSniffer PHP Code Sniffer]''' (<code>phpcs</code>) and its counterpart '''PHP Code Beautifier''' (<code>phpcbf</code>) work to ensure your code adheres to standards. Project Documentation for PHP CodeSniffer is at https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki


Suffice it to say, you can <code>composer phpcs</code> to run the tool from the project root. For more on how to run it, see [[mw:Continuous_integration/PHP_CodeSniffer]] Documentation for PHP_CodeSniffer is at https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki
For using phpcs in MediaWiki, see [[mw:Manual:Coding_conventions/PHP|Manual:Coding_conventions/PHP]]. phpcs is enabled in ~89% of repositories hosted by WMF<ref>https://phpcs.toolforge.org/</ref>  '''[https://github.com/wikimedia/mediawiki-tools-codesniffer MediaWiki Code Sniffer]''' is the '''set of rules''' (or ruleset to be more precise) that defines the standards for the MediaWiki project.
 
You can <code>composer phpcs</code> to run the tool from the project root. For more on how to run it, see [[mw:Continuous_integration/PHP_CodeSniffer|Continuous_integration/PHP_CodeSniffer]]
 
You can list the standards available in the MediaWiki project using the <code>-i</code> option. The standard you want to enforce/use is ''''MediaWiki'''<nowiki/>'


The standards available in the MediaWiki project include 'MediaWiki'
<br>
<code>php ./vendor/bin/phpcs -i</code>
<code>php ./vendor/bin/phpcs -i</code>
<br>
<poem>
The installed coding standards are MySource, PEAR, PSR1, PSR2, PSR12, Squiz, Zend, MediaWiki, Modernize, NormalizedArrays, Universal and PHPCSUtils
The installed coding standards are  
 
MySource,  
PEAR,  
PSR1,  
PSR2,  
PSR12,  
Squiz,  
Zend,  
'''MediaWiki''',  
Modernize,  
NormalizedArrays,  
Universal and  
PHPCSUtils
</poem>


== Configuration ==
If you're a MediaWiki extension developer, you can create a <code>.phpcs.xml</code> configuration file that sets things up for the project and integrates with the MediaWiki vendored binaries. See [[using docker-compose-ci]]
{{References}}
{{References}}
[[Category:CSS]]
[[Category:CSS]]

Latest revision as of 21:35, 26 November 2025

Code is sometimes ugly. You want to make it look pretty. JS-beautify is one such tool.

For PHP, JavaScript and CSS, PHP Code Sniffer (phpcs) and its counterpart PHP Code Beautifier (phpcbf) work to ensure your code adheres to standards. Project Documentation for PHP CodeSniffer is at https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki

For using phpcs in MediaWiki, see Manual:Coding_conventions/PHP. phpcs is enabled in ~89% of repositories hosted by WMF[1] MediaWiki Code Sniffer is the set of rules (or ruleset to be more precise) that defines the standards for the MediaWiki project.

You can composer phpcs to run the tool from the project root. For more on how to run it, see Continuous_integration/PHP_CodeSniffer

You can list the standards available in the MediaWiki project using the -i option. The standard you want to enforce/use is 'MediaWiki'

php ./vendor/bin/phpcs -i

The installed coding standards are
MySource,
PEAR,
PSR1,
PSR2,
PSR12,
Squiz,
Zend,
MediaWiki,
Modernize,
NormalizedArrays,
Universal and
PHPCSUtils

Configuration[edit]

If you're a MediaWiki extension developer, you can create a .phpcs.xml configuration file that sets things up for the project and integrates with the MediaWiki vendored binaries. See using docker-compose-ci

References[edit]