Skip to content

Commit f389894

Browse files
chintankavathiaspike-rabbit
authored andcommitted
refactor: prefer arrow functions
1 parent 46a802b commit f389894

19 files changed

+96
-92
lines changed

eslint.config.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ export const tsConfig = typescriptEslint.config({
5252
'@angular-eslint/no-input-rename': ['off'],
5353
'@angular-eslint/no-output-native': ['off'],
5454
'@angular-eslint/directive-class-suffix': ['off'],
55-
'@angular-eslint/no-conflicting-lifecycle': ['off'],
56-
'prefer-arrow/prefer-arrow-functions': ['off']
55+
'@angular-eslint/no-conflicting-lifecycle': ['off']
5756
}
5857
});
5958

projects/ngx-datatable/src/lib/components/body/summary/summary-row.component.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ describe('DataTableSummaryRowComponent', () => {
4343
fixture.detectChanges();
4444
});
4545

46-
function triggerChange() {
46+
const triggerChange = () => {
4747
component.ngOnChanges();
4848
fixture.detectChanges();
49-
}
49+
};
5050

5151
describe('fixture', () => {
5252
it('should have a component instance', () => {

projects/ngx-datatable/src/lib/components/body/summary/summary-row.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Component, Input, OnChanges } from '@angular/core';
33
import { TableColumnInternal } from '../../../types/internal.types';
44
import { DataTableBodyRowComponent } from '../body-row.component';
55

6-
function defaultSumFunc(cells: any[]): any {
6+
const defaultSumFunc = (cells: any[]): any => {
77
const cellsWithValues = cells.filter(cell => !!cell);
88

99
if (!cellsWithValues.length) {
@@ -14,11 +14,11 @@ function defaultSumFunc(cells: any[]): any {
1414
}
1515

1616
return cellsWithValues.reduce((res, cell) => res + cell);
17-
}
17+
};
1818

19-
function noopSumFunc(cells: any[]): void {
19+
const noopSumFunc = (cells: any[]): void => {
2020
return;
21-
}
21+
};
2222

2323
@Component({
2424
selector: 'datatable-summary-row',

projects/ngx-datatable/src/lib/components/datatable.component.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,26 +546,26 @@ describe('DatatableComponent With Frozen columns', () => {
546546
/**
547547
* mimics the act of a user clicking a column to sort it
548548
*/
549-
function sortBy({ column }: { column: number }, fixture: ComponentFixture<unknown>) {
549+
const sortBy = ({ column }: { column: number }, fixture: ComponentFixture<unknown>) => {
550550
const columnIndex = column - 1;
551551
const headerCellDe = fixture.debugElement.queryAll(By.css('datatable-header-cell'))[columnIndex];
552552
const de = headerCellDe.query(By.css('span:last-child'));
553553
de.triggerEventHandler('click', null);
554-
}
554+
};
555555

556556
/**
557557
* test helper function to return text content of a cell within the
558558
* body of the ngx-datatable component
559559
*/
560-
function textContent(
560+
const textContent = (
561561
{ row, column }: { row: number; column: number },
562562
fixture: ComponentFixture<unknown>
563-
) {
563+
) => {
564564
const [rowIndex, columnIndex] = [row - 1, column - 1];
565565
const bodyRowDe = fixture.debugElement.queryAll(By.directive(DataTableBodyRowComponent))[
566566
rowIndex
567567
];
568568
const bodyCellDe = bodyRowDe.queryAll(By.directive(DataTableBodyCellComponent))[columnIndex];
569569

570570
return bodyCellDe.nativeElement.textContent;
571-
}
571+
};

projects/ngx-datatable/src/lib/components/footer/pager.component.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@ describe('DataTablePagerComponent', () => {
264264
.map((button, index) => ({ button, page: index + 1 }));
265265
});
266266

267-
function ariaLabel(element: DebugElement): string | null {
267+
const ariaLabel = (element: DebugElement): string | null => {
268268
return element?.attributes['aria-label'] ?? null;
269-
}
269+
};
270270

271271
describe('has default values without messages from table', () => {
272272
it('first button', () => {
@@ -293,11 +293,11 @@ describe('DataTablePagerComponent', () => {
293293
});
294294

295295
describe('takes messages-overrides from table', () => {
296-
function setMessages(messages: DatatableComponent['messages']) {
296+
const setMessages = (messages: DatatableComponent['messages']) => {
297297
(pager as any).dataTable = { messages };
298298
// do a change detection on the real changeDetectionRef
299299
fixture.componentRef.injector.get(ChangeDetectorRef).detectChanges();
300-
}
300+
};
301301

302302
it('first button', () => {
303303
setMessages({ ariaFirstPageMessage: 'link: first page' });

projects/ngx-datatable/src/lib/components/header/header.component.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe('DataTableHeaderComponent', () => {
8181
});
8282
});
8383

84-
function createColumn(id: string, resizeable = true): TableColumnInternal {
84+
const createColumn = (id: string, resizeable = true): TableColumnInternal => {
8585
return {
8686
$$id: id,
8787
prop: id,
@@ -93,4 +93,4 @@ function createColumn(id: string, resizeable = true): TableColumnInternal {
9393
maxWidth: 200,
9494
isTarget: false
9595
} as any;
96-
}
96+
};

projects/ngx-datatable/src/lib/directives/orderable.directive.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('OrderableDirective', () => {
5656
});
5757

5858
describe('when a draggable is removed', () => {
59-
function checkAllSubscriptionsForActiveObservers() {
59+
const checkAllSubscriptionsForActiveObservers = () => {
6060
const subs = directive.draggables.map(d => {
6161
expect(d.dragEnd.isStopped).toBe(false);
6262
expect(d.dragStart.isStopped).toBe(false);
@@ -71,11 +71,11 @@ describe('OrderableDirective', () => {
7171
expect(sub.dragStart.length).toBe(1);
7272
expect(sub.dragEnd.length).toBe(1);
7373
});
74-
}
74+
};
7575

76-
function newDraggable(name: string): TableColumnInternal {
76+
const newDraggable = (name: string): TableColumnInternal => {
7777
return toInternalColumn([{ name }])[0];
78-
}
78+
};
7979

8080
beforeEach(() => {
8181
component.draggables = [newDraggable('d1'), newDraggable('d2'), newDraggable('d3')];

projects/ngx-datatable/src/lib/ngx-datatable.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ export type INgxDatatableConfig = NgxDatatableConfig;
7474
*
7575
* @param overrides The overrides of the table configuration.
7676
*/
77-
export function providedNgxDatatableConfig(overrides: AllPartial<NgxDatatableConfig>): Provider {
77+
export const providedNgxDatatableConfig = (overrides: AllPartial<NgxDatatableConfig>): Provider => {
7878
return {
7979
provide: NGX_DATATABLE_CONFIG,
8080
useValue: overrides
8181
};
82-
}
82+
};

projects/ngx-datatable/src/lib/utils/camel-case.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Converts strings from something to camel case
33
* http://stackoverflow.com/questions/10425287/convert-dash-separated-string-to-camelcase
44
*/
5-
export function camelCase(str: string): string {
5+
export const camelCase = (str: string): string => {
66
// Replace special characters with a space
77
str = str.replace(/[^a-zA-Z0-9 ]/g, ' ');
88
// put a space before an uppercase letter
@@ -15,17 +15,17 @@ export function camelCase(str: string): string {
1515
.toLowerCase();
1616

1717
// uppercase characters preceded by a space or number
18-
str = str.replace(/([ 0-9]+)([a-zA-Z])/g, function (a, b, c) {
18+
str = str.replace(/([ 0-9]+)([a-zA-Z])/g, (a, b, c) => {
1919
return b.trim() + c.toUpperCase();
2020
});
2121

2222
return str;
23-
}
23+
};
2424

2525
/**
2626
* Converts strings from camel case to words
2727
* http://stackoverflow.com/questions/7225407/convert-camelcasetext-to-camel-case-text
2828
*/
29-
export function deCamelCase(str: string): string {
29+
export const deCamelCase = (str: string): string => {
3030
return str.replace(/([A-Z])/g, match => ` ${match}`).replace(/^./, match => match.toUpperCase());
31-
}
31+
};

projects/ngx-datatable/src/lib/utils/column-helper.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import { getterForProp } from './column-prop-getters';
99
import { id } from './id';
1010
import { orderByComparator } from './sort';
1111

12-
export function toInternalColumn<T extends Row>(
12+
export const toInternalColumn = <T extends Row>(
1313
columns: TableColumn<T>[] | QueryList<DataTableColumnDirective<T>>,
1414
defaultColumnWidth = 150
15-
): TableColumnInternal<T>[] {
15+
): TableColumnInternal<T>[] => {
1616
let hasTreeColumn = false;
1717
// TS fails to infer the type here.
1818
return (columns as TableColumn<T>[]).map(column => {
@@ -45,4 +45,4 @@ export function toInternalColumn<T extends Row>(
4545
treeToggleTemplate: column.treeToggleTemplate
4646
} as TableColumnInternal; // TS cannot cast here
4747
});
48-
}
48+
};

0 commit comments

Comments
 (0)