Skip to content

Commit

Permalink
style: lints + typos
Browse files Browse the repository at this point in the history
  • Loading branch information
AlansCodeLog committed Dec 16, 2024
1 parent 3b39a72 commit 83c26a7
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/Lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export interface TokenCategoryType<
TTokens extends RealTokenType<$T, any>[] = RealTokenType<$T, any>[],
> extends BaseTokenType<TC> {
isCategory: true
entries: Partial<{[ key in TTokens[number]["type"]]: TTokens[number] }>
entries: Partial<Record<TTokens[number]["type"], TTokens[number]>>
// entries: Partial<Record<TTokens[number]["type"], TTokens[number]>>
}

Expand Down Expand Up @@ -181,10 +181,10 @@ export class Lexer {

branches: {[key in keyof typeof MODE]?: TokenType<$T>[] }

opts: FullParserOptions<{}>
opts: FullParserOptions<any>

constructor(
opts: Partial<FullParserOptions<{}>> = {},
opts: Partial<FullParserOptions<any>> = {},
) {
this.opts = parseParserOptions(opts)
checkParserOpts(this.opts)
Expand Down
2 changes: 1 addition & 1 deletion src/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const tokenVariable = [TOKEN_TYPE.BACKTICK, TOKEN_TYPE.DOUBLEQUOTE, TOKEN_TYPE.S
/**
* Creates the main parser class which handles all functionality (evaluation, validation, etc).
*/
export class Parser<T extends {} = {}> {
export class Parser<T = any> {
// needed for evaluate and validate so they are only checked on demand
private evaluationOptionsChecked: boolean = false

Expand Down
2 changes: 1 addition & 1 deletion src/ast/builders/delim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function delim<
{
left: TLeft extends string ? true : TLeft
right: TRight extends string ? true : TRight
} & TType extends undefined ? {} : { type: TType } {
} & TType extends undefined ? Record<string,never> : { type: TType } {
let quoteType
if (typeof left === "string") quoteType = type(left)
else if (typeof right === "string") quoteType = type(right)
Expand Down
6 changes: 3 additions & 3 deletions src/ast/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ export function condition(
node.sep = {}
if (sepL) {
node.sep.left = sepL
node.property ||= error(sepL.start, [TOKEN_TYPE.VALUE])
node.propertyOperator ||= error(sepL?.end ?? sepR?.start, [TOKEN_TYPE.VALUE])
node.property ??= error(sepL.start, [TOKEN_TYPE.VALUE])
node.propertyOperator ??= error(sepL?.end ?? sepR?.start, [TOKEN_TYPE.VALUE])
}
if (sepR) node.sep.right = sepR
else if (!node.value || node.value.type === AST_TYPE.VARIABLE) {
node.sep.right = error(node.value?.start ?? end, [TOKEN_TYPE.OP_EXPANDED_SEP])
}
} else if (propertyOperator) {
node.property ||= error(propertyOperator.start, [TOKEN_TYPE.VALUE])
node.property ??= error(propertyOperator.start, [TOKEN_TYPE.VALUE])
}
return createConditionNode(node as ConditionNode)
}
Expand Down
6 changes: 3 additions & 3 deletions src/internal/checkParserOpts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ERROR_CODES } from "../types/errors.js"
import type { FullParserOptions, ParserOptions } from "../types/parser.js"

/** @internal */
export function checkParserOpts<T extends {}>(opts: FullParserOptions<T>, evaluatorChecks: boolean = false, validatorChecks: boolean = false): void {
export function checkParserOpts<T>(opts: FullParserOptions<T>, evaluatorChecks: boolean = false, validatorChecks: boolean = false): void {
if (!evaluatorChecks) {
const keywordsList = [...opts.keywords.and, ...opts.keywords.or, ...opts.keywords.not].map(keyword => keyword.value)
const symNots = opts.keywords.not.filter(op => op.isSymbol).map(op => op.value)
Expand Down Expand Up @@ -48,8 +48,8 @@ export function checkParserOpts<T extends {}>(opts: FullParserOptions<T>, evalua
`prefixableStrings cannot contain blank entries`,
)
}
for (const key of ["and", "or", "not"]) {
const invalid = opts.keywords[key as keyof FullParserOptions["keywords"]]
for (const key of ["and", "or", "not"] as const) {
const invalid = opts.keywords[key]
?.find(_ => isBlank(_.value))
?.value
if (invalid !== undefined) {
Expand Down
4 changes: 2 additions & 2 deletions src/internal/parseParserOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { defaultValueComparer } from "../defaults/defaultValueComparer.js"
import type { FullParserOptions, ParserOptions } from "../types/parser.js"

/** @internal */
export function parseParserOptions<T extends {} = {}>(
export function parseParserOptions<T>(
options: ParserOptions<T>,
): FullParserOptions<T> {
const opts: ParserOptions = {
const opts: ParserOptions<T> = {
prefixApplier: defaultPrefixApplier,
keyParser: defaultKeyParser,
valueComparer: defaultValueComparer,
Expand Down
12 changes: 6 additions & 6 deletions src/types/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ArrayNode, ConditionNode, NormalizedCondition, Position, TOKEN_TYP


// #partially-synced
export type FullParserOptions<T extends {} = {}> = MakeRequired<
export type FullParserOptions<T = any> = MakeRequired<
ParserOptions<T>,
// makes required all except:
Exclude<keyof ParserOptions<T>,
Expand All @@ -18,7 +18,7 @@ export type FullParserOptions<T extends {} = {}> = MakeRequired<
// overrides
keywords: DeepRequired<KeywordOptions>
}
export type ParserOptions<T extends {} = {}> = {
export type ParserOptions<T = any> = {
/**
* Allows any conditions (i.e. a variable or negated variable) to precede groups and append themselves to all variables inside them. Regular use of groups for changing precedence (e.g. `(a || b) && c` ) or negating expressions `!(a || b)` is still supported even if `prefixableGroups` is false.
*
Expand Down Expand Up @@ -116,7 +116,7 @@ export type ParserOptions<T extends {} = {}> = {
/**
* Enables regex strings as values. The value is treated as if it was quoted by forward slashes. Any repetition of lowercase characters (even if there are multiple) attached to the end are assumed to be flags and added as a single token to the value's `quotes.mode` property.
*
* Can be passed a custom function to determine when to use the regex value or not (it is converted to a regular value). The function is passed the property, the operator, and whether it's an expanded operator. If their is an error token for the property or operator, an empty string is passed.
* Can be passed a custom function to determine when to use the regex value or not (it is converted to a regular value). The function is passed the property, the operator, and whether it's an expanded operator. If there is an error token for the property or operator, an empty string is passed.
*
* ```ts
* // allow anything (`prop=/val/`, `prop:op:/val`, `prop=(/val/)`, `prop:op(/val/)`) but the value alone (`/regex/`)
Expand Down Expand Up @@ -272,7 +272,7 @@ export type ParserOptions<T extends {} = {}> = {
* ```ts
* type Operators = "contains"
* function valueComparer(condition: Omit<Condition, "negate">, contextValue: any, context: any): boolean {
* switch (operator as Operators) {
* switch (condition.operator as Operators) {
* case "contains": return (contextValue as string[]).includes(condition.value as string)
* // ...
* }
Expand Down Expand Up @@ -307,13 +307,13 @@ export type ParserOptions<T extends {} = {}> = {
* if (prefix) {
* const val = value as string // it's always a string if prefixed
* switch (prefix as RawPrefixes) {
* case "num": finalValue = parseInt(val, 2); break
* case "num": finalValue = parseInt(val, 10); break
* // ...
* }
* }
* // another way to allow special unquoted value types is something like this:
* if (typeof value === "string" && !isQuoted) {
* const asNum = parseInt(value, 2)
* const asNum = parseInt(value, 10)
* if (!isNaN(asNum)) finalValue = asNum
* if (["true","false"].includes(value)) {
* finalValue = value === "true" ? true : false
Expand Down
2 changes: 1 addition & 1 deletion src/utils/getCursorInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function getCursorInfo(
}
}
if (token.start >= index) {
info.next ||= token
info.next ??= token
if (token.valid && !info.valid.next) {
info.valid.next = token
break
Expand Down
1 change: 1 addition & 0 deletions tests/db/useDb.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { readMigrationFiles } from "drizzle-orm/migrator"
import path from "path"
import url from "url"
// eslint-disable-next-line @typescript-eslint/naming-convention
const __dirname = url.fileURLToPath(new URL(".", import.meta.url))

const tests = path.resolve(__dirname)
Expand Down

0 comments on commit 83c26a7

Please sign in to comment.