Skip to content

Commit

Permalink
js checking with typescript compilers
Browse files Browse the repository at this point in the history
  • Loading branch information
arshaw committed Jan 19, 2019
1 parent cc68659 commit 0ea41cb
Show file tree
Hide file tree
Showing 20 changed files with 151 additions and 76 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
"copyright": "2019 Adam Shaw",
"main": "main.js",
"devDependencies": {
"@types/jasmine": "^3.3.7",
"@types/jasmine-jquery": "^1.5.33",
"@types/jquery": "^3.3.29",
"@types/luxon": "^1.4.1",
"bootstrap": "^3.4.0",
"chokidar": "^2.0.4",
Expand Down
6 changes: 3 additions & 3 deletions src/core/Calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ export default class Calendar {
// -----------------------------------------------------------------------------------------------------------------


formatDate(d: Date, formatter): string {
formatDate(d: DateInput, formatter): string {
const { dateEnv } = this
return dateEnv.format(
dateEnv.createMarker(d),
Expand All @@ -788,7 +788,7 @@ export default class Calendar {


// `settings` is for formatter AND isEndExclusive
formatRange(d0: Date, d1: Date, settings) {
formatRange(d0: DateInput, d1: DateInput, settings) {
const { dateEnv } = this
return dateEnv.formatRange(
dateEnv.createMarker(d0),
Expand All @@ -799,7 +799,7 @@ export default class Calendar {
}


formatIso(d: Date, omitTime?: boolean) {
formatIso(d: DateInput, omitTime?: boolean) {
const { dateEnv } = this
return dateEnv.formatIso(dateEnv.createMarker(d), { omitTime })
}
Expand Down
10 changes: 6 additions & 4 deletions src/core/datelib/duration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { isInt } from '../util/misc'

export interface DurationInput {
export type DurationInput = DurationObjectInput | string | number

export interface DurationObjectInput {
years?: number
year?: number
months?: number
Expand Down Expand Up @@ -33,7 +35,7 @@ const PARSE_RE = /^(-?)(?:(\d+)\.)?(\d+):(\d\d)(?::(\d\d)(?:\.(\d\d\d))?)?/

// Parsing and Creation

export function createDuration(input, unit?: string): Duration | null {
export function createDuration(input: DurationInput, unit?: string): Duration | null {
if (typeof input === 'string') {
return parseString(input)
} else if (typeof input === 'object' && input) { // non-null object
Expand Down Expand Up @@ -64,7 +66,7 @@ function parseString(s: string): Duration {
return null
}

function normalizeObject(obj: DurationInput): Duration {
function normalizeObject(obj: DurationObjectInput): Duration {
return {
years: obj.years || obj.year || 0,
months: obj.months || obj.month || 0,
Expand All @@ -79,7 +81,7 @@ function normalizeObject(obj: DurationInput): Duration {
}
}

export function getWeeksFromInput(obj: DurationInput) {
export function getWeeksFromInput(obj: DurationObjectInput) {
return obj.weeks || obj.week || 0
}

Expand Down
11 changes: 8 additions & 3 deletions src/core/types/input-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ export interface OptionsInputBase {
selectMirror?: boolean
unselectAuto?: boolean
unselectCancel?: string
defaultAllDayEventDuration?: DurationInput
defaultTimedEventDuration?: DurationInput
cmdFormatter?: string
defaultRangeSeparator?: string

selectConstraint?: ConstraintInput
selectOverlap?: boolean | OverlapFunc
Expand Down Expand Up @@ -181,7 +185,7 @@ export interface OptionsInputBase {
eventClick?(arg: { el: HTMLElement, event: EventApi, jsEvent: MouseEvent, view: View }): boolean | void
eventMouseEnter?(arg: { el: HTMLElement, event: EventApi, jsEvent: MouseEvent, view: View }): void
eventMouseLeave?(arg: { el: HTMLElement, event: EventApi, jsEvent: MouseEvent, view: View }): void
select?(arg: { start: Date, end: Date, allDay: boolean, resource: any, jsEvent: MouseEvent, view: View }): void // resource for Scheduler
select?(arg: { start: Date, end: Date, startStr: string, endStr: string, allDay: boolean, resource: any, jsEvent: MouseEvent, view: View }): void // resource for Scheduler
unselect?(arg: { view: View, jsEvent: Event }): void
eventDataTransform?: EventInputTransformer
loading?(isLoading: boolean, view: View): void
Expand All @@ -195,8 +199,9 @@ export interface OptionsInputBase {
eventResizeStart?(arg: { el: HTMLElement, event: EventApi, jsEvent: MouseEvent, view: View }): void
eventResizeStop?(arg: { el: HTMLElement, event: EventApi, jsEvent: MouseEvent, view: View }): void
eventResize?(arg: { el: HTMLElement, event: EventApi, delta: Duration, revert: () => void, jsEvent: Event, view: View }): void
drop?(arg: { date: Date, allDay: boolean, draggedEl: HTMLElement, jsEvent: MouseEvent, view: View }): void
drop?(arg: { date: Date, dateStr: string, allDay: boolean, draggedEl: HTMLElement, jsEvent: MouseEvent, view: View }): void
eventReceive?(arg: { event: EventApi, draggedEl: HTMLElement, view: View }): void
eventLeave?(arg: { draggedEl: HTMLElement, event: EventApi, view: View }): void
}

export interface ViewOptionsInput extends OptionsInputBase {
Expand All @@ -207,5 +212,5 @@ export interface ViewOptionsInput extends OptionsInputBase {
export interface OptionsInput extends OptionsInputBase {
buttonText?: ButtonTextCompoundInput
views?: { [viewId: string]: ViewOptionsInput }
plugins: PluginDef[]
plugins?: PluginDef[]
}
21 changes: 1 addition & 20 deletions tasks/lint.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const gulp = require('gulp')
const shell = require('gulp-shell')
const eslint = require('gulp-eslint')
const tslint = require('gulp-tslint')
const tslintLib = require('tslint')
Expand Down Expand Up @@ -64,25 +63,7 @@ gulp.task('lint:js:tests', function() {
.pipe(
eslint({
configFile: 'eslint.json',
envs: [ 'browser', 'jasmine', 'jquery' ],
globals: [
'FullCalendar',
'moment',
'karmaConfig',
'pushOptions',
'describeOptions',
'describeTimeZones',
'describeValues',
'pit',
'getCurrentOptions',
'initCalendar',
'currentCalendar',
'spyOnMethod',
'spyOnCalendarCallback',
'spyCall',
'oneCall',
'XHRMock'
]
envs: [ 'browser', 'jasmine', 'jquery' ]
})
)
.pipe(eslint.format())
Expand Down
1 change: 1 addition & 0 deletions tests/automated/date-selection/implicit-unselect.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

describe('implicit unselection', function() {
pushOptions({
defaultView: 'month',
Expand Down
8 changes: 4 additions & 4 deletions tests/automated/datelib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function formatPrettyTimeZoneOffset(date) {
return 'GMT' + sign + hours + (mins ? ':' + pad(mins) : '')
}

function pad(n) {
function pad(n) { // always pads for 2 digits
return n < 10 ? '0' + n : '' + n
}

Expand All @@ -28,9 +28,9 @@ export function formatIsoDay(date) {
}

export function formatIsoTime(date) {
return pad(date.getUTCHours(), 2) + ':' +
pad(date.getUTCMinutes(), 2) + ':' +
pad(date.getUTCSeconds(), 2)
return pad(date.getUTCHours()) + ':' +
pad(date.getUTCMinutes()) + ':' +
pad(date.getUTCSeconds())
}

export function formatIsoWithoutTz(date) {
Expand Down
4 changes: 0 additions & 4 deletions tests/automated/event-render/EventRenderUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ export function getFirstEventEl() {
return getEventEls().first()
}

export function getLastEventEl() {
return getEventEls().last()
}

export function getEventElTitleEl(eventEl) {
return eventEl.find(`.${TITLE_CLASS}`)
}
Expand Down
52 changes: 52 additions & 0 deletions tests/automated/globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

// for when you need to change types of vars in JS, to make checks pass:
// https://github.com/Microsoft/TypeScript/wiki/Type-Checking-JavaScript-Files

declare let karmaConfig: any
declare let initCalendar: any
declare let pushOptions: any
declare let getCurrentOptions: any
declare let currentCalendar: any
declare let describeOptions: any
declare let describeValues: any
declare let describeTimeZones: any
declare let spyOnCalendarCallback: any
declare let spyOnMethod: any
declare let spyCall: any
declare let oneCall: any

declare let XHRMock: any

interface Function {
calls: any // for jasmine spies
}

interface JQueryStatic {
simulate: any
simulateMouseClick: any
simulateTouchClick: any
simulateByPoint: any
_data: any
}

interface JQuery {
simulate: any
draggable: any
sortable: any
}

declare namespace jasmine {

interface Matchers<T> {
toEqualDate: any
toEqualNow: any
toBeBoundedBy: any
toIntersectWith: any
toBeAbove: any
toBeBelow: any
toBeRightOf: any
toBeLeftOf: any
toHaveScrollbars: any
}

}

0 comments on commit 0ea41cb

Please sign in to comment.