Skip to content

Commit

Permalink
Working on JSCS cleanup/implementation. Not finished.
Browse files Browse the repository at this point in the history
  • Loading branch information
MeoMix committed May 18, 2015
1 parent 327ec9c commit 948cb91
Show file tree
Hide file tree
Showing 59 changed files with 245 additions and 163 deletions.
63 changes: 63 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch"
],
"requireOperatorBeforeLineBreak": true,
"requireCamelCaseOrUpperCaseIdentifiers": true,
"maximumLineLength": {
"value": 200,
"allowComments": true,
"allowRegex": true
},
"validateIndentation": 4,
"validateQuoteMarks": "'",

"disallowMultipleLineStrings": true,
"disallowMixedSpacesAndTabs": true,
"disallowTrailingWhitespace": true,
"disallowSpaceAfterPrefixUnaryOperators": true,
"disallowMultipleVarDecl": true,
"disallowKeywordsOnNewLine": ["else"],

"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"return",
"try",
"catch"
],
"requireSpaceBeforeBinaryOperators": [
"=", "+=", "-=", "*=", "/=", "%=", "<<=", ">>=", ">>>=",
"&=", "|=", "^=", "+=",

"+", "-", "*", "/", "%", "<<", ">>", ">>>", "&",
"|", "^", "&&", "||", "===", "==", ">=",
"<=", "<", ">", "!=", "!=="
],
"requireSpaceAfterBinaryOperators": true,
"requireSpacesInConditionalExpression": true,
"requireSpaceBeforeBlockStatements": true,
"requireSpacesInForStatement": true,
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"disallowSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInsideObjectBrackets": "all",
"disallowSpacesInsideArrayBrackets": "all",
"disallowSpacesInsideParentheses": true,

"disallowMultipleLineBreaks": true,
"disallowNewlineBeforeBlockStatements": true
}
8 changes: 8 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,14 @@ module.exports = function(grunt) {
files: ['src/less/*'],
tasks: ['less']
}
},
jscs: {
src: ['src/js/**/*.js', '!src/js/thirdParty/**/*.js'],
options: {
config: '.jscsrc',
verbose: true,
fix: true
}
}
});

Expand Down
3 changes: 2 additions & 1 deletion Streamus Chrome Extension.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@
<Content Include="src\js\background\key\youTubeAPIKey.js.example" />
<Content Include="changelog.md" />
<Content Include="CONTRIBUTING.md" />
<Content Include=".jscsrc" />
<None Include="src\js\thirdParty\chrome-api-vsdoc.js" />
<Content Include="src\less\color.less" />
<Content Include="src\less\font.less" />
Expand Down Expand Up @@ -541,7 +542,7 @@
<Content Include="src\js\test\main.js" />
<Content Include="src\js\test\background\model\relatedSongsManager.spec.js" />
<Content Include="src\js\test\background\model\dataSource.spec.js" />
<Content Include="src\js\test\common\model\utility.spec.js" />
<Content Include="src\js\test\common\utility.spec.js" />
<Content Include="src\js\test\background\model\youTubeV3API.spec.js" />
<Content Include="src\js\test\test.js" />
<Content Include="src\js\test\testUtility.js" />
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"grunt-contrib-requirejs": "~0.4.1",
"grunt-contrib-uglify": "^0.8.0",
"grunt-contrib-watch": "^0.6.1",
"grunt-jscs": "^1.8.0",
"grunt-recess": "https://github.com/MeoMix/grunt-recess/tarball/master",
"grunt-text-replace": "^0.4.0",
"grunt-usemin": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/js/background/collection/playlists.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},

getActivePlaylist: function() {
return this.findWhere({ active: true });
return this.findWhere({active: true});
},

// Expects options: { playlistId, success, error };
Expand Down
16 changes: 8 additions & 8 deletions src/js/background/collection/streamItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},

getActiveItem: function() {
return this.findWhere({ active: true });
return this.findWhere({active: true});
},

getActiveSongId: function() {
Expand All @@ -48,7 +48,7 @@
},

notPlayedRecently: function() {
return this.where({ playedRecently: false });
return this.where({playedRecently: false});
},

getBySong: function(song) {
Expand Down Expand Up @@ -120,7 +120,7 @@

if (options.playOnAdd || options.markFirstActive) {
if (createdStreamItems.length > 0) {
createdStreamItems[0].save({ active: true });
createdStreamItems[0].save({active: true});
} else {
var songToActivate = this.getBySong(songs[0]);

Expand All @@ -131,7 +131,7 @@
if (songToActivate.get('active')) {
songToActivate.trigger('change:active', songToActivate, true);
} else {
songToActivate.save({ active: true });
songToActivate.save({active: true});
}
}
}
Expand All @@ -143,7 +143,7 @@
_onAdd: function(model) {
// Ensure a streamItem is always active
if (_.isUndefined(this.getActiveItem())) {
model.save({ active: true });
model.save({active: true});
}
},

Expand Down Expand Up @@ -222,7 +222,7 @@
this.each(function(streamItem) {
// Be sure to check if it is active before saving to avoid hammering localStorage.
if (streamItem !== changedStreamItem && streamItem.get('active')) {
streamItem.save({ active: false });
streamItem.save({active: false});
}
});
},
Expand Down Expand Up @@ -270,10 +270,10 @@
// When all streamItems have been played recently, reset to not having been played recently.
// Allows for de-prioritization of played streamItems during shuffling.
_ensureAllNotPlayedRecentlyExcept: function(model) {
if (this.where({ playedRecently: true }).length === this.length) {
if (this.where({playedRecently: true}).length === this.length) {
this.each(function(streamItem) {
if (streamItem !== model) {
streamItem.save({ playedRecently: false });
streamItem.save({playedRecently: false});
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/js/background/mixin/collectionMultiSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@

// Return a list of selected models.
selected: function() {
return this.where({ selected: true });
return this.where({selected: true});
},

// Returns the model which was first selected (or selected last if ctrl was pressed)
firstSelected: function() {
return this.findWhere({ firstSelected: true });
return this.findWhere({firstSelected: true});
},

// Returns the underlying Songs of the collection.
Expand Down
4 changes: 2 additions & 2 deletions src/js/background/mixin/collectionSequence.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ define(function(require) {
if (currentIndex !== index) {
moveResult.direction = currentIndex < index ? Direction.Down : Direction.Up;
var sequence = this.getSequenceFromIndexDuringMove(index, moveResult.direction);
model.save({ sequence: sequence }, { patch: true });
model.save({sequence: sequence}, {patch: true});

// Collections with a comparator will not automatically re-sort if you later change model attributes
this.sort({ silent: options.silent });
this.sort({silent: options.silent});
moveResult.moved = true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/js/background/mixin/collectionUniqueSong.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
_copyId: function(preparedModel, existingModel) {
if (existingModel.has('id')) {
if (preparedModel instanceof Backbone.Model) {
preparedModel.set('id', existingModel.get('id'), { silent: true });
preparedModel.set('id', existingModel.get('id'), {silent: true});
} else {
preparedModel.id = existingModel.get('id');
}
Expand Down
4 changes: 2 additions & 2 deletions src/js/background/model/analyticsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
initialize: function() {
// Setup temporary Google Analytics objects.
window.GoogleAnalyticsObject = 'ga';
window.ga = function () {
window.ga = function() {
(window.ga.q = window.ga.q || []).push(arguments);
};
window.ga.l = 1 * new Date();
Expand All @@ -21,7 +21,7 @@
// Bug: UA doesn't work out of the box with Chrome extensions.
// https://code.google.com/p/analytics-issues/issues/detail?id=312
// http://stackoverflow.com/questions/16135000/how-do-you-integrate-universal-analytics-in-to-chrome-extensions
window.ga('set', 'checkProtocolTask', function () {
window.ga('set', 'checkProtocolTask', function() {
});
window.ga('require', 'displayfeatures');
window.ga('require', 'linkid', 'linkid.js');
Expand Down
6 changes: 3 additions & 3 deletions src/js/background/model/chromeContextMenusManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@

_onClickPlayContextMenu: function(onClickData) {
var url = onClickData.linkUrl || onClickData.pageUrl;
var dataSource = new DataSource({ url: url });
var dataSource = new DataSource({url: url});

dataSource.getSong({
success: function(song) {
Expand All @@ -257,7 +257,7 @@
_onClickAddContextMenu: function(onClickData) {
var url = onClickData.linkUrl || onClickData.pageUrl;

var dataSource = new DataSource({ url: url });
var dataSource = new DataSource({url: url});
dataSource.getSong({
success: function(song) {
this.get('streamItems').addSongs(song);
Expand All @@ -268,7 +268,7 @@
_onClickSaveContextMenu: function(playlist, onClickData) {
var url = onClickData.linkUrl || onClickData.pageUrl;

var dataSource = new DataSource({ url: url });
var dataSource = new DataSource({url: url});
dataSource.getSong({
success: function(song) {
playlist.get('items').addSongs(song);
Expand Down
2 changes: 1 addition & 1 deletion src/js/background/model/chromeNotificationsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
},

_isForegroundActive: function(callback) {
var foreground = chrome.extension.getViews({ type: 'popup' });
var foreground = chrome.extension.getViews({type: 'popup'});

if (foreground.length === 0) {
this.get('tabManager').isStreamusTabActive(function(streamusTabActive) {
Expand Down
5 changes: 2 additions & 3 deletions src/js/background/model/nextButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@
var shuffleEnabled = this.get('shuffleButton').get('enabled');
var repeatButtonState = this.get('repeatButton').get('state');

// You can skip with shuffle enabled if there are multiple items to shuffle between.
if (shuffleEnabled && streamItems.length > 1) {
// You can skip with shuffle enabled if there are multiple items to shuffle between.
enabled = true;
}
} else if (radioEnabled || repeatButtonState !== RepeatButtonState.Off) {
// You can always continue if radio is enabled or if repeating is enabled
else if (radioEnabled || repeatButtonState !== RepeatButtonState.Off) {
enabled = true;
} else {
// Enable only if there are more items to skip to.
Expand Down
2 changes: 1 addition & 1 deletion src/js/background/model/playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ define(function(require) {
title: title
});

this.save({ title: title }, { patch: true });
this.save({title: title}, {patch: true});
},

_onChangeActive: function(model, active) {
Expand Down
2 changes: 1 addition & 1 deletion src/js/background/model/playlistItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
// Need to convert song object to Backbone.Model
if (!(song instanceof Backbone.Model)) {
// Silent because song is just being properly set.
this.set('song', new Song(song), { silent: true });
this.set('song', new Song(song), {silent: true});
}
}
});
Expand Down
10 changes: 5 additions & 5 deletions src/js/background/model/signInManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
signedInUser.mergeByGooglePlusId();
} else {
// Otherwise, no account -- safe to patch in a save and use this account as the main one.
signedInUser.save({ googlePlusId: profileUserInfo.id }, { patch: true });
signedInUser.save({googlePlusId: profileUserInfo.id}, {patch: true});
}
}.bind(this));
}.bind(this));
Expand Down Expand Up @@ -225,7 +225,7 @@
}
},

_onChromeRuntimeMessage: function (request, sender, sendResponse) {
_onChromeRuntimeMessage: function(request, sender, sendResponse) {
switch (request.method) {
case 'getSignedInState':
sendResponse({
Expand All @@ -238,14 +238,14 @@
}
},

_onChromeRuntimeMessageExternal: function (request, sender, sendResponse) {
_onChromeRuntimeMessageExternal: function(request, sender, sendResponse) {
var sendAsynchronousResponse = false;

switch (request.method) {
case 'copyPlaylist':
if (this._canSignIn()) {
// TODO: What if sign in fails?
this.once('change:signedInUser', function () {
this.once('change:signedInUser', function() {
this._handleCopyPlaylistRequest(request, sendResponse);
});

Expand All @@ -268,7 +268,7 @@
return sendAsynchronousResponse;
},

_handleCopyPlaylistRequest: function (request, sendResponse) {
_handleCopyPlaylistRequest: function(request, sendResponse) {
// TODO: Probably house this logic on signedInUser or on playlists?
this.get('signedInUser').get('playlists').copyPlaylist({
playlistId: request.playlistId,
Expand Down

0 comments on commit 948cb91

Please sign in to comment.