diff --git a/packages/file-handling/.eslintignore b/packages/file-handling/.eslintignore new file mode 100644 index 0000000000000000000000000000000000000000..c139ed4c11bae3aeb416c866e2a9aa248930c65f --- /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 0000000000000000000000000000000000000000..dcb3daa3e43a01208a022e30711870901c24f1f0 --- /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 0cfed3b8825f52659fa466046ada8ce74f6eb469..f111c09720ecb0f3d03600ee03ebe46a23720f3d 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 5be11fd6af2255360c8b50facf4aac3686eff5f8..34d6b3698a25742757531e1dde8ab096168b8b44 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 3b9736c3b27a3a6c9e696ccd6f239cc59cbf1fb3..3af358ae63ab5a6511ca20dfb3bad61048496b48 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 c38d41418610209afbf653689815b308b84eb575..015f408b30bf517ac9c0db57453fae63f948a61c 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 274b9bb45dd07a33ed59b8107a8cf31b05862fa2..720bdd2d38724c096f5b95e7b0defdd4880fc2d3 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