Topic on Manual talk:Coding conventions/JavaScript

Jump to navigation Jump to search

Whitespace for function parameter lists

7
Mattflaschen (talkcontribs)

The convention to put spaces around function parameter lists was not documented. It is documented for PHP, and is de facto for JS. However, I think it's better to add it specifically here.

This post was posted by Mattflaschen, but signed as Superm401.

Jdforrester (WMF) (talkcontribs)
Automatik (talkcontribs)

Hi,

The page says "We use JSHint as our code quality tool."

But when I use JSHint it tells me not to use space between parenthesis and parameters. So this is not consistent.

Thank you to enlighten me.

Krinkle (talkcontribs)

JSHint is a code quality tool, not coding style. It has some legacy options for whitespace enforcement, however those are deprecated, disabled by default, and our configurations don't enable that option (as reflected by the lint job that runs from Jenkins, which uses the same configuration, and as such should also never enforce or warn for options like that).

The whitespace style option in JSHint is not flexible (it was a boolean option for backwards-compatibility with JSLint to enforce Crockford's code conventions).

If JSHint is warning you about those whitespace rules, make sure you find out why that option is enabled and disable it.

Automatik (talkcontribs)

Actually I was using JSLint instead of JSHint which does not consider these spaces as an error.

Thanks for the expanations furthermore.

Danmichaelo (talkcontribs)

Under "Line length", there is an example mw.foo.getThatFrom('this'). Should it be mw.foo.getThatFrom( 'this' )?

Jdforrester (WMF) (talkcontribs)

Indeed; I've fixed this. Thanks for the spot.