From fe67c4b19d6e8eae5326b4b904ea382490f01c4e Mon Sep 17 00:00:00 2001
From: Christoph Reiter <reiter.christoph@gmail.com>
Date: Mon, 21 Dec 2020 15:13:43 +0100
Subject: [PATCH] file-handling: add eslint support

---
 packages/file-handling/.eslintignore          |  4 +++
 packages/file-handling/.eslintrc.json         | 25 +++++++++++++++++++
 packages/file-handling/package.json           |  7 ++++--
 .../src/dbp-nextcloud-file-picker.js          | 14 +++++------
 packages/file-handling/src/file-sink.js       |  2 +-
 packages/file-handling/src/file-source.js     | 16 ++++++------
 packages/file-handling/src/styles.js          |  2 +-
 7 files changed, 50 insertions(+), 20 deletions(-)
 create mode 100644 packages/file-handling/.eslintignore
 create mode 100644 packages/file-handling/.eslintrc.json

diff --git a/packages/file-handling/.eslintignore b/packages/file-handling/.eslintignore
new file mode 100644
index 00000000..c139ed4c
--- /dev/null
+++ b/packages/file-handling/.eslintignore
@@ -0,0 +1,4 @@
+/vendor/**
+/dist/**
+*.conf.js
+*.config.js
\ No newline at end of file
diff --git a/packages/file-handling/.eslintrc.json b/packages/file-handling/.eslintrc.json
new file mode 100644
index 00000000..dcb3daa3
--- /dev/null
+++ b/packages/file-handling/.eslintrc.json
@@ -0,0 +1,25 @@
+{
+    "env": {
+        "browser": true,
+        "es6": true,
+        "mocha": true
+    },
+    "globals": {
+        "Atomics": "readonly",
+        "SharedArrayBuffer": "readonly"
+    },
+    "parser": "babel-eslint",
+    "parserOptions": {
+        "ecmaVersion": 2018,
+        "sourceType": "module"
+    },
+    "rules": {
+        "no-unused-vars": ["error", { "args": "none" }],
+        "semi": [2, "always"],
+        "jsdoc/require-jsdoc": 0,
+        "jsdoc/require-param-description": 0,
+        "jsdoc/require-returns": 0,
+        "jsdoc/require-returns-description": 0,
+        "jsdoc/require-param-type": 0
+    }
+}
\ No newline at end of file
diff --git a/packages/file-handling/package.json b/packages/file-handling/package.json
index 0cfed3b8..f111c097 100644
--- a/packages/file-handling/package.json
+++ b/packages/file-handling/package.json
@@ -29,7 +29,9 @@
     "rollup-plugin-copy": "^3.1.0",
     "rollup-plugin-delete": "^2.0.0",
     "rollup-plugin-serve": "^1.0.1",
-    "rollup-plugin-terser": "^7.0.2"
+    "rollup-plugin-terser": "^7.0.2",
+    "eslint": "^7.3.1",
+    "eslint-plugin-jsdoc": "^30.6.4"
   },
   "dependencies": {
     "@dbp-toolkit/common": "^0.1.0",
@@ -55,6 +57,7 @@
     "watch": "npm run watch-local",
     "watch-local": "rollup -c --watch",
     "watch-dev": "rollup -c --watch --environment BUILD:development",
-    "test": "npm run build-test && karma start --singleRun"
+    "test": "npm run build-test && karma start --singleRun",
+    "lint": "eslint ."
   }
 }
diff --git a/packages/file-handling/src/dbp-nextcloud-file-picker.js b/packages/file-handling/src/dbp-nextcloud-file-picker.js
index 5be11fd6..34d6b369 100644
--- a/packages/file-handling/src/dbp-nextcloud-file-picker.js
+++ b/packages/file-handling/src/dbp-nextcloud-file-picker.js
@@ -140,7 +140,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
                             if (typeof cell.getValue() === 'undefined') {
                                 return "";
                             }
-                            const [fileMainType, fileSubType] = cell.getValue().split('/');
+                            const [, fileSubType] = cell.getValue().split('/');
                             return fileSubType;
                         }},
                     {title: i18n.t('nextcloud-file-picker.last-modified'), responsive: 3, widthGrow:1, minWidth: 100, field: "lastmod",sorter: (a, b, aRow, bRow, column, dir, sorterParams) => {
@@ -404,7 +404,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
                 this.activeDirectoryACL = '';
             }
         } else {
-            this.activeDirectoryRights = 'SGDNVCK'
+            this.activeDirectoryRights = 'SGDNVCK';
         }
         this.loadDirectory(file.filename);
         event.preventDefault();
@@ -483,7 +483,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
         this.statusText = i18n.t('nextcloud-file-picker.upload-to', {path: directory});
         this.fileList = files;
         this.forAll = false;
-        this.setRepeatForAllConflicts()
+        this.setRepeatForAllConflicts();
         this.uploadFile(directory);
     }
 
@@ -510,7 +510,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
             let that = this;
             this.loading = true;
             this.statusText = i18n.t('nextcloud-file-picker.upload-to', {path: path});
-            let contents = await this.webDavClient
+            await this.webDavClient
                     .putFileContents(path, file,  { overwrite: false, onUploadProgress: progress => {
                             /* console.log(`Uploaded ${progress.loaded} bytes of ${progress.total}`);*/
                         }}).then(function() {
@@ -591,7 +591,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
 
         let that = this;
         // https://github.com/perry-mitchell/webdav-client#putfilecontents
-        let contents = await this.webDavClient
+        await this.webDavClient
             .putFileContents(path, file, {
                 overwrite: overwrite, onUploadProgress: progress => {
                     /*console.log(`Uploaded ${progress.loaded} bytes of ${progress.total}`);*/
@@ -845,8 +845,6 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
             this._('#add-folder-button').setAttribute("title", i18n.t('nextcloud-file-picker.add-folder-close'));
             this._('#new-folder').focus();
         }
-
-        let that = this;
     }
 
     /**
@@ -1515,7 +1513,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
                                 <span style="word-break: break-all;">${this.replaceFilename}</span>
                                 ${i18n.t('nextcloud-file-picker.replace-title-2')}.
                             </h2>
-                            <button title="${i18n.t('file-sink.modal-close')}" class="modal-close"  aria-label="Close modal" @click="${() => {this.closeDialog()}}">
+                            <button title="${i18n.t('file-sink.modal-close')}" class="modal-close"  aria-label="Close modal" @click="${() => {this.closeDialog();}}">
                                 <dbp-icon title="${i18n.t('file-sink.modal-close')}" name="close" class="close-icon"></dbp-icon>
                             </button> 
                         </header>
diff --git a/packages/file-handling/src/file-sink.js b/packages/file-handling/src/file-sink.js
index 3b9736c3..3af358ae 100644
--- a/packages/file-handling/src/file-sink.js
+++ b/packages/file-handling/src/file-sink.js
@@ -208,7 +208,7 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) {
                             </div>
                         </nav>
                             <div class="modal-header">
-                                <button title="${i18n.t('file-sink.modal-close')}" class="modal-close"  aria-label="Close modal" @click="${() => { this.closeDialog()}}">
+                                <button title="${i18n.t('file-sink.modal-close')}" class="modal-close"  aria-label="Close modal" @click="${() => { this.closeDialog();}}">
                                         <dbp-icon title="${i18n.t('file-sink.modal-close')}" name="close" class="close-icon"></dbp-icon>
                                 </button> 
                                 <p class="modal-context"> ${this.context}</p>
diff --git a/packages/file-handling/src/file-source.js b/packages/file-handling/src/file-source.js
index c38d4141..015f408b 100644
--- a/packages/file-handling/src/file-source.js
+++ b/packages/file-handling/src/file-source.js
@@ -7,7 +7,7 @@ import {Icon, MiniSpinner} from '@dbp-toolkit/common';
 import * as commonStyles from '@dbp-toolkit/common/styles';
 import {NextcloudFilePicker} from "./dbp-nextcloud-file-picker";
 import {classMap} from 'lit-html/directives/class-map.js';
-import MicroModal from './micromodal.es'
+import MicroModal from './micromodal.es';
 import * as fileHandlingStyles from './styles';
 
 function mimeTypesToAccept(mimeTypes) {
@@ -113,13 +113,13 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) {
         this.updateComplete.then(() => {
             this.dropArea = this._('#dropArea');
             ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
-                this.dropArea.addEventListener(eventName, this.preventDefaults, false)
+                this.dropArea.addEventListener(eventName, this.preventDefaults, false);
             });
             ['dragenter', 'dragover'].forEach(eventName => {
-                this.dropArea.addEventListener(eventName, this.highlight.bind(this), false)
+                this.dropArea.addEventListener(eventName, this.highlight.bind(this), false);
             });
             ['dragleave', 'drop'].forEach(eventName => {
-                this.dropArea.addEventListener(eventName, this.unhighlight.bind(this), false)
+                this.dropArea.addEventListener(eventName, this.unhighlight.bind(this), false);
             });
             this.dropArea.addEventListener('drop', this.handleDrop.bind(this), false);
             this._('#fileElem').addEventListener('change', this.handleChange.bind(this));
@@ -132,11 +132,11 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) {
     }
 
     highlight(e) {
-        this.dropArea.classList.add('highlight')
+        this.dropArea.classList.add('highlight');
     }
 
     unhighlight(e) {
-        this.dropArea.classList.remove('highlight')
+        this.dropArea.classList.remove('highlight');
     }
 
     handleDrop(e) {
@@ -177,7 +177,7 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) {
 
         await commonUtils.asyncArrayForEach(files, async (file) => {
             if (file.size === 0) {
-                console.log('file \'' + file.name + '\' has size=0 and is denied!')
+                console.log('file \'' + file.name + '\' has size=0 and is denied!');
                 return;
             }
 
@@ -422,7 +422,7 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) {
                             
                         </nav>
                         <div class="modal-header">
-                            <button title="${i18n.t('file-source.modal-close')}" class="modal-close"  aria-label="Close modal"  @click="${() => {this.closeDialog()}}">
+                            <button title="${i18n.t('file-source.modal-close')}" class="modal-close"  aria-label="Close modal"  @click="${() => {this.closeDialog();}}">
                                     <dbp-icon name="close" class="close-icon"></dbp-icon>
                             </button>
                        
diff --git a/packages/file-handling/src/styles.js b/packages/file-handling/src/styles.js
index 274b9bb4..720bdd2d 100644
--- a/packages/file-handling/src/styles.js
+++ b/packages/file-handling/src/styles.js
@@ -1,4 +1,4 @@
-import {css, unsafeCSS, CSSResult} from 'lit-element';
+import {css} from 'lit-element';
 
 export function getFileHandlingCss() {
     // language=css
-- 
GitLab