Support comma first style of variable declaration
See original GitHub issueAllow code to be formatted like this:
var a = 1
, b = "somethign else"
, isAwesome = true;
And apparently, we have a somewhat ready patch available. Would be great if this can get included in here!
Issue Analytics
- State:
- Created 10 years ago
- Comments:27 (13 by maintainers)
Top Results From Across the Web
Support comma first style of variable declaration · Issue #59 ... - GitHub
Allow code to be formatted like this: var a = 1 , b = "somethign else" , isAwesome = true; JSBeautifier supports it...
Read more >comma-style - ESLint - Pluggable JavaScript Linter
"first" requires a comma before and on the same line as an array element, object property, or variable declaration. This rule also accepts...
Read more >Comma operator (,) - JavaScript - MDN Web Docs
The comma ( , ) operator evaluates each of its operands (from left to right) and returns the value of the last operand....
Read more >JavaScript Code Styling Best Practices — Commas and ...
In JavaScript code, there's a standard style for arranging commas. For instance, for a comma-separated list of variable or constant declarations ...
Read more >scope - what is the purpose of comma in declaring variables ...
what is the purpose of comma (,) after div? var div, container = document.getElementById("container");. is it for declaring two variables at ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve been working on a patch to support this feature “on demand” (the user can enable or disable the option of using comma first with a setting I’ve created).
I’ve achieved the following formatting for variable declaration (using 2 spaces):
But I have some doubts.
How should we treat arrays, objects and arguments declarations? Lately I’ve been using the following format:
Which, as you can see, is not exactly the same as the variable declaration formatting: this last one includes a +1 indentation level for the second variable (notice the two spaces before the comma that are not present before the comma for “item2” nor for the one for “prop2”). Var declarations use this extra indentation in order to align in the same column the start of each variable name as stated by @lukemartin.
The reasons for using the formatting shown on the above code are:
1.- To avoid the linting errors that would be thrown by jshint (indentation errors). For example:
Throws “Expected ] to have an indentation at 3, instead at 1”. If we follow the suggestion, we get a very ugly result.
2.- To maintain the advantage of aligning the start of each property name, array item, etc. For example:
Also doesn’t produce a linting error, but doesn’t look as nice as the examples above.
With a more clear idea of how I should treat those cases I could finish the implementation of this feature and issue a Pull Request.
What about 4 spaces per tab? Actual tabs?
On Fri, Nov 8, 2013 at 9:36 AM, Luke Martin notifications@github.com wrote: