Skip to content

Commit

Permalink
fix: fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tams sokari committed Oct 31, 2023
1 parent b7536d5 commit c4b3ced
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
1 change: 1 addition & 0 deletions packages/components/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = {
indent: ['error', 2],
'max-classes-per-file': 'off',
'max-len': 'off',
'no-bitwise': 'off',
'no-console': ['error', { allow: ['warn', 'error', 'info'] }],
'no-plusplus': 'off',
'no-underscore-dangle': 'off',
Expand Down
27 changes: 15 additions & 12 deletions packages/components/smart-camera-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -1186,13 +1186,13 @@ class PoweredBySmileId extends HTMLElement {
}

class SmileIdCanvas {
static hasMoreThanNColors(data, n=16) {
static hasMoreThanNColors(data, n = 16) {
const colors = new Set();
for (let i = 0; i < Math.min(data.length, 10000); i += 4) {
colors.add((data[i] << 16) | (data[i + 1] << 8) | data[i + 2]);
if (colors.size > n) {
return true;
}
colors.add((data[i] << 16) | (data[i + 1] << 8) | data[i + 2]);
if (colors.size > n) {
return true;
}
}
return false;
}
Expand Down Expand Up @@ -1578,7 +1578,8 @@ class SmartCameraWeb extends HTMLElement {
}
}

_drawImage(canvas, testImages = false, video = this._video,) {
/* eslint-disable consistent-return */
_drawImage(canvas, testImages = false, video = this._video) {
this.resetErrorMessage();
try {
const context = canvas.getContext('2d');
Expand All @@ -1596,21 +1597,23 @@ class SmartCameraWeb extends HTMLElement {
);

if (testImages) {
const imageData = context.getImageData(0, 0, canvas.width, canvas.height)
const imageData = context.getImageData(0, 0, canvas.width, canvas.height);

const hasManyColors = SmileIdCanvas.hasMoreThanNColors(imageData.data);

if (!hasManyColors) {
this.selectSelfie.disabled = true;
throw new Error("Selfie image does not show adequate detail. Check that your camera is unblocked, and that there is enough light.");
if (hasManyColors) {
return context;
}
this.selectSelfie.disabled = true;
throw new Error('Selfie image does not show adequate detail. Check that your camera is unblocked, and that there is enough light.');
} else {
return context;
}

return context;
} catch (error) {
this.handleError(error);
}
}
/* eslint-enable consistent-return */

_capturePOLPhoto() {
const canvas = document.createElement('canvas');
Expand Down

0 comments on commit c4b3ced

Please sign in to comment.