Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Oct 22, 2023
1 parent 4728e5c commit c679408
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/config/cwd.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const removeBases = (configWithBases) =>
exclude(configWithBases, '**', isBaseProp, { entries: true })

const isBaseProp = ({ path }) => {
const key = path[path.length - 1]
const key = path.at(-1)
return (
typeof key === 'string' &&
(key.endsWith(BASE_KEY_SUFFIX) || key.endsWith(BASE_ITEMS_SUFFIX))
Expand All @@ -126,13 +126,13 @@ export const getPropCwd = (

// Retrieve the path to the `*[Items]CwdBase` property
const getBasePath = (originalPath) => {
const lastKey = originalPath[originalPath.length - 1]
const lastKey = originalPath.at(-1)

if (!Number.isInteger(lastKey)) {
return [...originalPath.slice(0, -1), `${lastKey}${BASE_KEY_SUFFIX}`]
}

const secondLastKey = originalPath[originalPath.length - 2]
const secondLastKey = originalPath.at(-2)
return [
...originalPath.slice(0, -2),
`${secondLastKey}${BASE_ITEMS_SUFFIX}`,
Expand Down
4 changes: 1 addition & 3 deletions src/history/delta/formats/find.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// We sort metadataGroups by timestamp, and only consider the timestamp of the
// most recent result.
export const findByTime = (metadataGroups, timestamp) =>
metadataGroups.findIndex(
(metadata) => metadata[metadata.length - 1].timestamp >= timestamp,
)
metadataGroups.findIndex((metadata) => metadata.at(-1).timestamp >= timestamp)
3 changes: 1 addition & 2 deletions src/history/merge/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ export const normalizeId = (newResult, history) => {
return newResult
}

const id =
history.length === 0 ? getDefaultId() : history[history.length - 1].id
const id = history.length === 0 ? getDefaultId() : history.at(-1).id
return { ...newResult, id }
}

Expand Down
2 changes: 1 addition & 1 deletion src/history/merge/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const groupMetadata = (metadata) => {
}

const getMetadataGroupOrder = (metadataGroup) => {
const lastMetadatum = metadataGroup[metadataGroup.length - 1]
const lastMetadatum = metadataGroup.at(-1)
return lastMetadatum.timestamp
}

Expand Down
4 changes: 2 additions & 2 deletions src/history/serialize/contents.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ export const serializeRawResult = (rawResult) => {
// - This creates better git stats when it comes to amount of lines changes
// We only do this for arrays of simple types.
const flattenArray = (rawResultStr) =>
rawResultStr.replace(SIMPLE_ARRAY_REGEXP, flattenArrayItems)
rawResultStr.replaceAll(SIMPLE_ARRAY_REGEXP, flattenArrayItems)

// Matches `[...]` but not `[{ ... }]` nor `[[...]]`
const SIMPLE_ARRAY_REGEXP = /(\[)([^[\]{]+)(\])/gmu

// eslint-disable-next-line max-params
const flattenArrayItems = (_, start, match, end) => {
const matchA = match.replace(WHITESPACES_REGEXP, ' ')
const matchA = match.replaceAll(WHITESPACES_REGEXP, ' ')
return `${start}${matchA}${end}`
}

Expand Down
2 changes: 1 addition & 1 deletion src/report/normalize/computed.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const addLastResult = async ({
return result
}

const lastResult = history[history.length - 1]
const lastResult = history.at(-1)
const lastResultA = { ...lastResult, combinations }
const lastResultB = await normalizeCombAll(lastResultA, {
sinceResult,
Expand Down
2 changes: 1 addition & 1 deletion src/report/normalize/stats/scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
export const getScale = (minMeasure, kind) => {
const scales = SCALES[kind]
const scaleA = scales.find((scale) => minMeasure >= scale)
return scaleA === undefined ? scales[scales.length - 1] : scaleA
return scaleA === undefined ? scales.at(-1) : scaleA
}

// Possible scales for each unit kind.
Expand Down
2 changes: 1 addition & 1 deletion src/report/reporters/histogram/characters.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const HISTOGRAM_CHARS = canDisplayUnicode
: [' ', '\u2584', '\u2588']
// Characters displaying 0% and 100% visually
export const [EMPTY_HISTOGRAM_CHAR] = HISTOGRAM_CHARS
export const FULL_HISTOGRAM_CHAR = HISTOGRAM_CHARS[HISTOGRAM_CHARS.length - 1]
export const FULL_HISTOGRAM_CHAR = HISTOGRAM_CHARS.at(-1)

// To compensate from the lack of characters on Windows, we increase the number
// of characters shown per column
Expand Down
2 changes: 1 addition & 1 deletion src/runners/common/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const handleEvents = async (handlers) => {
// Send HTTP request to parent
const sendReturnValue = async (body) =>
await got({
url: argv[argv.length - 1],
url: argv.at(-1),
method: 'POST',
body,
responseType: 'json',
Expand Down
5 changes: 1 addition & 4 deletions src/select/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ const parseToken = (
}

return {
intersect: [
...intersect.slice(0, -1),
[...intersect[intersect.length - 1], token],
],
intersect: [...intersect.slice(0, -1), [...intersect.at(-1), token]],
negation,
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/stats/critical_values/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ const getCriticalValueEntry = ({
const preciseEntries = entries.slice(0, lastPreciseKey + 1)
const impreciseEntries = entries.slice(lastPreciseKey)
const preciseMap = new Map(preciseEntries)
const [impreciseEntriesMaxIndex] =
impreciseEntries[impreciseEntries.length - 1]
const [impreciseEntriesMaxIndex] = impreciseEntries.at(-1)
return [
roundDecimals(significanceLevel),
{ preciseMap, impreciseEntries, impreciseEntriesMaxIndex, getMaxValue },
Expand Down
2 changes: 1 addition & 1 deletion src/stats/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const mergeSort = (bigArray, smallArray) => {
// `bigArray`. We use one of its element to ensure the new array slots have
// the correct type which speeds up memory allocation when re-assigned.
const resizeArray = (bigArray, smallArray) => {
const lastElement = bigArray[bigArray.length - 1]
const lastElement = bigArray.at(-1)
const smallArrayLength = smallArray.length

// eslint-disable-next-line fp/no-loops, fp/no-let, fp/no-mutation
Expand Down
2 changes: 1 addition & 1 deletion src/utils/last.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Like `[...array, lastElement]`
export const pickLast = (array) => {
const arrayA = array.slice(0, -1)
const lastElement = array[array.length - 1]
const lastElement = array.at(-1)
return [arrayA, lastElement]
}

0 comments on commit c679408

Please sign in to comment.