From 838628c126e4932fcffac597ee94a2818d63233e Mon Sep 17 00:00:00 2001 From: ssube Date: Sat, 15 Aug 2020 12:38:33 -0500 Subject: [PATCH] lint(labels): fix helper names --- src/labels.ts | 15 ++++++++------- src/resolve.ts | 10 +++++----- src/sync.ts | 18 +++++++++--------- test/TestLabels.ts | 6 +++--- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/labels.ts b/src/labels.ts index 2154cb7..ed20fd5 100644 --- a/src/labels.ts +++ b/src/labels.ts @@ -1,4 +1,5 @@ import { doesExist, InvalidArgumentError } from '@apextoaster/js-utils'; + import { randomItem } from './utils'; /** @@ -84,18 +85,18 @@ export function getLabelNames(flags: Array, states: Array for (const state of states) { for (const value of state.values) { - labels.push(valueName(state, value)); + labels.push(getValueName(state, value)); } } return new Set(labels); } -export function splitName(name: string): Array { +export function splitValueName(name: string): Array { return name.split('/'); } -export function valueName(state: StateLabel, value: StateValue): string { +export function getValueName(state: StateLabel, value: StateValue): string { return `${state.name}/${value.name}`; } @@ -104,7 +105,7 @@ export function valueName(state: StateLabel, value: StateValue): string { * * TODO: add some sort options: high-first or low-first, case-sensitivity */ -export function prioritizeLabels(labels: Array): Array { +export function prioritySort(labels: Array): Array { return labels.sort((a, b) => { if (a.priority === b.priority) { const aName = a.name.toLocaleLowerCase(); @@ -122,9 +123,9 @@ export function prioritizeLabels(labels: Array * * TODO: this is a terrible overload */ -export function colorizeLabel(flag: FlagLabel, colors: Array): string; -export function colorizeLabel(state: StateLabel, value: StateValue, colors: Array): string; -export function colorizeLabel(label: BaseLabel, colorsOrValue: Array | StateValue, maybeColors?: Array): string { +export function getLabelColor(flag: FlagLabel, colors: Array): string; +export function getLabelColor(state: StateLabel, value: StateValue, colors: Array): string; +export function getLabelColor(label: BaseLabel, colorsOrValue: Array | StateValue, maybeColors?: Array): string { if (Array.isArray(colorsOrValue)) { const { color } = label; if (doesExist(color)) { diff --git a/src/resolve.ts b/src/resolve.ts index afe21b6..a359aaa 100644 --- a/src/resolve.ts +++ b/src/resolve.ts @@ -1,4 +1,4 @@ -import { FlagLabel, prioritizeLabels, StateLabel, valueName } from './labels'; +import { FlagLabel, getValueName, prioritySort, StateLabel } from './labels'; /** * How a label changed. @@ -62,7 +62,7 @@ export function resolveLabels(options: ResolveInput): ResolveResult { const changes: Array = []; const errors: Array = []; - const sortedFlags = prioritizeLabels(options.flags); + const sortedFlags = prioritySort(options.flags); for (const flag of sortedFlags) { const { name } = flag; if (activeLabels.has(name)) { @@ -71,11 +71,11 @@ export function resolveLabels(options: ResolveInput): ResolveResult { } } - const sortedStates = prioritizeLabels(options.states); + const sortedStates = prioritySort(options.states); for (const state of sortedStates) { - const sortedValues = prioritizeLabels(state.values); + const sortedValues = prioritySort(state.values); for (const value of sortedValues) { - const name = valueName(state, value); + const name = getValueName(state, value); if (activeLabels.has(name)) { // TODO: check higher-priority values // TODO: check removes diff --git a/src/sync.ts b/src/sync.ts index 6219d5c..4ca5dcf 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -1,7 +1,7 @@ import { doesExist, mustExist } from '@apextoaster/js-utils'; import { Logger } from 'noicejs'; -import { colorizeLabel, FlagLabel, getLabelNames, StateLabel, valueName } from './labels'; +import { FlagLabel, getLabelColor, getLabelNames, getValueName, StateLabel } from './labels'; import { LabelUpdate, Remote } from './remote'; import { resolveLabels } from './resolve'; import { defaultTo, defaultUntil } from './utils'; @@ -89,7 +89,7 @@ export async function createLabel(options: SyncOptions, name: string) { const flag = options.flags.find((it) => name === it.name); if (doesExist(flag)) { await options.remote.createLabel({ - color: colorizeLabel(flag, options.colors), + color: getLabelColor(flag, options.colors), desc: mustExist(flag.desc), name, project: options.project, @@ -100,12 +100,12 @@ export async function createLabel(options: SyncOptions, name: string) { const state = options.states.find((it) => name.startsWith(it.name)); if (doesExist(state)) { - const value = state.values.find((it) => valueName(state, it) === name); + const value = state.values.find((it) => getValueName(state, it) === name); if (doesExist(value)) { await options.remote.createLabel({ - color: colorizeLabel(state, value, options.colors), + color: getLabelColor(state, value, options.colors), desc: defaultUntil(value.desc, state.desc, ''), - name: valueName(state, value), + name: getValueName(state, value), project: options.project, }); @@ -139,7 +139,7 @@ export async function syncSingleLabel(options: SyncOptions, label: LabelUpdate): const flag = options.flags.find((it) => label.name === it.name); if (doesExist(flag)) { await syncLabelDiff(options, label, { - color: colorizeLabel(flag, options.colors), + color: getLabelColor(flag, options.colors), desc: defaultTo(flag.desc, label.desc), name: flag.name, project: options.project, @@ -150,12 +150,12 @@ export async function syncSingleLabel(options: SyncOptions, label: LabelUpdate): const state = options.states.find((it) => label.name.startsWith(it.name)); if (doesExist(state)) { - const value = state.values.find((it) => valueName(state, it) === label.name); + const value = state.values.find((it) => getValueName(state, it) === label.name); if (doesExist(value)) { await syncLabelDiff(options, label, { - color: colorizeLabel(state, value, options.colors), + color: getLabelColor(state, value, options.colors), desc: defaultTo(value.desc, label.desc), - name: valueName(state, value), + name: getValueName(state, value), project: options.project, }); diff --git a/test/TestLabels.ts b/test/TestLabels.ts index 4f82972..54ec9fc 100644 --- a/test/TestLabels.ts +++ b/test/TestLabels.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; -import { getLabelNames, prioritizeLabels } from '../src/labels'; +import { getLabelNames, prioritySort } from '../src/labels'; describe('label helpers', () => { describe('label name helper', () => { @@ -72,7 +72,7 @@ describe('label helpers', () => { requires: [], }; - const sorted = prioritizeLabels([LOW_LABEL, HIGH_LABEL]); + const sorted = prioritySort([LOW_LABEL, HIGH_LABEL]); expect(sorted[0]).to.deep.equal(HIGH_LABEL); }); @@ -88,7 +88,7 @@ describe('label helpers', () => { requires: [], }; - const sorted = prioritizeLabels([SECOND_LABEL, FIRST_LABEL]); + const sorted = prioritySort([SECOND_LABEL, FIRST_LABEL]); expect(sorted[0]).to.deep.equal(FIRST_LABEL); }); });