Skip to content

Commit

Permalink
formatting fix
Browse files Browse the repository at this point in the history
  • Loading branch information
absorbb committed Feb 12, 2024
1 parent 4252697 commit 3ec04af
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 44 deletions.
22 changes: 8 additions & 14 deletions libs/jsondiffpatch/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
module.exports = {
root: true,
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended-type-checked',
],
plugins: ['@typescript-eslint'],
parser: '@typescript-eslint/parser',
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended-type-checked"],
plugins: ["@typescript-eslint"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: true,
tsconfigRootDir: __dirname,
},
overrides: [
{
files: ['test/**/*.ts'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended-type-checked',
],
plugins: ['@typescript-eslint'],
parser: '@typescript-eslint/parser',
files: ["test/**/*.ts"],
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended-type-checked"],
plugins: ["@typescript-eslint"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: './test/tsconfig.json',
project: "./test/tsconfig.json",
tsconfigRootDir: __dirname,
},
},
Expand Down
14 changes: 7 additions & 7 deletions libs/jsondiffpatch/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
extensionsToTreatAsEsm: ['.ts'],
preset: "ts-jest",
testEnvironment: "node",
extensionsToTreatAsEsm: [".ts"],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
"^(\\.{1,2}/.*)\\.js$": "$1",
},
transform: {
'^.+\\.ts$': [
'ts-jest',
"^.+\\.ts$": [
"ts-jest",
{
tsconfig: 'test/tsconfig.json',
tsconfig: "test/tsconfig.json",
useESM: true,
},
],
Expand Down
4 changes: 2 additions & 2 deletions libs/jsondiffpatch/src/contexts/context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Options } from '../types.js';
import type { Options } from "../types.js";

export default abstract class Context<TResult> {
abstract pipe: string;
Expand Down Expand Up @@ -27,7 +27,7 @@ export default abstract class Context<TResult> {

push(child: this, name?: string | number) {
child.parent = this;
if (typeof name !== 'undefined') {
if (typeof name !== "undefined") {
child.childName = name;
}
child.root = this.root || this;
Expand Down
8 changes: 4 additions & 4 deletions libs/jsondiffpatch/src/contexts/patch.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import Context from './context.js';
import type { Delta } from '../types.js';
import Context from "./context.js";
import type { Delta } from "../types.js";

class PatchContext extends Context<unknown> {
left: unknown;
delta: Delta;
pipe: 'patch';
pipe: "patch";

nested?: boolean;

constructor(left: unknown, delta: Delta) {
super();
this.left = left;
this.delta = delta;
this.pipe = 'patch';
this.pipe = "patch";
}
}

Expand Down
10 changes: 4 additions & 6 deletions libs/jsondiffpatch/src/filters/dates.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type { Filter } from '../types.js';
import type DiffContext from '../contexts/diff.js';
import type { Filter } from "../types.js";
import type DiffContext from "../contexts/diff.js";

export const diffFilter: Filter<DiffContext> = function datesDiffFilter(
context,
) {
export const diffFilter: Filter<DiffContext> = function datesDiffFilter(context) {
if (context.left instanceof Date) {
if (context.right instanceof Date) {
if (context.left.getTime() !== context.right.getTime()) {
Expand All @@ -19,4 +17,4 @@ export const diffFilter: Filter<DiffContext> = function datesDiffFilter(
context.setResult([context.left, context.right]).exit();
}
};
diffFilter.filterName = 'dates';
diffFilter.filterName = "dates";
20 changes: 9 additions & 11 deletions libs/jsondiffpatch/src/pipe.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type Context from './contexts/context.js';
import type Processor from './processor.js';
import type { Filter } from './types.js';
import type Context from "./contexts/context.js";
import type Processor from "./processor.js";
import type { Filter } from "./types.js";

// eslint-disable-next-line @typescript-eslint/no-explicit-any
class Pipe<TContext extends Context<any>> {
Expand All @@ -17,7 +17,7 @@ class Pipe<TContext extends Context<any>> {

process(input: TContext) {
if (!this.processor) {
throw new Error('add this pipe to a processor before using it');
throw new Error("add this pipe to a processor before using it");
}
const debug = this.debug;
const length = this.filters.length;
Expand All @@ -28,7 +28,7 @@ class Pipe<TContext extends Context<any>> {
this.log(`filter: ${filter.filterName}`);
}
filter(context);
if (typeof context === 'object' && context.exiting) {
if (typeof context === "object" && context.exiting) {
context.exiting = false;
break;
}
Expand All @@ -54,7 +54,7 @@ class Pipe<TContext extends Context<any>> {

indexOf(filterName: string) {
if (!filterName) {
throw new Error('a filter name is required');
throw new Error("a filter name is required");
}
for (let index = 0; index < this.filters.length; index++) {
const filter = this.filters[index];
Expand All @@ -66,7 +66,7 @@ class Pipe<TContext extends Context<any>> {
}

list() {
return this.filters.map((f) => f.filterName);
return this.filters.map(f => f.filterName);
}

after(filterName: string, ...params: Filter<TContext>[]) {
Expand Down Expand Up @@ -106,12 +106,10 @@ class Pipe<TContext extends Context<any>> {
if (this.resultCheck) {
return;
}
this.resultCheck = (context) => {
this.resultCheck = context => {
if (!context.hasResult) {
console.log(context);
const error: Error & { noResult?: boolean } = new Error(
`${this.name} failed`,
);
const error: Error & { noResult?: boolean } = new Error(`${this.name} failed`);
error.noResult = true;
throw error;
}
Expand Down

0 comments on commit 3ec04af

Please sign in to comment.