Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .eslintrc.js

This file was deleted.

11 changes: 11 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineConfig } from 'eslint/config';
import { configs } from '@croct/eslint-plugin';

export default defineConfig(
configs.typescript,
{
rules: {
'@typescript-eslint/unbound-method': 'off',
}
}
);
4,607 changes: 2,686 additions & 1,921 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
"build": "tsc -p tsconfig.build.json"
},
"devDependencies": {
"@croct/eslint-plugin": "^0.7.0",
"@croct/eslint-plugin": "^0.8.3",
"@swc/jest": "^0.2.24",
"@types/jest": "^29.0.0",
"@typescript-eslint/parser": "^8.0.0",
"eslint": "^8.57.1",
"@typescript-eslint/parser": "^8.54.0",
"eslint": "^9.39.2",
"jest": "^29.0.0",
"jest-extended": "^4.0.0",
"ts-node": "^10.8.2",
Expand Down
2 changes: 1 addition & 1 deletion src/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {SourceLocation} from './location';
import type {SourceLocation} from './location';

export class JsonError extends Error {
public constructor(message: string) {
Expand Down
11 changes: 6 additions & 5 deletions src/lexer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable max-len -- Long regex patterns */
import {JsonToken, JsonTokenType} from './token';
import {SourcePosition} from './location';
import type {JsonToken} from './token';
import {JsonTokenType} from './token';
import type {SourcePosition} from './location';
import {identifierRegex} from './identifier';
import {JsonParseError} from './error';

type TokenPattern = {
type: JsonTokenType,
pattern: RegExp|string,
pattern: RegExp | string,
};

export class JsonLexer implements Iterable<JsonToken> {
Expand Down Expand Up @@ -62,6 +62,7 @@ export class JsonLexer implements Iterable<JsonToken> {
},
{
type: JsonTokenType.NUMBER,
// eslint-disable-next-line @stylistic/max-len -- Regex cannot be separated.
pattern: /^[-+]?((?:NaN|Infinity)(?![$_\u200C\u200D\p{ID_Continue}])|0[xX][\da-fA-F]+|(?:(?:0|[1-9]\d*)(?:\.\d*)?|\.\d*)(?:[eE][+-]?\d+)?)/u,
},
{
Expand All @@ -80,7 +81,7 @@ export class JsonLexer implements Iterable<JsonToken> {

private remaining: string;

private current: JsonToken|null = null;
private current: JsonToken | null = null;

public constructor(source: string) {
this.remaining = source;
Expand Down
3 changes: 2 additions & 1 deletion src/manipulator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {JsonTokenType} from './token';
import {JsonNode, JsonTokenNode, JsonValueNode} from './node';
import type {JsonNode} from './node';
import {JsonTokenNode, JsonValueNode} from './node';

export type NodeMatcher = (node: JsonNode) => boolean;

Expand Down
22 changes: 11 additions & 11 deletions src/node/arrayNode.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {JsonArray, JsonValue} from '@croct/json';
import {JsonValueNode} from './valueNode';
import type {JsonArray, JsonValue} from '@croct/json';
import type {JsonValueNode} from './valueNode';
import {JsonStructureNode, StructureDelimiter} from './structureNode';
import {JsonCompositeDefinition, JsonCompositeNode, PartialJsonCompositeDefinition} from './compositeNode';
import type {JsonCompositeDefinition, JsonCompositeNode, PartialJsonCompositeDefinition} from './compositeNode';
import {JsonValueFactory} from './factory';
import {JsonError} from '../error';

Expand All @@ -18,11 +18,11 @@ export class JsonArrayNode extends JsonStructureNode implements JsonArrayDefinit
this.elementNodes = [...definition.elements];
}

public static of(...elements: ReadonlyArray<JsonValue|JsonValueNode>): JsonArrayNode {
public static of(...elements: ReadonlyArray<JsonValue | JsonValueNode>): JsonArrayNode {
return new JsonArrayNode({elements: elements.map(JsonValueFactory.create)});
}

public update(other: JsonValueNode|JsonValue): JsonValueNode {
public update(other: JsonValueNode | JsonValue): JsonValueNode {
if (!(other instanceof JsonArrayNode) && !Array.isArray(other)) {
return JsonValueFactory.create(other);
}
Expand Down Expand Up @@ -75,7 +75,7 @@ export class JsonArrayNode extends JsonStructureNode implements JsonArrayDefinit
return element;
}

public set(index: number, element: JsonValue|JsonValueNode): void {
public set(index: number, element: JsonValue | JsonValueNode): void {
if (index < 0 || index >= this.elementNodes.length) {
throw new Error(`Index ${index} is out of bounds.`);
}
Expand All @@ -95,23 +95,23 @@ export class JsonArrayNode extends JsonStructureNode implements JsonArrayDefinit
this.splice(index, 1);
}

public unshift(...elements: Array<JsonValue|JsonValueNode>): void {
public unshift(...elements: Array<JsonValue | JsonValueNode>): void {
this.elementNodes.unshift(...elements.map(JsonValueFactory.create));
}

public push(...elements: Array<JsonValue|JsonValueNode>): void {
public push(...elements: Array<JsonValue | JsonValueNode>): void {
this.elementNodes.push(...elements.map(JsonValueFactory.create));
}

public shift(): JsonValueNode|undefined {
public shift(): JsonValueNode | undefined {
return this.elementNodes.shift();
}

public pop(): JsonValueNode|undefined {
public pop(): JsonValueNode | undefined {
return this.elementNodes.pop();
}

public splice(start: number, deleteCount: number, ...elements: Array<JsonValue|JsonValueNode>): JsonValueNode[] {
public splice(start: number, deleteCount: number, ...elements: Array<JsonValue | JsonValueNode>): JsonValueNode[] {
return this.elementNodes.splice(start, deleteCount, ...elements.map(JsonValueFactory.create));
}

Expand Down
5 changes: 3 additions & 2 deletions src/node/compositeNode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {JsonNode, JsonNodeDefinition} from './node';
import {Formatting} from '../formatting';
import type {JsonNodeDefinition} from './node';
import {JsonNode} from './node';
import type {Formatting} from '../formatting';

export interface JsonCompositeDefinition extends JsonNodeDefinition {
readonly children: JsonNode[];
Expand Down
30 changes: 12 additions & 18 deletions src/node/factory.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import type {JsonArray, JsonObject, JsonPrimitive, JsonValue} from '@croct/json';
import {JsonArrayNode} from './arrayNode';
import {JsonObjectNode} from './objectNode';
import {
type JsonBooleanNode,
type JsonNullNode,
type JsonNumberNode,
type JsonStringNode,
JsonPrimitiveNode,
} from './primitiveNode';
import type {JsonArrayNode} from './arrayNode';
import type {JsonObjectNode} from './objectNode';
import type {JsonPrimitiveNode, JsonBooleanNode, JsonNullNode, JsonNumberNode, JsonStringNode} from './primitiveNode';
import {JsonValueNode} from './valueNode';

export namespace JsonValueFactory {
Expand All @@ -23,16 +17,16 @@ export namespace JsonValueFactory {
factories[type] = factory;
}

export function create(value: JsonArray|JsonArrayNode): JsonArrayNode;
export function create(value: JsonObject|JsonObjectNode): JsonObjectNode;
export function create(value: string|JsonStringNode): JsonStringNode;
export function create(value: number|JsonNumberNode): JsonNumberNode;
export function create(value: boolean|JsonBooleanNode): JsonBooleanNode;
export function create(value: null|JsonNullNode): JsonNullNode;
export function create(value: JsonPrimitive|JsonPrimitiveNode): JsonPrimitiveNode;
export function create(value: JsonValue|JsonValueNode): JsonValueNode;
export function create(value: JsonArray | JsonArrayNode): JsonArrayNode;
export function create(value: JsonObject | JsonObjectNode): JsonObjectNode;
export function create(value: string | JsonStringNode): JsonStringNode;
export function create(value: number | JsonNumberNode): JsonNumberNode;
export function create(value: boolean | JsonBooleanNode): JsonBooleanNode;
export function create(value: null | JsonNullNode): JsonNullNode;
export function create(value: JsonPrimitive | JsonPrimitiveNode): JsonPrimitiveNode;
export function create(value: JsonValue | JsonValueNode): JsonValueNode;

export function create(value: JsonValue|JsonValueNode): JsonValueNode {
export function create(value: JsonValue | JsonValueNode): JsonValueNode {
if (value instanceof JsonValueNode) {
return value;
}
Expand Down
8 changes: 4 additions & 4 deletions src/node/identifierNode.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {JsonValue} from '@croct/json';
import {JsonNode} from './node';
import type {JsonValue} from '@croct/json';
import type {JsonNode} from './node';
import {JsonValueNode} from './valueNode';
import {JsonCompositeDefinition, PartialJsonCompositeDefinition} from './compositeNode';
import type {JsonCompositeDefinition, PartialJsonCompositeDefinition} from './compositeNode';
import {NodeManipulator} from '../manipulator';
import {JsonTokenNode} from './tokenNode';
import {JsonTokenType} from '../token';
Expand Down Expand Up @@ -35,7 +35,7 @@ export class JsonIdentifierNode extends JsonValueNode implements JsonIdentifierD
});
}

public update(other: JsonValueNode|JsonValue): JsonValueNode {
public update(other: JsonValueNode | JsonValue): JsonValueNode {
const node = JsonValueFactory.create(other);

if (!this.isEquivalent(node)) {
Expand Down
2 changes: 1 addition & 1 deletion src/node/node.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {SourceLocation} from '../location';
import {Formatting} from '../formatting';
import type {Formatting} from '../formatting';

export interface JsonNodeDefinition {
readonly location: SourceLocation;
Expand Down
17 changes: 9 additions & 8 deletions src/node/objectNode.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {JsonObject, JsonValue} from '@croct/json';
import type {JsonObject, JsonValue} from '@croct/json';
import {JsonValueNode} from './valueNode';
import {JsonNode} from './node';
import type {JsonNode} from './node';
import {JsonStructureNode, StructureDelimiter} from './structureNode';
import {JsonPropertyNode} from './propertyNode';
import {JsonCompositeDefinition, JsonCompositeNode, PartialJsonCompositeDefinition} from './compositeNode';
import {JsonPrimitiveNode, JsonStringNode} from './primitiveNode';
import type {JsonCompositeDefinition, JsonCompositeNode, PartialJsonCompositeDefinition} from './compositeNode';
import type {JsonStringNode} from './primitiveNode';
import {JsonPrimitiveNode} from './primitiveNode';
import {JsonValueFactory} from './factory';
import {JsonIdentifierNode} from './identifierNode';
import type {JsonIdentifierNode} from './identifierNode';
import {JsonError} from '../error';
import {NodeMatcher} from '../manipulator';
import {JsonTokenNode} from './tokenNode';
Expand All @@ -29,7 +30,7 @@ export class JsonObjectNode extends JsonStructureNode implements JsonCompositeDe
this.propertyNodes = [...definition.properties];
}

public static of(properties: Record<string, JsonValueNode|JsonValue>): JsonObjectNode {
public static of(properties: Record<string, JsonValueNode | JsonValue>): JsonObjectNode {
return new JsonObjectNode({
properties: Object.entries(properties).map(
([key, value]) => new JsonPropertyNode({
Expand Down Expand Up @@ -199,7 +200,7 @@ export class JsonObjectNode extends JsonStructureNode implements JsonCompositeDe
return [startIndex, endIndex];
}

public update(other: JsonValueNode|JsonValue): JsonValueNode {
public update(other: JsonValueNode | JsonValue): JsonValueNode {
if (!(other instanceof JsonValueNode)) {
if (typeof other !== 'object' || other === null || Array.isArray(other)) {
return JsonValueFactory.create(other);
Expand Down Expand Up @@ -281,7 +282,7 @@ export class JsonObjectNode extends JsonStructureNode implements JsonCompositeDe
return [...this.propertyNodes];
}

public set(name: string|JsonStringNode|JsonIdentifierNode, value: JsonValue|JsonValueNode): void {
public set(name: string | JsonStringNode | JsonIdentifierNode, value: JsonValue | JsonValueNode): void {
const normalizedName = typeof name === 'string' ? name : name.toJSON();
const index = this.propertyNodes.findIndex(current => current.key.toJSON() === normalizedName);

Expand Down
15 changes: 8 additions & 7 deletions src/node/primitiveNode.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {JsonPrimitive, JsonValue} from '@croct/json';
import {JsonNode} from './node';
import type {JsonPrimitive, JsonValue} from '@croct/json';
import type {JsonNode} from './node';
import {JsonValueNode} from './valueNode';
import {JsonCompositeDefinition, PartialJsonCompositeDefinition} from './compositeNode';
import type {JsonCompositeDefinition, PartialJsonCompositeDefinition} from './compositeNode';
import {NodeManipulator} from '../manipulator';
import {JsonTokenNode} from './tokenNode';
import {JsonPrimitiveTokenType, JsonPrimitiveValue, JsonTokenType} from '../token';
import type {JsonPrimitiveTokenType, JsonPrimitiveValue} from '../token';
import {JsonTokenType} from '../token';
import {JsonValueFactory} from './factory';
import {Formatting} from '../formatting';
import type {Formatting} from '../formatting';

export interface JsonPrimitiveDefinition<T extends JsonPrimitiveTokenType> extends JsonCompositeDefinition {
readonly token: JsonTokenNode<T>;
Expand Down Expand Up @@ -44,7 +45,7 @@ export class JsonPrimitiveNode<T extends JsonPrimitiveTokenType = JsonPrimitiveT

public static of(value: JsonPrimitiveNode): JsonPrimitiveNode;

public static of(value: JsonPrimitive|JsonPrimitiveNode): JsonPrimitiveNode {
public static of(value: JsonPrimitive | JsonPrimitiveNode): JsonPrimitiveNode {
return JsonValueFactory.create(value);
}

Expand All @@ -58,7 +59,7 @@ export class JsonPrimitiveNode<T extends JsonPrimitiveTokenType = JsonPrimitiveT
});
}

public update(other: JsonValueNode|JsonValue): JsonValueNode {
public update(other: JsonValueNode | JsonValue): JsonValueNode {
const node = JsonValueFactory.create(other);

if (!this.isEquivalent(node)) {
Expand Down
14 changes: 8 additions & 6 deletions src/node/propertyNode.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import {JsonValue} from '@croct/json';
import {JsonValueNode} from './valueNode';
import {JsonNode} from './node';
import type {JsonValue} from '@croct/json';
import type {JsonValueNode} from './valueNode';
import type {JsonNode} from './node';
import {JsonTokenNode} from './tokenNode';
import {JsonTokenType} from '../token';
import {JsonCompositeDefinition, JsonCompositeNode, PartialJsonCompositeDefinition} from './compositeNode';
import type {JsonCompositeDefinition, PartialJsonCompositeDefinition} from './compositeNode';
import {JsonCompositeNode} from './compositeNode';
import {NodeManipulator} from '../manipulator';
import {JsonValueFactory} from './factory';
import {JsonIdentifierNode} from './identifierNode';
import {isIdentifier} from '../identifier';
import {JsonPrimitiveNode, JsonStringNode} from './primitiveNode';
import {Formatting} from '../formatting';
import type {JsonStringNode} from './primitiveNode';
import {JsonPrimitiveNode} from './primitiveNode';
import type {Formatting} from '../formatting';

export interface JsonPropertyDefinition extends JsonCompositeDefinition {
readonly key: JsonStringNode | JsonIdentifierNode;
Expand Down
7 changes: 4 additions & 3 deletions src/node/structureNode.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {JsonValueNode} from './valueNode';
import {JsonNode} from './node';
import type {JsonNode} from './node';
import {JsonTokenType} from '../token';
import {JsonTokenDefinition, JsonTokenNode} from './tokenNode';
import type {JsonTokenDefinition} from './tokenNode';
import {JsonTokenNode} from './tokenNode';
import {NodeManipulator, NodeMatcher} from '../manipulator';
import {JsonCompositeNode} from './compositeNode';
import {JsonPropertyNode} from './propertyNode';
Expand All @@ -10,7 +11,7 @@ import WHITESPACE = NodeMatcher.WHITESPACE;
import NEWLINE = NodeMatcher.NEWLINE;
import SPACE = NodeMatcher.SPACE;
import INSIGNIFICANT = NodeMatcher.INSIGNIFICANT;
import {BlockFormatting, Formatting} from '../formatting';
import type {BlockFormatting, Formatting} from '../formatting';

type DescendantNode = {
depth: number,
Expand Down
6 changes: 4 additions & 2 deletions src/node/tokenNode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {JsonToken, JsonTokenType} from '../token';
import {JsonNode, JsonNodeDefinition, PartialJsonNodeDefinition} from './node';
import type {JsonTokenType} from '../token';
import {JsonToken} from '../token';
import type {JsonNodeDefinition, PartialJsonNodeDefinition} from './node';
import {JsonNode} from './node';

export interface JsonTokenDefinition<T extends JsonTokenType = JsonTokenType> extends JsonNodeDefinition, JsonToken<T> {
}
Expand Down
4 changes: 2 additions & 2 deletions src/node/valueNode.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {JsonValue} from '@croct/json';
import type {JsonValue} from '@croct/json';
import {JsonCompositeNode} from './compositeNode';
import {JsonError} from '../error';

export abstract class JsonValueNode extends JsonCompositeNode {
public abstract update(other: JsonValueNode|JsonValue): JsonValueNode;
public abstract update(other: JsonValueNode | JsonValue): JsonValueNode;

public abstract clone(): JsonValueNode;

Expand Down
Loading
Loading