Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javascript Standards #96

Open
okonomiyaki3000 opened this issue Mar 16, 2015 · 2 comments
Open

Javascript Standards #96

okonomiyaki3000 opened this issue Mar 16, 2015 · 2 comments

Comments

@okonomiyaki3000
Copy link

I think it's worth considering some revisions to the JS coding standards as there are a few things about them at the moment that stand out to me as a little funny. I know people sometimes get overly sensitive about this kind of stuff but, let's face it, much of any coding standard is just arbitrary. Considering that, a coding standard should be as easy for the developer to follow properly as possible.

In PHP, we have PHPCS which can find and explain any CS errors you may have. If you have a decent IDE, you may even be able to hook it up to show your CS errors in real time. This kind of thing makes it really easy to write properly formatted code the first time and avoid going back over your code just to clean up the style.

For Javascript, we don't have such a thing (that I know of) but we do have jsbeautifier which will clean up your code automatically. Whatever the standard is, it would be best if it can be defined as jsbeautifier settings without exceptions. That way:

  • Cleaning up any file (old or new) is just a single command instead of a bunch of manual checks
  • The developer doesn't have to care too much about all details of the standard while coding
  • A test can easily be set up to determine if the code in a PR adheres to the standard

This mostly works today except for a few parts of the Joomla JS standard which should probably change:

  • The exceptions for spacing around function arguments
  • Maybe the rule about chained function calls

That's all. Change that and correct js formatting can just be automatic.

There's at least one more change that would really help which is unrelated to jsbeautifier. In PHP, our multiline comments are like:

/**
 * Start with two asterisks.
 * One asterisk on each subsequent line.
 */ 

But in JS, it's like:

/*
** Start with one asterisk.
** Two on each subsequent line.
*/

A good ide can help a lot with writing comments and especially docblocks but it may be difficult or troublesome to configure different styles for different languages. Why should we have such a different standard for something that doesn't matter at all? Let's just keep this part the same between Javascript and PHP.

@piotr-cz
Copy link
Contributor

I'd start with deciding whether we use tabs or spaces, because current CS allows both (Tabs, 4 spaces), and actually both styles are being used in core-uncompressed.js.

By the way: I'd prefer having core.js and core.min.js.

A good tool for javascript code styling is JSCS, available in for many editors and as gulp/ grunt task. plugin.

Alternatively JHint may give little hints while editing with a .jshintrc placed in project root.

@okonomiyaki3000
Copy link
Author

👍 for .min.js instead of -uncompressed

Maybe this topic isn't going anywhere but what about something like this? https://github.com/prettier/prettier

wilsonge pushed a commit to wilsonge/coding-standards that referenced this issue Oct 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants