Skip to content

Commit

Permalink
Update: packages (#43)
Browse files Browse the repository at this point in the history
* Update: packages
* Chore: De-structing objects properly
* Chore: specify Number.isNaN
* Chore: Removing chai-as-promised
  • Loading branch information
pramodsum authored Nov 20, 2017
1 parent 42e29ce commit 97a91c3
Show file tree
Hide file tree
Showing 15 changed files with 880 additions and 916 deletions.
7 changes: 7 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@
"String": "string"
}
}
],
"prefer-destructuring": [
"error",
{
"object": true,
"array": false
}
]
},
"settings": {
Expand Down
1 change: 0 additions & 1 deletion build/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ module.exports = (config) => config.set({
'mocha',
'sinon-stub-promise',
'chai-sinon',
'chai-as-promised',
'chai-dom',
'chai',
'sinon',
Expand Down
46 changes: 22 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"devDependencies": {
"autobind-decorator": "^1.3.4",
"autoprefixer": "^6.7.7",
"autoprefixer": "^7.1.6",
"babel-cli": "^6.26.0",
"babel-core": "^6.25.0",
"babel-eslint": "^8.0.1",
Expand All @@ -31,29 +31,28 @@
"babel-preset-es2015": "^6.24.0",
"babel-preset-es2016": "^6.22.0",
"babel-preset-react": "^6.23.0",
"chai": "^3.5.0",
"chai-as-promised": "5.3.0",
"chai": "^4.1.2",
"chai-dom": "^1.5.0",
"conventional-github-releaser": "^2.0.0",
"commitlint": "^5.0.1",
"conventional-changelog-cli": "^1.3.2",
"conventional-changelog-lint": "^1.1.7",
"conventional-github-releaser": "^2.0.0",
"cpx": "^1.5.0",
"css-loader": "^0.27.3",
"css-loader": "^0.28.7",
"cssnano-cli": "^1.0.5",
"eslint": "^4.7.2",
"eslint-config-airbnb": "^15.1.0",
"eslint-config-prettier": "^2.6.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-config-prettier": "^2.7.0",
"eslint-import-resolver-webpack": "^0.8.3",
"eslint-plugin-babel": "^4.1.1",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-jsx-a11y": "^5.1.1",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-react": "^7.4.0",
"extract-text-webpack-plugin": "2.1.0",
"extract-text-webpack-plugin": "^3.0.2",
"fetch-mock": "^5.12.1",
"fetch-mock-forwarder": "^1.0.0",
"husky": "^0.13.4",
"husky": "^0.14.3",
"karma": "^1.5.0",
"karma-chai": "^0.1.0",
"karma-chai-as-promised": "^0.1.2",
"karma-chai-dom": "^1.1.0",
"karma-chai-sinon": "^0.1.5",
"karma-chrome-launcher": "^2.2.0",
Expand All @@ -68,26 +67,25 @@
"karma-sinon-stub-promise": "^1.0.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^2.0.4",
"lint-staged": "^4.2.3",
"mocha": "^3.4.2",
"lint-staged": "^5.0.0",
"mocha": "^4.0.1",
"node-noop": "^1.0.0",
"node-sass": "^4.5.0",
"optimize-css-assets-webpack-plugin": "^1.3.0",
"postcss-loader": "^1.3.3",
"optimize-css-assets-webpack-plugin": "^3.2.0",
"postcss-loader": "^2.0.8",
"prettier": "^1.5.3",
"prettier-eslint-cli": "^4.1.1",
"raw-loader": "^0.5.1",
"sass-loader": "^6.0.6",
"sinon": "1.17.7",
"sinon-chai": "2.8.0",
"sinon": "^1.17.7",
"sinon-chai": "^2.8.0",
"sinon-stub-promise": "^4.0.0",
"string-replace-loader": "^1.3.0",
"style-loader": "^0.18.2",
"stylelint": "^8.1.1",
"style-loader": "^0.19.0",
"stylelint": "^8.2.0",
"stylelint-config-standard": "^17.0.0",
"stylelint-order": "^0.7.0",
"stylelint-scss": "^2.1.0",
"webpack": "^2.2.1",
"webpack": "^3.8.1",
"webpack-bundle-analyzer": "^2.8.3",
"whatwg-fetch": "^2.0.3"
},
Expand All @@ -98,9 +96,9 @@
"debug": "NODE_ENV=test ./node_modules/.bin/karma start build/karma.conf.js --no-single-run --auto-watch",
"lint": "NODE_ENV=dev ./node_modules/.bin/eslint src && ./node_modules/.bin/stylelint 'src/**/*.scss'",
"precommit": "lint-staged",
"commitmsg": "commitlint -e",
"prepush": "yarn run lint",
"prettier": "prettier-eslint \"src/**/*.js\" --print-width 120 --single-quote --tab-width 4 --write",
"commitmsg": "conventional-changelog-lint -e",
"ci": "yarn run clean && yarn run lint && yarn run test",
"clean": "rm -rf dist && rm -rf lib && rm -rf reports/coverage && rm -rf src/i18n/json",
"github-release": "./node_modules/.bin/conventional-github-releaser",
Expand Down
2 changes: 1 addition & 1 deletion src/AnnotationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class AnnotationService extends EventEmitter {
// Construct map of thread ID to annotations
Object.keys(annotations).forEach((annotationID) => {
const annotation = annotations[annotationID];
const threadID = annotation.threadID;
const { threadID } = annotation;
const thread = threadMap[threadID] || [];
threadMap[threadID] = thread;
thread[annotation.annotationID] = annotation;
Expand Down
22 changes: 11 additions & 11 deletions src/__tests__/AnnotationThread-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe('AnnotationThread', () => {
stubs.updateTemp = sandbox.stub(thread, 'updateTemporaryAnnotation');

const promise = thread.saveAnnotation('point', 'blah');
promise.should.be.fulfilled.then(() => {
promise.then(() => {
expect(stubs.updateTemp).to.be.called;
done();
}).catch(() => {
Expand All @@ -176,7 +176,7 @@ describe('AnnotationThread', () => {
stubs.serverSave = sandbox.stub(thread, 'updateTemporaryAnnotation');

const promise = thread.saveAnnotation('point', 'blah');
promise.should.be.fulfilled.then(() => {
promise.then(() => {
expect(stubs.handleError).to.be.called;
done();
}).catch(() => {
Expand Down Expand Up @@ -325,8 +325,8 @@ describe('AnnotationThread', () => {
stubs.dialogMock.expects('hideMobileDialog').never();

const promise = thread.deleteAnnotation('someID', false);
promise.should.be.fulfilled.then(() => {
stubs.threadPromise.should.be.fulfilled.then(() => {
promise.then(() => {
stubs.threadPromise.then(() => {
expect(stubs.destroy).to.be.called;
done();
});
Expand All @@ -341,7 +341,7 @@ describe('AnnotationThread', () => {
stubs.dialogMock.expects('hideMobileDialog');

const promise = thread.deleteAnnotation('someID', false);
promise.should.be.fulfilled.then(() => {
promise.then(() => {
done();
}).catch(() => {
sinon.assert.failException;
Expand All @@ -354,7 +354,7 @@ describe('AnnotationThread', () => {
stubs.dialogMock.expects('removeAnnotation').withArgs('someID');

const promise = thread.deleteAnnotation('someID', false);
promise.should.be.fulfilled.then(() => {
promise.then(() => {
done();
}).catch(() => {
sinon.assert.failException;
Expand All @@ -363,7 +363,7 @@ describe('AnnotationThread', () => {

it('should make a server call to delete an annotation with the specified ID if useServer is true', (done) => {
const promise = thread.deleteAnnotation('someID', true);
promise.should.be.fulfilled.then(() => {
promise.then(() => {
expect(stubs.emit).to.not.be.calledWith(THREAD_EVENT.threadCleanup);
expect(annotationService.delete).to.be.calledWith('someID');
done();
Expand All @@ -378,7 +378,7 @@ describe('AnnotationThread', () => {
stubs.isPlain.returns(true);

const promise = thread.deleteAnnotation('someID', true);
promise.should.be.fulfilled.then(() => {
promise.then(() => {
expect(annotationService.delete).to.be.calledWith('someID');
done();
}).catch(() => {
Expand All @@ -388,7 +388,7 @@ describe('AnnotationThread', () => {

it('should not make a server call to delete an annotation with the specified ID if useServer is false', (done) => {
const promise = thread.deleteAnnotation('someID', false);
promise.should.be.fulfilled.then(() => {
promise.then(() => {
expect(annotationService.delete).to.not.be.called;
done();
}).catch(() => {
Expand All @@ -401,7 +401,7 @@ describe('AnnotationThread', () => {
stubs.serviceDelete.returns(Promise.reject());

const promise = thread.deleteAnnotation('someID', true);
promise.should.be.fulfilled.then(() => {
promise.then(() => {
sinon.assert.failException;
}).catch(() => {
expect(annotationService.delete).to.be.called;
Expand All @@ -423,7 +423,7 @@ describe('AnnotationThread', () => {
stubs.isPlain.returns(true);

const promise = thread.deleteAnnotation('someID');
promise.should.be.fulfilled.then(() => {
promise.then(() => {
expect(stubs.emit).to.be.calledWith(THREAD_EVENT.threadCleanup);
expect(stubs.emit).to.be.calledWith(THREAD_EVENT.delete);
done();
Expand Down
8 changes: 4 additions & 4 deletions src/__tests__/Annotator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ describe('Annotator', () => {
};

const result = annotator.fetchAnnotations();
result.should.be.fulfilled.then(() => {
result.then(() => {
expect(result).to.be.truthy;
done();
}).catch(() => {
Expand All @@ -444,7 +444,7 @@ describe('Annotator', () => {
};

const result = annotator.fetchAnnotations();
result.should.be.fulfilled.then(() => {
result.then(() => {
expect(result).to.be.truthy;
expect(annotator.threadMap).to.not.be.undefined;
expect(annotator.emit).to.be.calledWith(ANNOTATOR_EVENT.fetch);
Expand All @@ -462,9 +462,9 @@ describe('Annotator', () => {
};

const result = annotator.fetchAnnotations();
result.should.be.fulfilled.then(() => {
result.then(() => {
expect(result).to.be.truthy;
stubs.threadPromise.should.be.fulfilled.then(() => {
stubs.threadPromise.then(() => {
expect(annotator.threadMap).to.not.be.undefined;
expect(annotator.emit).to.be.calledWith(ANNOTATOR_EVENT.fetch);
done();
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/DrawingModeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class DrawingModeController extends AnnotationModeController {
this.unregisterThread(thread);

// Redraw any threads that the deleted thread could have been overlapping
const page = thread.location.page;
const { page } = thread.location;
this.threads[page].all().forEach((drawingThread) => drawingThread.show());
}

Expand Down
6 changes: 3 additions & 3 deletions src/doc/DocAnnotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class DocAnnotator extends Annotator {
let [x, y] = browserCoordinates;

// Do not create annotation if event doesn't have coordinates
if (isNaN(x) || isNaN(y)) {
if (Number.isNaN(x) || Number.isNaN(y)) {
this.emit(ANNOTATOR_EVENT.error, this.localized.createError);
return location;
}
Expand Down Expand Up @@ -918,7 +918,7 @@ class DocAnnotator extends Annotator {
let consumed = false;
let activeThread = null;

const page = annotatorUtil.getPageInfo(event.target).page;
const { page } = annotatorUtil.getPageInfo(event.target);
const pageThreads = this.threads[page] || {};

Object.keys(pageThreads).forEach((threadID) => {
Expand Down Expand Up @@ -1027,7 +1027,7 @@ class DocAnnotator extends Annotator {
* @return {void}
*/
removeRangyHighlight(highlight) {
const highlights = this.highlighter.highlights;
const { highlights } = this.highlighter;
if (!Array.isArray(highlights)) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/doc/DocHighlightThread.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ class DocHighlightThread extends AnnotationThread {
let eventOccurredInHighlight = false;

const points = this.location.quadPoints;
const length = points.length;
const { length } = points;

let index = 0;
while (index < length && !eventOccurredInHighlight) {
Expand Down
2 changes: 1 addition & 1 deletion src/doc/__tests__/DocAnnotator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ describe('doc/DocAnnotator', () => {
stubs.validateThread.returns(false);
const thread = annotator.createAnnotationThread([], {}, TYPES.highlight);
expect(thread instanceof DocHighlightThread).to.be.false;
expect(thread).to.be.empty;
expect(thread).to.be.undefined;
expect(annotator.handleValidationError).to.be.called;
});

Expand Down
5 changes: 2 additions & 3 deletions src/doc/docAnnotatorUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ export function getBrowserCoordinatesFromLocation(location, annotatedElement) {
const pageDimensions = pageEl.getBoundingClientRect();
const pageHeight = pageDimensions.height - PAGE_PADDING_TOP - PAGE_PADDING_BOTTOM;
const zoomScale = annotatorUtil.getScale(annotatedElement);
let x = location.x;
let y = location.y;
let { x, y } = location;

// If needed, scale coords comparing current dimensions with saved dimensions
const dimensionScale = annotatorUtil.getDimensionScale(
Expand Down Expand Up @@ -322,7 +321,7 @@ export function isValidSelection(selection) {
export function scaleCanvas(pageEl, annotationLayerEl) {
const pageDimensions = pageEl.getBoundingClientRect();
const pxRatio = window.devicePixelRatio || 1;
const width = pageDimensions.width;
const { width } = pageDimensions;
const height = pageDimensions.height - PAGE_PADDING_TOP - PAGE_PADDING_BOTTOM;

const scaledCanvas = annotationLayerEl;
Expand Down
2 changes: 1 addition & 1 deletion src/drawing/DrawingPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class DrawingPath {
* @return {Object} A bounding rectangle and the stroke paths it contains
*/
static extractDrawingInfo(pathA, accumulator) {
let paths = accumulator.paths;
let { paths } = accumulator;
const apath = { path: pathA.path };
if (!paths) {
paths = [apath];
Expand Down
4 changes: 2 additions & 2 deletions src/drawing/DrawingThread.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class DrawingThread extends AnnotationThread {
* the amount of re-renders onto a temporary memory canvas.
*/
if (clearCanvas) {
const canvas = context.canvas;
const { canvas } = context;
context.clearRect(0, 0, canvas.width, canvas.height);
}

Expand Down Expand Up @@ -417,7 +417,7 @@ class DrawingThread extends AnnotationThread {
*/
clearBoundary() {
if (this.drawingContext) {
const canvas = this.drawingContext.canvas;
const { canvas } = this.drawingContext;
this.drawingContext.clearRect(0, 0, canvas.width, canvas.height);
}

Expand Down
2 changes: 1 addition & 1 deletion src/image/ImageAnnotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ImageAnnotator extends Annotator {
let [x, y] = [clientEvent.clientX - imageDimensions.left, clientEvent.clientY - imageDimensions.top];

// Do not create annotation if event doesn't have coordinates
if (isNaN(x) || isNaN(y)) {
if (Number.isNaN(x) || Number.isNaN(y)) {
this.emit(ANNOTATOR_EVENT.error, this.localized.createError);
return location;
}
Expand Down
Loading

0 comments on commit 97a91c3

Please sign in to comment.