Skip to content

Commit

Permalink
Fix the failing lint rules (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Sep 21, 2018
1 parent ea35646 commit 47a3c33
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 54 deletions.
3 changes: 3 additions & 0 deletions benchmark/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
rules:
no-console: off
14 changes: 7 additions & 7 deletions benchmark/workload.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ class Workload {
this.opCounts = {};
this.totalOpCount = 0;

for (let operation of OPERATIONS) {
let weight = parseFloat(this.options.get(operation));
for (const operation of OPERATIONS) {
const weight = parseFloat(this.options.get(operation));

if (weight <= 0) {
continue;
}

let shortOpName = operation.replace('proportion', '');
const shortOpName = operation.replace('proportion', '');

this.operations.push(shortOpName);
this.latencies[shortOpName] = [];
Expand All @@ -73,11 +73,11 @@ class Workload {
const end = timeSpan();

for (let i = 0; i < operationCount; i++) {
let randomWeight = Math.random() * this.totalWeight;
const randomWeight = Math.random() * this.totalWeight;

for (let j = 0; j < this.weights.length; j++) {
let weight = this.weights[j];
let operation = this.operations[j];
const weight = this.weights[j];
const operation = this.operations[j];

if (randomWeight <= weight) {
this.queue.add(() => this.runOperation(operation));
Expand All @@ -91,7 +91,7 @@ class Workload {

runOperation(operation) {
if (typeof this[operation] !== 'function') {
throw new Error(`unsupported operation: ${type}`);
throw new Error(`unsupported operation: ${operation.type}`);
}

const end = timeSpan();
Expand Down
8 changes: 3 additions & 5 deletions benchmark/ycsb.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ function parseWorkloadFile(filePath) {

function printMetrics(workload) {
const numBucket = workload.options.get('numBucket');
const operationCount = workload.options.get('operationcount');

let totalOps = 0;

workload.operations.forEach(operation => {
Expand Down Expand Up @@ -103,12 +101,12 @@ function printMetrics(workload) {
);

for (let i = 0; i < numBucket; i++) {
let hi = bounds.lt(lats, i + 1);
let lo = bounds.le(lats, i);
const hi = bounds.lt(lats, i + 1);
const lo = bounds.le(lats, i);
console.log(`${opName}, ${i}, ${hi - lo}`);
}

let lo = bounds.le(lats, numBucket);
const lo = bounds.le(lats, numBucket);
console.log(`${opName}, ${numBucket}, ${ops - lo}`);
});
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"system-test": "mocha system-test/*.js --timeout 600000",
"test-no-cover": "mocha test/*.js",
"test": "npm run cover",
"ycsb": "node ./benchmark/ycsb.js run -P ./benchmark/workloada -p table=usertable -p cloudspanner.instance=ycsb-instance -p operationcount=100 -p cloudspanner.database=ycsb"
"ycsb": "node ./benchmark/ycsb.js run -P ./benchmark/workloada -p table=usertable -p cloudspanner.instance=ycsb-instance -p operationcount=100 -p cloudspanner.database=ycsb",
"fix": "eslint --fix '**/*.js' && npm run prettier"
},
"dependencies": {
"@google-cloud/common-grpc": "^0.8.0",
Expand Down
24 changes: 12 additions & 12 deletions src/codec.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,11 @@ function decode(value, field) {
break;
}
case 'STRUCT': {
let struct = new Struct();
let fields = type.structType.fields;
const struct = new Struct();
const fields = type.structType.fields;

fields.forEach((field, index) => {
let name = field.name;
const name = field.name;
let value = decoded[name] || decoded[index];

value = decodeValue_(value, field.type);
Expand Down Expand Up @@ -353,7 +353,7 @@ function getType(field) {
}

if (Struct.isStruct(field)) {
let fields = field.map(function(field) {
const fields = field.map(function(field) {
return {
name: field.name,
type: getType(field.value),
Expand Down Expand Up @@ -423,14 +423,14 @@ function encodeQuery(query) {
query = extend({}, query);

if (query.params) {
let fields = {};
const fields = {};

if (!query.types) {
query.types = {};
}

for (let prop in query.params) {
let field = query.params[prop];
for (const prop in query.params) {
const field = query.params[prop];

if (!query.types[prop]) {
query.types[prop] = codec.getType(field);
Expand All @@ -443,9 +443,9 @@ function encodeQuery(query) {
}

if (query.types) {
let formattedTypes = {};
const formattedTypes = {};

for (let field in query.types) {
for (const field in query.types) {
formattedTypes[field] = codec.createTypeObject(query.types[field]);
}

Expand Down Expand Up @@ -523,14 +523,14 @@ function createTypeObject(config) {
config = {type: config};
}

let type = config.type;
const type = config.type;
let code = TYPES.indexOf(type);

if (code === -1) {
code = 0; // unspecified
}

let typeObject = {code};
const typeObject = {code};

if (type === 'array') {
typeObject.arrayElementType = createTypeObject(config.child);
Expand All @@ -539,7 +539,7 @@ function createTypeObject(config) {
if (type === 'struct') {
typeObject.structType = {};
typeObject.structType.fields = arrify(config.fields).map(field => {
let fieldConfig = is.object(field.type) ? field.type : field;
const fieldConfig = is.object(field.type) ? field.type : field;

return {
name: field.name,
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ class Spanner extends Service {
gapic.v1.InstanceAdminClient,
gapic.v1.SpannerClient,
];
for (let clientClass of clientClasses) {
for (let scope of clientClass.scopes) {
for (const clientClass of clientClasses) {
for (const scope of clientClass.scopes) {
if (scopes.indexOf(scope) === -1) {
scopes.push(scope);
}
Expand Down
2 changes: 1 addition & 1 deletion src/row-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class RowBuilder {
toJSON(rows) {
return rows.map(values => {
const formattedRow = values.map((value, index) => {
let field = this.fields[index];
const field = this.fields[index];
return {
name: field.name,
value: RowBuilder.formatValue(field, value),
Expand Down
12 changes: 6 additions & 6 deletions src/session-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class SessionPool extends EventEmitter {
this.database = database;
this.options = Object.assign({}, DEFAULTS, options);

let {writes} = this.options;
const {writes} = this.options;

if (writes < 0 || writes > 1) {
throw new WritePercentError();
Expand Down Expand Up @@ -556,9 +556,9 @@ class SessionPool extends EventEmitter {
let evicted = 0;

while (count-- > maxIdle && size - evicted++ > min) {
let session = idle.pop();
let type = session.type;
let index = this._inventory[type].indexOf(session);
const session = idle.pop();
const type = session.type;
const index = this._inventory[type].indexOf(session);

this._inventory[type].splice(index, 1);
this._destroy(session);
Expand Down Expand Up @@ -652,8 +652,8 @@ class SessionPool extends EventEmitter {
const timeout = this.options.acquireTimeout;

if (!is.infinite(timeout)) {
let elapsed = Date.now() - startTime;
let remaining = timeout - elapsed;
const elapsed = Date.now() - startTime;
const remaining = timeout - elapsed;

promises.push(delay.reject(remaining, {value: new TimeoutError()}));
}
Expand Down
2 changes: 1 addition & 1 deletion src/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ class Transaction extends TransactionRequest {
* @return {object}
*/
static createDeadlineError_(err) {
let apiError = new common.util.ApiError({
const apiError = new common.util.ApiError({
message: 'Deadline for Transaction exceeded.',
code: DEADLINE_EXCEEDED,
errors: [err],
Expand Down
2 changes: 1 addition & 1 deletion src/v1/database_admin_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class DatabaseAdminClient {
'getIamPolicy',
'testIamPermissions',
];
for (let methodName of databaseAdminStubMethods) {
for (const methodName of databaseAdminStubMethods) {
this._innerApiCalls[methodName] = gax.createApiCall(
databaseAdminStub.then(
stub =>
Expand Down
2 changes: 1 addition & 1 deletion src/v1/instance_admin_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class InstanceAdminClient {
'getIamPolicy',
'testIamPermissions',
];
for (let methodName of instanceAdminStubMethods) {
for (const methodName of instanceAdminStubMethods) {
this._innerApiCalls[methodName] = gax.createApiCall(
instanceAdminStub.then(
stub =>
Expand Down
2 changes: 1 addition & 1 deletion src/v1/spanner_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class SpannerClient {
'partitionQuery',
'partitionRead',
];
for (let methodName of spannerStubMethods) {
for (const methodName of spannerStubMethods) {
this._innerApiCalls[methodName] = gax.createApiCall(
spannerStub.then(
stub =>
Expand Down
3 changes: 1 addition & 2 deletions test/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ describe('Database', function() {
});

it('should inherit from ServiceObject', function(done) {
let database;
const options = {};

const instanceInstance = extend({}, INSTANCE, {
Expand All @@ -203,7 +202,7 @@ describe('Database', function() {
},
});

database = new Database(instanceInstance, NAME);
const database = new Database(instanceInstance, NAME);
assert(database instanceof FakeGrpcServiceObject);

const calledWith = database.calledWith_[0];
Expand Down
4 changes: 1 addition & 3 deletions test/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ describe('Instance', function() {
});

it('should inherit from ServiceObject', function(done) {
let instance;
const options = {};

const spannerInstance = extend({}, SPANNER, {
createInstance: function(name, options_, callback) {
assert.strictEqual(name, instance.formattedName_);
Expand All @@ -139,7 +137,7 @@ describe('Instance', function() {
},
});

instance = new Instance(spannerInstance, NAME);
const instance = new Instance(spannerInstance, NAME);
assert(instance instanceof FakeGrpcServiceObject);

const calledWith = instance.calledWith_[0];
Expand Down
4 changes: 2 additions & 2 deletions test/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ describe('Session', function() {
});

it('should pass the transaction options', function(done) {
let OPTIONS = {};
const OPTIONS = {};

session.transaction = function(options) {
assert.strictEqual(options, OPTIONS);
Expand All @@ -222,7 +222,7 @@ describe('Session', function() {
});

it('should return any api errors', function(done) {
let ERROR = new Error('err');
const ERROR = new Error('err');

TRANSACTION.begin = function(callback) {
callback(ERROR, RESPONSE);
Expand Down
12 changes: 3 additions & 9 deletions test/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,6 @@ describe('Transaction', function() {
it('should retry the transaction for UNKNOWN', function(done) {
const error = {code: 2};
const fakeDelay = 123;
let stream;
const getRetryDelay = Transaction.getRetryDelay_;

Transaction.getRetryDelay_ = function(err) {
Expand All @@ -774,7 +773,7 @@ describe('Transaction', function() {
done();
};

stream = transaction.requestStream(config);
const stream = transaction.requestStream(config);
stream.on('error', done); // should not be called

fakeStream.emit('error', error);
Expand All @@ -783,8 +782,6 @@ describe('Transaction', function() {
it('should retry the transaction for ABORTED', function(done) {
const error = {code: 10};
const fakeDelay = 123;
let stream;

const getRetryDelay = Transaction.getRetryDelay_;

Transaction.getRetryDelay_ = function(err) {
Expand All @@ -806,16 +803,14 @@ describe('Transaction', function() {
done();
};

stream = transaction.requestStream(config);
const stream = transaction.requestStream(config);
stream.on('error', done); // should not be called

fakeStream.emit('error', error);
});

it('should send a deadline error to the runFn', function(done) {
const error = {code: 10};
let stream;

const deadlineError = {};
const createDeadlineError = Transaction.createDeadlineError_;

Expand All @@ -839,9 +834,8 @@ describe('Transaction', function() {
done();
};

stream = transaction.requestStream(config);
const stream = transaction.requestStream(config);
stream.on('error', done); // should not be called

fakeStream.emit('error', error);
});
});
Expand Down

0 comments on commit 47a3c33

Please sign in to comment.