Just to keep track of the idea and point to the standards:

http://drupal.org/node/172169

It seems that there are just 2 basic rules.

Comments

stella’s picture

Assigned: Unassigned » stella

I've spent the last while trying to get consensus on the coding standards for JS files. I published the final version of the new standards yesterday, so we'll now be adding them to the Coder module in the near future.

Cheers,
Stella

douggreen’s picture

We now read js files and can write rules for them. All rules are excluded from js by default, but you can add js only rules using '#filename' => '\.js$' and you can add existing rules to js files with '#filename-not' => ''. This second empty rule is needed to override the default '#filename-not' => '\.js$'.

douggreen’s picture

The #filename and #filename-not directives have recently changed slightly, but hopefully for the better. The default rules are only valid for php files. And js files are only read if a rule in one of the reviews being run, accesses it. It should be pretty easy to add the #filename to existing style rules that should also apply to js, such the many spacing, parenthesis, and bracket rules. Note that the directive now takes an array of extensions instead of a regex, so, to add js you'd now write:

'#filename' => array('js'),

stella’s picture

So '#filename' => array('js'), will add js files to the list of file types that the review is being run on? What if you want a js only rule?

douggreen’s picture

hmm, that is a js only review. The problem in my logic here is that unlike what my comments say, there's not a way to add a rule to js without explicitly naming array('js', 'php', 'module', 'inc', 'test'), and that's not good....

Manuel Garcia’s picture

+1 for this feature request -- can help testing also :)

gagarine’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev

What the statue on this?

gagarine’s picture

Assigned: stella » Unassigned

So what I really want to review is the proper use of attr to avoid problem when we upgrade to jquery 1.5 to 1.7. This is documented in this issue #1498858: [meta] attr and prop.

Any guidance how I should do this in coder?

EDIT:
I think of course of http://php.net/manual/en/book.v8js.php and as you can see in http://css.dzone.com/articles/running-javascript-inside-php you can do some code introspection.

gagarine’s picture

Mmmh how I get it is _coder_review_read_and_parse_file is PHP centric.

nod_’s picture

gagarine’s picture

I create a sandbox https://drupal.org/sandbox/gagarine/1674242 it's now working but need some more work and a configuration page...

nod_’s picture

Issue summary: View changes

Using eslint for everything JS now :)

klausi’s picture

Version: 7.x-1.x-dev » 8.x-2.x-dev

Note that our phpcs standard can also check and fix coding standard errors in JS files, but it is by far not complete and perfect :-)

klausi’s picture

Status: Active » Fixed

Hm, I think we can even call this fixed.

Check your JS coding standards like this:

phpcs --standard=Drupal /path/to/mymodule/mymodule.js

Or if you want to check your whole module/theme folder anyway:

phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,js,css,info,txt,md /file/to/drupal/example_module

And if you want to automatically fix stuff replace "phpcs" with "phpcbf" in the above commands.

Please open separate issues for additional checks that we could add for javascript or bug reports or whatever you find :-)

Maybe nod_ can add some pointers here how people can install/run eslint?

nod_’s picture

Title: provide javascript review » Provide javascript comments review

Let's not lie about what it's actually doing :D

nod_’s picture

Title: Provide javascript comments review » Provide basic javascript syntax and comment review
nod_’s picture

klausi’s picture

Excellent, I'm currently working on a patch for pareview.sh to include eslint checking.

nod_’s picture

To note that some things checked and raised as errors by phpcs are not errors. Fixing them would make eslint complain. So would be good to add a warning about this when checking js files or something.

klausi’s picture

Yeah, we should probably run phpcs on the D8 core javascript and add issues for false positives.

So the basic eslint prototype in pareview.sh works now, example: #2448867-24: [D7] Custom Cookie Compliance.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.