Skip to content

Commit

Permalink
Upgrade to ESLint v9
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperupcall committed Jul 12, 2024
1 parent 27db9bd commit 75d1920
Show file tree
Hide file tree
Showing 5 changed files with 360 additions and 1,640 deletions.
27 changes: 0 additions & 27 deletions .eslintrc.json

This file was deleted.

83 changes: 43 additions & 40 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// <binding AfterBuild='build' />
import path from 'node:path'
import fs from 'node:fs'
import readline from 'node:readline/promises'
import readline from 'node:readline'
import addFormats from 'ajv-formats'
import ajvFormatsDraft2019 from 'ajv-formats-draft2019'
import AjvDraft04 from 'ajv-draft-04'
Expand Down Expand Up @@ -702,7 +702,7 @@ function showSchemaVersions() {
let obj
try {
obj = getObj_(schema.jsonObj)
} catch (err) {
} catch {
// suppress possible JSON.parse exception. It will be processed as obj = undefined
}
if (obj) {
Expand Down Expand Up @@ -733,49 +733,52 @@ async function taskNewSchema() {
})

console.log('Enter the name of the schema (without .json extension)')
/** @type {string} */
let schemaName
do {
schemaName = await rl.question('input: ')
} while (schemaName.endsWith('.json'))

const schemaFile = path.join(schemaDir, schemaName + '.json')
const testDir = path.join(testPositiveDir, schemaName)
const testFile = path.join(testDir, `${schemaName}.json`)

if (fs.existsSync(schemaFile)) {
throw new Error(`Schema file already exists: ${schemaFile}`)
}
await handleInput()
async function handleInput(schemaName) {
if (!schemaName || schemaName.endsWith('.json')) {
rl.question('input: ', handleInput)
return
}

const schemaFile = path.join(schemaDir, schemaName + '.json')
const testDir = path.join(testPositiveDir, schemaName)
const testFile = path.join(testDir, `${schemaName}.json`)

console.info(`Creating schema file at 'src/${schemaFile}'...`)
console.info(`Creating positive test file at 'src/${testFile}'...`)
if (fs.existsSync(schemaFile)) {
throw new Error(`Schema file already exists: ${schemaFile}`)
}

console.info(`Creating schema file at 'src/${schemaFile}'...`)
console.info(`Creating positive test file at 'src/${testFile}'...`)

await fs.promises.mkdir(path.dirname(schemaFile), { recursive: true })
await fs.promises.writeFile(
schemaFile,
`{
"$id": "https://json.schemastore.org/${schemaName}.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": true,
"properties": {
await fs.promises.mkdir(path.dirname(schemaFile), { recursive: true })
await fs.promises.writeFile(
schemaFile,
`{
"$id": "https://json.schemastore.org/${schemaName}.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": true,
"properties": {
},
"type": "object"
},
"type": "object"
}\n`,
)
await fs.promises.mkdir(testDir, { recursive: true })
await fs.promises.writeFile(
testFile,
`"Replace this file with an example/test that passes schema validation. Supported formats are JSON, YAML, and TOML. We recommend adding as many files as possible to make your schema most robust."\n`,
)
)
await fs.promises.mkdir(testDir, { recursive: true })
await fs.promises.writeFile(
testFile,
`"Replace this file with an example/test that passes schema validation. Supported formats are JSON, YAML, and TOML. We recommend adding as many files as possible to make your schema most robust."\n`,
)

console.info(`Please add the following to 'src/api/json/catalog.json':
console.info(`Please add the following to 'src/api/json/catalog.json':
{
"name": "",
"description": "",
"fileMatch": ["${schemaName}.yml", "${schemaName}.yaml"],
"url": "https://json.schemastore.org/${schemaName}.json"
"name": "",
"description": "",
"fileMatch": ["${schemaName}.yml", "${schemaName}.yaml"],
"url": "https://json.schemastore.org/${schemaName}.json"
}`)
process.exit(0)
}
}

function taskLint() {
Expand Down Expand Up @@ -1346,7 +1349,7 @@ function printDowngradableSchemaVersions() {

ajvSelected.compile(schemaJson)
return true
} catch (err) {
} catch {
return false
}
}
Expand Down Expand Up @@ -1964,7 +1967,7 @@ function printStrictAndNotStrictAjvValidatedSchemas() {

try {
ajvSelected.compile(mainSchema)
} catch (err) {
} catch {
// failed to compile in strict mode.
schemaInNotStrictMode.push(schemaJsonName)
return
Expand Down
31 changes: 31 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import js from '@eslint/js'
import promise from 'eslint-plugin-promise'
import node from 'eslint-plugin-n'
import prettier from 'eslint-config-prettier'
import globals from 'globals'

/** @type {import('eslint').Linter.FlatConfig} */
export default [
{
ignores: ['**/schema.json.translated.to.js'],
},
promise.configs['flat/recommended'],
node.configs['flat/recommended-script'],
prettier,
{
languageOptions: {
globals: {
...globals.es2021,
...globals.node,
},
ecmaVersion: 2022,
sourceType: 'module',
},
rules: {
...js.configs.recommended.rules,
'no-empty': 'off',
'object-shorthand': ['error', 'always'],
'n/no-process-exit': 'off',
},
},
]
Loading

0 comments on commit 75d1920

Please sign in to comment.