Dev Wiki:Coding conventions


 * For code review, see Board:Code Review.
 * For requesting a new script, see Board:Script Suggestions.

This page is a help resource for users maintaining scripts on Dev Wiki. It lists naming conventions, best documentation practice and coding conventions.

Naming conventions
The following table lists expected page titles for Dev Wiki items: NB: Historically, Dev scripts and stylesheets didn't obey these conventions:
 * They were named  and were stored as subpages of the documentation page.
 * However, due to security concerns, these were moved to the MediaWiki namespace.
 * This makes  unnecessary for new scripts.

JavaScript

 * When developing a library or platform-agnostic script, wrap code in a IIFE:
 * When writing JavaScript, enclose script code in a modil statement:
 * Cache MediaWiki variables using
 * Scope window variables to :

CSS

 * In stylesheets, please don't use HTML tag names as selectors - this causes style leakage:
 * Limit your CSS in scope with >=3 selectors - this reduces bugs:

Lua

 * Create the exported package table at the start of the module, not the end:

Documentation best practice
A script's documentation likely includes a number of things. The most common are:
 * A description of the script and its features
 * Import instructions and any setup instructions
 * Details about configuration, interface changes and commands

Much of the information you might want to include is in ready-to-use templates. Information and attribution is added using a infobox template. CSS and JS documentation should use the installation templates.
 * JS: Infobox JavaScript and Script Install.
 * CSS: Infobox CSS and CSS Install.
 * Lua: Infobox Lua
 * Application: Infobox Application
 * Wikitext: Documentation

To facilitate i18n in your script documentation, you can structure the main documentation page like so:



Installation
And create language-specific subpages in the following format: