Open main menu

Changes

1,401 bytes added ,  18:51, 17 October 2023
no edit summary
{{ambox|type=content|text=Merge this article with the [[Coding Standards]] article.}} When doing [[continuous integration]], or really any development process where you want to enforce a coding standard (aka coding conventions, or code style), you want to be able to do that automatically. You might have code reviews in your process, but you don't want engineers using eyeballs to check the syntax of code and brace style etc. -- that is so 1990last century. This is where Developer tools like [https://github.com/dsheiko/jscodesniffer jscodesniffer] or [https://github.com/squizlabs/PHP_CodeSniffer PHP CodeSniffer] come into playcan be used to clean up old inconsistent code. While PHP CodeSniffer is great for PHP projects, you can use an '''EditorConfig''' file in your project which is [https://github.com/editorconfig/editorconfig/wiki/Projects-Using-EditorConfig supported natively by most leading IDEs and many open source projects] for all programming languages. See https://editorconfig.org/ on how to systematically define and enforce your coding style and syntactic standards.
jscodesniffer is pretty cool in that it's a nodejs app can be easily integrated with your [[Jenkins]] environment <ref>The example given is using it with the static code analyzer '[http://checkstyle.sourceforge.net/ CheckStyle]' for Java projects via the CheckStyle plugin for Jenkins. However, you can have Jenkins employ jscodesniffer on any source</ref>, or used with a commit hook in your [[Version Control]] system.
 
== MediaWiki editorconfig ==
Here is an example of an editor config file. This is the one used by the MediaWiki project
https://phabricator.wikimedia.org/source/mediawiki/browse/master/.editorconfig
<syntaxhighlight lang=editorconfig>
root = true
 
[*]
indent_style = tab
indent_size = tab
tab_width = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
 
# Ensure text editors don't turn leading spaces into tabs,
# e.g. in multi-line bullet list items
[*.md]
indent_style = space
indent_size = 2
 
# Tabs may not be valid YAML
# @see https://yaml.org/spec/1.2/spec.html#id2777534
[*.{yml,yaml}]
indent_style = space
indent_size = 2
 
[.git/**]
indent_style = space
indent_size = 2
 
# Trailing whitespace is intended in parser test files
# T278066
[**/tests/parser/*.txt]
trim_trailing_whitespace = false
</syntaxhighlight>
{{References}}