-
Notifications
You must be signed in to change notification settings - Fork 254
Tabs to 2 spaces, idiomatic.js / jsbeautify, cleaning #88
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
Conversation
|
Nice work, @tony. Thanks for taking the time to better enforce some of iditomatics principles to the codebase. I've made one minor comment but so far the rest looks readable. I'll spend a little more time inspecting the changes. @dustinboston do you have any thoughts on this? |
|
While you're at it, I would suggest using multiple var statements, var declarations at the top of the function, space around arguments, and more spacing top/bottom where it fits (currently the code is a little cramped vertically). I would also suggest you use Example: From: function foo(bar,fum) {
var ret,
hello = 'Hello';
for (var i = 0, l = bar.length; i < l; i++) {
if (bar[i] === hello) {
ret = fum(out);
}
}
return ret;
}To: function foo( bar, fum ) {
var i, l, ret;
var hello = 'Hello';
for ( i = 0, l = bar.length; i < l; i++ ) {
if ( bar[ i ] === hello ) {
ret = fum( out );
}
}
return ret;
} |
|
I'm more than happy to consider any suggestions @sindresorhus has to offer in this area. He's by far the biggest code style nazi I know and I mean that in the nicest way possible :)
I agree with this. We've also been using |
|
@addyosmani @tony looks good. I'm up for |
|
The space stuff is just for readability, but theres actually some very good arguments for the use of multiple var statements. But yeah, consistency ++ |
|
@sindresorhus You're right. Those are good arguments. I'm sold :-) |
|
I'm going to take another look at this and |
"use strict";
… define, no newline between use strict and beginning of define
|
@sindresorhus Thanks for that link on multiple vars. I think that readability / maintainability has improved. I've taken a look at backbone.marionette's approach to newlines. Function properties are separated with a new line. There is no beginning or serial new line inside of the marionette module unless the first property begins with a comment. We don't really have a standard for newlines, but for now I did a few consistency changes, most of which are for new lines:
Module properties new lines:
I'm inclined toward making Backbone Aura exportable to a http://jashkenas.github.com/docco/. I made a ticket #89 to look into it later. |
|
@sindresorhus Any best practices / habits you have for new lines? @dustinboston? I also saw the code comment for single quote |
So, good and clean code style isn't always about doing the same in all instances. You have to take into consideration the context. Just an example from the first file I could find: function fetchModuleList( keyword, cb ) {
var moduleList = JSON.parse( localStorage.getItem( 'npm-' + keyword ) ) || [];
var url = 'http://isaacs.iriscouch.com/registry/_design/app/_view/byKeyword?startkey=[%22' +
keyword + '%22]&endkey=[%22' + keyword + '%22,{}]&group_level=3&callback=?';
$.getJSON( url ).done(function( data ) {
var urls = $.map( data.rows, function( el ) {
var moduleName = el.key[1];
var moduleExists = !!$.grep( moduleList, function( el ) {
return el.name === moduleName;
}).length;
if ( !moduleExists ) {
return 'http://isaacs.iriscouch.com/registry/' + moduleName + '?callback=?';
}
});
if ( urls.length ) {
$.whenMany( $.getJSON, urls ).then(function() {
moduleList = $.map( arguments, function( el ) {
return el[0];
});
localStorage.setItem( 'npmlist-' + keyword, JSON.stringify( moduleList ) );
localStorage.setItem( 'npmlist-timestamp-', new Date() );
cb( moduleList );
});
} else {
cb( moduleList );
}
});
}
fetchModuleList( 'gruntplugin', function( modules ) {
var template = $('#plugin-list-template').html();
$('.main').html( _.template( template, { data: modules } ) );
});As you can see, I usually place a newline after
Yes, I do that too. |
|
I think we should wrap up this PR and address the larger conversation in it's own issue #92. My PR's are biting at a few too many things. @addyosmani @dustinboston Anything else for the moment? Look OK to you? |
|
Looks good to me! |
Tabs to 2 spaces, new lines, multiple var declarations, use strict.
|
@tony FYI, looks good. |
This may be a bit bigger of a change than needed, but here is what it includes:
Using a vim mode of
ts=2 sts=2 et sw=2and a jsbeautify mode of
let g:jsbeautify = {'indent_size': 2, 'indent_char': ' '}.I was pretty careful to double check for tabs and grunt. And I did fine-tooth comb to see what the ramifications of jsbeautify did:
added spacing to control structures
(var i=0; i<files.length; i++)would be(var i = 0; i < files.length; i++)I'm agnostic to this. Idiomatic.js does add spaces in this way. https://github.com/rwldrn/idiomatic.js/#spacing. Seeing this control structure a thousand times, it's tempting to scrunch, but for someone new reading it, I'd tolerate it so other's can read.
var declaration
it will remove the tabs indentation in:
and change to
idiomatic.js is ok with it. It's ok to read, and easier to maintain. All formatting on these seem ok by idiomatic, but indentation is processed differently based on if varable is set, if it's inlined, if it's a literal notation, etc. This needs to be handled outside of a script if it's to look totally consistent.
function declarations
Right now, in some areas we will have a space between arg parens and function
function (arg)and also no space between the ending arg paren and initial bracketfunction (arg){.This changes it to:
function(arg) {.Also it corrects spaces in argument lists that may have been forgotten.
Unlike idiotmatic however, it does not add spaces in between arguments
( arg )and( arg1, arg2 ). I haven't seen many projects that do this, probably because it's a pain in the ass.Do we want to split this into smaller parts, handling just tabs->spaces, opting out of formatting, css, etc? Take a step back and try reading it anew. Imo it feels more consistent with viewing source on backbone.js.