Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/mpsuesser/effect-oxlint/llms.txt

Use this file to discover all available pages before exploring further.

The Token module provides boolean predicates and accessors for working with oxlint Token nodes. Tokens are the lexical units that oxlint’s parser emits — keywords, identifiers, punctuators, string literals, and more. Two predicates (isKeyword and isPunctuator) support the dual API pattern, which lets you use them both data-first and data-last for pipe composition.

Dual API predicates

Token.isKeyword

Returns true if the token is a keyword with the given value.
export const isKeyword: {
  (keyword: string): (token: Token) => boolean;
  (token: Token, keyword: string): boolean;
}
Both call styles are equivalent:
// Data-first
Token.isKeyword(token, 'const')   // true if keyword "const"
Token.isKeyword(token, 'return')  // true if keyword "return"

// Data-last (pipe-friendly)
pipe(token, Token.isKeyword('const'))
Arr.filter(tokens, Token.isKeyword('return'))
keyword
string
required
The keyword string to match against token.value (e.g., "const", "return", "async").
token
Token
required
An oxlint Token node.
boolean
boolean
true when token.type === "Keyword" and token.value === keyword.

Token.isPunctuator

Returns true if the token is a punctuator with the given value.
export const isPunctuator: {
  (value: string): (token: Token) => boolean;
  (token: Token, value: string): boolean;
}
// Data-first
Token.isPunctuator(token, '{')   // true if punctuator "{"
Token.isPunctuator(token, ';')   // true if punctuator ";"

// Data-last (pipe-friendly)
pipe(token, Token.isPunctuator('=>'))
Arr.filter(tokens, Token.isPunctuator(','))
value
string
required
The punctuator string to match against token.value (e.g., "{", ";", "=>").
token
Token
required
An oxlint Token node.
boolean
boolean
true when token.type === "Punctuator" and token.value === value.

Simple predicates

These predicates take only a Token and return a boolean. They do not support the dual API.

Token.isIdentifier

export const isIdentifier = (token: Token): boolean
true when token.type === "Identifier".

Token.isString

export const isString = (token: Token): boolean
true when token.type === "String".

Token.isNumeric

export const isNumeric = (token: Token): boolean
true when token.type === "Numeric".

Token.isBoolean

export const isBoolean = (token: Token): boolean
true when token.type === "Boolean".

Token.isNull

export const isNull = (token: Token): boolean
true when token.type === "Null".

Token.isTemplate

export const isTemplate = (token: Token): boolean
true when token.type === "Template". Matches template literal parts (`, ${, }).

Token.isRegularExpression

export const isRegularExpression = (token: Token): boolean
true when token.type === "RegularExpression".

Token.isPrivateIdentifier

export const isPrivateIdentifier = (token: Token): boolean
true when token.type === "PrivateIdentifier". Matches class private fields such as #foo.

Accessors

Token.value

Returns the string value of a token.
export const value = (token: Token): string
token
Token
required
An oxlint Token node.
string
string
The raw token.value string (e.g., "const", "{", "hello").

Token.type

Returns the type discriminant of a token.
export const type = (token: Token): string
token
Token
required
An oxlint Token node.
string
string
One of "Keyword", "Identifier", "Punctuator", "String", "Numeric", "Boolean", "Null", "Template", "RegularExpression", or "PrivateIdentifier".

Usage example

The following rule checks that every const declaration is immediately followed by a semicolon, using SourceCode.getTokens to walk the tokens of a node:
import { Token, Rule, RuleContext, Diagnostic, SourceCode } from 'effect-oxlint'
import * as Arr from 'effect/Array'
import * as Effect from 'effect/Effect'

const requireSemiAfterConst = Rule.define({
  name: 'require-semi-after-const',
  meta: Rule.meta({ type: 'layout', description: 'Require semicolon after const' }),
  create: function* () {
    const ctx = yield* RuleContext;
    return {
      VariableDeclaration: (node) =>
        Effect.gen(function* () {
          const tokens = yield* SourceCode.getTokens(node)
          const hasConst = Arr.some(tokens, Token.isKeyword('const'))
          const hasSemi = Arr.some(tokens, Token.isPunctuator(';'))
          if (hasConst && !hasSemi) {
            yield* ctx.report(
              Diagnostic.make({ node, message: 'Missing semicolon after const declaration' })
            )
          }
        })
    };
  }
})
Token.isKeyword and Token.isPunctuator both use the dual combinator from effect/Function. When called with one argument they return a curried predicate, making them directly usable as Arr.filter callbacks.

Build docs developers (and LLMs) love