Browse files

Apply code review comments

  • Loading branch information...
1 parent 276630a commit c6b7037fcf50c9020664646b1b3f76dae52b8df4 @andrerod andrerod committed Feb 17, 2013
View
16 .jshintrc
@@ -1,5 +1,4 @@
{
- "node": true,
"bitwise": true,
"camelcase": true,
"curly": false,
@@ -8,20 +7,21 @@
"immed": true,
"indent": 2,
"latedef": true,
+ "maxparams": false,
+ "maxdepth": false,
+ "maxstatements": false,
+ "maxcomplexity": false,
"newcap": true,
"noarg": true,
+ "node": true,
"noempty": true,
"nonew": true,
"plusplus": false,
"quotmark": "single",
"regexp": true,
- "undef": true,
- "unused": true,
+ "sub": true,
"strict": false,
"trailing": true,
- "maxparams": false,
- "maxdepth": false,
- "maxstatements": false,
- "maxcomplexity": false,
- "sub": true
+ "undef": true,
+ "unused": true
}
View
33 lib/http/webresource.js
@@ -202,16 +202,15 @@ WebResource.prototype.addOptionalQueryParam = function (name, value, defaultValu
* @return {object} An object with the query string values.
*/
WebResource.prototype.getQueryStringValues = function (uriEncode) {
+ var self = this;
var queryString = {};
if (this._queryString) {
- for (var queryStringName in this._queryString) {
- if (this._queryString.hasOwnProperty(queryStringName)) {
- var queryStringEntry = this._queryString[queryStringName];
- queryString[queryStringName] = (uriEncode && queryStringEntry.uriEncodable) ?
- azureutil.encodeUri(queryStringEntry.value) :
- queryStringEntry.value;
- }
- }
+ Object.keys(this._queryString).forEach(function (queryStringName) {
+ var queryStringEntry = self._queryString[queryStringName];
+ queryString[queryStringName] = (uriEncode && queryStringEntry.uriEncodable) ?
+ azureutil.encodeUri(queryStringEntry.value) :
+ queryStringEntry.value;
+ });
}
return queryString;
@@ -227,11 +226,9 @@ WebResource.prototype.getQueryString = function (uriEncode) {
var queryStringValues = this.getQueryStringValues(uriEncode);
if (queryStringValues) {
var parametersString = [];
- for (var parameter in queryStringValues) {
- if (queryStringValues.hasOwnProperty(parameter)) {
- parametersString.push(parameter + '=' + queryStringValues[parameter]);
- }
- }
+ Object.keys(queryStringValues).forEach(function (parameter) {
+ parametersString.push(parameter + '=' + queryStringValues[parameter]);
+ });
if (parametersString.length > 0) {
queryString += '?' + parametersString.join('&');
@@ -280,12 +277,12 @@ WebResource.prototype.addOptionalHeader = function (name, value) {
};
WebResource.prototype.addOptionalMetadataHeaders = function (metadata) {
+ var self = this;
+
if (metadata) {
- for (var metadataHeader in metadata) {
- if (metadata.hasOwnProperty(metadataHeader)) {
- this.addOptionalHeader(HeaderConstants.PREFIX_FOR_STORAGE_METADATA + metadataHeader.toLowerCase(), metadata[metadataHeader]);
- }
- }
+ Object.keys(metadata).forEach(function (metadataHeader) {
+ self.addOptionalHeader(HeaderConstants.PREFIX_FOR_STORAGE_METADATA + metadataHeader.toLowerCase(), metadata[metadataHeader]);
+ });
}
return this;
View
13 lib/serviceruntime/roleenvironment.js
@@ -51,6 +51,11 @@ function validateCallback(callback) {
}
}
+/**
+* Validates the node version, throwing if the version is invalid.
+*
+* @return {undefined}
+*/
function validateNodeVersion() {
var version = process.version.replace('v', '').split('.');
if (parseInt(version[0], 10) === 0 &&
@@ -609,11 +614,9 @@ RoleEnvironment._calculateChanges = function (callback) {
}
}
- for (var changedRole in changedRoleSet) {
- if (changedRoleSet.hasOwnProperty(changedRole)) {
- changes.push({ type: 'TopologyChange', name: changedRoleSet[changedRole] });
- }
- }
+ Object.keys(changedRoleSet).forEach(function (changedRole) {
+ changes.push({ type: 'TopologyChange', name: changedRoleSet[changedRole] });
+ });
callback(undefined, changes);
} else {
View
2 lib/serviceruntime/xmlcurrentstateserializer.js
@@ -19,7 +19,7 @@ var js2xml = require('../util/js2xml');
var Constants = require('../util/constants');
var ServiceRuntimeConstants = Constants.ServiceRuntimeConstants;
-function XmlCurrentStateSerializer () {}
+function XmlCurrentStateSerializer() {}
XmlCurrentStateSerializer.prototype.serialize = function (currentState) {
var currentStateXml = {};
View
2 lib/services/blob/blobservice.js
@@ -60,7 +60,7 @@ var ListContainersResultContinuation = require('./models/listcontainersresultcon
function BlobService(storageAccountOrConnectionString, storageAccessKey, host, authenticationProvider) {
var storageServiceSettings = StorageServiceClient.getStorageSettings(storageAccountOrConnectionString, storageAccessKey, host);
- StorageServiceClient.call(this,
+ BlobService['super_'].call(this,
storageServiceSettings._name,
storageServiceSettings._key,
storageServiceSettings._blobEndpointUri,
View
16 lib/services/blob/sharedkey.js
@@ -92,18 +92,14 @@ SharedKey.prototype._getCanonicalizedResource = function (webResource) {
// Build the canonicalized resource by sorting the values by name.
if (queryStringValues) {
var paramNames = [];
- for (var n in queryStringValues) {
- if (queryStringValues.hasOwnProperty(n)) {
- paramNames.push(n);
- }
- }
+ Object.keys(queryStringValues).forEach(function (n) {
+ paramNames.push(n);
+ });
paramNames = paramNames.sort();
- for (var name in paramNames) {
- if (paramNames.hasOwnProperty(name)) {
- canonicalizedResource += '\n' + paramNames[name] + ':' + queryStringValues[paramNames[name]];
- }
- }
+ Object.keys(paramNames).forEach(function (name) {
+ canonicalizedResource += '\n' + paramNames[name] + ':' + queryStringValues[paramNames[name]];
+ });
}
return canonicalizedResource;
View
2 lib/services/core/servicebusserviceclient.js
@@ -33,7 +33,7 @@ var HeaderConstants = Constants.HeaderConstants;
* @param {object} [authenticationProvider] The authentication provider.
*/
function ServiceBusServiceClient(accessKey, issuer, host, acsHost, authenticationProvider) {
- ServiceClient.call(this, host, authenticationProvider);
+ ServiceBusServiceClient['super_'].call(this, host, authenticationProvider);
this.authenticationProvider = authenticationProvider;
if (!this.authenticationProvider) {
View
2 lib/services/core/serviceclient.js
@@ -40,7 +40,7 @@ var DEFAULT_PROTOCOL = Constants.HTTP + '://';
* @param {object} authenticationProvider The authentication provider object (e.g. sharedkey / sharedkeytable / sharedaccesssignature).
*/
function ServiceClient(host, authenticationProvider) {
- events.EventEmitter.call(this);
+ ServiceClient['super_'].call(this);
this._initDefaultFilter();
View
2 lib/services/core/servicemanagementclient.js
@@ -36,7 +36,7 @@ var HeaderConstants = Constants.HeaderConstants;
* }
*/
function ServiceManagementClient(authentication, hostOptions) {
- ServiceClient.call(this);
+ ServiceManagementClient['super_'].call(this);
this._setAuthentication(authentication);
this._setServiceHost(hostOptions);
this._setDefaultProxy();
View
10 lib/services/core/servicesettings.js
@@ -64,13 +64,11 @@ exports.parseAndValidateKeys = function (connectionString, validKeys) {
var tokenizedSettings = ConnectionStringParser.parse(connectionString);
// Assure that all given keys are valid.
- for (var key in tokenizedSettings) {
- if (tokenizedSettings.hasOwnProperty(key)) {
- if (!util.inArrayInsensitive(key, validKeys)) {
- throw new Error('Invalid connection string setting key "' + key + '"');
- }
+ Object.keys(tokenizedSettings).forEach(function (key) {
+ if (!util.inArrayInsensitive(key, validKeys)) {
+ throw new Error('Invalid connection string setting key "' + key + '"');
}
- }
+ });
return tokenizedSettings;
};
View
2 lib/services/core/sqlserviceclient.js
@@ -34,7 +34,7 @@ var HeaderConstants = Constants.HeaderConstants;
* @param {object} [authenticationProvider] The authentication provider.
*/
function SqlServiceClient(serverName, administratorLogin, administratorLoginPassword, host, acsHost, authenticationProvider) {
- ServiceClient.call(this, host, authenticationProvider);
+ SqlServiceClient['super_'].call(this, host, authenticationProvider);
this.authenticationProvider = authenticationProvider;
if (!this.authenticationProvider) {
View
2 lib/services/core/storageserviceclient.js
@@ -41,7 +41,7 @@ function StorageServiceClient(storageAccount, storageAccessKey, host, usePathSty
this.apiVersion = HeaderConstants.TARGET_STORAGE_VERSION;
this.usePathStyleUri = usePathStyleUri;
- ServiceClient.call(this, host, authenticationProvider);
+ StorageServiceClient['super_'].call(this, host, authenticationProvider);
this._initDefaultFilter();
}
View
2 lib/services/queue/queueservice.js
@@ -49,7 +49,7 @@ var servicePropertiesResult = require('./models/servicepropertiesresult');
function QueueService(storageAccountOrConnectionString, storageAccessKey, host, authenticationProvider) {
var storageServiceSettings = StorageServiceClient.getStorageSettings(storageAccountOrConnectionString, storageAccessKey, host);
- StorageServiceClient.call(this,
+ QueueService['super_'].call(this,
storageServiceSettings._name,
storageServiceSettings._key,
storageServiceSettings._queueEndpointUri,
View
8 lib/services/serviceBus/models/queuemessageresult.js
@@ -31,11 +31,9 @@ exports.parse = function (responseObject) {
queueMessageResult.brokerProperties = {};
var brokerProperties = JSON.parse(responseObject.headers[HeaderConstants.BROKER_PROPERTIES_HEADER]);
- for (var property in brokerProperties) {
- if (brokerProperties.hasOwnProperty(property)) {
- queueMessageResult.brokerProperties[property] = brokerProperties[property];
- }
- }
+ Object.keys(brokerProperties).forEach(function (property) {
+ queueMessageResult.brokerProperties[property] = brokerProperties[property];
+ });
}
// Process custom properties
View
2 lib/services/serviceBus/notificationhubservice.js
@@ -37,7 +37,7 @@ var NotificationHubResult = require('./models/notificationhubresult');
* @param {object} [authenticationProvider] The authentication provider.
*/
function NotificationHubService(namespaceOrConnectionString, accessKey, issuer, acsNamespace, host, authenticationProvider) {
- ServiceBusServiceBase.call(this,
+ NotificationHubService['super_'].call(this,
namespaceOrConnectionString,
accessKey,
issuer,
View
2 lib/services/serviceBus/servicebusservice.js
@@ -48,7 +48,7 @@ var ruleResult = require('./models/ruleresult');
* @param {object} [authenticationProvider] The authentication provider.
*/
function ServiceBusService(namespaceOrConnectionString, accessKey, issuer, acsNamespace, host, authenticationProvider) {
- ServiceBusServiceBase.call(this,
+ ServiceBusService['super_'].call(this,
namespaceOrConnectionString,
accessKey,
issuer,
View
2 lib/services/serviceBus/servicebusservicebase.js
@@ -88,7 +88,7 @@ function ServiceBusServiceBase(namespaceOrConnectionString, accessKey, issuer, a
serviceBusSettings = ServiceBusSettings.createFromSettings(settings);
}
- ServiceBusServiceClient.call(this,
+ ServiceBusServiceBase['super_'].call(this,
serviceBusSettings._wrapPassword,
serviceBusSettings._wrapName,
serviceBusSettings._serviceBusEndpointUri,
View
2 lib/services/serviceBus/wrapservice.js
@@ -57,7 +57,7 @@ function WrapService(acsHost, issuer, accessKey) {
this.accessKey = process.env[ServiceClient.EnvironmentVariables.AZURE_SERVICEBUS_ACCESS_KEY];
}
- ServiceClient.call(this, acsHost);
+ WrapService['super_'].call(this, acsHost);
}
util.inherits(WrapService, ServiceClient);
View
24 lib/services/serviceManagement/models/roleparser.js
@@ -31,19 +31,19 @@ function RoleParser() {
* @param {object} output The object to hold the serialized result.
*/
RoleParser.prototype.parse = function (roleSchema, role, serializeTo, output) {
- for (var key in roleSchema) {
- if (roleSchema.hasOwnProperty(key)) {
- var value = roleSchema[key];
- var typeInfo = this.getTypeInfo(value.Type);
- if (typeInfo.isCollection) {
- this.handleCollectionType(value, role, key, serializeTo, typeInfo, output);
- } else if (typeInfo.isComplex) {
- this.handleComplexType(value, role, key, serializeTo, output);
- } else if (typeInfo.isPrimitive) {
- this.handlePrimitiveType(value, role, key, serializeTo, output);
- }
+ var self = this;
+
+ Object.keys(roleSchema).forEach(function (key) {
+ var value = roleSchema[key];
+ var typeInfo = self.getTypeInfo(value.Type);
+ if (typeInfo.isCollection) {
+ self.handleCollectionType(value, role, key, serializeTo, typeInfo, output);
+ } else if (typeInfo.isComplex) {
+ self.handleComplexType(value, role, key, serializeTo, output);
+ } else if (typeInfo.isPrimitive) {
+ self.handlePrimitiveType(value, role, key, serializeTo, output);
}
- }
+ });
};
View
2 lib/services/serviceManagement/servicebusmanagementservice.js
@@ -53,7 +53,7 @@ function ServiceBusManagementService(subscriptionId, authentication, hostOptions
throw new Error('A subscriptionId or a connection string is required');
}
- ServiceManagementClient.call(this, authentication, hostOptions);
+ ServiceBusManagementService['super_'].call(this, authentication, hostOptions);
this.subscriptionId = subscriptionId;
}
View
2 lib/services/serviceManagement/servicemanagementservice.js
@@ -252,7 +252,7 @@ function ServiceManagementService(subscriptionId, authentication, hostOptions) {
throw new Error('A subscriptionId or a connection string is required');
}
- ServiceManagementClient.call(this, authentication, hostOptions);
+ ServiceManagementService['super_'].call(this, authentication, hostOptions);
this.subscriptionId = subscriptionId;
this.serialize = new ServiceManagementSerialize();
View
2 lib/services/serviceManagement/sqlmanagementservice.js
@@ -54,7 +54,7 @@ function SqlManagementService(subscriptionId, authentication, hostOptions) {
}
hostOptions.serializetype = 'XML';
- ServiceManagementClient.call(this, authentication, hostOptions);
+ SqlManagementService['super_'].call(this, authentication, hostOptions);
this.subscriptionId = subscriptionId;
}
View
2 lib/services/sqlAzure/sqlserveracs.js
@@ -42,7 +42,7 @@ function SqlServerAcs(acsHost, serverName, administratorLogin, administratorLogi
this.administratorLogin = administratorLogin;
this.administratorLoginPassword = administratorLoginPassword;
- ServiceClient.call(this, acsHost);
+ SqlServerAcs['super_'].call(this, acsHost);
}
util.inherits(SqlServerAcs, ServiceClient);
View
2 lib/services/sqlAzure/sqlservice.js
@@ -59,7 +59,7 @@ function SqlService(serverName, administratorLogin, administratorLoginPassword,
var endpoint = url.format({ protocol: 'https:', port: 443, hostname: serverName + '.' + ServiceClient.CLOUD_DATABASE_HOST });
var acsEndpoint = url.format({ protocol: 'https:', port: 443, hostname: serverName + '.' + ServiceClient.CLOUD_DATABASE_HOST });
- SqlServiceClient.call(this,
+ SqlService['super_'].call(this,
serverName,
administratorLogin,
administratorLoginPassword,
View
10 lib/services/table/batchserviceclient.js
@@ -33,7 +33,7 @@ var HeaderConstants = Constants.HeaderConstants;
* @constructor
*/
function BatchServiceClient(storageAccount, storageAccessKey, host, usePathStyleUri, authenticationProvider) {
- StorageServiceClient.call(this, storageAccount, storageAccessKey, host, usePathStyleUri, authenticationProvider);
+ BatchServiceClient['super_'].call(this, storageAccount, storageAccessKey, host, usePathStyleUri, authenticationProvider);
this.operations = null;
}
@@ -111,11 +111,9 @@ BatchServiceClient.prototype.addOperation = function (webResource, outputData) {
operation.content = webResource.httpVerb + ' ' + webResource.requestUrl + ' HTTP/1.1\n';
- for (var header in webResource.headers) {
- if (webResource.headers.hasOwnProperty(header)) {
- operation.content += header + ': ' + webResource.headers[header] + '\n';
- }
- }
+ Object.keys(webResource.headers).forEach(function (header) {
+ operation.content += header + ': ' + webResource.headers[header] + '\n';
+ });
operation.content += '\n';
operation.content += outputData;
View
10 lib/services/table/tableservice.js
@@ -52,7 +52,7 @@ var QueryEntitiesResultContinuation = require('./models/queryentitiesresultconti
function TableService(storageAccountOrConnectionString, storageAccessKey, host, authenticationProvider) {
var storageServiceSettings = StorageServiceClient.getStorageSettings(storageAccountOrConnectionString, storageAccessKey, host);
- BatchServiceClient.call(this,
+ TableService['super_'].call(this,
storageServiceSettings._name,
storageServiceSettings._key,
storageServiceSettings._tableEndpointUri,
@@ -499,11 +499,9 @@ TableService.prototype.queryEntities = function (tableQuery, optionsOrCallback,
webResource.addOptionalHeader(HeaderConstants.MAX_DATA_SERVICE_VERSION, '2.0;NetFx');
}
- for (var queryStringName in queryString) {
- if (queryString.hasOwnProperty(queryStringName)) {
- webResource.addOptionalQueryParam(queryStringName, queryString[queryStringName]);
- }
- }
+ Object.keys(queryString).forEach(function (queryStringName) {
+ webResource.addOptionalQueryParam(queryStringName, queryString[queryStringName]);
+ });
webResource.addOptionalHeader(HeaderConstants.CONTENT_TYPE, 'application/atom+xml;charset="utf-8"');
webResource.addOptionalHeader(HeaderConstants.CONTENT_LENGTH, 0);
View
16 lib/util/js2xml.js
@@ -39,11 +39,9 @@ function _writeElementValue(parentElement, name, value) {
!_.isDate(value)) {
if (Array.isArray(value) && value.length > 0) {
- for (var i in value) {
- if (value.hasOwnProperty(i)) {
- parentElement = _writeElementValue(parentElement, name, value[i]);
- }
- }
+ Object.keys(value).forEach(function (i) {
+ parentElement = _writeElementValue(parentElement, name, value[i]);
+ });
// For an array no element was actually added at this level, so skip uping level.
ignored = true;
@@ -68,11 +66,9 @@ function _writeElementValue(parentElement, name, value) {
if (value && value[Constants.XML_METADATA_MARKER]) {
// include the metadata
var attributeList = value[Constants.XML_METADATA_MARKER];
- for (var attribute in attributeList) {
- if (attributeList.hasOwnProperty(attribute)) {
- parentElement = parentElement.att(attribute, attributeList[attribute]);
- }
- }
+ Object.keys(attributeList).forEach(function (attribute) {
+ parentElement = parentElement.att(attribute, attributeList[attribute]);
+ });
}
if (!ignored) {
View
17 lib/util/odatahandler.js
@@ -181,6 +181,7 @@ OdataHandler.prototype._setProperty = function (entity, propertyName, value, typ
};
OdataHandler.prototype.serialize = function (entity) {
+ var self = this;
var doc = xmlbuilder.create();
doc = doc.begin('entry', { version: '1.0', encoding: 'utf-8', standalone: 'yes' })
@@ -194,11 +195,9 @@ OdataHandler.prototype.serialize = function (entity) {
doc = doc.att('xmlns:' + this.nsData, 'http://schemas.microsoft.com/ado/2007/08/dataservices');
}
- for (var attribute in entity) {
- if (entity.hasOwnProperty(attribute)) {
- doc = this._writeAtomEntryValue(doc, attribute, entity[attribute]);
- }
- }
+ Object.keys(entity).forEach(function (attribute) {
+ doc = self._writeAtomEntryValue(doc, attribute, entity[attribute]);
+ });
doc = doc.doc();
@@ -268,11 +267,9 @@ OdataHandler.prototype._writeAtomEntryValue = function (parentElement, name, val
if (value && value[Constants.XML_METADATA_MARKER]) {
// include the metadata
var attributeList = value[Constants.XML_METADATA_MARKER];
- for (var attribute in attributeList) {
- if (attributeList.hasOwnProperty(attribute)) {
- parentElement = parentElement.att(attribute, attributeList[attribute]);
- }
- }
+ Object.keys(attributeList).forEach(function (attribute) {
+ parentElement = parentElement.att(attribute, attributeList[attribute]);
+ });
}
if (!ignored) {
View
8 lib/util/util.js
@@ -53,12 +53,8 @@ exports.objectKeysLength = function (value) {
* @return {number} The name of the first key in the object.
*/
exports.objectFirstKey = function (value) {
- if (value) {
- for (var key in value) {
- if (value.hasOwnProperty(key)) {
- return key;
- }
- }
+ if (value && Object.keys(value).length > 0) {
+ return Object.keys(value)[0];
}
// Object has no properties

0 comments on commit c6b7037

Please sign in to comment.