Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Eslint fixes #201

Merged
merged 5 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/competition.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const CONFLICTING_PACKAGES = [
* @returns {boolean}
*/
function alreadyNotifying(pkg) {
return atom.notifications.getNotifications().some((note) => note.getOptions()._src == `ide-rust-conflict-${pkg}`)
return atom.notifications.getNotifications().some((note) => note.getOptions()._src === `ide-rust-conflict-${pkg}`)
}

/** Scans current active packages and shows notifications to help handle conflicts */
Expand Down
45 changes: 28 additions & 17 deletions lib/dist-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ function manifest_includes_rls(manifest) {
* @param {string} [channel] Defaults to `nightly`
* @returns {Promise<string>} Toolchain name
*/
async function checkDatedDistHasRls(date, channel = "nightly") {
function checkDatedDistHasRls(date, channel = "nightly") {
const dateString = _.isString(date) ? date : date.toISOString().split("T")[0]
const cacheKey = `${channel}-${dateString}`

let fetch =
const fetch =
datedNightlyHasRlsCache.get(cacheKey) ||
new Promise((resolve, reject) => {
https
Expand All @@ -33,7 +33,9 @@ async function checkDatedDistHasRls(date, channel = "nightly") {
let body = ""
res.on("data", (data) => {
body += data
if (manifest_includes_rls(body)) resolve(cacheKey)
if (manifest_includes_rls(body)) {
resolve(cacheKey)
}
})
res.on("end", () => reject(new Error("no 'rls-preview'")))
})
Expand All @@ -54,17 +56,22 @@ async function checkDatedDistHasRls(date, channel = "nightly") {
* @param {string} [channel] Defaults to `nightly`
* @returns {Promise<string>} Latest channel dated version with rls-preview
*/
async function fetchLatestDatedDistWithRls(channel) {
function fetchLatestDatedDistWithRls(channel) {
const aDayMillis = 24 * 60 * 60 * 1000
const minDate = new Date(Date.now() - 30 * aDayMillis)

const check = (day) => {
return checkDatedDistHasRls(day, channel).catch((e) => {
if (e && e.code === "ENOTFOUND") throw e
if (e && e.code === "ENOTFOUND") {
throw e
}

const yesterday = new Date(day - aDayMillis)
if (yesterday >= minDate) return check(yesterday)
else throw new Error("No nightly with 'rls-preview'")
if (yesterday >= minDate) {
return check(yesterday)
} else {
throw new Error("No nightly with 'rls-preview'")
}
})
}

Expand All @@ -76,7 +83,7 @@ async function fetchLatestDatedDistWithRls(channel) {
* @param {string} [arg.currentVersion] Current installed rustc version
* @returns {Promise<?string>} New version of update available (falsy otherwise)
*/
async function fetchLatestDist({ toolchain, currentVersion = "none" }) {
function fetchLatestDist({ toolchain, currentVersion = "none" }) {
return new Promise((resolve, reject) => {
https
.get(`https://static.rust-lang.org/dist/channel-rust-${toolchain}.toml`, (res) => {
Expand All @@ -89,9 +96,11 @@ async function fetchLatestDist({ toolchain, currentVersion = "none" }) {
res.on("data", (data) => (body += data))
res.on("end", () => {
// use a subsection as toml is slow to parse fully
let rustcInfo = body.match(/(\[pkg\.rustc\][^[]*)/m)
if (!rustcInfo) return reject(new Error("could not split channel toml output"))
let rustcVersion = require("toml").parse(rustcInfo[1]).pkg.rustc.version.trim()
const rustcInfo = body.match(/(\[pkg\.rustc][^[]*)/m)
if (!rustcInfo) {
return reject(new Error("could not split channel toml output"))
}
const rustcVersion = require("toml").parse(rustcInfo[1]).pkg.rustc.version.trim()
resolve(
!currentVersion.trim().endsWith(rustcVersion) && manifest_includes_rls(body) && `rustc ${rustcVersion}`
)
Expand All @@ -110,15 +119,15 @@ async function fetchLatestDist({ toolchain, currentVersion = "none" }) {
* @param {string} toolchain
* @returns {Promise<boolean>}
*/
async function checkHasRls(toolchain) {
let dated = toolchain.match(DATED_REGEX)
function checkHasRls(toolchain) {
const dated = toolchain.match(DATED_REGEX)
if (dated) {
return checkDatedDistHasRls(dated[2], dated[1])
.then(() => true)
.catch(() => false)
}
return fetchLatestDist({ toolchain })
.then((v) => !!v)
.then((v) => Boolean(v))
.catch(() => false)
}

Expand All @@ -127,10 +136,12 @@ async function checkHasRls(toolchain) {
* @returns {Promise<string>} Latest channel dated version with rls-preview or the channel itself if ok
*/
async function suggestChannelOrDated(channel) {
let latestDatedPromise = fetchLatestDatedDistWithRls(channel)
const latestDatedPromise = fetchLatestDatedDistWithRls(channel)
try {
let latestIsOk = await fetchLatestDist({ toolchain: channel })
if (latestIsOk) return channel
const latestIsOk = await fetchLatestDist({ toolchain: channel })
if (latestIsOk) {
return channel
}
} catch (e) {
console.warn(e)
}
Expand Down
Loading