Skip to content

Commit d665b65

Browse files
committed
refactor: Inline Field.parseSortLine()
Replace remaining parseSortLine() calls with createSorterFromLine()
1 parent 222800f commit d665b65

File tree

4 files changed

+5
-23
lines changed

4 files changed

+5
-23
lines changed

src/Query/Filter/Field.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,6 @@ export abstract class Field {
131131
return false;
132132
}
133133

134-
/**
135-
* Parse a 'sort by' line and return a {@link Sorter} object.
136-
*
137-
* Returns null line does not match this field or is invalid,
138-
* or this field does not support sorting.
139-
*/
140-
public parseSortLine(line: string): Sorter | null {
141-
if (!this.supportsSorting()) {
142-
return null;
143-
}
144-
145-
return this.createSorterFromLine(line);
146-
}
147-
148134
/**
149135
* Parse the line, and return either a {@link Sorter} object or null.
150136
*

src/Query/FilterParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export function parseSorter(sorterString: string): Sorter | null {
8181
// See if any of the fields can parse the line.
8282
for (const creator of fieldCreators) {
8383
const field = creator();
84-
const sorter = field.parseSortLine(sorterString);
84+
const sorter = field.createSorterFromLine(sorterString);
8585
if (sorter) {
8686
return sorter;
8787
}

tests/Query/Filter/Field.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ describe('sorting - base class usability and implementation', () => {
6363

6464
it('should fail to parse a "valid" line', () => {
6565
const line = 'sort by unsupported';
66-
expect(unsupported.createSorterFromLine(line)).toBeNull();
67-
const sorting = unsupported.parseSortLine(line);
66+
const sorting = unsupported.createSorterFromLine(line);
6867
expect(sorting).toBeNull();
6968
});
7069
});
@@ -82,16 +81,14 @@ describe('sorting - base class usability and implementation', () => {
8281

8382
it('should parse a valid line', () => {
8483
const line = 'sort by description-length';
85-
expect(supported.createSorterFromLine(line)).not.toBeNull();
86-
const sorting = supported.parseSortLine(line);
84+
const sorting = supported.createSorterFromLine(line);
8785
expect(sorting).not.toBeNull();
8886
expect(sorting?.property).toEqual('description-length');
8987
});
9088

9189
it('should fail to parse a invalid line', () => {
9290
const line = 'sort by jsdajhasdfa';
93-
expect(supported.createSorterFromLine(line)).toBeNull();
94-
const sorting = supported.parseSortLine(line);
91+
const sorting = supported.createSorterFromLine(line);
9592
expect(sorting).toBeNull();
9693
});
9794

tests/Query/Filter/TagsField.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,7 @@ describe('Sort by tags', () => {
395395

396396
it('should fail to parse a invalid line', () => {
397397
const line = 'sort by jsdajhasdfa';
398-
expect(tagsField.createSorterFromLine(line)).toBeNull();
399-
const sorting = tagsField.parseSortLine(line);
398+
const sorting = tagsField.createSorterFromLine(line);
400399
expect(sorting).toBeNull();
401400
});
402401
});

0 commit comments

Comments
 (0)