chore: lint

This commit is contained in:
typicode
2023-02-22 22:34:39 +01:00
parent 39f615c530
commit ed2767416a
11 changed files with 2638 additions and 1178 deletions

View File

@ -38,12 +38,12 @@ describe('cli', () => {
posts: [{ id: 1 }, { _id: 2 }],
comments: [{ id: 1, post_id: 1 }],
}),
'db.json'
'db.json',
)
routesFile = tempWrite.sync(
JSON.stringify({ '/blog/*': '/$1' }),
'routes.json'
'routes.json',
)
++PORT

View File

@ -33,7 +33,7 @@ describe('mixins', () => {
assert.deepStrictEqual(
_.getRemovable(db, { foreignKeySuffix: 'Id' }),
expected
expected,
)
})
@ -45,7 +45,7 @@ describe('mixins', () => {
assert.deepStrictEqual(
_.getRemovable(db, { foreignKeySuffix: 'Id' }),
expected
expected,
)
})
})

3761
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -38,6 +38,7 @@
"please-upgrade-node": "^3.2.0",
"pluralize": "^8.0.0",
"server-destroy": "^1.0.1",
"standard": "^17.0.0",
"yargs": "^17.0.1"
},
"devDependencies": {

View File

@ -15,7 +15,7 @@ function ResourceList({ db }) {
ResourceItem({
name,
length: Array.isArray(db[name]) && db[name].length,
})
}),
)
.join('')}
</ul>
@ -40,7 +40,7 @@ window
.then((response) => response.json())
.then(
(db) =>
(document.getElementById('resources').innerHTML = ResourcesBlock({ db }))
(document.getElementById('resources').innerHTML = ResourcesBlock({ db })),
)
function CustomRoutesBlock({ customRoutes }) {
@ -56,7 +56,7 @@ function CustomRoutesBlock({ customRoutes }) {
`<tr>
<td>${rule}</td>
<td><code>⇢</code> ${customRoutes[rule]}</td>
</tr>`
</tr>`,
)
.join('')}
</table>
@ -72,5 +72,5 @@ window
(customRoutes) =>
(document.getElementById('custom-routes').innerHTML = CustomRoutesBlock({
customRoutes,
}))
})),
)

View File

@ -39,7 +39,7 @@ function createApp(db, routes, middlewares, argv) {
const router = jsonServer.router(
db,
foreignKeySuffix ? { foreignKeySuffix } : undefined
foreignKeySuffix ? { foreignKeySuffix } : undefined,
)
const defaultsOpts = {
@ -138,8 +138,8 @@ module.exports = function (argv) {
if (error.errno === 'EADDRINUSE')
console.log(
chalk.red(
`Cannot bind to the port ${error.port}. Please specify another port number either through --port argument or through the json-server.json configuration file`
)
`Cannot bind to the port ${error.port}. Please specify another port number either through --port argument or through the json-server.json configuration file`,
),
)
else console.log('Some error occurred', error)
process.exit(1)
@ -153,8 +153,8 @@ module.exports = function (argv) {
// Snapshot
console.log(
chalk.gray(
' Type s + enter at any time to create a snapshot of the database'
)
' Type s + enter at any time to create a snapshot of the database',
),
)
// Support nohup
@ -171,7 +171,7 @@ module.exports = function (argv) {
const state = app.db.getState()
fs.writeFileSync(file, JSON.stringify(state, null, 2), 'utf-8')
console.log(
` Saved snapshot to ${path.relative(process.cwd(), file)}\n`
` Saved snapshot to ${path.relative(process.cwd(), file)}\n`,
)
}
})
@ -214,7 +214,7 @@ module.exports = function (argv) {
const isDatabaseDifferent = !_.isEqual(obj, app.db.getState())
if (isDatabaseDifferent) {
console.log(
chalk.gray(` ${source} has changed, reloading...`)
chalk.gray(` ${source} has changed, reloading...`),
)
server && server.destroy(() => start())
}
@ -231,7 +231,7 @@ module.exports = function (argv) {
const watchedFile = path.resolve(watchedDir, file)
if (watchedFile === path.resolve(argv.routes)) {
console.log(
chalk.gray(` ${argv.routes} has changed, reloading...`)
chalk.gray(` ${argv.routes} has changed, reloading...`),
)
server && server.destroy(() => start())
}

View File

@ -53,7 +53,7 @@ module.exports = function (source) {
if (typeof dataFn !== 'function') {
throw new Error(
'The database is a JavaScript file but the export is not a function.'
'The database is a JavaScript file but the export is not a function.',
)
}

View File

@ -40,7 +40,7 @@ module.exports = function (opts) {
logger('dev', {
skip: (req) =>
process.env.NODE_ENV === 'test' || req.path === '/favicon.ico',
})
}),
)
}

View File

@ -19,7 +19,7 @@ function getRemovable(db, opts) {
// Remove foreign key suffix and pluralize it
// Example postId -> posts
const refName = pluralize.plural(
key.replace(new RegExp(`${opts.foreignKeySuffix}$`), '')
key.replace(new RegExp(`${opts.foreignKeySuffix}$`), ''),
)
// Test if table exists
if (db[refName]) {

View File

@ -165,7 +165,7 @@ module.exports = (db, name, opts) => {
res.setHeader('X-Total-Count', chain.size())
res.setHeader(
'Access-Control-Expose-Headers',
`X-Total-Count${_page ? ', Link' : ''}`
`X-Total-Count${_page ? ', Link' : ''}`,
)
}
@ -180,28 +180,28 @@ module.exports = (db, name, opts) => {
if (page.first) {
links.first = fullURL.replace(
`page=${page.current}`,
`page=${page.first}`
`page=${page.first}`,
)
}
if (page.prev) {
links.prev = fullURL.replace(
`page=${page.current}`,
`page=${page.prev}`
`page=${page.prev}`,
)
}
if (page.next) {
links.next = fullURL.replace(
`page=${page.current}`,
`page=${page.next}`
`page=${page.next}`,
)
}
if (page.last) {
links.last = fullURL.replace(
`page=${page.current}`,
`page=${page.last}`
`page=${page.last}`,
)
}

View File

@ -20,7 +20,7 @@ module.exports = (obj) => {
`Data must be an object. Found ${
Array.isArray(obj) ? 'array' : typeof obj
}
'See https://github.com/typicode/json-server for example.`
'See https://github.com/typicode/json-server for example.`,
)
}
}