Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linting #518

Merged
merged 6 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
coverage/
webpack.config.js
.eslintrc.js
27 changes: 18 additions & 9 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 All @@ -56,7 +57,7 @@ module.exports = {
avoidEscape: true,
},
],
'@typescript-eslint/semi': ['error', 'never'],
'@typescript-eslint/semi': 'off',
'@typescript-eslint/triple-slash-reference': [
'error',
{
Expand All @@ -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: 'error',
quotes: 'off',
radix: 'error',
semi: 'error',
'space-before-function-paren': ['error', 'always'],
semi: 'off',
'space-in-parens': ['error', 'never'],
'spaced-comment': [
'error',
Expand All @@ -125,4 +126,12 @@ module.exports = {
],
'use-isnan': 'error',
},
overrides: [
{
files: ['*.test.*'],
rules: {
'@typescript-eslint/no-unused-expressions': 'off',
},
},
],
}
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
"url": "git://github.com/jakubroztocil/rrule.git"
},
"scripts": {
"build": "yarn lint && yarn format-check && tsc && webpack && tsc dist/esm/**/*.d.ts",
"lint": "yarn eslint --ext .ts,.js --fix --config .eslintrc.js",
"prebuild": "yarn clean",
"build": "yarn lint && yarn format-check && tsc -b tsconfig.build.json && webpack && tsc dist/esm/**/*.d.ts",
"clean": "rm -rf dist/",
"lint": "yarn eslint . --fix --config .eslintrc.js",
"format": "yarn prettier --write .",
"format-check": "yarn prettier --check .",
"run-ts": "TS_NODE_PROJECT=tsconfig.test.json node --loader ts-node/esm",
"run-ts": "TS_NODE_PROJECT=tsconfig.json node --loader ts-node/esm",
"test": "yarn run-ts ./node_modules/.bin/mocha **/*.test.ts",
"test-ci": "yarn run-ts ./node_modules/.bin/nyc yarn run-ts ./node_modules/.bin/mocha **/*.test.ts"
},
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: 0 additions & 5 deletions src/fake-luxon.ts

This file was deleted.

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