Skip to content

Commit

Permalink
Fix ESLint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
yhatt committed Sep 15, 2024
1 parent bf16916 commit 23700cb
Show file tree
Hide file tree
Showing 23 changed files with 83 additions and 642 deletions.
12 changes: 6 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ module.exports = {
es6: true,
node: true,
},
extends: ['eslint:recommended', 'plugin:import/recommended', 'prettier'],
extends: ['eslint:recommended', 'plugin:import-x/recommended', 'prettier'],
parserOptions: {
ecmaVersion: 'latest',
ecmaFeatures: { jsx: true },
},
rules: {
'import/no-unresolved': ['error', { ignore: ['ts-key-enum'] }],
'import/order': ['error', { alphabetize: { order: 'asc' } }],
'import-x/no-unresolved': ['error', { ignore: ['ts-key-enum'] }],
'import-x/order': ['error', { alphabetize: { order: 'asc' } }],
},
settings: {
'import/resolver': {
'import-x/resolver': {
node: { extensions: ['.mjs', '.js', '.jsx', '.json', '.ts', '.tsx'] },
},
'import/ignore': ['@rollup/plugin-node-resolve'],
'import-x/ignore': ['@rollup/plugin-node-resolve'],
},
overrides: [
{
Expand All @@ -28,7 +28,7 @@ module.exports = {
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/stylistic',
'plugin:import/typescript',
'plugin:import-x/typescript',
'prettier',
],
rules: {
Expand Down
5 changes: 4 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
const { jsWithBabel } = require('ts-jest/presets')

const esModules = [
'@sindresorhus/merge-streams',
'ansi-regex',
'array-union',
'chalk',
'chrome-launcher',
'find-up',
'globby',
'import-meta-resolve',
'is-inside-container',
'is-docker',
'is-inside-container',
'is-wsl',
'lighthouse-logger',
'locate-path',
Expand All @@ -18,9 +19,11 @@ const esModules = [
'p-limit',
'p-locate',
'path-exists',
'path-type',
'pkg-up',
'slash',
'strip-ansi',
'unicorn-magic',
'yocto-queue',
]

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"clean": "rimraf lib",
"format": "prettier \"**/*.{css,js,jsx,json,md,mjs,scss,ts,tsx,yaml,yml}\"",
"format:write": "yarn -s format --write",
"lint:js": "eslint --ext .js,.mjs,.jsx,.ts,.tsx --report-unused-disable-directives --cache .",
"lint:js": "ESLINT_USE_FLAT_CONFIG=false eslint --ext .js,.mjs,.jsx,.ts,.tsx --report-unused-disable-directives --cache .",
"lint:css": "stylelint \"src/**/*.{css,scss}\"",
"prepack": "npm-run-all --parallel check:* lint:* test:coverage --parallel build types",
"preversion": "run-p check:* lint:* test:coverage",
Expand Down Expand Up @@ -105,7 +105,7 @@
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-exports": "^1.0.0-beta.5",
"eslint-import-resolver-typescript": "^3.6.3",
"eslint-plugin-import": "^2.30.0",
"eslint-plugin-import-x": "^4.2.1",
"eslint-plugin-jest": "^28.8.3",
"express": "^4.21.0",
"fast-plist": "^0.1.3",
Expand Down
3 changes: 2 additions & 1 deletion rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import replace from '@rollup/plugin-replace'
import terser from '@rollup/plugin-terser'
import typescript from '@rollup/plugin-typescript'
import url from '@rollup/plugin-url'
import builtinModules from 'builtin-modules'
import license from 'rollup-plugin-license'
import postcss from 'rollup-plugin-postcss'
import pugPlugin from 'rollup-plugin-pug'

const __dirname = path.dirname(fileURLToPath(import.meta.url))
const require = createRequire(import.meta.url)

const { default: builtinModules } = await import('builtin-modules')
const { dependencies, name, version } = require('./package.json')

const compact = !process.env.ROLLUP_WATCH
Expand Down
2 changes: 1 addition & 1 deletion src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ export class Converter {
failedFileSet.add(url.href)
}
}
} catch (e: unknown) {
} catch {
// No ops
}
})
Expand Down
10 changes: 5 additions & 5 deletions src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class ResolvedEngine<T extends Engine = Engine> {

// Bundled Marp Core
Object.assign(
// eslint-disable-next-line @typescript-eslint/no-var-requires -- import statement brings TypeError in the standalone binary
// eslint-disable-next-line @typescript-eslint/no-require-imports -- import statement brings TypeError in the standalone binary
() => Promise.resolve(require('@marp-team/marp-core').Marp),
{ [preResolveAsyncSymbol]: true }
),
Expand Down Expand Up @@ -114,7 +114,7 @@ export class ResolvedEngine<T extends Engine = Engine> {
const pkgPath = await pkgUp({ cwd: path.dirname(classPath) })
if (!pkgPath) return null

// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports
return require(pkgPath) as Record<string, any>
}

Expand Down Expand Up @@ -145,7 +145,7 @@ export class ResolvedEngine<T extends Engine = Engine> {
const stat = await fs.promises.stat(moduleFilePath)

if (stat.isFile()) moduleId = url.pathToFileURL(moduleFilePath).toString()
} catch (e: unknown) {
} catch {
// No ops
}

Expand All @@ -162,14 +162,14 @@ export class ResolvedEngine<T extends Engine = Engine> {

// NOTE: Fallback cannot test because of overriding `import` in Jest context.
/* c8 ignore start */
} catch (e) {
} catch {
/* fallback */
}
}

return await import(resolved)
/* c8 ignore stop */
} catch (e) {
} catch {
return null
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine/meta-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function metaPlugin({ marpit }: { marpit: Marpit }) {
// URL validation
try {
if (v) new URL(v)
} catch (e: unknown) {
} catch {
warn(`Specified canonical URL is ignored since invalid URL: ${v}`)
return {}
}
Expand Down
4 changes: 2 additions & 2 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class File {
cleanup: async () => {
try {
await this.cleanup(tmp)
} catch (e: unknown) {
} catch {
// No ops
}
},
Expand Down Expand Up @@ -178,7 +178,7 @@ export class File {
dirs.push(path.resolve(p))
continue
}
} catch (e: unknown) {
} catch {
// No ops
}

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default apiInterface

// ---

// eslint-disable-next-line @typescript-eslint/no-empty-interface -- Use interface instead of type for better IntelliSense
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface Config<Engine extends typeof Marpit = typeof Marp>
extends Overwrite<
Omit<
Expand Down
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export class Server extends (EventEmitter as new () => TypedEmitter<Server.Event
try {
stats = fetchedStats || (await fs.promises.stat(targetPath))
valid = valid && !!stats?.isFile()
} catch (e: unknown) {
} catch {
valid = false
}

Expand Down
8 changes: 4 additions & 4 deletions src/templates/bespoke/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const storage = (() => {
localStorage.removeItem(key)

return true
} catch (e: unknown) {
} catch {
return false
}
})()
Expand All @@ -100,23 +100,23 @@ export const storage = (() => {
get: (key: string): string | null => {
try {
return localStorage.getItem(key)
} catch (e: unknown) {
} catch {
return null
}
},
set: (key: string, value: string): boolean => {
try {
localStorage.setItem(key, value)
return true
} catch (e: unknown) {
} catch {
return false
}
},
remove: (key: string): boolean => {
try {
localStorage.removeItem(key)
return true
} catch (e: unknown) {
} catch {
return false
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/templates/bespoke/utils/transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export const parseTransitionData = (rawJSON: string | undefined) => {
try {
const json = JSON.parse(rawJSON)
if (isTransitionData(json)) return json
} catch (_) {
} catch {
/* fault tolerance */
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/templates/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ interface RenderedSize {

export type TemplateOption = TemplateBareOption | TemplateBespokeOption

interface TemplateBareOption {} // eslint-disable-line @typescript-eslint/no-empty-interface
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface TemplateBareOption {}

interface TemplateBespokeOption {
osc?: boolean
Expand Down
2 changes: 1 addition & 1 deletion src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class ThemeSet {

if (stat.isFile() || stat.isDirectory() || stat.isSymbolicLink())
fnForWatch.add(path.resolve(f))
} catch (e: unknown) {
} catch {
// No ops
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/chrome-finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const withNormalizedChromePathForDarwin = async <T>(
)
}
}
} catch (e) {
} catch {
// ignore
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/edge-finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const findAccessiblePath = (paths: string[]): string | undefined =>
try {
accessSync(p, constants.X_OK)
return true
} catch (e: unknown) {
} catch {
// no ops
}
return false
Expand Down
2 changes: 1 addition & 1 deletion src/utils/puppeteer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const isShebang = (path: string) => {
fs.readSync(fd, shebangBuffer, 0, 2, 0)

if (shebangBuffer[0] === 0x23 && shebangBuffer[1] === 0x21) return true
} catch (e: unknown) {
} catch {
// no ops
} finally {
if (fd !== null) fs.closeSync(fd)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/wsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const isWSL = async (): Promise<number> => {

const gccMatched = verStr.match(/gcc[^,]+?(\d+)\.\d+\.\d+/)
if (gccMatched && Number.parseInt(gccMatched[1], 10) >= 8) return true
} catch (e: unknown) {
} catch {
// no ops
}
})()
Expand Down
6 changes: 3 additions & 3 deletions test/marp-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from 'fs'
import path from 'path'
import { version as coreVersion } from '@marp-team/marp-core/package.json'
import { version as marpitVersion } from '@marp-team/marpit/package.json'
import * as cosmiconfigExplorer from 'cosmiconfig/dist/Explorer'
import * as cosmiconfigExplorer from 'cosmiconfig/dist/Explorer' // eslint-disable-line import-x/namespace
import getStdin from 'get-stdin'
import stripAnsi from 'strip-ansi'
import { version as cliVersion } from '../package.json'
Expand All @@ -26,7 +26,7 @@ import { Watcher } from '../src/watcher'

const { Explorer } = cosmiconfigExplorer as any
const observationHelpers: ObservationHelper[] = []
const previewEmitter = new EventEmitter() as Preview
const previewEmitter = new EventEmitter() as unknown as Preview

const runForObservation = async (argv: string[]) => {
const ret = await Promise.race([marpCli(argv), waitForObservation()])
Expand Down Expand Up @@ -1101,7 +1101,7 @@ describe('Marp CLI', () => {
try {
const conf = assetFn('_configs/custom-engine/anonymous.js')
const md = assetFn('_configs/custom-engine/md.md')
const { engine } = require(conf) // eslint-disable-line @typescript-eslint/no-var-requires
const { engine } = require(conf) // eslint-disable-line @typescript-eslint/no-require-imports

expect(await marpCli(['-c', conf, md, '--no-output'])).toBe(0)
expect(engine).toHaveBeenCalledWith(
Expand Down
3 changes: 2 additions & 1 deletion test/utils/puppeteer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-require-imports */
import os from 'os'
import path from 'path'

Expand All @@ -6,7 +7,7 @@ jest.mock('../../src/utils/edge-finder')
jest.mock('../../src/utils/wsl')

const CLIError = (): typeof import('../../src/error').CLIError =>
require('../../src/error').CLIError // eslint-disable-line @typescript-eslint/no-var-requires
require('../../src/error').CLIError

const puppeteer = (): typeof import('puppeteer-core') =>
require('puppeteer-core')
Expand Down
2 changes: 1 addition & 1 deletion test/utils/wsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fs from 'fs'
jest.mock('is-wsl')

const wsl = (): typeof import('../../src/utils/wsl') =>
require('../../src/utils/wsl')
require('../../src/utils/wsl') // eslint-disable-line @typescript-eslint/no-require-imports

beforeEach(() => jest.resetModules())
afterEach(() => jest.restoreAllMocks())
Expand Down
3 changes: 2 additions & 1 deletion test/watcher.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import http from 'http'
import chokidar from 'chokidar'
import portfinder = require('portfinder')
// import * as portfinder from 'portfinder'
import { File, FileType } from '../src/file'
import { ThemeSet } from '../src/theme'
import { Watcher, WatchNotifier, notifier } from '../src/watcher'

const portfinder = require('portfinder') // eslint-disable-line @typescript-eslint/no-require-imports
const mockWsOn = jest.fn()

jest.mock('chokidar', () => ({
Expand Down
Loading

0 comments on commit 23700cb

Please sign in to comment.