Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
hahnlee committed Apr 19, 2024
1 parent 9b745f1 commit 06577bd
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 17 deletions.
8 changes: 7 additions & 1 deletion libs/eslint-config/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ import tseslint from 'typescript-eslint'
export default function config(tsconfigDirName, ...args) {
return tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.strictTypeChecked,
{
files: ['**/*.js', '**/*.jsx', '**/*.mjs', '**/*.cjs'],
...tseslint.configs.disableTypeChecked,
},
{
rules: {
'@typescript-eslint/no-unsafe-enum-comparison': 'off',
'@typescript-eslint/restrict-template-expressions': ['error', {
allowNever: true,
}],
'@typescript-eslint/unbound-method': ['error', {
ignoreStatic: true,
}]
},
},
{
Expand Down
3 changes: 3 additions & 0 deletions packages/parser/src/constants/ctrl-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export function makeCtrlID(
return (firstCode << 24) | (secondCode << 16) | (thirdCode << 8) | fourthCode
}

/* eslint-disable @typescript-eslint/prefer-literal-enum-member */
export enum CommonCtrlID {
Table = makeCtrlID('t', 'b', 'l', ' '),
Line = makeCtrlID('$', 'l', 'i', 'n'),
Expand All @@ -45,6 +46,7 @@ export enum CommonCtrlID {
GenShapeObject = makeCtrlID('g', 's', 'o', ' '),
}


export enum OtherCtrlID {
Section = makeCtrlID('s', 'e', 'c', 'd'),
Column = makeCtrlID('c', 'o', 'l', 'd'),
Expand Down Expand Up @@ -101,3 +103,4 @@ export enum FieldCtrlID {
PrivateInfoSecurity = makeCtrlID('%', 'c', 'p', 'r'),
TableOfContents = makeCtrlID('%', 't', 'o', 'c'),
}
/* eslint-enable @typescript-eslint/prefer-literal-enum-member */
2 changes: 2 additions & 0 deletions packages/parser/src/constants/tag-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

export const HWPTAG_BEGIN: number = 0x10

/* eslint-disable @typescript-eslint/prefer-literal-enum-member */
export enum DocInfoTagID {
HWPTAG_DOCUMENT_PROPERTIES = HWPTAG_BEGIN,
HWPTAG_ID_MAPPINGS = HWPTAG_BEGIN + 1,
Expand Down Expand Up @@ -73,3 +74,4 @@ export enum SectionTagID {
HWPTAG_VIDEO_DATA = HWPTAG_BEGIN + 82,
HWPTAG_SHAPE_COMPONENT_UNKNOWN = HWPTAG_BEGIN + 99,
}
/* eslint-enable @typescript-eslint/prefer-literal-enum-member */
3 changes: 1 addition & 2 deletions packages/parser/src/models/doc-info/bullet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import { DocInfoTagID } from '../../constants/tag-id.js'
import { ByteReader } from '../../utils/byte-reader.js'
import type { HWPRecord } from '../record.js'
import { HWPVersion } from '../version.js'
import { ParagraphHead } from './numbering.js'

export class Bullet {
Expand All @@ -34,7 +33,7 @@ export class Bullet {
public checkedChar: string,
) {}

static fromRecord(record: HWPRecord, version: HWPVersion) {
static fromRecord(record: HWPRecord) {
if (record.id !== DocInfoTagID.HWPTAG_BULLET) {
throw new Error('DocInfo: Bullet: Record has wrong ID')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
import { DocInfoTagID } from '../../constants/tag-id.js'
import type { HWPRecord } from '../record.js'

// eslint-disable-next-line @typescript-eslint/no-extraneous-class
export class ChangeTrackingAuthor {
constructor() {}

static fromRecord(record: HWPRecord) {
if (record.id !== DocInfoTagID.HWPTAG_TRACK_CHANGE_AUTHOR) {
throw new Error('DocInfo: ChangeTrackingAuthor: Record has wrong ID')
Expand Down
1 change: 1 addition & 0 deletions packages/parser/src/models/doc-info/change-tracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { DocInfoTagID } from '../../constants/tag-id.js'
import type { HWPRecord } from '../record.js'

// eslint-disable-next-line @typescript-eslint/no-extraneous-class
export class ChangeTracking {
static fromRecord(record: HWPRecord) {
if (record.id !== DocInfoTagID.HWPTAG_TRACK_CHANGE) {
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/src/models/doc-info/compatible-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class CompatibleDocument {

static fromRecords(
record: HWPRecord,
records: Generator<HWPRecord, void, unknown>,
records: Generator<HWPRecord, void>,
) {
if (record.id !== DocInfoTagID.HWPTAG_COMPATIBLE_DOCUMENT) {
throw new Error('DocInfo: CompatibleDocument: Record has wrong ID')
Expand Down
2 changes: 2 additions & 0 deletions packages/parser/src/models/doc-info/doc-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ export class DocInfo {
const reader = new ByteReader(bytes.buffer)
const records = reader.records()

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion
const properties = Properties.fromRecord(records.next().value!)
const idMappings = IDMappings.fromRecords(records, version)

const info = new DocInfo(properties, idMappings)

// eslint-disable-next-line no-constant-condition, @typescript-eslint/no-unnecessary-condition
while (true) {
const current = records.next()
if (current.done) {
Expand Down
3 changes: 2 additions & 1 deletion packages/parser/src/models/doc-info/id-mappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export class IDMappings {
public changeTrackingAuthors: ChangeTrackingAuthor[],
) {}

static fromRecords(records: Generator<HWPRecord>, version: HWPVersion) {
static fromRecords(records: Generator<HWPRecord, void>, version: HWPVersion) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion
const record = records.next().value!
if (record.id !== DocInfoTagID.HWPTAG_ID_MAPPINGS) {
throw new Error('DocInfo: IDMappings: Record has wrong ID')
Expand Down
1 change: 1 addition & 0 deletions packages/parser/src/models/doc-info/memo-shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { DocInfoTagID } from '../../constants/tag-id.js'
import type { HWPRecord } from '../record.js'

// eslint-disable-next-line @typescript-eslint/no-extraneous-class
export class MemoShape {
static fromRecord(record: HWPRecord) {
if (record.id !== DocInfoTagID.HWPTAG_MEMO_SHAPE) {
Expand Down
8 changes: 4 additions & 4 deletions packages/parser/src/utils/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import type { PeekableIterator } from './generator.js'

type FromRecord<T> = (record: HWPRecord, version: HWPVersion) => T

export function readItems<T extends FromRecord<any>>(
records: Generator<HWPRecord, void, unknown>,
export function readItems<T>(
records: Generator<HWPRecord, void>,
count: number,
version: HWPVersion,
fromRecord: T,
fromRecord: FromRecord<T>,
) {
const items: ReturnType<T>[] = []
const items: T[] = []
for (let i = 0; i < count; i++) {
const record = records.next()
if (record.done) {
Expand Down
10 changes: 4 additions & 6 deletions packages/viewer/src/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@ export class Header {

this.observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
if (entry.isIntersecting && entry.target.parentElement) {
const page = entry.target.getAttribute('data-page-number')
const pageNumber = Number(page) + 1
this.updatePageNumber(pageNumber)
}
if (entry.isIntersecting && entry.target.parentElement) {
const page = entry.target.getAttribute('data-page-number')
const pageNumber = Number(page) + 1
this.updatePageNumber(pageNumber)
}
})
}, {
Expand Down
1 change: 1 addition & 0 deletions packages/viewer/src/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

/* eslint-disable */
export class HWPViewer {
constructor(container: HTMLElement, data: Uint8Array) {
// TODO: 새 구조에 맞추어 해결
Expand Down

0 comments on commit 06577bd

Please sign in to comment.