Fix eslint warnings

This commit is contained in:
Luke "Jared" Bennett 2017-07-15 02:54:51 +01:00
parent b2afa71d98
commit 2e0250231e
No known key found for this signature in database
GPG key ID: 402ED51FB5D306C2
15 changed files with 191 additions and 192 deletions

View file

@ -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 = $('<div>').css({ visibility: 'hidden', width: 100, overflow: 'scroll' }).appendTo('body'),
widthWithScroll = $('<div>').css({ width: '100%' }).appendTo($outer).outerWidth();
$outer.remove();
return 100 - widthWithScroll;
};
}
$('body').attr('data-scroll-width', getScrollBarWidth());

View file

@ -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) {
case 'image/png':
this.binaryTypes.png = true;
break;
default:
new Flash('Blob could not be loaded'); // eslint-disable-line no-new
break;
}
}
}
},
},
});
}
}

View file

@ -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() {

View file

@ -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();
@ -34,8 +34,8 @@ export default class RepoEditor {
monacoEditor.setModel(
monaco.editor.createModel(
this.blobRaw,
'plain'
)
'plain',
),
);
}
},
@ -67,12 +67,12 @@ export default class RepoEditor {
self.monacoEditor.setModel(
monaco.editor.createModel(
this.blobRaw,
this.activeFile.mime_type
)
this.activeFile.mime_type,
),
);
}
}
}
},
},
});
}
}

View file

@ -1,4 +1,4 @@
let RepoFile = {
const RepoFile = {
template: `
<tr v-if='!loading.tree || hasFiles'>
<td>
@ -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;

View file

@ -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;
});
},
@ -53,8 +48,9 @@ let RepoHelper = {
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,15 +59,15 @@ 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) {
Store.blobRaw = file.base64;
console.log('binary', file)
} else {
Store.blobRaw = file.plain;
}
@ -82,28 +78,26 @@ let RepoHelper = {
},
removeFromOpenedFiles(file) {
console.log('file remove', file)
if (file.type === 'tree') return;
Store.openedFiles = Store.openedFiles.filter((openedFile) => {
return openedFile.url !== file.url;
});
Store.openedFiles = Store.openedFiles.filter(openedFile => openedFile.url !== file.url);
},
addToOpenedFiles(file) {
const openedFilesAlreadyExists = Store.openedFiles.some((openedFile) => {
return openedFile.url === file.url
});
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) {
tree.opened = true;
tree.icon = 'fa-folder-open';
}
},
/* eslint-enable no-param-reassign */
getRawURLFromBlobURL(url) {
return url.replace('blob', 'raw');
@ -113,9 +107,9 @@ 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) {
@ -128,14 +122,13 @@ let RepoHelper = {
loading: true,
mime_type: 'loading',
name: 'loading',
url: randomURL
url: randomURL,
};
Store.openedFiles.push(newFakeFile);
return newFakeFile;
} else {
}
this.removeFromOpenedFiles(file);
return null;
}
},
setLoading(loading, file) {
@ -145,16 +138,16 @@ let RepoHelper = {
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) {
@ -164,7 +157,7 @@ let RepoHelper = {
Store.binaryMimeType = data.mime_type;
this.setBinaryDataAsBase64(
this.getRawURLFromBlobURL(file.url),
data
data,
);
data.binary = true;
data.url = file.url;
@ -182,15 +175,14 @@ let RepoHelper = {
} 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,6 +190,7 @@ let RepoHelper = {
return `fa-${icon}`;
},
/* eslint-disable no-param-reassign */
removeChildFilesOfTree(tree) {
let foundTree = false;
Store.files = Store.files.filter((file) => {
@ -205,19 +198,18 @@ let RepoHelper = {
foundTree = true;
}
if (foundTree) {
return file.level <= tree.level
} else {
return true;
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
data.blobs.forEach((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)
return this.Time.now().toFixed(3);
},
_key: '',
key: '',
getStateKey() {
return this._key
return this.key;
},
setStateKey(key) {
this._key = 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;

View file

@ -1,4 +1,4 @@
let RepoLoadingFile = {
const RepoLoadingFile = {
template: `
<tr v-if='loading.tree && !hasFiles'>
<td>
@ -36,7 +36,7 @@ let RepoLoadingFile = {
props: {
loading: Object,
hasFiles: Boolean,
isMini: Boolean
}
isMini: Boolean,
},
};
export default RepoLoadingFile;

View file

@ -1,10 +1,10 @@
import Store from './repo_store'
import Store from './repo_store';
let RepoMiniMixin = {
const RepoMiniMixin = {
computed: {
isMini() {
return !!Store.openedFiles.length;
}
},
},
};

View file

@ -1,4 +1,4 @@
let RepoPreviousDirectory = {
const RepoPreviousDirectory = {
template: `
<tr>
<td colspan='3'>
@ -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;

View file

@ -1,11 +1,11 @@
import axios from 'axios';
let RepoService = {
const RepoService = {
url: '',
params: {
params: {
format: 'json'
}
format: 'json',
},
},
setUrl(url) {
@ -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;

View file

@ -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,7 +34,7 @@ export default class RepoSidebar {
addPopEventListener() {
window.addEventListener('popstate', () => {
this.linkClicked({
url: location.href
url: location.href,
});
});
},
@ -55,7 +55,7 @@ export default class RepoSidebar {
}
Helper.getContent(file);
}
}
},
},
});
}

View file

@ -1,4 +1,4 @@
let RepoStore = {
const RepoStore = {
service: '',
editor: '',
sidebar: '',
@ -17,11 +17,11 @@ let RepoStore = {
// scroll bar space for windows
scrollWidth: 0,
binaryTypes: {
png: false
png: false,
},
loading: {
tree: false,
blob: false
}
blob: false,
},
};
export default RepoStore;

View file

@ -1,6 +1,6 @@
import RepoHelper from './repo_helper'
import RepoHelper from './repo_helper';
let RepoTab = {
const RepoTab = {
template: `
<li>
<a href='#' @click.prevent='xClicked(tab)' v-if='!tab.loading'>
@ -23,7 +23,7 @@ let RepoTab = {
xClicked(file) {
RepoHelper.removeFromOpenedFiles(file);
}
}
},
},
};
export default RepoTab;

View file

@ -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,7 +20,7 @@ export default class RepoTabs {
});
}
styleTabsForWindows() {
static styleTabsForWindows() {
const scrollWidth = Number(document.body.dataset.scrollWidth);
Store.scrollWidth = scrollWidth;
}

View file

@ -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() {