Skip to content

Commit

Permalink
chore: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Mar 14, 2022
1 parent c42e1f2 commit cac2914
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 16,375 deletions.
2 changes: 0 additions & 2 deletions .npmignore

This file was deleted.

13 changes: 7 additions & 6 deletions git-host-info.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable max-len */
'use strict'
const maybeJoin = (...args) => args.every(arg => arg) ? args.join('') : ''
const maybeEncode = (arg) => arg ? encodeURIComponent(arg) : ''
Expand All @@ -13,7 +14,7 @@ const defaults = {
shortcuttemplate: ({ type, user, project, committish }) => `${type}:${user}/${project}${maybeJoin('#', committish)}`,
pathtemplate: ({ user, project, committish }) => `${user}/${project}${maybeJoin('#', committish)}`,
bugstemplate: ({ domain, user, project }) => `https://${domain}/${user}/${project}/issues`,
hashformat: formatHashFragment
hashformat: formatHashFragment,
}

const gitHosts = {}
Expand Down Expand Up @@ -45,7 +46,7 @@ gitHosts.github = Object.assign({}, defaults, {
}

return { user, project, committish }
}
},
})

gitHosts.bitbucket = Object.assign({}, defaults, {
Expand All @@ -68,7 +69,7 @@ gitHosts.bitbucket = Object.assign({}, defaults, {
}

return { user, project, committish: url.hash.slice(1) }
}
},
})

gitHosts.gitlab = Object.assign({}, defaults, {
Expand All @@ -95,7 +96,7 @@ gitHosts.gitlab = Object.assign({}, defaults, {
}

return { user, project, committish: url.hash.slice(1) }
}
},
})

gitHosts.gist = Object.assign({}, defaults, {
Expand Down Expand Up @@ -136,7 +137,7 @@ gitHosts.gist = Object.assign({}, defaults, {
},
hashformat: function (fragment) {
return fragment && 'file-' + formatHashFragment(fragment)
}
},
})

gitHosts.sourcehut = Object.assign({}, defaults, {
Expand Down Expand Up @@ -166,7 +167,7 @@ gitHosts.sourcehut = Object.assign({}, defaults, {
}

return { user, project, committish: url.hash.slice(1) }
}
},
})

const names = Object.keys(gitHosts)
Expand Down
19 changes: 13 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const protocolToRepresentationMap = {
'git+ssh:': 'sshurl',
'git+https:': 'https',
'ssh:': 'sshurl',
'git:': 'git'
'git:': 'git',
}

function protocolToRepresentation (protocol) {
Expand All @@ -21,10 +21,11 @@ const authProtocols = {
'https:': true,
'git+https:': true,
'http:': true,
'git+http:': true
'git+http:': true,
}

const knownProtocols = Object.keys(gitHosts.byShortcut).concat(['http:', 'https:', 'git:', 'git+ssh:', 'git+https:', 'ssh:'])
const knownProtocols = Object.keys(gitHosts.byShortcut)
.concat(['http:', 'https:', 'git:', 'git+ssh:', 'git+https:', 'ssh:'])

module.exports.fromUrl = function (giturl, opts) {
if (typeof giturl !== 'string') {
Expand Down Expand Up @@ -52,7 +53,10 @@ function fromUrl (giturl, opts) {
}

const gitHostShortcut = gitHosts.byShortcut[parsed.protocol]
const gitHostDomain = gitHosts.byDomain[parsed.hostname.startsWith('www.') ? parsed.hostname.slice(4) : parsed.hostname]
const gitHostDomain =
gitHosts.byDomain[parsed.hostname.startsWith('www.') ?
parsed.hostname.slice(4) :
parsed.hostname]
const gitHostName = gitHostShortcut || gitHostDomain
if (!gitHostName) {
return
Expand Down Expand Up @@ -172,11 +176,14 @@ const isGitHubShorthand = (arg) => {
const colonOnlyAfterHash = firstColon === -1 || (firstHash > -1 && firstColon > firstHash)
const secondSlashOnlyAfterHash = secondSlash === -1 || (firstHash > -1 && secondSlash > firstHash)
const hasSlash = firstSlash > 0
// if a # is found, what we really want to know is that the character immediately before # is not a /
// if a # is found, what we really want to know is that the character
// immediately before # is not a /
const doesNotEndWithSlash = firstHash > -1 ? arg[firstHash - 1] !== '/' : !arg.endsWith('/')
const doesNotStartWithDot = !arg.startsWith('.')

return spaceOnlyAfterHash && hasSlash && doesNotEndWithSlash && doesNotStartWithDot && atOnlyAfterHash && colonOnlyAfterHash && secondSlashOnlyAfterHash
return spaceOnlyAfterHash && hasSlash && doesNotEndWithSlash &&
doesNotStartWithDot && atOnlyAfterHash && colonOnlyAfterHash &&
secondSlashOnlyAfterHash
}

// attempt to correct an scp style url so that it will parse with `new URL()`
Expand Down
Loading

0 comments on commit cac2914

Please sign in to comment.