Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgoli committed Jun 9, 2022
1 parent 653cc42 commit 803c03b
Show file tree
Hide file tree
Showing 24 changed files with 180 additions and 171 deletions.
13 changes: 7 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ module.exports = {
},
},
],
'@typescript-eslint/naming-convention': 'error',
'@typescript-eslint/naming-convention': 'off',
'@typescript-eslint/no-empty-function': 'error',
'@typescript-eslint/no-extra-semi': 'off',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-misused-new': 'error',
'@typescript-eslint/no-unnecessary-qualifier': 'error',
Expand Down Expand Up @@ -68,15 +69,14 @@ module.exports = {
'@typescript-eslint/type-annotation-spacing': 'error',
'@typescript-eslint/unified-signatures': 'error',
'brace-style': ['error', '1tbs'],
'comma-dangle': 'error',
'comma-dangle': 'off',
curly: ['error', 'multi-line'],
'eol-last': 'error',
eqeqeq: ['error', 'smart'],
'id-denylist': [
'error',
'any',
'Number',
'number',
'String',
'string',
'Boolean',
Expand All @@ -91,6 +91,7 @@ module.exports = {
'jsdoc/newline-after-description': 'error',
'new-parens': 'error',
'no-caller': 'error',
'no-case-declarations': 'off',
'no-cond-assign': 'error',
'no-constant-condition': 'error',
'no-control-regex': 'error',
Expand All @@ -106,15 +107,15 @@ module.exports = {
'no-return-await': 'error',
'no-throw-literal': 'error',
'no-trailing-spaces': 'error',
'no-underscore-dangle': 'error',
'no-unused-expressions': 'error',
'no-underscore-dangle': 'off',
'no-unexpected-multiline': 'off',
'no-unused-expressions': 'off',
'no-unused-labels': 'error',
'no-var': 'error',
'one-var': ['error', 'never'],
quotes: 'off',
radix: 'error',
semi: 'off',
'space-before-function-paren': ['error', 'never'],
'space-in-parens': ['error', 'never'],
'spaced-comment': [
'error',
Expand Down
14 changes: 7 additions & 7 deletions src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ export class Cache {
if (what === 'all') {
this.all = value as Date[]
} else {
args!._value = value
args._value = value
this[what].push(args as IterArgs)
}
}

/**
* @return false - not in the cache
* null - cached, but zero occurrences (before/after)
* Date - cached (before/after)
* [] - cached, but zero occurrences (all/between)
* [Date1, DateN] - cached (all/between)
* @return null - cached, but zero occurrences (before/after)
* @return Date - cached (before/after)
* @return [] - cached, but zero occurrences (all/between)
* @return [Date1, DateN] - cached (all/between)
*/
public _cacheGet(
what: CacheKeys | 'all',
Expand All @@ -68,7 +68,7 @@ export class Cache {
const findCacheDiff = function (item: IterArgs) {
for (let i = 0; i < argsKeys.length; i++) {
const key = argsKeys[i]
if (!argsMatch(args![key], item[key])) {
if (!argsMatch(args[key], item[key])) {
return true
}
}
Expand All @@ -92,7 +92,7 @@ export class Cache {
if (!cached && this.all) {
// Not in the cache, but we already know all the occurrences,
// so we can find the correct dates from the cached ones.
const iterResult = new IterResult(what, args!)
const iterResult = new IterResult(what, args)
for (let i = 0; i < (this.all as Date[]).length; i++) {
if (!iterResult.accept((this.all as Date[])[i])) break
}
Expand Down
6 changes: 3 additions & 3 deletions src/datetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class DateTime extends Time {
this.hour += Math.floor((23 - this.hour) / hours) * hours
}

while (true) {
for (;;) {
this.hour += hours
const { div: dayDiv, mod: hourMod } = divmod(this.hour, 24)
if (dayDiv) {
Expand All @@ -169,7 +169,7 @@ export class DateTime extends Time {
Math.floor((1439 - (this.hour * 60 + this.minute)) / minutes) * minutes
}

while (true) {
for (;;) {
this.minute += minutes
const { div: hourDiv, mod: minuteMod } = divmod(this.minute, 60)
if (hourDiv) {
Expand Down Expand Up @@ -202,7 +202,7 @@ export class DateTime extends Time {
) * seconds
}

while (true) {
for (;;) {
this.second += seconds
const { div: minuteDiv, mod: secondMod } = divmod(this.second, 60)
if (minuteDiv) {
Expand Down
1 change: 1 addition & 0 deletions src/dateutil.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-namespace */
import { padStart } from './helpers'
import { Time } from './datetime'

Expand Down
5 changes: 3 additions & 2 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const toArray = function <T>(item: T | T[]): T[] {
export function padStart(
item: string | number,
targetLength: number,
padString: string = ' '
padString = ' '
) {
const str = String(item)
targetLength = targetLength >> 0
Expand Down Expand Up @@ -99,7 +99,7 @@ export const split = function (str: string, sep: string, num: number) {
* @param {number} a The dividend.
* @param {number} b The divisor.
* @return {number} a % b where the result is between 0 and b (either 0 <= x < b
* or b < x <= 0, depending on the sign of b).
* or b < x <= 0, depending on the sign of b).
*/
export const pymod = function (a: number, b: number) {
const r = a % b
Expand All @@ -120,6 +120,7 @@ export const empty = function <T>(obj: T[] | null | undefined) {

/**
* Python-like boolean
*
* @return {Boolean} value of an object/primitive, taking into account
* the fact that in Python an empty list's/tuple's
* boolean value is False, whereas in JS it's true
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*!
/* !
* rrule.js - Library for working with recurrence rules for calendar dates.
* https://github.com/jakubroztocil/rrule
*
Expand Down
20 changes: 10 additions & 10 deletions src/iter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ export function iter<M extends QueryMethodTypes>(
return emitResult(iterResult)
}

let counterDate = DateTime.fromDate(dtstart)
const counterDate = DateTime.fromDate(dtstart)

const ii = new Iterinfo(options)
ii.rebuild(counterDate.year, counterDate.month)

let timeset = makeTimeset(ii, counterDate, options)

while (true) {
let [dayset, start, end] = ii.getdayset(freq)(
for (;;) {
const [dayset, start, end] = ii.getdayset(freq)(
counterDate.year,
counterDate.month,
counterDate.day
)

let filtered = removeFilteredDays(dayset, start, end, ii, options)
const filtered = removeFilteredDays(dayset, start, end, ii, options)

if (notEmpty(bysetpos)) {
const poslist = buildPoslist(bysetpos, timeset!, start, end, ii, dayset)
const poslist = buildPoslist(bysetpos, timeset, start, end, ii, dayset)

for (let j = 0; j < poslist.length; j++) {
const res = poslist[j]
Expand Down Expand Up @@ -67,8 +67,8 @@ export function iter<M extends QueryMethodTypes>(
}

const date = dateutil.fromOrdinal(ii.yearordinal + currentDay)
for (let k = 0; k < timeset!.length; k++) {
const time = timeset![k]
for (let k = 0; k < timeset.length; k++) {
const time = timeset[k]
const res = dateutil.combine(date, time)
if (until && res > until) {
return emitResult(iterResult)
Expand Down Expand Up @@ -131,10 +131,10 @@ function isFiltered(

return (
(notEmpty(bymonth) && !includes(bymonth, ii.mmask[currentDay])) ||
(notEmpty(byweekno) && !ii.wnomask![currentDay]) ||
(notEmpty(byweekno) && !ii.wnomask[currentDay]) ||
(notEmpty(byweekday) && !includes(byweekday, ii.wdaymask[currentDay])) ||
(notEmpty(ii.nwdaymask) && !ii.nwdaymask[currentDay]) ||
(byeaster !== null && !includes(ii.eastermask!, currentDay)) ||
(byeaster !== null && !includes(ii.eastermask, currentDay)) ||
((notEmpty(bymonthday) || notEmpty(bynmonthday)) &&
!includes(bymonthday, ii.mdaymask[currentDay]) &&
!includes(bynmonthday, ii.nmdaymask[currentDay])) ||
Expand Down Expand Up @@ -165,7 +165,7 @@ function removeFilteredDays(
) {
let filtered = false
for (let dayCounter = start; dayCounter < end; dayCounter++) {
let currentDay = dayset[dayCounter] as number
const currentDay = dayset[dayCounter]

filtered = isFiltered(ii, currentDay, options)

Expand Down
2 changes: 1 addition & 1 deletion src/iterinfo/easter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function easter(y: number, offset: number = 0) {
export function easter(y: number, offset = 0) {
const a = y % 19
const b = Math.floor(y / 100)
const c = y % 100
Expand Down
3 changes: 2 additions & 1 deletion src/iterinfo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default class Iterinfo {
public monthinfo: MonthInfo
public eastermask: number[] | null

// eslint-disable-next-line no-empty-function
constructor(private options: ParsedOptions) {}

rebuild(year: number, month: number) {
Expand All @@ -28,7 +29,7 @@ export default class Iterinfo {
}

if (
notEmpty(options.bynweekday!) &&
notEmpty(options.bynweekday) &&
(month !== this.lastmonth || year !== this.lastyear)
) {
const { yearlen, mrange, wdaymask } = this.yearinfo
Expand Down
4 changes: 2 additions & 2 deletions src/iterinfo/monthinfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ export function rebuildMonth(
const first = rang[0]
const last = rang[1] - 1

for (let k = 0; k < options.bynweekday!.length; k++) {
for (let k = 0; k < options.bynweekday.length; k++) {
let i
const [wday, n] = options.bynweekday![k]
const [wday, n] = options.bynweekday[k]
if (n < 0) {
i = last + (n + 1) * 7
i -= pymod(wdaymask[i] - wday, 7)
Expand Down
17 changes: 8 additions & 9 deletions src/iterresult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,23 @@ export default class IterResult<M extends QueryMethodTypes> {

if (method === 'between') {
this.maxDate = args.inc
? args.before!
: new Date(args.before!.getTime() - 1)
this.minDate = args.inc
? args.after!
: new Date(args.after!.getTime() + 1)
? args.before
: new Date(args.before.getTime() - 1)
this.minDate = args.inc ? args.after : new Date(args.after.getTime() + 1)
} else if (method === 'before') {
this.maxDate = args.inc ? args.dt! : new Date(args.dt!.getTime() - 1)
this.maxDate = args.inc ? args.dt : new Date(args.dt.getTime() - 1)
} else if (method === 'after') {
this.minDate = args.inc ? args.dt! : new Date(args.dt!.getTime() + 1)
this.minDate = args.inc ? args.dt : new Date(args.dt.getTime() + 1)
}
}

/**
* Possibly adds a date into the result.
*
* @param {Date} date - the date isn't necessarly added to the result
* list (if it is too late/too early)
* list (if it is too late/too early)
* @return {Boolean} true if it makes sense to continue the iteration
* false if we're done.
* false if we're done.
*/
accept(date: Date) {
++this.total
Expand Down Expand Up @@ -81,6 +79,7 @@ export default class IterResult<M extends QueryMethodTypes> {
/**
* 'before' and 'after' return only one date, whereas 'all'
* and 'between' an array.
*
* @return {Date,Array?}
*/
getValue(): IterResultType<M> {
Expand Down
2 changes: 1 addition & 1 deletion src/iterset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function iterSet<M extends QueryMethodTypes>(
}

if (iterResult.method === 'between') {
evalExdate(iterResult.args.after!, iterResult.args.before!)
evalExdate(iterResult.args.after, iterResult.args.before)
iterResult.accept = function (date) {
const dt = Number(date)
if (!_exdateHash[dt]) {
Expand Down
30 changes: 15 additions & 15 deletions src/nlp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { RRule } from '../rrule'
import { Frequency } from '../types'
import ENGLISH, { Language } from './i18n'

/*!
/* !
* rrule.js - Library for working with recurrence rules for calendar dates.
* https://github.com/jakubroztocil/rrule
*
Expand Down Expand Up @@ -35,13 +35,13 @@ import ENGLISH, { Language } from './i18n'
* RULES
*
* Every ([n])
* day(s)
* | [weekday], ..., (and) [weekday]
* | weekday(s)
* | week(s)
* | month(s)
* | [month], ..., (and) [month]
* | year(s)
* day(s)
* | [weekday], ..., (and) [weekday]
* | weekday(s)
* | week(s)
* | month(s)
* | [month], ..., (and) [month]
* | year(s)
*
*
* Plus 0, 1, or multiple of these:
Expand All @@ -67,10 +67,10 @@ import ENGLISH, { Language } from './i18n'
* Definitely no supported for parsing:
*
* (for year):
* in week(s) [n], ..., (and) [n]
* in week(s) [n], ..., (and) [n]
*
* on the [yearday], ..., (and) [n] day of the year
* on day [yearday], ..., (and) [n]
* on the [yearday], ..., (and) [n] day of the year
* on day [yearday], ..., (and) [n]
*
*
* NON-TERMINALS
Expand All @@ -81,10 +81,10 @@ import ENGLISH, { Language } from './i18n'
* [nth-weekday]: first [weekday], 2nd [weekday], ... last [weekday], ...
* [monthday]: first, 1., 2., 1st, 2nd, second, ... 31st, last day, 2nd last day, ..
* [date]:
* [month] (0-31(,) ([year])),
* (the) 0-31.(1-12.([year])),
* (the) 0-31/(1-12/([year])),
* [weekday]
* - [month] (0-31(,) ([year])),
* - (the) 0-31.(1-12.([year])),
* - (the) 0-31/(1-12/([year])),
* - [weekday]
*
* [year]: 0000, 0001, ... 01, 02, ..
*
Expand Down
Loading

0 comments on commit 803c03b

Please sign in to comment.