Skip to content

Commit b550db6

Browse files
committed
Changes from node scripts/eslint_all_files --no-cache --fix
1 parent e8e8940 commit b550db6

1 file changed

Lines changed: 28 additions & 27 deletions

File tree

  • src/platform/plugins/shared/workflows_management/public/widgets/workflow_yaml_editor/lib/snippets

src/platform/plugins/shared/workflows_management/public/widgets/workflow_yaml_editor/lib/snippets/insert_step_snippet.ts

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
99

10-
import { type Document, isMap, isPair, isScalar, isSeq, type Pair, parseDocument, visit } from 'yaml';
10+
import {
11+
type Document,
12+
isMap,
13+
isPair,
14+
isScalar,
15+
isSeq,
16+
type Pair,
17+
parseDocument,
18+
visit,
19+
} from 'yaml';
1120
import { monaco } from '@kbn/monaco';
1221
import { isBuiltInStepType } from '@kbn/workflows';
1322
import { generateBuiltInStepSnippet } from './generate_builtin_step_snippet';
@@ -21,8 +30,8 @@ import {
2130
} from './snippet_insertion_utils';
2231
import {
2332
getStepNodeAtPosition,
24-
getStepsAndElseKeyOffsets,
2533
getStepNodesWithType,
34+
getStepsAndElseKeyOffsets,
2635
isStepLikeMap,
2736
} from '../../../../../common/lib/yaml';
2837
import { getIndentLevelFromLineNumber } from '../get_indent_level';
@@ -76,9 +85,7 @@ function findStepWithMaxEndOffsetAtOrBefore(
7685
for (const node of nodes) {
7786
const range = getMonacoRangeFromYamlNode(model, node);
7887
if (!range) continue;
79-
const endOffset = model.getOffsetAt(
80-
new monaco.Position(range.endLineNumber, range.endColumn)
81-
);
88+
const endOffset = model.getOffsetAt(new monaco.Position(range.endLineNumber, range.endColumn));
8289
if (endOffset <= cursorOffset && endOffset > bestEndOffset) {
8390
bestEndOffset = endOffset;
8491
best = node;
@@ -92,7 +99,8 @@ function getStepsInInnermostBlockContainingCursor(
9299
model: monaco.editor.ITextModel,
93100
cursorOffset: number
94101
): StepNodeLike[] {
95-
const candidates: Array<{ seq: { items?: unknown[] }; rangeStart: number; rangeEnd: number }> = [];
102+
const candidates: Array<{ seq: { items?: unknown[] }; rangeStart: number; rangeEnd: number }> =
103+
[];
96104
visit(document, {
97105
Pair(_key, pair) {
98106
if (!pair.key || !isScalar(pair.key)) return;
@@ -121,10 +129,7 @@ function getStepsInInnermostBlockContainingCursor(
121129
return steps;
122130
}
123131

124-
function getLastRootStepEndLine(
125-
model: monaco.editor.ITextModel,
126-
stepsPair: Pair
127-
): number | null {
132+
function getLastRootStepEndLine(model: monaco.editor.ITextModel, stepsPair: Pair): number | null {
128133
const sequence = stepsPair.value;
129134
if (!isSeq(sequence) || !sequence.items || sequence.items.length === 0) return null;
130135
const lastItem = sequence.items[sequence.items.length - 1];
@@ -166,7 +171,8 @@ function getLastThenStepBeforeElseLine(
166171
const line = model.getPositionAt(keyNode.range[0])?.lineNumber;
167172
if (line !== elseKeyLineNumber) return;
168173
const pathEnd = path.length >= 1 ? path[path.length - 1] : null;
169-
const parent = pathEnd && isPair(pathEnd) && path.length >= 2 ? path[path.length - 2] : pathEnd;
174+
const parent =
175+
pathEnd && isPair(pathEnd) && path.length >= 2 ? path[path.length - 2] : pathEnd;
170176
if (!parent || !isMap(parent)) return;
171177
if ((parent as { get?: (k: string) => unknown }).get?.('type') !== 'if') return;
172178
const stepsSeq = (parent as { get?: (k: string) => unknown }).get?.('steps');
@@ -212,8 +218,7 @@ function findStepNodeToInsertAfter(
212218
if (stepAtCursor) {
213219
if (stepAtCursor.get('type') === 'if') {
214220
const elsePair = stepAtCursor.items?.find(
215-
(item): item is Pair =>
216-
isPair(item) && isScalar(item.key) && item.key.value === 'else'
221+
(item): item is Pair => isPair(item) && isScalar(item.key) && item.key.value === 'else'
217222
);
218223
const elseKeyRange =
219224
elsePair?.key && typeof (elsePair.key as { range?: number[] }).range !== 'undefined'
@@ -246,11 +251,7 @@ function findStepNodeToInsertAfter(
246251
);
247252
});
248253
if (nestedStepsInsideCurrentStep) {
249-
const bestStep = findStepWithMaxEndOffsetAtOrBefore(
250-
stepsInBlock,
251-
model,
252-
cursorOffset
253-
);
254+
const bestStep = findStepWithMaxEndOffsetAtOrBefore(stepsInBlock, model, cursorOffset);
254255
return bestStep ?? stepsInBlock[stepsInBlock.length - 1];
255256
}
256257
}
@@ -322,7 +323,10 @@ function getInsertPointAfterStep(
322323
const isAfterStep =
323324
cursorLine > stepRange.endLineNumber ||
324325
(cursorLine === stepRange.endLineNumber && cursorColumn > stepRange.endColumn);
325-
if (cursorLineEmpty && (cursorLineIndent >= stepIndent || cursorLine >= stepRange.startLineNumber)) {
326+
if (
327+
cursorLineEmpty &&
328+
(cursorLineIndent >= stepIndent || cursorLine >= stepRange.startLineNumber)
329+
) {
326330
insertAtLineNumber = cursorLine;
327331
} else if (isAfterStep && (cursorLineEmpty || cursorLineIndent >= stepIndent)) {
328332
insertAtLineNumber = cursorLine;
@@ -371,8 +375,7 @@ function getDefaultInsertPoint(
371375
elseKeyLines
372376
);
373377
if (cursorInsertPoint) return cursorInsertPoint;
374-
const insertAt =
375-
model.getLineContent(cursorLine).trim() === '' ? cursorLine : cursorLine + 1;
378+
const insertAt = model.getLineContent(cursorLine).trim() === '' ? cursorLine : cursorLine + 1;
376379
return atLine(insertAt);
377380
}
378381
}
@@ -409,11 +412,7 @@ function getInsertPointFromCursor(
409412
} | null {
410413
const cursorLine = cursorPosition.lineNumber;
411414
const rootLine = stepsKeyRange.startLineNumber;
412-
const at = (
413-
insertAtLineNumber: number,
414-
insertAfterComment: boolean,
415-
commentCount?: number
416-
) => ({
415+
const at = (insertAtLineNumber: number, insertAfterComment: boolean, commentCount?: number) => ({
417416
insertAtLineNumber,
418417
indentLevel: getStepIndentForInsertLine(document, model, insertAtLineNumber, rootLine),
419418
insertAfterComment,
@@ -583,7 +582,9 @@ export function insertStepSnippet(
583582
: insertText;
584583

585584
const cursorOnElseLine =
586-
cursorPosition !== undefined && cursorPosition !== null && elseKeyLines.has(cursorPosition.lineNumber);
585+
cursorPosition !== undefined &&
586+
cursorPosition !== null &&
587+
elseKeyLines.has(cursorPosition.lineNumber);
587588

588589
if (
589590
!replaceRange &&

0 commit comments

Comments
 (0)