Skip to content

Commit

Permalink
fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
luludotdev committed Aug 28, 2023
1 parent 603ccaf commit d9e095b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"root": true,
"extends": ["./common.js", "./node.js", "./prettier.js"],
"extends": ["./lint/common.js", "./lint/node.js", "./lint/prettier.js"],
"rules": {
"jsdoc/valid-types": 0,
"sort-keys": ["error", "asc", { "allowLineSeparatedGroups": true }]
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ docs

# Root Exports
/*.js

# Lint Dir
/lint
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
"*.js"
],
"scripts": {
"prelint": "node ./scripts/copy.mjs --lint",
"lint": "prettier --check . && eslint src --ext js,ts",
"postlint": "node ./scripts/clean.mjs --lint",
"preformat": "npm run prelint",
"format": "prettier --write . && eslint src --ext js,ts --fix",
"postformat": "npm run postlint",
"fmt": "npm run format",
"prepack": "node ./scripts/copy.mjs",
"postpack": "node ./scripts/clean.mjs"
Expand Down
28 changes: 17 additions & 11 deletions scripts/clean.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { unlink } from 'node:fs/promises'
import { iterateDir } from './common.mjs'
import { rm, unlink } from 'node:fs/promises'
import { isLint, iterateDir, LINT_DIR } from './common.mjs'

const entries = await iterateDir()
const jobs = entries.map(async ([name]) => {
try {
await unlink(`./${name}`)
} catch {
// Pass
}
})
const lint = isLint()

await Promise.all(jobs)
if (lint) {
await rm(LINT_DIR, { force: true, recursive: true })
} else {
const entries = await iterateDir()
const jobs = entries.map(async ([name]) => {
try {
await unlink(`./${name}`)
} catch {
// Pass
}
})

await Promise.all(jobs)
}
6 changes: 6 additions & 0 deletions scripts/common.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { readdir } from 'node:fs/promises'
import { dirname, join } from 'node:path'
import { argv } from 'node:process'
import { fileURLToPath } from 'node:url'

const SCRIPTS_DIR = dirname(fileURLToPath(import.meta.url))
const SRC_DIR = join(SCRIPTS_DIR, '..', 'src')

export const LINT_DIR = join(SCRIPTS_DIR, '..', 'lint')
export const isLint = () => {
return argv.includes('--lint')
}

export const iterateDir = async () => {
/**
* @type {[name: string, path: string][]}
Expand Down
15 changes: 10 additions & 5 deletions scripts/copy.mjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// @ts-check

import { writeFile } from 'node:fs/promises'
import { parse } from 'node:path'
import { iterateDir } from './common.mjs'
import { mkdir, writeFile } from 'node:fs/promises'
import { join, parse } from 'node:path'
import { isLint, iterateDir, LINT_DIR } from './common.mjs'

const lint = isLint()

/**
* @param {string} name
*/
const legacy = name =>
`
const src = require('./src/${name}.js')
const src = require('${lint ? '..' : '.'}/src/${name}.js')
/** @type {import('eslint').Linter.Config} */
module.exports = {
Expand All @@ -19,11 +21,14 @@ module.exports = {
}
`.trim()

if (lint) await mkdir(LINT_DIR, { recursive: true })

const entries = await iterateDir()
const jobs = entries.map(async ([base]) => {
const { name } = parse(base)
const path = lint ? join(LINT_DIR, `./${base}`) : `./${base}`

await writeFile(`./${base}`, legacy(name) + '\n')
await writeFile(path, legacy(name) + '\n')
})

await Promise.all(jobs)

0 comments on commit d9e095b

Please sign in to comment.