Skip to content

Commit

Permalink
refactor: convert most CommonJS-style import/exports to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperupcall committed Oct 13, 2023
1 parent 21022c6 commit 76a93fe
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 32 deletions.
4 changes: 1 addition & 3 deletions src/cli/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export interface Formatter extends EventEmitter {
on(event: 'end', listener: (event: FormatterEndEvent) => void): this
}

const formatter: Formatter = new EventEmitter() as Formatter
export const formatter: Formatter = new EventEmitter() as Formatter

formatter.getSupported = function () {
return arrSupportedFormatters
Expand Down Expand Up @@ -107,5 +107,3 @@ export type FormatterCallback = (
HTMLHint: typeof IHTMLHint,
options: { nocolor?: boolean }
) => void

module.exports = formatter
4 changes: 1 addition & 3 deletions src/cli/formatters/checkstyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as xml from 'xml'
import type { XmlObject } from 'xml'
import { FormatterCallback } from '../formatter'

const checkstyleFormatter: FormatterCallback = function (formatter) {
export const checkstyleFormatter: FormatterCallback = function (formatter) {
formatter.on('end', (event) => {
const arrFiles: XmlObject[] = []
const arrAllMessages = event.arrAllMessages
Expand Down Expand Up @@ -56,5 +56,3 @@ const checkstyleFormatter: FormatterCallback = function (formatter) {
)
})
}

module.exports = checkstyleFormatter
4 changes: 1 addition & 3 deletions src/cli/formatters/compact.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as chalk from 'chalk'
import { FormatterCallback } from '../formatter'

const compactFormatter: FormatterCallback = function (
export const compactFormatter: FormatterCallback = function (
formatter,
HTMLHint,
options
Expand Down Expand Up @@ -37,5 +37,3 @@ const compactFormatter: FormatterCallback = function (
}
})
}

module.exports = compactFormatter
4 changes: 1 addition & 3 deletions src/cli/formatters/default.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as chalk from 'chalk'
import { FormatterCallback } from '../formatter'

const defaultFormatter: FormatterCallback = function (
export const defaultFormatter: FormatterCallback = function (
formatter,
HTMLHint,
options
Expand Down Expand Up @@ -59,5 +59,3 @@ const defaultFormatter: FormatterCallback = function (
}
})
}

module.exports = defaultFormatter
4 changes: 1 addition & 3 deletions src/cli/formatters/html.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { writeFileSync } from 'fs'
import { FormatterCallback } from '../formatter'

const htmlFormatter: FormatterCallback = function (formatter) {
export const htmlFormatter: FormatterCallback = function (formatter) {
formatter.on('end', (event) => {
let fileContent = '<html>'
fileContent += '<head><title>HTML Hint Violation Report</title></head>'
Expand All @@ -28,5 +28,3 @@ const htmlFormatter: FormatterCallback = function (formatter) {
writeFileSync('report.html', fileContent)
})
}

module.exports = htmlFormatter
4 changes: 1 addition & 3 deletions src/cli/formatters/json.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { FormatterCallback } from '../formatter'

const jsonFormatter: FormatterCallback = function (formatter) {
export const jsonFormatter: FormatterCallback = function (formatter) {
formatter.on('end', (event) => {
console.log(JSON.stringify(event.arrAllMessages))
})
}

module.exports = jsonFormatter
7 changes: 4 additions & 3 deletions src/cli/formatters/junit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import * as xml from 'xml'
import type { XmlObject } from 'xml'
import { FormatterCallback } from '../formatter'

const junitFormatter: FormatterCallback = function (formatter, HTMLHint) {
export const junitFormatter: FormatterCallback = function (
formatter,
HTMLHint
) {
formatter.on('end', (event) => {
const arrTestcase: XmlObject[] = []
const arrAllMessages = event.arrAllMessages
Expand Down Expand Up @@ -57,5 +60,3 @@ const junitFormatter: FormatterCallback = function (formatter, HTMLHint) {
)
})
}

module.exports = junitFormatter
7 changes: 4 additions & 3 deletions src/cli/formatters/markdown.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { FormatterCallback } from '../formatter'

const markdownFormatter: FormatterCallback = function (formatter, HTMLHint) {
export const markdownFormatter: FormatterCallback = function (
formatter,
HTMLHint
) {
formatter.on('end', (event) => {
console.log('# TOC')

Expand Down Expand Up @@ -40,5 +43,3 @@ const markdownFormatter: FormatterCallback = function (formatter, HTMLHint) {
console.log(arrContents.join('\r\n'))
})
}

module.exports = markdownFormatter
4 changes: 1 addition & 3 deletions src/cli/formatters/unix.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as chalk from 'chalk'
import { FormatterCallback } from '../formatter'

const unixFormatter: FormatterCallback = function (
export const unixFormatter: FormatterCallback = function (
formatter,
HTMLHint,
options
Expand Down Expand Up @@ -36,5 +36,3 @@ const unixFormatter: FormatterCallback = function (
}
})
}

module.exports = unixFormatter
7 changes: 2 additions & 5 deletions src/cli/htmlhint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ import { parseGlob } from './parse-glob'
import { dirname, resolve, sep } from 'path'
import fetch from 'node-fetch'
import * as stripJsonComments from 'strip-json-comments'
import type { HTMLHint as IHTMLHint } from '../core/core'
import { HTMLHint } from '../core/core'
import type { Hint, Ruleset } from '../core/types'
import { Formatter } from './formatter'

const HTMLHint: typeof IHTMLHint = require('../htmlhint.js').HTMLHint
const formatter: Formatter = require('./formatter')
import { formatter, type Formatter } from './formatter'

const pkg = require('../../package.json')

Expand Down

0 comments on commit 76a93fe

Please sign in to comment.