Jump to content

Chemical Markup support for Wikimedia Commons/Internship Report/Stylize

From mediawiki.org

You are a sloppy or lazy boy like me? Here is what I use to comply with MediaWiki's coding conventions:

Instructions for OpenSUSE.

Open a "sudo termal" and run

$ zypper in nodejs
$ npm -g install js-beautify

Create your configuration file with the following contents. I call it jsbeautify.cfg.json:

{
	"indent_size": 4,
	"indent_char": "\t",
	"indent_level": 0,
	"indent_with_tabs": true,
	"preserve_newlines": true,
	"max_preserve_newlines": 3,
	"jslint_happy": false,
	"brace_style": "collapse",
	"space_in_paren": true,
	"keep_array_indentation": false,
	"keep_function_indentation": false,
	"space_before_conditional": true,
	"break_chained_methods": true,
	"eval_code": false,
	"unescape_strings": false,
	"wrap_line_length": 0
}

And beautify!

$ js-beautify --config jsbeautify.cfg.json -f infile.js -o outfile.js

PHP

[edit]

Clone the code utils:

$ git clone https://github.com/wikimedia/mediawiki-tools-code-utils.git --depth=1

… and run it over your code:

$ stylize.php infile.php

As a git pre-commit hook

[edit]

If you are extremely sloppy about whitespace and you are not working too much with third party code (i.e. all the code is written by you), consider a pre-commit hook in your repo. It will run over all the files with amendments (and its purpose is to check for coding convention violations -- but you can use it for automated beautifying as well) before they are "committed".

In ./.git/hooks/ create a hook-file called pre-commit and make it executable.

$ sudo chmod g+x ./.git/hooks/pre-commit
Implementation of pre-commit hook

I use a modified version of <node>css.dzone.com/articles/why-your-need-git-pre-commit</node> - Just comment the line doing git --reset --hard.

- subprocess.call(['git', 'reset', '--hard'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ # subprocess.call(['git', 'reset', '--hard'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)