Skip to content

Commit 4f0937c

Browse files
author
SebastianMC
committed
Removed the parser method prefixes like _l1s3_.... which were a residue of early development stage naming allowing clear ordering of these functions in the code. No longer needed
1 parent 13f76cc commit 4f0937c

File tree

2 files changed

+48
-48
lines changed

2 files changed

+48
-48
lines changed

src/custom-sort/sorting-spec-processor.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,71 +1158,71 @@ describe('convertPlainStringSortingGroupSpecToArraySpec', () => {
11581158
});
11591159
it('should recognize infix', () => {
11601160
const s = 'Advanced adv...ed, etc. and so on'
1161-
expect(processor._l2s2_convertPlainStringSortingGroupSpecToArraySpec(s)).toEqual([
1161+
expect(processor.convertPlainStringSortingGroupSpecToArraySpec(s)).toEqual([
11621162
'Advanced adv', '...', 'ed, etc. and so on'
11631163
])
11641164
})
11651165
it('should recognize suffix', () => {
11661166
const s = 'Advanced... '
1167-
expect(processor._l2s2_convertPlainStringSortingGroupSpecToArraySpec(s)).toEqual([
1167+
expect(processor.convertPlainStringSortingGroupSpecToArraySpec(s)).toEqual([
11681168
'Advanced', '...'
11691169
])
11701170
})
11711171
it('should recognize prefix', () => {
11721172
const s = ' ...tion. !!!'
1173-
expect(processor._l2s2_convertPlainStringSortingGroupSpecToArraySpec(s)).toEqual([
1173+
expect(processor.convertPlainStringSortingGroupSpecToArraySpec(s)).toEqual([
11741174
'...', 'tion. !!!'
11751175
])
11761176
})
11771177
it('should recognize some edge case', () => {
11781178
const s = 'Edge...... ... ..... ... eee?'
1179-
expect(processor._l2s2_convertPlainStringSortingGroupSpecToArraySpec(s)).toEqual([
1179+
expect(processor.convertPlainStringSortingGroupSpecToArraySpec(s)).toEqual([
11801180
'Edge', '...', '... ... ..... ... eee?'
11811181
])
11821182
})
11831183
it('should recognize some other edge case', () => {
11841184
const s = 'Edge... ... ... ..... ... eee?'
1185-
expect(processor._l2s2_convertPlainStringSortingGroupSpecToArraySpec(s)).toEqual([
1185+
expect(processor.convertPlainStringSortingGroupSpecToArraySpec(s)).toEqual([
11861186
'Edge', '...', ' ... ... ..... ... eee?'
11871187
])
11881188
})
11891189
it('should recognize another edge case', () => {
11901190
const s = '...Edge ... ... ... ..... ... eee? ...'
1191-
expect(processor._l2s2_convertPlainStringSortingGroupSpecToArraySpec(s)).toEqual([
1191+
expect(processor.convertPlainStringSortingGroupSpecToArraySpec(s)).toEqual([
11921192
'...', 'Edge ... ... ... ..... ... eee? ...'
11931193
])
11941194
})
11951195
it('should recognize yet another edge case', () => {
11961196
const s = '. .. ... ...'
1197-
const result = processor._l2s2_convertPlainStringSortingGroupSpecToArraySpec(s)
1197+
const result = processor.convertPlainStringSortingGroupSpecToArraySpec(s)
11981198
expect(result).toEqual([
11991199
'. .. ... ', '...' // Edge case -> splitting here is neutral, syntax error should be raised later on
12001200
])
12011201
})
12021202
it('should recognize tricky edge case', () => {
12031203
const s = '... ...'
1204-
const result = processor._l2s2_convertPlainStringSortingGroupSpecToArraySpec(s)
1204+
const result = processor.convertPlainStringSortingGroupSpecToArraySpec(s)
12051205
expect(result).toEqual([
12061206
'...', ' ...' // Edge case -> splitting here is neutral, syntax error should be raised later on
12071207
])
12081208
})
12091209
it('should recognize a variant of tricky edge case', () => {
12101210
const s = '......'
1211-
const result = processor._l2s2_convertPlainStringSortingGroupSpecToArraySpec(s)
1211+
const result = processor.convertPlainStringSortingGroupSpecToArraySpec(s)
12121212
expect(result).toEqual([
12131213
'...', '...' // Edge case -> splitting here is neutral, syntax error should be raised later on
12141214
])
12151215
})
12161216
it('edge case behavior', () => {
12171217
const s = ' ...... .......... '
1218-
const result = processor._l2s2_convertPlainStringSortingGroupSpecToArraySpec(s)
1218+
const result = processor.convertPlainStringSortingGroupSpecToArraySpec(s)
12191219
expect(result).toEqual([
12201220
'...', '... ..........' // Edge case -> splitting here is neutral, syntax error should be raised later on
12211221
])
12221222
})
12231223
it('intentional edge case parsing', () => {
12241224
const s = ' Abc......def..........ghi '
1225-
const result = processor._l2s2_convertPlainStringSortingGroupSpecToArraySpec(s)
1225+
const result = processor.convertPlainStringSortingGroupSpecToArraySpec(s)
12261226
expect(result).toEqual([
12271227
'Abc', '...', '...def..........ghi' // Edge case -> splitting here is neutral, syntax error should be raised later on
12281228
])
@@ -1232,7 +1232,7 @@ describe('convertPlainStringSortingGroupSpecToArraySpec', () => {
12321232
'... ',
12331233
' ...'
12341234
])('should not split >%s< and only trim', (s: string) => {
1235-
const result = processor._l2s2_convertPlainStringSortingGroupSpecToArraySpec(s)
1235+
const result = processor.convertPlainStringSortingGroupSpecToArraySpec(s)
12361236
expect(result).toEqual([s.trim()])
12371237
})
12381238
})

src/custom-sort/sorting-spec-processor.ts

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -430,18 +430,18 @@ export class SortingSpecProcessor {
430430

431431
success = false // Empty lines and comments are OK, that's why setting so late
432432

433-
const attr: ParsedSortingAttribute | null = this._l1s1_parseAttribute(entryLine);
433+
const attr: ParsedSortingAttribute | null = this.parseAttribute(entryLine);
434434
if (attr) {
435-
success = this._l1s2_processParsedSortingAttribute(attr);
435+
success = this.processParsedSortingAttribute(attr);
436436
this.ctx.previousValidEntryWasTargetFolderAttr = success && (attr.attribute === Attribute.TargetFolder)
437-
} else if (!this.problemAlreadyReportedForCurrentLine && !this._l1s3_checkForRiskyAttrSyntaxError(entryLine)) {
438-
let group: ParsedSortingGroup | null = this._l1s4_parseSortingGroupSpec(entryLine);
437+
} else if (!this.problemAlreadyReportedForCurrentLine && !this.checkForRiskyAttrSyntaxError(entryLine)) {
438+
let group: ParsedSortingGroup | null = this.parseSortingGroupSpec(entryLine);
439439
if (!this.problemAlreadyReportedForCurrentLine && !group) {
440440
// Default for unrecognized syntax: treat the line as exact name (of file or folder)
441441
group = {plainSpec: trimmedEntryLine}
442442
}
443443
if (group) {
444-
success = this._l1s5_processParsedSortGroupSpec(group);
444+
success = this.processParsedSortGroupSpec(group);
445445
}
446446
this.ctx.previousValidEntryWasTargetFolderAttr = undefined
447447
}
@@ -456,7 +456,7 @@ export class SortingSpecProcessor {
456456
if (success) {
457457
if (this.ctx.specs.length > 0) {
458458
for (let spec of this.ctx.specs) {
459-
this._l1s6_postprocessSortSpec(spec)
459+
this.postprocessSortSpec(spec)
460460
}
461461

462462
let sortspecByWildcard: FolderWildcardMatching<CustomSortSpec> | undefined
@@ -533,7 +533,7 @@ export class SortingSpecProcessor {
533533

534534
// level 1 parser functions defined in order of occurrence and dependency
535535

536-
private _l1s1_parseAttribute = (line: string): ParsedSortingAttribute | null => {
536+
private parseAttribute = (line: string): ParsedSortingAttribute | null => {
537537
const lineTrimmedStart: string = line.trimStart()
538538
const nestingLevel: number = line.length - lineTrimmedStart.length
539539

@@ -575,18 +575,18 @@ export class SortingSpecProcessor {
575575
return null; // Seemingly not an attribute or not a valid attribute expression (respective syntax error could have been logged)
576576
}
577577

578-
private _l1s2_processParsedSortingAttribute(attr: ParsedSortingAttribute): boolean {
578+
private processParsedSortingAttribute(attr: ParsedSortingAttribute): boolean {
579579
if (attr.attribute === Attribute.TargetFolder) {
580580
if (attr.nesting === 0) { // root-level attribute causing creation of new spec or decoration of a previous one
581581
if (this.ctx.previousValidEntryWasTargetFolderAttr) {
582582
if (this.ctx.currentSpec) {
583583
this.ctx.currentSpec.targetFoldersPaths.push(attr.value)
584584
} else {
585585
// Should never reach this execution path, yet for sanity and clarity:
586-
this.ctx.currentSpec = this._l2s2_putNewSpecForNewTargetFolder(attr.value)
586+
this.ctx.currentSpec = this.putNewSpecForNewTargetFolder(attr.value)
587587
}
588588
} else {
589-
this.ctx.currentSpec = this._l2s2_putNewSpecForNewTargetFolder(attr.value)
589+
this.ctx.currentSpec = this.putNewSpecForNewTargetFolder(attr.value)
590590
}
591591
return true
592592
} else {
@@ -596,7 +596,7 @@ export class SortingSpecProcessor {
596596
} else if (attr.attribute === Attribute.OrderAsc || attr.attribute === Attribute.OrderDesc || attr.attribute === Attribute.OrderStandardObsidian) {
597597
if (attr.nesting === 0) {
598598
if (!this.ctx.currentSpec) {
599-
this.ctx.currentSpec = this._l2s2_putNewSpecForNewTargetFolder()
599+
this.ctx.currentSpec = this.putNewSpecForNewTargetFolder()
600600
}
601601
if (this.ctx.currentSpec.defaultOrder) {
602602
const folderPathsForProblemMsg: string = this.ctx.currentSpec.targetFoldersPaths.join(' :: ');
@@ -627,7 +627,7 @@ export class SortingSpecProcessor {
627627
return false;
628628
}
629629

630-
private _l1s3_checkForRiskyAttrSyntaxError = (line: string): boolean => {
630+
private checkForRiskyAttrSyntaxError = (line: string): boolean => {
631631
const lineTrimmedStart: string = line.trimStart()
632632
const lineTrimmedStartLowerCase: string = lineTrimmedStart.toLowerCase()
633633
// no space present, check for potential syntax errors
@@ -646,7 +646,7 @@ export class SortingSpecProcessor {
646646
return false
647647
}
648648

649-
private _l1s4_parseSortingGroupSpec = (line: string): ParsedSortingGroup | null => {
649+
private parseSortingGroupSpec = (line: string): ParsedSortingGroup | null => {
650650
const s: string = line.trim()
651651

652652
if (hasMoreThanOneNumericSortingSymbol(s)) {
@@ -692,27 +692,27 @@ export class SortingSpecProcessor {
692692
return null;
693693
}
694694

695-
private _l1s5_processParsedSortGroupSpec(group: ParsedSortingGroup): boolean {
695+
private processParsedSortGroupSpec(group: ParsedSortingGroup): boolean {
696696
if (!this.ctx.currentSpec) {
697-
this.ctx.currentSpec = this._l2s2_putNewSpecForNewTargetFolder()
697+
this.ctx.currentSpec = this.putNewSpecForNewTargetFolder()
698698
}
699699

700700
if (group.plainSpec) {
701-
group.arraySpec = this._l2s2_convertPlainStringSortingGroupSpecToArraySpec(group.plainSpec)
701+
group.arraySpec = this.convertPlainStringSortingGroupSpecToArraySpec(group.plainSpec)
702702
delete group.plainSpec
703703
}
704704

705705
if (group.itemToHide) {
706-
if (!this._l2s3_consumeParsedItemToHide(group)) {
706+
if (!this.consumeParsedItemToHide(group)) {
707707
this.problem(ProblemCode.ItemToHideNoSupportForThreeDots, 'For hiding of file or folder, the exact name with ext is required and no numeric sorting indicator allowed')
708708
return false
709709
} else {
710710
return true
711711
}
712712
} else { // !group.itemToHide
713-
const newGroup: CustomSortGroup | null = this._l2s4_consumeParsedSortingGroupSpec(group)
713+
const newGroup: CustomSortGroup | null = this.consumeParsedSortingGroupSpec(group)
714714
if (newGroup) {
715-
if (this._l2s5_adjustSortingGroupForNumericSortingSymbol(newGroup)) {
715+
if (this.adjustSortingGroupForNumericSortingSymbol(newGroup)) {
716716
if (this.ctx.currentSpec) {
717717
this.ctx.currentSpec.groups.push(newGroup)
718718
this.ctx.currentSpecGroup = newGroup
@@ -729,7 +729,7 @@ export class SortingSpecProcessor {
729729
}
730730
}
731731

732-
private _l1s6_postprocessSortSpec(spec: CustomSortSpec): void {
732+
private postprocessSortSpec(spec: CustomSortSpec): void {
733733
// clean up to prevent false warnings in console
734734
spec.outsidersGroupIdx = undefined
735735
spec.outsidersFilesGroupIdx = undefined
@@ -798,7 +798,7 @@ export class SortingSpecProcessor {
798798

799799
// level 2 parser functions defined in order of occurrence and dependency
800800

801-
private _l2s1_validateTargetFolderAttrValue = (v: string): string | null => {
801+
private validateTargetFolderAttrValue = (v: string): string | null => {
802802
if (v) {
803803
const trimmed: string = v.trim();
804804
return trimmed ? trimmed : null; // Can't use ?? - it treats '' as a valid value
@@ -807,28 +807,28 @@ export class SortingSpecProcessor {
807807
}
808808
}
809809

810-
private _l2s1_internal_validateOrderAttrValue = (v: string): CustomSortOrderAscDescPair | null => {
810+
private internalValidateOrderAttrValue = (v: string): CustomSortOrderAscDescPair | null => {
811811
v = v.trim();
812812
return v ? OrderLiterals[v.toLowerCase()] : null
813813
}
814814

815-
private _l2s1_validateOrderAscAttrValue = (v: string): RecognizedOrderValue | null => {
816-
const recognized: CustomSortOrderAscDescPair | null = this._l2s1_internal_validateOrderAttrValue(v)
815+
private validateOrderAscAttrValue = (v: string): RecognizedOrderValue | null => {
816+
const recognized: CustomSortOrderAscDescPair | null = this.internalValidateOrderAttrValue(v)
817817
return recognized ? {
818818
order: recognized.asc,
819819
secondaryOrder: recognized.secondary
820820
} : null;
821821
}
822822

823-
private _l2s1_validateOrderDescAttrValue = (v: string): RecognizedOrderValue | null => {
824-
const recognized: CustomSortOrderAscDescPair | null = this._l2s1_internal_validateOrderAttrValue(v)
823+
private validateOrderDescAttrValue = (v: string): RecognizedOrderValue | null => {
824+
const recognized: CustomSortOrderAscDescPair | null = this.internalValidateOrderAttrValue(v)
825825
return recognized ? {
826826
order: recognized.desc,
827827
secondaryOrder: recognized.secondary
828828
} : null;
829829
}
830830

831-
private _l2s1_validateSortingAttrValue = (v: string): RecognizedOrderValue | null => {
831+
private validateSortingAttrValue = (v: string): RecognizedOrderValue | null => {
832832
// for now only a single fixed lexem
833833
const recognized: boolean = v.trim().toLowerCase() === 'standard'
834834
return recognized ? {
@@ -837,13 +837,13 @@ export class SortingSpecProcessor {
837837
}
838838

839839
attrValueValidators: { [key in Attribute]: AttrValueValidatorFn } = {
840-
[Attribute.TargetFolder]: this._l2s1_validateTargetFolderAttrValue.bind(this),
841-
[Attribute.OrderAsc]: this._l2s1_validateOrderAscAttrValue.bind(this),
842-
[Attribute.OrderDesc]: this._l2s1_validateOrderDescAttrValue.bind(this),
843-
[Attribute.OrderStandardObsidian]: this._l2s1_validateSortingAttrValue.bind(this)
840+
[Attribute.TargetFolder]: this.validateTargetFolderAttrValue.bind(this),
841+
[Attribute.OrderAsc]: this.validateOrderAscAttrValue.bind(this),
842+
[Attribute.OrderDesc]: this.validateOrderDescAttrValue.bind(this),
843+
[Attribute.OrderStandardObsidian]: this.validateSortingAttrValue.bind(this)
844844
}
845845

846-
_l2s2_convertPlainStringSortingGroupSpecToArraySpec = (spec: string): Array<string> => {
846+
convertPlainStringSortingGroupSpecToArraySpec = (spec: string): Array<string> => {
847847
spec = spec.trim()
848848
if (isThreeDots(spec)) {
849849
return [ThreeDots]
@@ -868,7 +868,7 @@ export class SortingSpecProcessor {
868868
return [spec];
869869
}
870870

871-
private _l2s2_putNewSpecForNewTargetFolder(folderPath?: string): CustomSortSpec {
871+
private putNewSpecForNewTargetFolder(folderPath?: string): CustomSortSpec {
872872
const newSpec: CustomSortSpec = {
873873
targetFoldersPaths: [folderPath ?? this.ctx.folderPath],
874874
groups: []
@@ -883,7 +883,7 @@ export class SortingSpecProcessor {
883883

884884
// Detection of slippery syntax errors which can confuse user due to false positive parsing with an unexpected sorting result
885885

886-
private _l2s3_consumeParsedItemToHide(spec: ParsedSortingGroup): boolean {
886+
private consumeParsedItemToHide(spec: ParsedSortingGroup): boolean {
887887
if (spec.arraySpec?.length === 1) {
888888
const theOnly: string = spec.arraySpec[0]
889889
if (!isThreeDots(theOnly)) {
@@ -903,7 +903,7 @@ export class SortingSpecProcessor {
903903
return false
904904
}
905905

906-
private _l2s4_consumeParsedSortingGroupSpec = (spec: ParsedSortingGroup): CustomSortGroup | null => {
906+
private consumeParsedSortingGroupSpec = (spec: ParsedSortingGroup): CustomSortGroup | null => {
907907
if (spec.outsidersGroup) {
908908
return {
909909
type: CustomSortGroupType.Outsiders,
@@ -985,7 +985,7 @@ export class SortingSpecProcessor {
985985
}
986986

987987
// Returns true if no numeric sorting symbol (hence no adjustment) or if correctly adjusted with regex
988-
private _l2s5_adjustSortingGroupForNumericSortingSymbol = (group: CustomSortGroup) => {
988+
private adjustSortingGroupForNumericSortingSymbol = (group: CustomSortGroup) => {
989989
switch (group.type) {
990990
case CustomSortGroupType.ExactPrefix:
991991
const numSymbolInPrefix = convertPlainStringWithNumericSortingSymbolToRegex(group.exactPrefix, RegexpUsedAs.Prefix)

0 commit comments

Comments
 (0)