Skip to content

Commit 7a3a3cb

Browse files
committed
refactor: Remove method canCreateSorterForLine()
It only created duplicate calls to methods which were already been called by createSorterFromLine(), so added no new value.
1 parent 8d3b397 commit 7a3a3cb

File tree

3 files changed

+0
-38
lines changed

3 files changed

+0
-38
lines changed

src/Query/Filter/Field.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -142,30 +142,9 @@ export abstract class Field {
142142
return null;
143143
}
144144

145-
if (!this.canCreateSorterForLine(line)) {
146-
return null;
147-
}
148-
149145
return this.createSorterFromLine(line);
150146
}
151147

152-
/**
153-
* Returns true if the class can parse the given 'sort by' instruction line.
154-
*
155-
* Current implementation simply checks whether the class does support sorting,
156-
* and whether the line matches this.sorterRegExp().
157-
* @param line - A line from a ```tasks``` block.
158-
*
159-
* @see {@link createSorterFromLine}
160-
*/
161-
public canCreateSorterForLine(line: string): boolean {
162-
if (!this.supportsSorting()) {
163-
return false;
164-
}
165-
166-
return Field.lineMatchesFilter(this.sorterRegExp(), line);
167-
}
168-
169148
/**
170149
* Parse the line, and return either a {@link Sorter} object or null.
171150
*
@@ -176,8 +155,6 @@ export abstract class Field {
176155
* this method.
177156
*
178157
* @param line - A 'sort by' line from a ```tasks``` block.
179-
*
180-
* @see {@link canCreateSorterForLine}
181158
*/
182159
public createSorterFromLine(line: string): Sorter | null {
183160
if (!this.supportsSorting()) {

tests/Query/Filter/Field.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ describe('sorting - base class usability and implementation', () => {
6464
it('should fail to parse a "valid" line', () => {
6565
// expect(unsupported.parseSortLine('sort by unsupported')).toThrow(Error);
6666
const line = 'sort by unsupported';
67-
expect(unsupported.canCreateSorterForLine(line)).toBe(false);
6867
expect(unsupported.createSorterFromLine(line)).toBeNull();
6968
const sorting = unsupported.parseSortLine(line);
7069
expect(sorting).toBeNull();
@@ -84,7 +83,6 @@ describe('sorting - base class usability and implementation', () => {
8483

8584
it('should parse a valid line', () => {
8685
const line = 'sort by description-length';
87-
expect(supported.canCreateSorterForLine(line)).toBe(true);
8886
expect(supported.createSorterFromLine(line)).not.toBeNull();
8987
const sorting = supported.parseSortLine(line);
9088
expect(sorting).not.toBeNull();
@@ -93,7 +91,6 @@ describe('sorting - base class usability and implementation', () => {
9391

9492
it('should fail to parse a invalid line', () => {
9593
const line = 'sort by jsdajhasdfa';
96-
expect(supported.canCreateSorterForLine(line)).toBe(false);
9794
expect(supported.createSorterFromLine(line)).toBeNull();
9895
const sorting = supported.parseSortLine(line);
9996
expect(sorting).toBeNull();

tests/Query/Filter/TagsField.test.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -345,17 +345,6 @@ describe('Sort by tags', () => {
345345
expect(tagsField.supportsSorting()).toEqual(true);
346346
});
347347

348-
it('should report whether it can parse lines', () => {
349-
// Valid sort by tag lines:
350-
expect(tagsField.canCreateSorterForLine('sort by tag')).toBe(true);
351-
expect(tagsField.canCreateSorterForLine('sort by tag 2')).toBe(true);
352-
expect(tagsField.canCreateSorterForLine('sort by tag reverse')).toBe(true);
353-
expect(tagsField.canCreateSorterForLine('sort by tag reverse 3')).toBe(true);
354-
355-
// Invalid lines:
356-
expect(tagsField.canCreateSorterForLine('sort by description')).toBe(false);
357-
});
358-
359348
const tag_a = new TaskBuilder().tags(['#a']).build();
360349
const tag_b = new TaskBuilder().tags(['#b']).build();
361350
const tags_a_b = new TaskBuilder().tags(['#a', '#b']).build();
@@ -406,7 +395,6 @@ describe('Sort by tags', () => {
406395

407396
it('should fail to parse a invalid line', () => {
408397
const line = 'sort by jsdajhasdfa';
409-
expect(tagsField.canCreateSorterForLine(line)).toBe(false);
410398
expect(tagsField.createSorterFromLine(line)).toBeNull();
411399
const sorting = tagsField.parseSortLine(line);
412400
expect(sorting).toBeNull();

0 commit comments

Comments
 (0)