Skip to content

Commit a6bb852

Browse files
committed
fix(chrono): lint errors
1 parent a458b0e commit a6bb852

27 files changed

+180
-191
lines changed

packages/chrono/.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist

packages/chrono/.eslintrc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"root": true,
3+
"extends": "@index-san/eslint-config/ts"
4+
}

packages/chrono/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"scripts": {
77
"test": "vitest",
88
"build": "tsup",
9+
"lint": "eslint . --ext .ts,.js --max-warnings 0",
910
"play": "tsx ./playground/PlayApp.ts"
1011
},
1112
"devDependencies": {

packages/chrono/playground/PlayApp.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import ChronoApp from "../src/ChronoApp";
2-
import PlayDrive from "./PlayDrive";
3-
import PlayHash from "./PlayHash";
1+
import ChronoApp from '../src/ChronoApp'
2+
import PlayDrive from './PlayDrive'
3+
import PlayHash from './PlayHash'
44

5-
const drive = new PlayDrive();
6-
const hash = new PlayHash();
5+
const drive = new PlayDrive()
6+
const hash = new PlayHash()
77

8-
const app = new ChronoApp(drive, hash);
8+
const app = new ChronoApp(drive, hash)
99

1010
// app.init()
1111

12-
app.objectService.hashAndSaveFile('message.md')
12+
app.objectService.hashAndSaveFile('message.md')
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import IDrive from "../src/gateways/IDrive";
2-
import path from "path";
3-
import fs from "fs/promises";
1+
import IDrive from '../src/gateways/IDrive'
2+
import path from 'path'
3+
import fs from 'fs/promises'
44

55
export default class PlayDrive implements IDrive {
66
public basePath = path.resolve(__dirname, '.data')
@@ -12,20 +12,21 @@ export default class PlayDrive implements IDrive {
1212
public async read(path: string) {
1313
return await fs.readFile(this.resolve(path))
1414
}
15-
16-
public write (path: string, content: Uint8Array) {
15+
16+
public write(path: string, content: Uint8Array) {
1717
return fs.writeFile(this.resolve(path), content)
1818
}
1919

2020
public async mkdir(path: string) {
2121
await fs.mkdir(this.resolve(path), {
22-
recursive: true
22+
recursive: true,
2323
})
2424
}
2525

2626
public async exists(path: string) {
27-
return fs.stat(this.resolve(path))
27+
return fs
28+
.stat(this.resolve(path))
2829
.then(() => true)
2930
.catch(() => false)
3031
}
31-
}
32+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import IHash from "../src/gateways/IHash";
1+
import IHash from '../src/gateways/IHash'
22
import crypto from 'crypto'
33

44
export default class PlayHash implements IHash {
55
public async hash(content: Uint8Array): Promise<string> {
66
const hash = crypto.createHash('sha1')
7-
7+
88
hash.update(content)
9-
9+
1010
return hash.digest('hex')
1111
}
12-
}
12+
}

packages/chrono/src/ChronoApp.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import IDrive from "./gateways/IDrive";
2-
import IHash from "./gateways/IHash";
3-
import ObjectRepositoryImpl from "./repositories/ObjectRepositoryImpl";
4-
import ObjectService from "./services/ObjectService";
5-
import HashFileUseCase from "./use-cases/HashFileUseCase";
6-
import InitUseCase from "./use-cases/InitUseCase";
1+
import IDrive from './gateways/IDrive'
2+
import IHash from './gateways/IHash'
3+
import ObjectRepositoryImpl from './repositories/ObjectRepositoryImpl'
4+
import ObjectService from './services/ObjectService'
5+
import HashFileUseCase from './use-cases/HashFileUseCase'
6+
import InitUseCase from './use-cases/InitUseCase'
77

88
export default class ChronoApp {
99
constructor(
@@ -28,4 +28,4 @@ export default class ChronoApp {
2828

2929
await useCase.execute({ path })
3030
}
31-
}
31+
}
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import IDrive from "../gateways/IDrive";
1+
import IDrive from '../gateways/IDrive'
22

33
interface InMemoryEntry {
44
type: 'file' | 'directory'
@@ -7,7 +7,6 @@ interface InMemoryEntry {
77
}
88

99
export default class InMemoryDrive implements IDrive {
10-
1110
public entries: InMemoryEntry[] = []
1211

1312
public resolve(...args: string[]) {
@@ -19,11 +18,11 @@ export default class InMemoryDrive implements IDrive {
1918
}
2019

2120
public async exists(path: string): Promise<boolean> {
22-
return !!this.entries.find(entry => entry.path === path)
21+
return !!this.entries.find((entry) => entry.path === path)
2322
}
2423

2524
public async read(path: string): Promise<Uint8Array | null> {
26-
const entry = this.entries.find(entry => entry.path === path)
25+
const entry = this.entries.find((entry) => entry.path === path)
2726

2827
if (!entry) {
2928
return null
@@ -33,25 +32,24 @@ export default class InMemoryDrive implements IDrive {
3332
}
3433

3534
public async write(path: string, content: Uint8Array): Promise<void> {
36-
const entry = this.entries.find(entry => entry.path === path)
35+
const entry = this.entries.find((entry) => entry.path === path)
3736

3837
if (entry) {
3938
entry.content = content
4039
return
4140
}
42-
41+
4342
this.entries.push({
4443
type: 'file',
4544
path,
46-
content
45+
content,
4746
})
4847
}
4948

5049
public async mkdir(path: string): Promise<void> {
5150
this.entries.push({
5251
type: 'directory',
53-
path
52+
path,
5453
})
5554
}
56-
57-
}
55+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import IHash from "../gateways/IHash";
1+
import IHash from '../gateways/IHash'
22
import crypto from 'crypto'
33

44
export default class InMemoryHash implements IHash {
55
public async hash(content: Uint8Array): Promise<string> {
66
const hash = crypto.createHash('sha1')
7-
7+
88
hash.update(content)
9-
9+
1010
return hash.digest('hex')
1111
}
12-
}
12+
}

packages/chrono/src/__tests__/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ describe('chrono', () => {
44
it('should work', () => {
55
expect(true).toBe(true)
66
})
7-
})
7+
})
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
1-
import { describe, test, expect } from 'vitest';
2-
import ChronoObject from './ChronoObject';
1+
import { describe, test, expect } from 'vitest'
2+
import ChronoObject from './ChronoObject'
33

44
describe('ChronoObject', () => {
5-
65
test('should throw an error if type is missing', () => {
76
const fileContent = `blob_name: 123\nsize: 3\n`
87
const bytes = new TextEncoder().encode(fileContent)
9-
8+
109
expect(() => ChronoObject.fromBytes(bytes)).toThrow('Missing type')
11-
});
10+
})
1211

1312
test('should transform bytes in CronoObject', async () => {
14-
1513
const fileContent = `type: file\nblob_name: 123\nsize: 3\n`
1614
const bytes = new TextEncoder().encode(fileContent)
17-
15+
1816
const chronoObject = ChronoObject.fromBytes(bytes)
19-
17+
2018
expect(chronoObject).toEqual({
2119
blobName: '123',
2220
size: '3',
2321
type: 'file',
2422
})
25-
});
23+
})
2624
})
Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
const decoder = new TextDecoder('utf-8');
2-
const encoder = new TextEncoder();
3-
import camelCase from "lodash/camelCase";
4-
import snakeCase from "lodash/snakeCase";
5-
import HelperService from "../services/HelperService";
1+
import camelCase from 'lodash/camelCase'
2+
import snakeCase from 'lodash/snakeCase'
3+
import HelperService from '../services/HelperService'
64

75
export default class ChronoObject {
86
public type: string;
9-
[key: string]: any;
7+
[key: string]: any
108

119
constructor(data?: Partial<ChronoObject>) {
1210
Object.assign(this, data)
@@ -16,38 +14,37 @@ export default class ChronoObject {
1614
}
1715
}
1816

19-
public toString(){
17+
public toString() {
2018
const result = Object.entries(this)
2119
.map(([key, value]) => `${snakeCase(key)}: ${value}`)
22-
.join('\n')
20+
.join('\n')
2321

2422
return result + '\n'
2523
}
2624

27-
public toBytes(){
25+
public toBytes() {
2826
return HelperService.encode(this.toString())
2927
}
3028

3129
public static parseContentString(content: string) {
32-
const lines = content.split('\n').filter(line => line.length)
30+
const lines = content.split('\n').filter((line) => line.length)
3331

3432
const entries = lines
35-
.map(line => line.split(':'))
33+
.map((line) => line.split(':'))
3634
.map(([key, value]) => [camelCase(key), value.trim()])
3735

3836
return Object.fromEntries(entries)
3937
}
4038

41-
4239
public static fromString(content: string) {
4340
const data = ChronoObject.parseContentString(content)
44-
41+
4542
return new ChronoObject(data)
4643
}
47-
44+
4845
public static fromBytes(bytes: Uint8Array) {
49-
const content = decoder.decode(bytes);
46+
const content = HelperService.decode(bytes)
5047

5148
return ChronoObject.fromString(content)
5249
}
53-
}
50+
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
export default class BaseException extends Error {
22
constructor(message: string, data?: any) {
3-
super(message);
3+
super(message)
44

5-
this.message = message;
6-
this.name = this.constructor.name;
5+
this.message = message
6+
this.name = this.constructor.name
77

88
if (data) {
9-
Object.assign(this, data);
9+
Object.assign(this, data)
1010
}
1111
}
12-
}
12+
}

packages/chrono/src/gateways/IDrive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ export default interface IDrive {
44
write: (path: string, content: Uint8Array) => Promise<void>
55
mkdir: (path: string) => Promise<void>
66
exists: (path: string) => Promise<boolean>
7-
}
7+
}

packages/chrono/src/gateways/IHash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export default interface IHash {
22
hash: (content: Uint8Array) => Promise<string>
3-
}
3+
}

packages/chrono/src/repositories/BlobRepositoryImpl.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import IDrive from "../gateways/IDrive";
2-
import IHash from "../gateways/IHash";
3-
import IBlobRepository from "./IBlobRepository";
1+
import IDrive from '../gateways/IDrive'
2+
import IHash from '../gateways/IHash'
3+
import IBlobRepository from './IBlobRepository'
44

55
export default class BlobRepositoryImpl implements IBlobRepository {
66
constructor(
@@ -17,7 +17,7 @@ export default class BlobRepositoryImpl implements IBlobRepository {
1717
const folderPath = this.drive.resolve('.chrono', 'blobs', startHash)
1818
const filePath = this.drive.resolve(folderPath, endHash)
1919

20-
if (!await this.drive.exists(folderPath)) {
20+
if (!(await this.drive.exists(folderPath))) {
2121
await this.drive.mkdir(folderPath)
2222
}
2323

@@ -33,7 +33,7 @@ export default class BlobRepositoryImpl implements IBlobRepository {
3333
const folderPath = this.drive.resolve('.chrono', 'blobs', startHash)
3434
const filePath = this.drive.resolve(folderPath, endHash)
3535

36-
if (!await this.drive.exists(filePath)) {
36+
if (!(await this.drive.exists(filePath))) {
3737
return null
3838
}
3939

@@ -45,4 +45,4 @@ export default class BlobRepositoryImpl implements IBlobRepository {
4545

4646
return bytes
4747
}
48-
}
48+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export default interface IBlobRepository {
22
save(content: Uint8Array): Promise<{ blobHash: string }>
33
find(blobHash: string): Promise<Uint8Array | null>
4-
}
4+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import ChronoObject from "../entities/ChronoObject"
1+
import ChronoObject from '../entities/ChronoObject'
22

33
export default interface IObjectRepository {
44
// exists(objectHash: string): Promise<boolean>
55
find(objectHash: string): Promise<any>
66
save(object: ChronoObject): Promise<{ objectHash: string }>
7-
}
7+
}

0 commit comments

Comments
 (0)