From 2e0250231e0a37b0cb667a7e4dd6e846d36dbb22 Mon Sep 17 00:00:00 2001 From: "Luke \"Jared\" Bennett" Date: Sat, 15 Jul 2017 02:54:51 +0100 Subject: [PATCH] Fix eslint warnings --- app/assets/javascripts/dispatcher.js | 11 +- .../javascripts/repo/repo_binary_viewer.js | 27 +-- app/assets/javascripts/repo/repo_bundle.js | 16 +- app/assets/javascripts/repo/repo_editor.js | 38 ++-- app/assets/javascripts/repo/repo_file.js | 8 +- app/assets/javascripts/repo/repo_helper.js | 172 +++++++++--------- .../javascripts/repo/repo_loading_file.js | 8 +- .../javascripts/repo/repo_mini_mixin.js | 8 +- .../javascripts/repo/repo_prev_directory.js | 10 +- app/assets/javascripts/repo/repo_service.js | 18 +- app/assets/javascripts/repo/repo_sidebar.js | 28 +-- app/assets/javascripts/repo/repo_store.js | 10 +- app/assets/javascripts/repo/repo_tab.js | 10 +- app/assets/javascripts/repo/repo_tabs.js | 12 +- .../javascripts/repo/repo_view_toggler.js | 7 +- 15 files changed, 191 insertions(+), 192 deletions(-) diff --git a/app/assets/javascripts/dispatcher.js b/app/assets/javascripts/dispatcher.js index f27dc141dba..8022c732351 100644 --- a/app/assets/javascripts/dispatcher.js +++ b/app/assets/javascripts/dispatcher.js @@ -72,19 +72,18 @@ import RepoBundle from './repo/repo_bundle'; } Dispatcher.prototype.initPageScripts = function() { - var page, path, shortcut_handler, fileBlobPermalinkUrlElement, fileBlobPermalinkUrl, os; + var page, path, shortcut_handler, fileBlobPermalinkUrlElement, fileBlobPermalinkUrl; page = $('body').attr('data-page'); if (!page) { return false; } - function getScrollBarWidth () { - var $outer = $('
').css({visibility: 'hidden', width: 100, overflow: 'scroll'}).appendTo('body'), - widthWithScroll = $('
').css({width: '100%'}).appendTo($outer).outerWidth(); + var $outer = $('
').css({ visibility: 'hidden', width: 100, overflow: 'scroll' }).appendTo('body'), + widthWithScroll = $('
').css({ width: '100%' }).appendTo($outer).outerWidth(); $outer.remove(); return 100 - widthWithScroll; - }; + } $('body').attr('data-scroll-width', getScrollBarWidth()); @@ -353,7 +352,7 @@ import RepoBundle from './repo/repo_bundle'; shortcut_handler = true; break; case 'projects:blob:show': - new RepoBundle(); + new RepoBundle(); break; case 'projects:blame:show': initBlob(); diff --git a/app/assets/javascripts/repo/repo_binary_viewer.js b/app/assets/javascripts/repo/repo_binary_viewer.js index 3b4024d8574..cc27f606041 100644 --- a/app/assets/javascripts/repo/repo_binary_viewer.js +++ b/app/assets/javascripts/repo/repo_binary_viewer.js @@ -1,8 +1,9 @@ -import Vue from 'vue' -import Store from './repo_store' +import Vue from 'vue'; +import Store from './repo_store'; +import Flash from '../flash'; export default class RepoBinaryViewer { - constructor(url) { + constructor() { this.initVue(); } @@ -15,19 +16,23 @@ export default class RepoBinaryViewer { computed: { pngBlobWithDataURI() { return `data:image/png;base64,${this.blobRaw}`; - } + }, }, watch: { blobRaw() { - if(!this.binary) return; - switch(this.binaryMimeType) { + if (!this.binary) return; + + switch (this.binaryMimeType) { case 'image/png': this.binaryTypes.png = true; - break; - } - } - } + break; + default: + new Flash('Blob could not be loaded'); // eslint-disable-line no-new + break; + } + }, + }, }); } -} \ No newline at end of file +} diff --git a/app/assets/javascripts/repo/repo_bundle.js b/app/assets/javascripts/repo/repo_bundle.js index 8ed53203c11..c407a304186 100644 --- a/app/assets/javascripts/repo/repo_bundle.js +++ b/app/assets/javascripts/repo/repo_bundle.js @@ -1,11 +1,11 @@ -import Tabs from './repo_tabs' -import Sidebar from './repo_sidebar' -import Editor from './repo_editor' -import BinaryViewer from './repo_binary_viewer' -import ViewToggler from './repo_view_toggler' -import Service from './repo_service' -import Store from './repo_store' -import Helper from './repo_helper' +import Tabs from './repo_tabs'; +import Sidebar from './repo_sidebar'; +import Editor from './repo_editor'; +import BinaryViewer from './repo_binary_viewer'; +import ViewToggler from './repo_view_toggler'; +import Service from './repo_service'; +import Store from './repo_store'; +import Helper from './repo_helper'; export default class RepoBundle { constructor() { diff --git a/app/assets/javascripts/repo/repo_editor.js b/app/assets/javascripts/repo/repo_editor.js index 05c0926effa..997acb90dfe 100644 --- a/app/assets/javascripts/repo/repo_editor.js +++ b/app/assets/javascripts/repo/repo_editor.js @@ -1,7 +1,7 @@ /* global monaco */ import Vue from 'vue'; -import Store from './repo_store' -import Helper from './repo_helper' +import Store from './repo_store'; +import Helper from './repo_helper'; export default class RepoEditor { constructor() { @@ -15,9 +15,9 @@ export default class RepoEditor { this.monacoEditor = monaco.editor .create( document.getElementById('ide'), { - model: null - } - ) + model: null, + }, + ); Helper.monacoInstance = monaco; this.initVue(); monaco.languages.getLanguages(); @@ -29,20 +29,20 @@ export default class RepoEditor { const monacoEditor = this.monacoEditor; this.vue = new Vue({ data: () => Store, - created () { - if(this.blobRaw !== ''){ + created() { + if (this.blobRaw !== '') { monacoEditor.setModel( monaco.editor.createModel( this.blobRaw, - 'plain' - ) + 'plain', + ), ); } }, watch: { isTree() { - if(this.isTree || !this.openedFiles.length) { + if (this.isTree || !this.openedFiles.length) { self.el.style.display = 'none'; } else { self.el.style.display = 'inline-block'; @@ -50,7 +50,7 @@ export default class RepoEditor { }, openedFiles() { - if((this.isTree || !this.openedFiles.length) || this.binary) { + if ((this.isTree || !this.openedFiles.length) || this.binary) { self.el.style.display = 'none'; } else { self.el.style.display = 'inline-block'; @@ -58,21 +58,21 @@ export default class RepoEditor { }, blobRaw() { - if(this.binary) { + if (this.binary) { self.el.style.display = 'none'; } else { - self.el.style.display = 'inline-block'; + self.el.style.display = 'inline-block'; } - if(!this.isTree) { + if (!this.isTree) { self.monacoEditor.setModel( monaco.editor.createModel( this.blobRaw, - this.activeFile.mime_type - ) + this.activeFile.mime_type, + ), ); } - } - } + }, + }, }); } -} \ No newline at end of file +} diff --git a/app/assets/javascripts/repo/repo_file.js b/app/assets/javascripts/repo/repo_file.js index b1f8e3bb0e5..55e8c176eeb 100644 --- a/app/assets/javascripts/repo/repo_file.js +++ b/app/assets/javascripts/repo/repo_file.js @@ -1,4 +1,4 @@ -let RepoFile = { +const RepoFile = { template: ` @@ -19,13 +19,13 @@ let RepoFile = { isTree: Boolean, isMini: Boolean, loading: Object, - hasFiles: Boolean + hasFiles: Boolean, }, methods: { linkClicked(file) { this.$emit('linkclicked', file); - } - } + }, + }, }; export default RepoFile; diff --git a/app/assets/javascripts/repo/repo_helper.js b/app/assets/javascripts/repo/repo_helper.js index 4f823f9cdc2..257f6241f43 100644 --- a/app/assets/javascripts/repo/repo_helper.js +++ b/app/assets/javascripts/repo/repo_helper.js @@ -1,9 +1,10 @@ -import Service from './repo_service' -import Store from './repo_store' +import Service from './repo_service'; +import Store from './repo_store'; +import Flash from '../flash'; -let RepoHelper = { +const RepoHelper = { isTree(data) { - return data.hasOwnProperty('blobs'); + return Object.hasOwnProperty.call(data, 'blobs'); }, monacoInstance: undefined, @@ -14,17 +15,11 @@ let RepoHelper = { : Date, getLanguagesForMimeType(mimetypeNeedle) { - const langs = monaco.languages.getLanguages(); - let lang = ''; - langs.every((lang) => { - const hasLang = lang.mimetypes.some((mimetype) => { - return mimetypeNeedle === mimetype - }); - if(hasLang) { - lang = lang.id; - return true; - } - return false; + const langs = window.monaco.languages.getLanguages(); + langs.map((lang) => { + const hasLang = lang.mimetypes.some(mimetype => mimetypeNeedle === mimetype); + if (hasLang) return lang.id; + return lang; }); }, @@ -32,7 +27,7 @@ let RepoHelper = { const split = url.split('/'); split.pop(); const blobIndex = split.indexOf('blob'); - if(blobIndex > -1) { + if (blobIndex > -1) { split[blobIndex] = 'tree'; } return split.join('/'); @@ -40,21 +35,22 @@ let RepoHelper = { insertNewFilesIntoParentDir(inDirectory, oldList, newList) { let indexOfFile; - if(!inDirectory) { + if (!inDirectory) { return newList; } oldList.find((file, i) => { - if(file.url === inDirectory.url){ - indexOfFile = i+1; + if (file.url === inDirectory.url) { + indexOfFile = i + 1; return true; } return false; }); - if(indexOfFile){ + if (indexOfFile) { // insert new list into old list newList.forEach((newFile) => { - newFile.level = inDirectory.level + 1; - oldList.splice(indexOfFile, 0, newFile); + const file = newFile; + file.level = inDirectory.level + 1; + oldList.splice(indexOfFile, 0, file); }); return oldList; } @@ -63,47 +59,45 @@ let RepoHelper = { setActiveFile(file) { Store.openedFiles = Store.openedFiles.map((openedFile) => { - openedFile.active = file.url === openedFile.url; - if(openedFile.active) { - Store.activeFile = openedFile; + const activeFile = openedFile; + activeFile.active = file.url === activeFile.url; // eslint-disable-line no-param-reassign + if (activeFile.active) { + Store.activeFile = activeFile; } - return openedFile; + return activeFile; }); - if(file.binary) { + if (file.binary) { Store.blobRaw = file.base64; - console.log('binary', file) } else { Store.blobRaw = file.plain; } - if(!file.loading){ - this.toURL(file.url); + if (!file.loading) { + this.toURL(file.url); } Store.binary = file.binary; }, removeFromOpenedFiles(file) { - console.log('file remove', file) - if(file.type === 'tree') return; - Store.openedFiles = Store.openedFiles.filter((openedFile) => { - return openedFile.url !== file.url; - }); + if (file.type === 'tree') return; + Store.openedFiles = Store.openedFiles.filter(openedFile => openedFile.url !== file.url); }, addToOpenedFiles(file) { - const openedFilesAlreadyExists = Store.openedFiles.some((openedFile) => { - return openedFile.url === file.url - }); - if(!openedFilesAlreadyExists) { + const openedFilesAlreadyExists = Store.openedFiles + .some(openedFile => openedFile.url === file.url); + if (!openedFilesAlreadyExists) { Store.openedFiles.push(file); } }, + /* eslint-disable no-param-reassign */ setDirectoryOpen(tree) { - if(tree) { + if (tree) { tree.opened = true; tree.icon = 'fa-folder-open'; } }, + /* eslint-enable no-param-reassign */ getRawURLFromBlobURL(url) { return url.replace('blob', 'raw'); @@ -113,58 +107,57 @@ let RepoHelper = { Service.getBase64Content(url) .then((response) => { Store.blobRaw = response; - file.base64 = response - console.log('file',file); - }); + file.base64 = response; // eslint-disable-line no-param-reassign + }) + .catch(this.loadingError); }, toggleFakeTab(loading, file) { - if(loading) { + if (loading) { const randomURL = this.Time.now(); const newFakeFile = { active: false, binary: true, type: 'blob', loading: true, - mime_type:'loading', + mime_type: 'loading', name: 'loading', - url: randomURL + url: randomURL, }; Store.openedFiles.push(newFakeFile); return newFakeFile; - } else { - this.removeFromOpenedFiles(file); - return null; } + this.removeFromOpenedFiles(file); + return null; }, setLoading(loading, file) { - if(Service.url.indexOf('tree') > -1) { + if (Service.url.indexOf('tree') > -1) { Store.loading.tree = loading; - } else if(Service.url.indexOf('blob') > -1) { + } else if (Service.url.indexOf('blob') > -1) { Store.loading.blob = loading; return this.toggleFakeTab(loading, file); } + + return undefined; }, // may be tree or file. getContent(file) { const loadingData = this.setLoading(true); - console.log('loading data', loadingData) Service.getContent() .then((response) => { - console.log('loadddd') - let data = response.data; + const data = response.data; this.setLoading(false, loadingData); Store.isTree = this.isTree(data); - if(!Store.isTree) { + if (!Store.isTree) { // it's a blob Store.binary = data.binary; - if(data.binary) { + if (data.binary) { Store.binaryMimeType = data.mime_type; this.setBinaryDataAsBase64( this.getRawURLFromBlobURL(file.url), - data + data, ); data.binary = true; data.url = file.url; @@ -177,20 +170,19 @@ let RepoHelper = { data.url = file.url; data.binary = false; this.addToOpenedFiles(data); - this.setActiveFile(data); + this.setActiveFile(data); } } else { // it's a tree this.setDirectoryOpen(file); - let newDirectory = this.dataToListOfFiles(data); + const newDirectory = this.dataToListOfFiles(data); Store.files = this.insertNewFilesIntoParentDir(file, Store.files, newDirectory); Store.prevURL = this.blobURLtoParent(Service.url); - console.log('Store.prevURL',Store.prevURL); } }) - .catch((response)=> { + .catch(() => { this.setLoading(false, loadingData); - new Flash('Unable to load the file at this time.') + this.loadingError(); }); }, @@ -198,28 +190,28 @@ let RepoHelper = { return `fa-${icon}`; }, + /* eslint-disable no-param-reassign */ removeChildFilesOfTree(tree) { let foundTree = false; Store.files = Store.files.filter((file) => { - if(file.url === tree.url) { + if (file.url === tree.url) { foundTree = true; } - if(foundTree) { - return file.level <= tree.level - } else { - return true; + if (foundTree) { + return file.level <= tree.level; } + return true; }); tree.opened = false; tree.icon = 'fa-folder'; - }, + /* eslint-enable no-param-reassign */ dataToListOfFiles(data) { - let a = []; + const a = []; - //push in blobs + // push in blobs data.blobs.forEach((blob) => { a.push({ type: 'blob', @@ -228,8 +220,8 @@ let RepoHelper = { icon: this.toFA(blob.icon), lastCommitMessage: blob.last_commit.message, lastCommitUpdate: blob.last_commit.committed_date, - level: 0 - }) + level: 0, + }); }); data.trees.forEach((tree) => { @@ -238,8 +230,8 @@ let RepoHelper = { name: tree.name, url: tree.url, icon: this.toFA(tree.icon), - level: 0 - }) + level: 0, + }); }); data.submodules.forEach((submodule) => { @@ -248,32 +240,36 @@ let RepoHelper = { name: submodule.name, url: submodule.url, icon: this.toFA(submodule.icon), - level: 0 - }) + level: 0, + }); }); return a; }, - genKey () { - return this.Time.now().toFixed(3) + genKey() { + return this.Time.now().toFixed(3); }, - _key: '', + key: '', - getStateKey () { - return this._key + getStateKey() { + return this.key; }, - setStateKey (key) { - this._key = key; + setStateKey(key) { + this.key = key; }, toURL(url) { - var history = window.history; - this._key = this.genKey(); - history.pushState({ key: this._key }, '', url); - } + const history = window.history; + this.key = this.genKey(); + history.pushState({ key: this.key }, '', url); + }, + + loadingError() { + new Flash('Unable to load the file at this time.'); // eslint-disable-line no-new + }, }; -export default RepoHelper; \ No newline at end of file +export default RepoHelper; diff --git a/app/assets/javascripts/repo/repo_loading_file.js b/app/assets/javascripts/repo/repo_loading_file.js index 39d0cc39fe4..66344b78998 100644 --- a/app/assets/javascripts/repo/repo_loading_file.js +++ b/app/assets/javascripts/repo/repo_loading_file.js @@ -1,4 +1,4 @@ -let RepoLoadingFile = { +const RepoLoadingFile = { template: ` @@ -36,7 +36,7 @@ let RepoLoadingFile = { props: { loading: Object, hasFiles: Boolean, - isMini: Boolean - } + isMini: Boolean, + }, }; -export default RepoLoadingFile; \ No newline at end of file +export default RepoLoadingFile; diff --git a/app/assets/javascripts/repo/repo_mini_mixin.js b/app/assets/javascripts/repo/repo_mini_mixin.js index 81978177fd7..e33956b6d15 100644 --- a/app/assets/javascripts/repo/repo_mini_mixin.js +++ b/app/assets/javascripts/repo/repo_mini_mixin.js @@ -1,11 +1,11 @@ -import Store from './repo_store' +import Store from './repo_store'; -let RepoMiniMixin = { +const RepoMiniMixin = { computed: { isMini() { return !!Store.openedFiles.length; - } + }, }, }; -export default RepoMiniMixin; \ No newline at end of file +export default RepoMiniMixin; diff --git a/app/assets/javascripts/repo/repo_prev_directory.js b/app/assets/javascripts/repo/repo_prev_directory.js index febd08e152e..59310bbf5e6 100644 --- a/app/assets/javascripts/repo/repo_prev_directory.js +++ b/app/assets/javascripts/repo/repo_prev_directory.js @@ -1,4 +1,4 @@ -let RepoPreviousDirectory = { +const RepoPreviousDirectory = { template: ` @@ -8,13 +8,13 @@ let RepoPreviousDirectory = { `, props: { name: 'repo-previous-directory', - prevurl: String + prevurl: String, }, methods: { linkClicked(file) { this.$emit('linkclicked', file); - } - } + }, + }, }; -export default RepoPreviousDirectory; \ No newline at end of file +export default RepoPreviousDirectory; diff --git a/app/assets/javascripts/repo/repo_service.js b/app/assets/javascripts/repo/repo_service.js index 137c468478d..f303a1270ca 100644 --- a/app/assets/javascripts/repo/repo_service.js +++ b/app/assets/javascripts/repo/repo_service.js @@ -1,11 +1,11 @@ import axios from 'axios'; -let RepoService = { +const RepoService = { url: '', params: { params: { - format: 'json' - } + format: 'json', + }, }, setUrl(url) { @@ -13,8 +13,8 @@ let RepoService = { }, getContent(url) { - if(url){ - return axios.get(url, this.params); + if (url) { + return axios.get(url, this.params); } return axios.get(this.url, this.params); }, @@ -22,10 +22,10 @@ let RepoService = { getBase64Content(url) { return axios .get(url, { - responseType: 'arraybuffer' + responseType: 'arraybuffer', }) - .then(response => new Buffer(response.data, 'binary').toString('base64')) - } + .then(response => new Buffer(response.data, 'binary').toString('base64')); + }, }; -export default RepoService; \ No newline at end of file +export default RepoService; diff --git a/app/assets/javascripts/repo/repo_sidebar.js b/app/assets/javascripts/repo/repo_sidebar.js index 979b687acba..5825a60d79a 100644 --- a/app/assets/javascripts/repo/repo_sidebar.js +++ b/app/assets/javascripts/repo/repo_sidebar.js @@ -1,11 +1,11 @@ -import Service from './repo_service' -import Helper from './repo_helper' -import Vue from 'vue' -import Store from './repo_store' -import RepoPreviousDirectory from './repo_prev_directory' -import RepoFile from './repo_file' -import RepoLoadingFile from './repo_loading_file' -import RepoMiniMixin from './repo_mini_mixin' +import Vue from 'vue'; +import Service from './repo_service'; +import Helper from './repo_helper'; +import Store from './repo_store'; +import RepoPreviousDirectory from './repo_prev_directory'; +import RepoFile from './repo_file'; +import RepoLoadingFile from './repo_loading_file'; +import RepoMiniMixin from './repo_mini_mixin'; export default class RepoSidebar { constructor(url) { @@ -34,29 +34,29 @@ export default class RepoSidebar { addPopEventListener() { window.addEventListener('popstate', () => { this.linkClicked({ - url: location.href + url: location.href, }); }); }, linkClicked(file) { let url = ''; - if(typeof file === 'string'){ + if (typeof file === 'string') { // go back url = file; } else { url = file.url; } Service.url = url; - if(typeof file === 'object') { - if(file.type === 'tree' && file.opened) { + if (typeof file === 'object') { + if (file.type === 'tree' && file.opened) { Helper.removeChildFilesOfTree(file); return; } Helper.getContent(file); } - } + }, }, }); } -} \ No newline at end of file +} diff --git a/app/assets/javascripts/repo/repo_store.js b/app/assets/javascripts/repo/repo_store.js index 50f96e1a395..8d2dbbfd540 100644 --- a/app/assets/javascripts/repo/repo_store.js +++ b/app/assets/javascripts/repo/repo_store.js @@ -1,4 +1,4 @@ -let RepoStore = { +const RepoStore = { service: '', editor: '', sidebar: '', @@ -14,14 +14,14 @@ let RepoStore = { files: [], binary: false, binaryMimeType: '', - //scroll bar space for windows + // scroll bar space for windows scrollWidth: 0, binaryTypes: { - png: false + png: false, }, loading: { tree: false, - blob: false - } + blob: false, + }, }; export default RepoStore; diff --git a/app/assets/javascripts/repo/repo_tab.js b/app/assets/javascripts/repo/repo_tab.js index ec6d31682d6..7c4ed25c06b 100644 --- a/app/assets/javascripts/repo/repo_tab.js +++ b/app/assets/javascripts/repo/repo_tab.js @@ -1,6 +1,6 @@ -import RepoHelper from './repo_helper' +import RepoHelper from './repo_helper'; -let RepoTab = { +const RepoTab = { template: `
  • @@ -23,7 +23,7 @@ let RepoTab = { xClicked(file) { RepoHelper.removeFromOpenedFiles(file); - } - } + }, + }, }; -export default RepoTab; \ No newline at end of file +export default RepoTab; diff --git a/app/assets/javascripts/repo/repo_tabs.js b/app/assets/javascripts/repo/repo_tabs.js index b89976c3458..50f953a5a4b 100644 --- a/app/assets/javascripts/repo/repo_tabs.js +++ b/app/assets/javascripts/repo/repo_tabs.js @@ -1,11 +1,11 @@ import Vue from 'vue'; -import Store from './repo_store' -import RepoTab from './repo_tab' -import RepoMiniMixin from './repo_mini_mixin' +import Store from './repo_store'; +import RepoTab from './repo_tab'; +import RepoMiniMixin from './repo_mini_mixin'; export default class RepoTabs { constructor() { - this.styleTabsForWindows(); + RepoTabs.styleTabsForWindows(); this.initVue(); } @@ -20,8 +20,8 @@ export default class RepoTabs { }); } - styleTabsForWindows() { + static styleTabsForWindows() { const scrollWidth = Number(document.body.dataset.scrollWidth); Store.scrollWidth = scrollWidth; } -} \ No newline at end of file +} diff --git a/app/assets/javascripts/repo/repo_view_toggler.js b/app/assets/javascripts/repo/repo_view_toggler.js index 577937d2c72..55c9c9208c5 100644 --- a/app/assets/javascripts/repo/repo_view_toggler.js +++ b/app/assets/javascripts/repo/repo_view_toggler.js @@ -1,6 +1,5 @@ -import Service from './repo_service' -import Vue from 'vue' -import Store from './repo_store' +import Vue from 'vue'; +import Store from './repo_store'; export default class RepoViewToggler { constructor() { @@ -14,4 +13,4 @@ export default class RepoViewToggler { data: () => Store, }); } -} \ No newline at end of file +}