Skip to content

Commit

Permalink
Code style fixes reported in codacy (#228)
Browse files Browse the repository at this point in the history
* Some code style fixes reported in Codacy

  - Test codes removed as they are broken at the moment.

* Additional fixes

* Multiple codacy fixes
  • Loading branch information
mebjas authored Jun 13, 2021
1 parent 37bd8a7 commit 67fc54d
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 336 deletions.
2 changes: 1 addition & 1 deletion dist/html5-qrcode.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/electron/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ You can download this from [Github release page](https://github.com/mebjas/html5
<script src="html5-qrcode.min.js"></script>
```

### And include the `html` placeholder:
### And include the `html` placeholder
```html
<div style="width: 600px" id="reader"></div>
```

### And `javascript` initialization:
### And `javascript` initialization
```js
function onScanSuccess(qrCodeMessage) {
// handle on success condition with the decoded message
Expand Down
1 change: 0 additions & 1 deletion examples/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
## How to build a `React Plugin / Component` using `html5-qrcode`
We shall be using React's recommendation on [Integrating with Other Libraries](https://reactjs.org/docs/integrating-with-other-libraries.html) to create a plugin for `React`.


### Download the latest library
You can download this from [Github release page](https://github.com/mebjas/html5-qrcode/releases) or [npm](https://www.npmjs.com/package/html5-qrcode). And include this in `index.html`.

Expand Down
2 changes: 1 addition & 1 deletion examples/vuejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<script src="https://unpkg.com/html5-qrcode/minified/html5-qrcode.min.js"></script>
```

### Create a `qrcode-scanner` component.
### Create a `qrcode-scanner` component

```js
Vue.component('qrcode-scanner', {
Expand Down
12 changes: 6 additions & 6 deletions examples/vuejs/style.css
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
body {
margin: 0px;
padding: 0px;
margin: 0px; /* no unit */
padding: 0px; /* no unit */
}

.header {
padding: 10px;
background: black;
color: white;
padding: 10px;
background: black;
color: white;
}

.section {
padding: auto;
padding: auto;
}
6 changes: 4 additions & 2 deletions scripts/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash
## Test script

echo 'Initiating test sequence'
mocha-phantomjs -p node_modules/phantomjs/bin/phantomjs -R dot ./test/test.html5-qrcode.html
# TODO(mebjas): Fix the testing script, it's broken at the moment.
# echo 'Initiating test sequence'
echo 'Testing is broken at the moment, fix WIP'
# mocha-phantomjs -p node_modules/phantomjs/bin/phantomjs -R dot ./test/test.html5-qrcode.html
2 changes: 1 addition & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export enum Html5QrcodeSupportedFormats {
}

/** Returns true if the passed object instance is a valid format. */
export function IsValidHtml5QrcodeSupportedFormats(format: any): boolean {
export function isValidHtml5QrcodeSupportedFormats(format: any): boolean {
return Object.values(Html5QrcodeSupportedFormats).includes(format);
}

Expand Down
42 changes: 21 additions & 21 deletions src/html5-qrcode-scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {

import {
Html5QrcodeScannerStrings,
} from "./strings"
} from "./strings";

/**
* Different states of QR Code Scanner.
Expand Down Expand Up @@ -65,7 +65,7 @@ function toHtml5QrcodeFullConfig(
return {
formatsToSupport: config.formatsToSupport,
verbose: verbose
}
};
}

export class Html5QrcodeScanner {
Expand Down Expand Up @@ -183,7 +183,7 @@ export class Html5QrcodeScanner {
return;
}
if (this.html5Qrcode.isScanning) {
this.html5Qrcode.stop().then(_ => {
this.html5Qrcode.stop().then((_) => {
if (!this.html5Qrcode) {
resolve();
return;
Expand All @@ -192,13 +192,13 @@ export class Html5QrcodeScanner {
this.html5Qrcode.clear();
emptyHtmlContainer();
resolve();
}).catch(error => {
}).catch((error) => {
if (this.verbose) {
this.logger.logError(
"Unable to stop qrcode scanner", error);
}
reject(error);
})
});
}
});
}
Expand Down Expand Up @@ -306,7 +306,7 @@ export class Html5QrcodeScanner {
const scpCameraScanRegion = document.createElement("div");
scpCameraScanRegion.id = this.getDashboardSectionCameraScanRegionId();
scpCameraScanRegion.style.display
= this.currentScanType == Html5QrcodeScanType.SCAN_TYPE_CAMERA
= this.currentScanType === Html5QrcodeScanType.SCAN_TYPE_CAMERA
? "block" : "none";
sectionControlPanel.appendChild(scpCameraScanRegion);

Expand All @@ -325,10 +325,10 @@ export class Html5QrcodeScanner {
$this.setHeaderMessage(
Html5QrcodeScannerStrings.cameraPermissionRequesting());

Html5Qrcode.getCameras().then(cameras => {
Html5Qrcode.getCameras().then((cameras) => {
$this.setStatus(Html5QrcodeScannerStrings.idleStatus());
$this.resetHeaderMessage();
if (!cameras || cameras.length == 0) {
if (!cameras || cameras.length === 0) {
$this.setStatus(
Html5QrcodeScannerStrings.noCameraFoundErrorStatus(),
Html5QrcodeScannerStatus.STATUS_WARNING);
Expand Down Expand Up @@ -360,23 +360,23 @@ export class Html5QrcodeScanner {
fileScanInput.type = "file";
fileScanInput.style.width = "200px";
fileScanInput.disabled
= this.currentScanType == Html5QrcodeScanType.SCAN_TYPE_CAMERA;
= this.currentScanType === Html5QrcodeScanType.SCAN_TYPE_CAMERA;
const fileScanLabel = document.createElement("span");
fileScanLabel.innerHTML = "&nbsp; Select Image";
fileBasedScanRegion.appendChild(fileScanInput);
fileBasedScanRegion.appendChild(fileScanLabel);
fileScanInput.addEventListener('change', (e: any) => {
fileScanInput.addEventListener("change", (e: any) => {
if (!$this.html5Qrcode) {
throw "html5Qrcode not defined";
}

if (e == null || e.target == null) {
return;
}
if ($this.currentScanType != Html5QrcodeScanType.SCAN_TYPE_FILE) {
if ($this.currentScanType !== Html5QrcodeScanType.SCAN_TYPE_FILE) {
return;
}
if (e.target.files.length == 0) {
if (e.target.files.length === 0) {
return;
}
const file = e.target.files[0];
Expand All @@ -387,7 +387,7 @@ export class Html5QrcodeScanner {
decodedText,
Html5QrcodeResultFactory.createFrom(decodedText));
})
.catch(error => {
.catch((error) => {
$this.setStatus(
Html5QrcodeScannerStrings.errorStatus(),
Html5QrcodeScannerStatus.STATUS_WARNING);
Expand Down Expand Up @@ -415,7 +415,7 @@ export class Html5QrcodeScanner {
for (const camera of cameras) {
const value = camera.id;
const name = camera.label == null ? value : camera.label;
const option = document.createElement('option');
const option = document.createElement("option");
option.value = value;
option.innerHTML = name;
cameraSelectionSelect.appendChild(option);
Expand All @@ -438,7 +438,7 @@ export class Html5QrcodeScanner {

scpCameraScanRegion.appendChild(cameraActionContainer);

cameraActionStartButton.addEventListener('click', _ => {
cameraActionStartButton.addEventListener("click", (_) => {
cameraSelectionSelect.disabled = true;
cameraActionStartButton.disabled = true;
$this.showHideScanTypeSwapLink(false);
Expand All @@ -448,7 +448,7 @@ export class Html5QrcodeScanner {
toHtml5QrcodeCameraScanConfig($this.config),
$this.qrCodeSuccessCallback!,
$this.qrCodeErrorCallback!)
.then(_ => {
.then((_) => {
cameraActionStopButton.disabled = false;
cameraActionStopButton.style.display = "inline-block";
cameraActionStartButton.style.display = "none";
Expand All @@ -464,7 +464,7 @@ export class Html5QrcodeScanner {
});
});

cameraActionStopButton.addEventListener('click', _ => {
cameraActionStopButton.addEventListener("click", (_) => {
if (!$this.html5Qrcode) {
throw "html5Qrcode not defined";
}
Expand Down Expand Up @@ -506,7 +506,7 @@ export class Html5QrcodeScanner {
= this.currentScanType == Html5QrcodeScanType.SCAN_TYPE_CAMERA
? TEXT_IF_CAMERA_SCAN_SELECTED : TEXT_IF_FILE_SCAN_SELECTED;
swithToFileBasedLink.href = "#scan-using-file";
swithToFileBasedLink.addEventListener('click', function () {
swithToFileBasedLink.addEventListener("click", function () {
if (!$this.sectionSwapAllowed) {
if ($this.verbose) {
$this.logger.logError(
Expand All @@ -522,7 +522,7 @@ export class Html5QrcodeScanner {

$this.sectionSwapAllowed = false;

if ($this.currentScanType == Html5QrcodeScanType.SCAN_TYPE_CAMERA) {
if ($this.currentScanType === Html5QrcodeScanType.SCAN_TYPE_CAMERA) {
// swap to file
$this.clearScanRegion();
$this.getFileScanInput().disabled = false;
Expand Down Expand Up @@ -629,7 +629,7 @@ export class Html5QrcodeScanner {
}

this.cameraScanImage = new Image;
this.cameraScanImage.onload = _ => {
this.cameraScanImage.onload = (_) => {
qrCodeScanRegion.innerHTML = "<br>";
qrCodeScanRegion.appendChild($this.cameraScanImage!);
}
Expand All @@ -650,7 +650,7 @@ export class Html5QrcodeScanner {
}

this.fileScanImage = new Image;
this.fileScanImage.onload = _ => {
this.fileScanImage.onload = (_) => {
qrCodeScanRegion.innerHTML = "<br>";
qrCodeScanRegion.appendChild($this.fileScanImage!);
}
Expand Down
Loading

0 comments on commit 67fc54d

Please sign in to comment.