Skip to content

Commit

Permalink
Fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbengtsson committed Apr 26, 2020
1 parent 2dec725 commit c4d3bbc
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 24 deletions.
13 changes: 4 additions & 9 deletions src/autoTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@ import { DocHandler, jsPDFDocument } from './documentHandler'
import { parseInput } from './inputParser'
import { calculateWidths } from './widthCalculator'
import { drawTable } from './tableDrawer'
import { ColumnOption, RowInput, UserOptions } from './config'
import { UserOptions } from './config'

// First definition is deprecated
export function autoTable(
columns: ColumnOption[],
data: RowInput[],
options: UserOptions
): jsPDFDocument
export function autoTable(options: UserOptions): jsPDFDocument
export function autoTable(this: jsPDFDocument) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function autoTable(this: jsPDFDocument, ...args: any) {
const doc = new DocHandler(this)

let win: Window | undefined
Expand All @@ -20,7 +15,7 @@ export function autoTable(this: jsPDFDocument) {
}

// 1. Parse and unify user input
const table = parseInput(arguments, doc, win)
const table = parseInput(args, doc, win)

// 2. Calculate preliminary table, column, row and cell dimensions
calculateWidths(table, doc)
Expand Down
1 change: 0 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { CellHookData } from './HookData'
import { CellHook, PageHook } from './models'

/**
Expand Down
3 changes: 3 additions & 0 deletions src/documentHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import { Color, Styles, UserOptions } from './config'

let globalDefaults: UserOptions = {}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type jsPDFConstructor = any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type jsPDFDocument = any

type Opts = { [key: string]: string | number }

export class DocHandler {
Expand Down
2 changes: 1 addition & 1 deletion src/htmlParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function parseHtml(
): { head: RowInput[]; body: RowInput[]; foot: RowInput[] } {
let tableElement: HTMLTableElement
if (typeof input === 'string') {
tableElement = <HTMLTableElement>window.document.querySelector(input)
tableElement = window.document.querySelector(input) as HTMLTableElement
} else {
tableElement = input
}
Expand Down
1 change: 1 addition & 0 deletions src/inputValidator.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { DocHandler } from './documentHandler'
import { HookData } from './HookData'
import { UserOptions } from './config'
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function applyPlugin(jsPDF: jsPDFConstructor) {
export type autoTable = (options: UserOptions) => void

try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const jsPDF = require('jspdf')
applyPlugin(jsPDF)
} catch (error) {
Expand Down
6 changes: 0 additions & 6 deletions src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ import { marginOrPadding, MarginPadding } from './common'
export type PageHook = (data: HookData) => void | boolean
export type CellHook = (data: CellHookData) => void | boolean

export type HookProp =
| 'didParseCell'
| 'willDrawCell'
| 'didDrawCell'
| 'didDrawPage'

export interface HookProps {
didParseCell: CellHook[]
willDrawCell: CellHook[]
Expand Down
5 changes: 2 additions & 3 deletions src/polyfills.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/*
* Include common small polyfills instead of requiring the user to to do it
*/
/* eslint-disable @typescript-eslint/no-unused-vars */

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
export function assign<T, U, V, W, X>(
Expand All @@ -15,6 +13,7 @@ export function assign<T, U, V, W, X>(
}
const to = Object(target)
for (let index = 1; index < arguments.length; index++) {
// eslint-disable-next-line prefer-rest-params
const nextSource = arguments[index]

if (nextSource != null) {
Expand Down
2 changes: 1 addition & 1 deletion src/tableDrawer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DocHandler } from './documentHandler'
import { assign } from './polyfills'
import autoTableText from './autoTableText'

export function drawTable(table: Table, doc: DocHandler) {
export function drawTable(table: Table, doc: DocHandler): void {
const settings = table.settings
const startY = settings.startY
const margin = settings.margin
Expand Down
2 changes: 1 addition & 1 deletion src/widthCalculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ function fitContent(table: Table, doc: DocHandler) {
}
}

function ellipsize(
export function ellipsize(
text: string[],
width: number,
styles: Styles,
Expand Down
4 changes: 2 additions & 2 deletions test/testCommon.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const assert = require('assert')
import { ellipsize } from '../src/common'
import { ellipsize } from '../src/widthCalculator'
import { DocHandler } from '../src/documentHandler'

describe('common', () => {
describe('ellipsize', () => {
let doc: any, jsPDF
before(() => {
jsPDF = require('./common').loadJspdf()
Expand Down
11 changes: 11 additions & 0 deletions test/testInitializer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { autoTable } from '../src/main'

const assert = require('assert')
import { loadJspdf } from './common'

Expand All @@ -8,8 +10,17 @@ describe('execution', () => {
require('../src/main')
})

it('types', () => {
const doc = new jsPDF()
;((doc as any).autoTable as autoTable)({
body: [['test']],
})
assert(true)
})

it('init', () => {
const autoTable = new jsPDF().autoTable
new jsPDF().autoTable({})
assert.equal(typeof autoTable, 'function')
})

Expand Down

0 comments on commit c4d3bbc

Please sign in to comment.