Skip to content

Commit

Permalink
refactor: apply airbnb eslint style
Browse files Browse the repository at this point in the history
  • Loading branch information
sgratzl committed Mar 2, 2021
1 parent c7f0fab commit 4587403
Show file tree
Hide file tree
Showing 29 changed files with 887 additions and 673 deletions.
23 changes: 18 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
/* eslint-env node */

// eslint-disable-next-line @typescript-eslint/no-var-requires
const pkg = require('./package.json');

module.exports = {
plugins: ['@typescript-eslint', 'prettier'],
extends: ['react-app', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended', 'prettier'],
extends: [
'airbnb-typescript',
'react-app',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
'prettier',
],
parserOptions: {
project: './tsconfig.eslint.json',
},
settings: {
react: {
version: '99.99.99',
version: pkg.devDependencies.react ? 'detect' : '99.99.99',
},
},
rules: {
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'no-continue': 'off',
// '@typescript-eslint/explicit-module-boundary-types': 'off',
// '@typescript-eslint/no-explicit-any': 'off',
// '@typescript-eslint/no-non-null-assertion': 'off',
},
};
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
node-version: '14.x'
- run: npm i -g yarn
- run: yarn set version berry
# - run: cat .yarnrc_patch.yml >> .yarnrc.yml
- run: cat .yarnrc_patch.yml >> .yarnrc.yml
- run: yarn config set checksumBehavior ignore
- name: Cache Node.js modules
uses: actions/[email protected]
Expand Down
4 changes: 4 additions & 0 deletions .yarnrc_patch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
packageExtensions:
eslint-module-utils@*:
dependencies:
eslint-import-resolver-node: '*'
17 changes: 11 additions & 6 deletions demo/cell.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
/* eslint-disable class-methods-use-this */
import { uniformContext } from '../src';
import { ACellRenderer, ICellContext } from '../src/cell/ACellRenderer';
import '../src/style.scss';

/** @internal */
export default class CellRenderer extends ACellRenderer {
protected readonly _context: ICellContext;
protected readonly privateContext: ICellContext;

constructor(root: HTMLElement, id: string, numberOfRows = 128, numberOfColumns = 128) {
super(root);
// eslint-disable-next-line no-param-reassign
root.id = id;

this._context = {
this.privateContext = {
col: uniformContext(numberOfColumns, 50),
row: uniformContext(numberOfRows, 50),
};
}

run() {
//wait till layouted
run(): void {
// wait till layouted
setTimeout(super.init.bind(this), 100);
}

protected get context() {
return this._context;
protected get context(): ICellContext {
return this.privateContext;
}

protected createCell(doc: Document, row: number, col: number): HTMLElement {
Expand All @@ -32,6 +34,7 @@ export default class CellRenderer extends ACellRenderer {
}

protected updateCell(node: HTMLElement, row: number, col: number): HTMLElement | void {
// eslint-disable-next-line no-param-reassign
node.textContent = `${row}/${col}`;
}

Expand All @@ -42,6 +45,7 @@ export default class CellRenderer extends ACellRenderer {
}

protected updateRowHeader(node: HTMLElement, row: number): HTMLElement | void {
// eslint-disable-next-line no-param-reassign
node.textContent = `#${row}`;
}

Expand All @@ -52,6 +56,7 @@ export default class CellRenderer extends ACellRenderer {
}

protected updateColumnHeader(node: HTMLElement, col: number): HTMLElement | void {
// eslint-disable-next-line no-param-reassign
node.textContent = `#${col}`;
}
}
6 changes: 4 additions & 2 deletions demo/column.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { IColumn } from '../src';
import '../src/style.scss';
import { CSS_CLASS_FROZEN } from '../src/styles';

/** @internal */
export class Column<T> implements IColumn {
export default class Column<T> implements IColumn {
constructor(
public readonly index: number,
public readonly name: string,
public readonly frozen: boolean = false,
public readonly width = 100
) {}

get id() {
get id(): string {
return `col${this.index}`;
}

Expand All @@ -35,6 +36,7 @@ export class Column<T> implements IColumn {
}

update(node: HTMLElement, row: T) {
// eslint-disable-next-line no-param-reassign
node.textContent = `${this.name}@${row.toString()}`;
return node;
}
Expand Down
50 changes: 25 additions & 25 deletions demo/index.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
/* eslint-disable class-methods-use-this */
import { ACellRenderer, ICellRenderContext, PrefetchMixin, uniformContext } from '../src';
import { Column } from './column';
import Column from './column';

/** @internal */
export default class TestRenderer extends ACellRenderer<Column<number>> {
protected readonly _context: ICellRenderContext<Column<number>>;
protected readonly privateContext: ICellRenderContext<Column<number>>;

constructor(root: HTMLElement, id: string, numberOfRows = 1000, numberOfColumns = 20) {
super(root, `#${id}`, { mixins: [PrefetchMixin], striped: true });
// eslint-disable-next-line no-param-reassign
root.id = id;

const defaultRowHeight = 20;

const columns: Column<number>[] = [];
for (let i = 0; i < numberOfColumns; ++i) {
for (let i = 0; i < numberOfColumns; i += 1) {
columns.push(new Column(i, i.toString(36), i === 0 || i === 2));
}
this._context = Object.assign(
{
columns,
column: uniformContext(columns.length, 100),
},
uniformContext(numberOfRows, defaultRowHeight)
);
this.privateContext = {
columns,
column: uniformContext(columns.length, 100),
...uniformContext(numberOfRows, defaultRowHeight),
};
}

protected createHeader(document: Document, column: Column<number>) {
return column.header(document);
protected createHeader(doc: Document, column: Column<number>): HTMLElement {
return column.header(doc);
}

protected updateHeader() {
protected updateHeader(): void {
// nothing do to
}

protected createCell(document: Document, index: number, column: Column<number>) {
return column.cell(index, document);
protected createCell(doc: Document, index: number, column: Column<number>): HTMLElement {
return column.cell(index, doc);
}

protected updateCell(node: HTMLElement, index: number, column: Column<number>) {
protected updateCell(node: HTMLElement, index: number, column: Column<number>): HTMLElement {
return column.update(node, index);
}

run() {
//wait till layouted
run(): void {
// wait till layouted
setTimeout(super.init.bind(this), 100);
}

protected get context() {
return this._context;
protected get context(): ICellRenderContext<Column<number>> {
return this.privateContext;
}

protected updateRow(node: HTMLElement, index: number) {
//return abortAble(resolveIn(2000)).then(() => {
super.updateRow(node, index);
//});
}
// protected updateRow(node: HTMLElement, index: number) {
// // return abortAble(resolveIn(2000)).then(() => {
// super.updateRow(node, index);
// // });
// }
}
50 changes: 25 additions & 25 deletions demo/table.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
/* eslint-disable class-methods-use-this */
import { ICellRenderContext, uniformContext, ACellTableSection } from '../src';
import { Column } from './column';
import Column from './column';
import MultiTableRowRenderer from '../src/table/MultiTableRowRenderer';

/** @internal */
export class TestRenderer extends ACellTableSection<Column<number>> {
protected _context: ICellRenderContext<Column<number>>;
protected privateContext: ICellRenderContext<Column<number>>;

id: string;

build(id: string, numberOfColumns = 15, numberOfRows = 1000, defaultRowHeight = 20) {
build(id: string, numberOfColumns = 15, numberOfRows = 1000, defaultRowHeight = 20): this {
this.id = id;
const columns: Column<number>[] = [];
for (let i = 0; i < numberOfColumns; ++i) {
columns.push(new Column(i, `${id}${i.toString(36)}`, false)); //i === 0));
for (let i = 0; i < numberOfColumns; i += 1) {
columns.push(new Column(i, `${id}${i.toString(36)}`, false)); // i === 0));
}
this._context = Object.assign(
{
columns,
column: uniformContext(columns.length, 100),
},
uniformContext(numberOfRows, defaultRowHeight)
);
this.privateContext = {
columns,
column: uniformContext(columns.length, 100),
...uniformContext(numberOfRows, defaultRowHeight),
};
return this;
}

protected createHeader(document: Document, column: Column<number>) {
protected createHeader(document: Document, column: Column<number>): HTMLElement {
return column.header(document);
}

protected updateHeader() {
protected updateHeader(): void {
// nothing do to
}

protected createCell(document: Document, index: number, column: Column<number>) {
protected createCell(document: Document, index: number, column: Column<number>): HTMLElement {
return column.cell(index, document);
}

protected updateCell(node: HTMLElement, index: number, column: Column<number>) {
protected updateCell(node: HTMLElement, index: number, column: Column<number>): HTMLElement {
return column.update(node, index);
}

protected get context() {
return this._context;
protected get context(): ICellRenderContext<Column<number>> {
return this.privateContext;
}

protected updateRow(node: HTMLElement, index: number) {
//return abortAble(resolveIn(2000)).then(() => {
super.updateRow(node, index);
//});
}
// protected updateRow(node: HTMLElement, index: number) {
// // return abortAble(resolveIn(2000)).then(() => {
// super.updateRow(node, index);
// // });
// }
}

export default function run(node: HTMLElement, id: string) {
const table = new MultiTableRowRenderer(node, id);
export default function run(node: HTMLElement, rootId: string): void {
const table = new MultiTableRowRenderer(node, rootId);

table.pushTable((header, body, id, style) => new TestRenderer(header, body, id, style).build('a'));
table.pushTable((header, body, id, style) => new TestRenderer(header, body, id, style).build('b'));
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"@yarnpkg/pnpify": "^2.4.0",
"css-loader": "^5.0.2",
"eslint": "^7.20.0",
"eslint-config-airbnb-typescript": "^12.3.1",
"eslint-config-prettier": "^8.1.0",
"eslint-config-react-app": "^6.0.0",
"eslint-plugin-flowtype": "^5.3.1",
Expand Down
Loading

0 comments on commit 4587403

Please sign in to comment.