diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e5fffaa..e6fa531 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -144,7 +144,6 @@ eslint: policy: pull script: - npm run lint:check - allow_failure: true artifacts: reports: codequality: gl-codequality.json diff --git a/lib/browser-history.js b/lib/browser-history.js index e0b84fa..dbbeab6 100644 --- a/lib/browser-history.js +++ b/lib/browser-history.js @@ -6,6 +6,7 @@ module.exports = { if (!this.isSupported()) { return Promise.resolve([]); } + // eslint-disable-next-line global-require return require('node-browser-history').getAllHistory(14320); }, isSupported() { diff --git a/lib/gitlab.js b/lib/gitlab.js index fa1b0de..3b7debf 100644 --- a/lib/gitlab.js +++ b/lib/gitlab.js @@ -44,6 +44,7 @@ module.exports = { * @param {object} options the GET options to append to the URL * @returns */ + // eslint-disable-next-line object-curly-newline async get(what, options = {}, host = store.host) { let params; if (!options || !options.access_token) { @@ -66,6 +67,7 @@ module.exports = { }, async parseUrl(input) { let link = input; + // eslint-disable-next-line no-useless-escape if (!/^(?:f|ht)tps?\:\/\//.test(input)) { link = `https://${input}`; } @@ -73,6 +75,7 @@ module.exports = { const urlInfo = await this.fetchUrlInfo(link); // Have to late import because of circular dependency (GitLab.get) + // eslint-disable-next-line global-require const parser = require('./url-parsers').createParserWithUrlInfo(urlInfo); return parser.run(link); diff --git a/lib/url-parsers/_base.js b/lib/url-parsers/_base.js index efae027..2e3ebe5 100644 --- a/lib/url-parsers/_base.js +++ b/lib/url-parsers/_base.js @@ -14,6 +14,7 @@ module.exports = class BaseParser { } get escapedNamespace() { + // eslint-disable-next-line prefer-const let { namespaceWithProject, type } = this.urlInfo; if (type === 'epics') { diff --git a/lib/url-parsers/index.js b/lib/url-parsers/index.js index f6bc194..1f3abd5 100644 --- a/lib/url-parsers/index.js +++ b/lib/url-parsers/index.js @@ -18,11 +18,13 @@ const parsers = [ module.exports = { createParserWithUrlInfo(urlInfo) { - for (const parser of parsers) { - if (parser.check(urlInfo.type)) { - return new parser(urlInfo); + /* eslint-disable no-restricted-syntax */ + for (const Parser of parsers) { + if (Parser.check(urlInfo.type)) { + return new Parser(urlInfo); } } + /* eslint-enable */ throw new Error('Unknown'); }, diff --git a/lib/url-parsers/unknown.js b/lib/url-parsers/unknown.js index d0e53c4..fec9646 100644 --- a/lib/url-parsers/unknown.js +++ b/lib/url-parsers/unknown.js @@ -17,9 +17,9 @@ module.exports = class UnknownParser extends BaseParser { unknownObject.parent_url = store.host + doc.querySelector('.context-header a').getAttribute('href'); if (titleArray.length === 3) { - unknownObject.parent_name = titleArray[1]; + [, unknownObject.parent_name] = titleArray; } else if (titleArray.length === 4) { - unknownObject.parent_name = titleArray[2]; + [, , unknownObject.parent_name] = titleArray; } } return unknownObject; diff --git a/lib/util.js b/lib/util.js index fda568a..d24615d 100644 --- a/lib/util.js +++ b/lib/util.js @@ -1,6 +1,7 @@ const { createHash } = require('crypto'); function escapeHtml(unsafe) { + /* eslint-disable no-useless-escape */ return (unsafe || '') .replace(/&/g, '&') .replace(/ { const item = Array.prototype.concat.apply([], history); @@ -578,6 +578,7 @@ async function getRecentlyVisited() { if (b.utc_time > a.utc_time) { return 1; } + return -1; }); let i = 0; for (let j = 0; j < item.length; j += 1) { @@ -603,13 +604,13 @@ async function getRecentlyVisited() { } const nameWithNamespace = item[j].url.replace(`${store.host}/`, '').split('/-/')[0]; if (nameWithNamespace.split('/')[0] !== 'groups') { - url = `${store.host}/api/v4/projects/${nameWithNamespace.split('/')[0]}%2F${ + item.url = `${store.host}/api/v4/projects/${nameWithNamespace.split('/')[0]}%2F${ nameWithNamespace.split('/')[1] }?access_token=${store.access_token}`; } else { - url = `${store.host}/api/v4/groups/${nameWithNamespace.split('/')[0]}?access_token=${ - store.access_token - }`; + item.url = `${store.host}/api/v4/groups/${ + nameWithNamespace.split('/')[0] + }?access_token=${store.access_token}`; } recentlyVisitedArray.push(item[j].title); if (item[j].title !== 'Checking your Browser - GitLab') { @@ -652,6 +653,7 @@ async function subscribeToRunningPipeline() { const pipeline = await GitLab.get( `projects/${runningPipeline.project_id}/pipelines/${runningPipeline.id}`, ); + let pipelineStatus; if (pipeline.status !== 'running') { if (pipeline.status === 'success') { pipelineStatus = 'succeeded'; @@ -780,8 +782,9 @@ function displayPagination(keysetLinks, type) { function renderCollabject(comment, collabject) { const collabObject = collabject; if (collabObject.message && collabObject.message === '404 Not found') { - console.log('deleted', collabObject.id); - } else if (comment.note.noteable_type === 'DesignManagement::Design') { + return 0; + } + if (comment.note.noteable_type === 'DesignManagement::Design') { collabObject.web_url += `/designs/${comment.target_title}`; return `
  • ${escapeHtml(comment.target_title)}
  • `; - } else { - return `
  • ${escapeHtml( - comment.note.body, - )}${timeSince( - new Date(comment.created_at), - )} ago · ${escapeHtml(comment.target_title)}
  • `; } + return `
  • ${escapeHtml( + comment.note.body, + )}${timeSince( + new Date(comment.created_at), + )} ago · ${escapeHtml( + comment.target_title, + )}
  • `; } function displayCommit(commit, project, focus = 'project') { @@ -888,11 +890,13 @@ async function getLastCommits(count = 20) { lastEventId = commits[0].id; getLastPipelines(commits); const committedArray = commits.filter( + /* eslint-disable implicit-arrow-linebreak */ (commit) => commit.action_name === 'pushed to' || (commit.action_name === 'pushed new' && commit.push_data.commit_to && commit.push_data.commit_count > 0), + /* eslint-enable */ ); if (committedArray && committedArray.length > 0) { [currentCommit] = committedArray; @@ -935,6 +939,7 @@ async function getRecentComments() { if (comments && comments.length > 0) { recentCommentsString += '`; mb.window.webContents.executeJavaScript( @@ -982,6 +988,7 @@ function handleLogin() { }) .then((result) => result.json()) .then((result) => { + // eslint-disable-next-line no-use-before-define saveUser(result.access_token); }); } @@ -989,10 +996,11 @@ function handleLogin() { async function saveUser(accessToken, url = store.host, customCertPath = undefined) { try { - /* eslint-disable-next-line object-curly-newline, max-len, prettier/prettier */ + /* eslint-disable operator-linebreak, object-curly-newline */ const options = customCertPath ? { access_token: accessToken, custom_cert_path: customCertPath } : { access_token: accessToken }; + /* eslint-enable */ const result = await GitLab.get('user', options, url); if (result && result.id && result.username) { store.access_token = accessToken; @@ -1040,7 +1048,7 @@ async function saveUser(accessToken, url = store.host, customCertPath = undefine }); } } catch (e) { - console.log(e); + throw new Error(e); } } @@ -1134,7 +1142,7 @@ async function getProjectCommits(project, count = 20) { } } -function changeCommit(forward = true, commitArray, chosenCommit) { +function changeCommit(forward, commitArray, chosenCommit) { let nextCommit; let index = commitArray.findIndex((commit) => commit.id === chosenCommit.id); if (forward) { @@ -1183,6 +1191,7 @@ async function getMoreRecentlyVisited() { if (b.utc_time > a.utc_time) { return 1; } + return -1; }); mb.window.webContents.executeJavaScript( `document.getElementById("detail-headline").innerHTML = "${escapeQuotes( @@ -1198,7 +1207,7 @@ async function getMoreRecentlyVisited() { url.includes('/-/issues/') || url.includes('/-/merge_requests/') || url.includes('/-/epics/'); - const wasNotProcessed = !moreRecentlyVisitedArray.some((item) => item.title === title); + const wasNotProcessed = !moreRecentlyVisitedArray.some((object) => object.title === title); const ignoredTitlePrefixes = [ 'Not Found ', 'New Issue ', @@ -1277,28 +1286,31 @@ async function getMoreRecentlyVisited() { } function searchRecentlyVisited(searchterm) { + /* eslint-disable implicit-arrow-linebreak, function-paren-newline */ const foundArray = moreRecentlyVisitedArray.filter((item) => item.title.toLowerCase().includes(searchterm), ); - foundString = '${displayPagination(keysetLinks, type)}`; mb.window.webContents.executeJavaScript( `document.getElementById("detail-content").innerHTML = "${escapeQuotes( @@ -1581,7 +1595,7 @@ async function getProjectMRs(project) { function addBookmark(link) { if (store && store.bookmarks && store.bookmarks.length > 0) { - sameBookmarks = store.bookmarks.filter((item) => item.web_url === link); + const sameBookmarks = store.bookmarks.filter((item) => item.web_url === link); if (sameBookmarks.length > 0) { displayAddError('bookmark', '-', 'This bookmark has already been added.'); return; diff --git a/src/command-palette/bar.js b/src/command-palette/bar.js index 546db6d..2c9d761 100644 --- a/src/command-palette/bar.js +++ b/src/command-palette/bar.js @@ -1,3 +1,4 @@ +/* eslint no-undef: 0 */ const $search = document.querySelector('input'); const $results = document.querySelector('#results'); let html = []; @@ -80,6 +81,7 @@ function matcher({ title }) { let matchCount = 1; + /* eslint-disable no-restricted-syntax */ for (const term of terms) { matchCount += lowerCaseTitle.split(' ').filter((x) => x.includes(term)).length; const newTitle = lowerCaseTitle.replace(term, ''); @@ -88,6 +90,7 @@ function matcher({ title }) { } lowerCaseTitle = newTitle; } + /* eslint-enable */ return matchCount; } @@ -181,6 +184,7 @@ function search() { if (availableOverviews.length > 0) { html.push('
    Overview
    '); + /* eslint-disable no-restricted-syntax */ for (const [key, action] of availableOverviews) { const icon = action.icon ? `${action.icon}` : ''; html.push( @@ -197,6 +201,7 @@ function search() { if (availableFavorites.length > 0) { html.push('
    Favorite projects
    '); + /* eslint-disable no-restricted-syntax */ for (const [key, action] of availableFavorites) { const avatar = action.avatar_url ? `` : projectIcon; html.push( @@ -208,11 +213,13 @@ function search() { ); i += 1; } + /* eslint-enable */ } if (availableBookmarks.length > 0) { html.push('
    Bookmarks
    '); + /* eslint-disable no-restricted-syntax */ for (const [key, action] of availableBookmarks) { let icon; if (action.type === 'issues') { @@ -232,11 +239,13 @@ function search() { ); i += 1; } + /* eslint-enable */ } if (availableRecents.length > 0) { html.push('
    Recently viewed
    '); + /* eslint-disable no-restricted-syntax */ for (const [key, action] of availableRecents) { let icon; if (action.type === 'issues') { @@ -256,11 +265,13 @@ function search() { ); i += 1; } + /* eslint-enable */ } if (availableActions.length > 0) { html.push('
    Actions
    '); + /* eslint-disable no-restricted-syntax */ for (const [key, action] of availableActions) { const icon = action.icon ? `${action.icon}` : ''; html.push( @@ -272,6 +283,7 @@ function search() { ); i += 1; } + /* eslint-enable */ } $results.innerHTML = html.join('\n'); diff --git a/src/command-palette/index.js b/src/command-palette/index.js index a71b78c..1f9b454 100644 --- a/src/command-palette/index.js +++ b/src/command-palette/index.js @@ -64,6 +64,7 @@ async function getRecentlyVisited() { store.access_token }`; } + // eslint-disable-next-line no-await-in-loop await gitdock.fetchUrlInfo(item[j].url).then((result) => { item[j].type = result.type; }); @@ -109,6 +110,7 @@ module.exports = class CommandPalette { }); } + // eslint-disable-next-line class-methods-use-this async unregister() { globalShortcut.unregisterAll(); @@ -116,6 +118,7 @@ module.exports = class CommandPalette { ipcMain.removeAllListeners('hide-command-palette'); } + // eslint-disable-next-line class-methods-use-this async open() { cpWindow.show(); // cpWindow.openDevTools();