Use standard and prettier (#10)

* switch from custom eslint config to standard + prettier

* fix new standard eslint violations

* add editorconfig file

* auto-fix all other violations

* update lint yarn script

* remove jshint comment
This commit is contained in:
Spencer
2019-07-09 13:24:13 -07:00
committed by GitHub
parent f69840c50f
commit 7c1573fb07
119 changed files with 4506 additions and 3521 deletions

View File

@ -1,4 +1,4 @@
describe('JSON serializer', function () {
describe('JSON serializer', function() {
var JsonSerializer = require('../../../src/lib/serializers/json');
var expect = require('expect.js');
var sinon = require('sinon');
@ -8,8 +8,8 @@ describe('JSON serializer', function () {
return new JsonSerializer();
}
describe('#serialize', function () {
it('defers to JSON.stringify', function () {
describe('#serialize', function() {
it('defers to JSON.stringify', function() {
var stub = sinon.stub(JSON, 'stringify');
var ser = makeSerializer();
ser.serialize({ some: 'object' });
@ -17,30 +17,30 @@ describe('JSON serializer', function () {
stub.restore();
});
it('does not modify strings', function () {
it('does not modify strings', function() {
var ser = makeSerializer();
var thing = 'pretend that I am serialized';
expect(ser.serialize(thing)).to.be(thing);
});
it('returns nothing for invalid values', function () {
it('returns nothing for invalid values', function() {
var ser = makeSerializer();
expect(ser.serialize(null)).to.be(undefined);
expect(ser.serialize(false)).to.be(undefined);
});
it('throws serialization errors', function () {
it('throws serialization errors', function() {
var ser = makeSerializer();
var thing = { name: 'thing' };
thing.self = thing;
expect(function () {
expect(function() {
ser.serialize(thing);
}).to.throwError();
});
it('utilizes replacer or spaces if passed', function () {
it('utilizes replacer or spaces if passed', function() {
sinon.spy(JSON, 'stringify');
var ser = makeSerializer();
var thing = { name: 'thing' };
@ -49,7 +49,7 @@ describe('JSON serializer', function () {
JSON.stringify.restore();
});
it('should call JSON.stringify with value only', function () {
it('should call JSON.stringify with value only', function() {
sinon.spy(JSON, 'stringify');
var ser = makeSerializer();
var thing = { name: 'thing' };
@ -59,15 +59,15 @@ describe('JSON serializer', function () {
});
});
describe('#deserialize', function () {
it('defers to JSON.parse', function () {
describe('#deserialize', function() {
it('defers to JSON.parse', function() {
stub(JSON, 'parse');
var ser = makeSerializer();
ser.deserialize('{ "some": "JSON" }');
expect(JSON.parse.callCount).to.eql(1);
});
it('ignores non string values', function () {
it('ignores non string values', function() {
var ser = makeSerializer();
var thing = ['pretend that I am not here'];
expect(ser.deserialize(thing)).to.be(undefined);
@ -75,42 +75,39 @@ describe('JSON serializer', function () {
expect(ser.deserialize(false)).to.be(undefined);
});
it('catches serialization errors, returns nothing', function () {
it('catches serialization errors, returns nothing', function() {
var ser = makeSerializer();
var thing = '{ name: \'thing\' }';
var thing = "{ name: 'thing' }";
expect(ser.deserialize(thing)).to.be(undefined);
});
});
describe('#bulkBody', function () {
var body = [
{ index: 'thing' },
{ document: 'hi' }
];
describe('#bulkBody', function() {
var body = [{ index: 'thing' }, { document: 'hi' }];
var bulk = '{"index":"thing"}\n{"document":"hi"}\n';
it('creates a string out of an array of obejcts', function () {
it('creates a string out of an array of obejcts', function() {
var ser = makeSerializer();
expect(ser.bulkBody(body)).to.eql(bulk);
});
it('adds a newline to the end of strings', function () {
it('adds a newline to the end of strings', function() {
var ser = makeSerializer();
expect(ser.bulkBody(bulk.substr(0, bulk.length - 1))).to.eql(bulk);
});
it('throws an error for anything else', function () {
it('throws an error for anything else', function() {
var ser = makeSerializer();
expect(function () {
expect(function() {
ser.bulkBody({});
}).to.throwError();
expect(function () {
expect(function() {
ser.bulkBody(null);
}).to.throwError();
expect(function () {
expect(function() {
ser.bulkBody(false);
}).to.throwError();
});