Skip to content

Commit 82c7b40

Browse files
committed
ci(lint): Fix linting
1 parent 1ecddb3 commit 82c7b40

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

lib/helpers/getDateFromMongoID.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
import isString from 'lodash/isString';
1+
import isString from 'lodash/isString';
22

3-
export default _id => {
4-
if (!isString(_id) || _id.length != 24) {
3+
export default (_id) => {
4+
if (!isString(_id) || _id.length !== 24) {
55
// not a mongo id
66
throw Error('Not a Mongo ID');
77
}
8-
const timehex = _id.substring(0,8);
8+
const timehex = _id.substring(0, 8);
99

1010
// convert to a number... base 16
1111
const secondsSinceEpoch = parseInt(timehex, 16);
12+
if (isNaN(secondsSinceEpoch)) {
13+
throw Error('Invalid date in Mongo ID');
14+
}
1215

1316
// convert to milliseconds, and create a new date
14-
return new Date(secondsSinceEpoch*1000);
15-
}
17+
return new Date(secondsSinceEpoch * 1000);
18+
};

lib/helpers/tests/getDateFromMongoID-test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { expect } from 'chai';
22
import getDateFromMongoID from '../getDateFromMongoID';
33

44
const _id = '5ad52af00000000000000000';
5-
describe.only('getDateFromMongoID', () => {
5+
describe('getDateFromMongoID', () => {
66
it('should return date for Mongo ID as string', () => {
77
const date = getDateFromMongoID(_id);
8-
const expectedDate = new Date("2018-04-16T23:00:00");
8+
const expectedDate = new Date('2018-04-16T23:00:00');
99
expect(date.getTime()).to.equal(expectedDate.getTime());
1010
});
1111

@@ -23,4 +23,7 @@ describe.only('getDateFromMongoID', () => {
2323
expect(getDateFromMongoID.bind(null, `${_id}0`)).to.throw(Error);
2424
});
2525

26+
it('should error when _id does not contain a valid hex date', () => {
27+
expect(getDateFromMongoID.bind(null, 'Zad52af00000000000000000')).to.throw(Error);
28+
});
2629
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import moment from 'moment';
22

3-
export default createdAt => {
3+
export default (createdAt) => {
44
if (!createdAt) return '';
55
return `Created ${moment(createdAt).fromNow()} - ${moment(createdAt).format('YYYY-MM-DD HH:mm:ss')}`;
6-
}
6+
};

ui/src/containers/Owner/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const getCreatedDate = (createdAt, _id) => {
1414
}
1515
}
1616
return createdAt;
17-
}
17+
};
1818

1919
const Creator = compose(
2020
withProps(({ model }) => ({ schema: 'user', id: model.get('owner') })),
@@ -35,7 +35,7 @@ export default ({ model }) => {
3535
const formattedDate = createdAtFormatter(date);
3636
return (
3737
model.has('owner')
38-
? <Creator model={model} date={ formattedDate } />
38+
? <Creator model={model} date={formattedDate} />
3939
: <div style={{ marginTop: 8 }}>{ formattedDate }</div>
40-
)
40+
);
4141
};

0 commit comments

Comments
 (0)