Skip to content

Commit

Permalink
feat(core): add ESLint npm script and add to prebuild script (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding authored Nov 2, 2020
1 parent d3951a0 commit 4064876
Show file tree
Hide file tree
Showing 73 changed files with 168 additions and 197 deletions.
11 changes: 11 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*.css
*.scss
*.html
*.png
*.json
*.js
*.d.ts
*.map
*.md
*.zip
**/dist/*.*
13 changes: 4 additions & 9 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"_": true
},
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"plugins": [
Expand Down Expand Up @@ -59,6 +58,9 @@
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-parameter-properties": "off",
"@typescript-eslint/no-shadow": [
"error"
],
"@typescript-eslint/no-this-alias": "error",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-var-requires": "off",
Expand Down Expand Up @@ -124,14 +126,7 @@
"no-redeclare": "error",
"no-return-await": "error",
"no-sequences": "error",
"no-shadow": [
"error",
{
"builtinGlobals": false,
"hoist": "functions",
"allow": []
}
],
"no-shadow": "off",
"no-sparse-arrays": "error",
"no-template-curly-in-string": "error",
"no-throw-literal": "error",
Expand Down
8 changes: 8 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"recommendations": [
"andys8.jest-snippets",
"editorconfig.editorconfig",
"msjsdiag.debugger-for-chrome",
"dbaeumer.vscode-eslint"
]
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"bundle:with-tests": "npm run test",
"build": "lerna run build --stream",
"build:demo": "lerna run build:demo --stream",
"rebuild": "run-s clean build",
"rebuild": "run-s clean lint build",
"clean": "rimraf --maxBusyTries=10 packages/*/dist dist",
"cypress": "cypress open --config-file test/cypress.json",
"cypress:ci": "cypress run --config-file test/cypress.json --reporter mochawesome",
Expand All @@ -22,6 +22,7 @@
"new-version": "lerna version --conventional-commits",
"publish": "lerna publish",
"serve:demo": "http-server ./docs -p 8888 -a localhost",
"lint": "eslint packages/** --ext .ts",
"test": "npx jest --runInBand --coverage=true --config ./test/jest.config.js",
"test:watch": "npx jest --watch --config ./test/jest.config.js"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ describe('cellExternalCopyManagerExtension', () => {

it('should expect a sanitized formatted and empty output after calling "dataItemColumnValueExtractor" callback', () => {
gridOptionsMock.exportOptions = { sanitizeDataExport: true };
const myBoldFormatter: Formatter = (row, cell, value, columnDef, dataContext) => value ? { text: `<b>${value}</b>` } : null;
const myBoldFormatter: Formatter = (_row, _cell, value) => value ? { text: `<b>${value}</b>` } : null;
jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(gridOptionsMock);
extension.register();

Expand All @@ -333,7 +333,7 @@ describe('cellExternalCopyManagerExtension', () => {
});

it('should expect a sanitized formatted output, from a Custom Formatter, after calling "dataItemColumnValueExtractor" callback', () => {
const myBoldFormatter: Formatter = (row, cell, value, columnDef, dataContext) => value ? { text: `<b>${value}</b>` } : '';
const myBoldFormatter: Formatter = (_row, _cell, value) => value ? { text: `<b>${value}</b>` } : '';
gridOptionsMock.exportOptions = { sanitizeDataExport: true };
jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(gridOptionsMock);
extension.register();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('columnPickerExtension', () => {
hideForceFitButton: false,
hideSyncResizeButton: true,
onExtensionRegistered: jest.fn(),
onColumnsChanged: (e, args: { columns: Column[] }) => { }
onColumnsChanged: () => { }
},
} as GridOption;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Grouping, GridOption, SlickGrid, SlickNamespace } from '../../interfaces/index';
import { GridOption, SlickGrid, SlickNamespace } from '../../interfaces/index';
import { DraggableGroupingExtension } from '../draggableGroupingExtension';
import { ExtensionUtility } from '../extensionUtility';
import { SharedService } from '../../services/shared.service';
Expand Down Expand Up @@ -32,7 +32,7 @@ describe('draggableGroupingExtension', () => {
dropPlaceHolderText: 'test',
groupIconCssClass: 'group-class',
onExtensionRegistered: jest.fn(),
onGroupChanged: (e: Event, args: { caller?: string; groupColumns: Grouping[] }) => { },
onGroupChanged: () => { },
}
} as GridOption;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('headerButtonExtension', () => {
command: 'toggle-highlight',
grid: gridStub
} as HeaderButtonOnCommandArgs;
const mockEventCallback = (e, args: HeaderButtonOnCommandArgs) => { };
const mockEventCallback = () => { };
const gridOptionsMock = {
enableHeaderButton: true,
headerButton: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ describe('rowMoveManagerExtension', () => {
singleRowMove: true,
disableRowSelection: true,
onExtensionRegistered: jest.fn(),
onBeforeMoveRows: (e, args: { insertBefore: number; rows: number[]; }) => { },
onMoveRows: (e, args: { insertBefore: number; rows: number[]; }) => { },
onBeforeMoveRows: () => { },
onMoveRows: () => { },
},
} as GridOption;

Expand Down Expand Up @@ -112,7 +112,7 @@ describe('rowMoveManagerExtension', () => {
columnsMock = [{
id: '_move', name: '', field: 'move', width: 40,
behavior: 'selectAndMove', selectable: false, resizable: false, cssClass: '',
formatter: (row, cell, value, columnDef, dataContext, grid) => ({ addClasses: 'cell-reorder dnd' })
formatter: () => ({ addClasses: 'cell-reorder dnd' })
}, ...columnsMock] as Column[];
const instance = extension.loadAddonWhenNotExists(columnsMock, gridOptionsMock);
const spy = jest.spyOn(instance, 'getColumnDefinition').mockReturnValue({ id: '_move', field: 'move' });
Expand Down Expand Up @@ -213,7 +213,7 @@ describe('rowMoveManagerExtension', () => {
const addonOptions = { ...gridOptionsMock, rowMoveManager: optionMock };
jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(addonOptions);

const instance = extension.create(columnsMock, gridOptionsMock);
extension.create(columnsMock, gridOptionsMock);
extension.register();

expect(mockAddon).toHaveBeenCalledWith(gridOptionsMock.rowMoveManager);
Expand Down
4 changes: 3 additions & 1 deletion packages/common/src/extensions/contextMenuExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,9 @@ export class ContextMenuExtension implements Extension {
}
}
}
} catch (e) { }
} catch (e) {
/* do nothing */
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FieldType, OperatorType } from '../../enums/index';
import { FieldType } from '../../enums/index';
import { FilterConditionOption } from '../../interfaces/index';
import { objectFilterCondition } from '../objectFilterCondition';
import { executeMappedCondition } from '../executeMappedCondition';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { FilterConditionOption } from './../interfaces/filterConditionOption.interface';
import { booleanFilterCondition } from './booleanFilterCondition';
import { executeMappedCondition } from './executeMappedCondition';
import { collectionSearchFilterCondition } from './collectionSearchFilterCondition';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ describe('AutoCompleteFilter', () => {
filterElm.dispatchEvent(new (window.window as any).KeyboardEvent('keydown', { keyCode: 109, bubbles: true, cancelable: true }));
filterElm.dispatchEvent(new (window.window as any).KeyboardEvent('keyup', { keyCode: 109, bubbles: true, cancelable: true }));
const filterFilledElms = divContainer.querySelectorAll<HTMLInputElement>('input.filter-gender.filled');
const autocompleteListElms = document.body.querySelectorAll<HTMLLIElement>('ul.ui-autocomplete li');

expect(filterFilledElms.length).toBe(1);
// expect(autocompleteListElms.length).toBe(2);
Expand Down Expand Up @@ -194,7 +193,6 @@ describe('AutoCompleteFilter', () => {
filterElm.focus();
filterElm.value = 'a';
filterElm.dispatchEvent(new (window.window as any).KeyboardEvent('keyup', { keyCode: 97, bubbles: true, cancelable: true }));
const autocompleteListElms = document.body.querySelectorAll<HTMLLIElement>('ul.ui-autocomplete li');

// expect(autocompleteListElms.length).toBe(2);
expect(spyCallback).toHaveBeenCalledWith(expect.anything(), { columnDef: mockColumn, operator: 'EQ', searchTerms: ['a'], shouldTriggerQuery: true });
Expand Down Expand Up @@ -623,7 +621,7 @@ describe('AutoCompleteFilter', () => {

it('should provide "renderItem" in the "filterOptions" and expect the jQueryUI "_renderItem" to be overriden', () => {
const mockTemplateString = `<div>Hello World</div>`;
const mockTemplateCallback = (item) => mockTemplateString;
const mockTemplateCallback = () => mockTemplateString;
mockColumn.filter.filterOptions = {
source: [],
renderItem: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,16 @@ describe('SelectFilter', () => {
let divContainer: HTMLDivElement;
let filter: SelectFilter;
let filterArguments: FilterArguments;
let spyGetHeaderRow;
let mockColumn: Column;
let collectionService: CollectionService;
let translateService: TranslateServiceStub;

beforeEach(() => {
translateService = new TranslateServiceStub();
collectionService = new CollectionService(translateService);

divContainer = document.createElement('div');
divContainer.innerHTML = template;
document.body.appendChild(divContainer);
spyGetHeaderRow = jest.spyOn(gridStub, 'getHeaderRowColumn').mockReturnValue(divContainer);
jest.spyOn(gridStub, 'getHeaderRowColumn').mockReturnValue(divContainer);

mockColumn = {
id: 'gender', field: 'gender', filterable: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/filters/sliderRangeFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export class SliderRangeFilter implements Filter {
step: +(step || 1),
values: [defaultStartValue, defaultEndValue],
change: (e: Event, ui: JQueryUiSliderResponse) => this.onValueChanged(e, ui),
slide: (e: Event, ui: JQueryUiSliderResponse) => {
slide: (_e: Event, ui: JQueryUiSliderResponse) => {
const values = ui.values;
if (!this.filterParams.hideSliderNumbers && Array.isArray(values)) {
this.renderSliderValues(values[0], values[1]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import { Column, GridOption, SlickGrid } from '../../interfaces/index';
import { decimalFormatter } from '../decimalFormatter';

describe('the Decimal Formatter', () => {
let consoleSpy;
const gridStub = {
getOptions: jest.fn()
} as unknown as SlickGrid;

beforeEach(() => {
consoleSpy = jest.spyOn(global.console, 'warn').mockReturnValue();
jest.spyOn(global.console, 'warn').mockReturnValue();
});

it('should display an empty string when no value is provided', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('the Hyperlink Formatter', () => {

const result1 = hyperlinkFormatter(0, 0, inputValue, { params: { hyperlinkUrl: hyperlinkUrl1, hyperlinkText: linkText1 } } as Column, {});
const result2 = hyperlinkFormatter(0, 0, inputValue, { params: { hyperlinkUrl: hyperlinkUrl2, hyperlinkText: linkText2 } } as Column, {});
const result3 = hyperlinkFormatter(0, 0, inputValue, { params: { hyperlinkUrl: hyperlinkUrl3, hyperlinkText: linkText3 } } as Column, {}); 3
const result3 = hyperlinkFormatter(0, 0, inputValue, { params: { hyperlinkUrl: hyperlinkUrl3, hyperlinkText: linkText3 } } as Column, {});

expect(result1).toBe(`<a href="${hyperlinkUrl1}">${linkText1}</a>`);
expect(result2).toBe(`<a href="${hyperlinkUrl2}">${linkText2}</a>`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Column, Formatter } from './../interfaces/index';

export const arrayObjectToCsvFormatter: Formatter = (row: number, cell: number, value: any, columnDef: Column, dataContext: any) => {
export const arrayObjectToCsvFormatter: Formatter = (_row: number, _cell: number, value: any, columnDef: Column, dataContext: any) => {
const columnParams = columnDef && columnDef.params || {};
const propertyNames = columnParams.propertyNames;
let parentObjectKeyName: string = columnParams.dataContextProperty;
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/formatters/arrayToCsvFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Column, Formatter } from './../interfaces/index';
import { Formatter } from './../interfaces/index';

export const arrayToCsvFormatter: Formatter = (row: number, cell: number, value: any, columnDef: Column, dataContext: any) => {
export const arrayToCsvFormatter: Formatter = (_row: number, _cell: number, value: any) => {
if (value && Array.isArray(value) && value.length > 0) {
const values = value.join(', ');
return `<span title="${values}">${values}</span>`;
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/formatters/boldFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Column, Formatter } from './../interfaces/index';
import { Formatter } from './../interfaces/index';

export const boldFormatter: Formatter = (row: number, cell: number, value: any, columnDef: Column, dataContext: any) => {
export const boldFormatter: Formatter = (_row: number, _cell: number, value: any) => {
return value ? `<b>${value}</b>` : '';
};
2 changes: 1 addition & 1 deletion packages/common/src/formatters/centerFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Formatter } from './../interfaces/index';

export const centerFormatter: Formatter = (row: number, cell: number, value: string | any): string => {
export const centerFormatter: Formatter = (_row: number, _cell: number, value: string | any): string => {
// make sure the value is a string
if (value !== undefined && typeof value !== 'string') {
value = value + '';
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/formatters/checkboxFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Column, Formatter } from './../interfaces/index';
import { Formatter } from './../interfaces/index';

export const checkboxFormatter: Formatter = (row: number, cell: number, value: any, columnDef: Column, dataContext: any) =>
export const checkboxFormatter: Formatter = (_row: number, _cell: number, value: any) =>
value ? '&#x2611;' : '';
4 changes: 2 additions & 2 deletions packages/common/src/formatters/checkmarkFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Column, Formatter } from './../interfaces/index';
import { Formatter } from './../interfaces/index';

export const checkmarkFormatter: Formatter = (row: number, cell: number, value: any, columnDef: Column, dataContext: any) => {
export const checkmarkFormatter: Formatter = (_row: number, _cell: number, value: any) => {
let isChecked = false;
const isNumber = (value === null || value === undefined || value === '') ? false : !isNaN(+value);

Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/formatters/checkmarkMaterialFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Column, Formatter } from './../interfaces/index';
import { Formatter } from './../interfaces/index';

export const checkmarkMaterialFormatter: Formatter = (row: number, cell: number, value: any, columnDef: Column, dataContext: any) => {
export const checkmarkMaterialFormatter: Formatter = (_row: number, _cell: number, value: any) => {
let isChecked = false;
const isNumber = (value === null || value === undefined || value === '') ? false : !isNaN(+value);

Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/formatters/complexObjectFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Column, Formatter } from './../interfaces/index';

export const complexObjectFormatter: Formatter = (row: number, cell: number, cellValue: any, columnDef: Column, dataContext: any) => {
export const complexObjectFormatter: Formatter = (_row: number, _cell: number, cellValue: any, columnDef: Column, dataContext: any) => {
if (!columnDef) {
return '';
}
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/formatters/decimalFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Column, Formatter, SlickGrid } from './../interfaces/index';
import { formatNumber } from './../services/utilities';
import { getValueFromParamsOrFormatterOptions } from './formatterUtilities';

export const decimalFormatter: Formatter = (row: number, cell: number, value: any, columnDef: Column, dataContext: any, grid: SlickGrid) => {
export const decimalFormatter: Formatter = (_row: number, _cell: number, value: any, columnDef: Column, _dataContext: any, grid: SlickGrid) => {
const isNumber = (value === null || value === undefined || value === '') ? false : !isNaN(+value);
const minDecimal = getValueFromParamsOrFormatterOptions('minDecimal', columnDef, grid, 2);
const maxDecimal = getValueFromParamsOrFormatterOptions('maxDecimal', columnDef, grid, 2);
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/formatters/deleteIconFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Column, Formatter } from './../interfaces/index';
import { Formatter } from './../interfaces/index';

export const deleteIconFormatter: Formatter = (row: number, cell: number, value: any, columnDef: Column, dataContext: any) =>
export const deleteIconFormatter: Formatter = () =>
`<i class="fa fa-trash pointer delete-icon" aria-hidden="true"></i>`;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Column, Formatter, SlickGrid } from './../interfaces/index';
import { formatNumber } from './../services/utilities';
import { getValueFromParamsOrFormatterOptions } from './formatterUtilities';

export const dollarColoredBoldFormatter: Formatter = (row: number, cell: number, value: any, columnDef: Column, dataContext: any, grid: SlickGrid) => {
export const dollarColoredBoldFormatter: Formatter = (_row: number, _cell: number, value: any, columnDef: Column, _dataContext: any, grid: SlickGrid) => {
const isNumber = (value === null || value === undefined || value === '') ? false : !isNaN(+value);
const minDecimal = getValueFromParamsOrFormatterOptions('minDecimal', columnDef, grid, 2);
const maxDecimal = getValueFromParamsOrFormatterOptions('maxDecimal', columnDef, grid, 4);
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/formatters/dollarColoredFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Column, Formatter, SlickGrid } from './../interfaces/index';
import { formatNumber } from './../services/utilities';
import { getValueFromParamsOrFormatterOptions } from './formatterUtilities';

export const dollarColoredFormatter: Formatter = (row: number, cell: number, value: any, columnDef: Column, dataContext: any, grid: SlickGrid) => {
export const dollarColoredFormatter: Formatter = (_row: number, _cell: number, value: any, columnDef: Column, _dataContext: any, grid: SlickGrid) => {
const isNumber = (value === null || value === undefined || value === '') ? false : !isNaN(+value);
const minDecimal = getValueFromParamsOrFormatterOptions('minDecimal', columnDef, grid, 2);
const maxDecimal = getValueFromParamsOrFormatterOptions('maxDecimal', columnDef, grid, 4);
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/formatters/dollarFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Column, Formatter, SlickGrid } from './../interfaces/index';
import { formatNumber } from './../services/utilities';
import { getValueFromParamsOrFormatterOptions } from './formatterUtilities';

export const dollarFormatter: Formatter = (row: number, cell: number, value: any, columnDef: Column, dataContext: any, grid: SlickGrid) => {
export const dollarFormatter: Formatter = (_row: number, _cell: number, value: any, columnDef: Column, _dataContext: any, grid: SlickGrid) => {
const isNumber = (value === null || value === undefined || value === '') ? false : !isNaN(+value);
const minDecimal = getValueFromParamsOrFormatterOptions('minDecimal', columnDef, grid, 2);
const maxDecimal = getValueFromParamsOrFormatterOptions('maxDecimal', columnDef, grid, 4);
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/formatters/editIconFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Column, Formatter } from './../interfaces/index';
import { Formatter } from './../interfaces/index';

export const editIconFormatter: Formatter = (row: number, cell: number, value: any, columnDef: Column, dataContext: any) =>
export const editIconFormatter: Formatter = () =>
`<i class="fa fa-pencil pointer edit-icon" aria-hidden="true"></i>`;
2 changes: 1 addition & 1 deletion packages/common/src/formatters/formatterUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function getValueFromParamsOrFormatterOptions(optionName: string, columnD
export function getAssociatedDateFormatter(fieldType: typeof FieldType[keyof typeof FieldType], defaultSeparator: string): Formatter {
const defaultDateFormat = mapMomentDateFormatWithFieldType(fieldType);

return (row: number, cell: number, value: any, columnDef: Column, dataContext: any, grid: SlickGrid) => {
return (_row: number, _cell: number, value: any, columnDef: Column, _dataContext: any, grid: SlickGrid) => {
const gridOptions = ((grid && typeof grid.getOptions === 'function') ? grid.getOptions() : {}) as GridOption;
const customSeparator = gridOptions?.formatterOptions?.dateSeparator ?? defaultSeparator;
const isParsingAsUtc = columnDef?.params?.parseDateAsUtc ?? false;
Expand Down
Loading

0 comments on commit 4064876

Please sign in to comment.