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 }], posts: [{ id: 1 }, { _id: 2 }],
comments: [{ id: 1, post_id: 1 }], comments: [{ id: 1, post_id: 1 }],
}), }),
'db.json' 'db.json',
) )
routesFile = tempWrite.sync( routesFile = tempWrite.sync(
JSON.stringify({ '/blog/*': '/$1' }), JSON.stringify({ '/blog/*': '/$1' }),
'routes.json' 'routes.json',
) )
++PORT ++PORT

View File

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

3765
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", "please-upgrade-node": "^3.2.0",
"pluralize": "^8.0.0", "pluralize": "^8.0.0",
"server-destroy": "^1.0.1", "server-destroy": "^1.0.1",
"standard": "^17.0.0",
"yargs": "^17.0.1" "yargs": "^17.0.1"
}, },
"devDependencies": { "devDependencies": {

View File

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

View File

@ -39,7 +39,7 @@ function createApp(db, routes, middlewares, argv) {
const router = jsonServer.router( const router = jsonServer.router(
db, db,
foreignKeySuffix ? { foreignKeySuffix } : undefined foreignKeySuffix ? { foreignKeySuffix } : undefined,
) )
const defaultsOpts = { const defaultsOpts = {
@ -138,8 +138,8 @@ module.exports = function (argv) {
if (error.errno === 'EADDRINUSE') if (error.errno === 'EADDRINUSE')
console.log( console.log(
chalk.red( 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) else console.log('Some error occurred', error)
process.exit(1) process.exit(1)
@ -153,8 +153,8 @@ module.exports = function (argv) {
// Snapshot // Snapshot
console.log( console.log(
chalk.gray( 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 // Support nohup
@ -171,7 +171,7 @@ module.exports = function (argv) {
const state = app.db.getState() const state = app.db.getState()
fs.writeFileSync(file, JSON.stringify(state, null, 2), 'utf-8') fs.writeFileSync(file, JSON.stringify(state, null, 2), 'utf-8')
console.log( 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()) const isDatabaseDifferent = !_.isEqual(obj, app.db.getState())
if (isDatabaseDifferent) { if (isDatabaseDifferent) {
console.log( console.log(
chalk.gray(` ${source} has changed, reloading...`) chalk.gray(` ${source} has changed, reloading...`),
) )
server && server.destroy(() => start()) server && server.destroy(() => start())
} }
@ -231,7 +231,7 @@ module.exports = function (argv) {
const watchedFile = path.resolve(watchedDir, file) const watchedFile = path.resolve(watchedDir, file)
if (watchedFile === path.resolve(argv.routes)) { if (watchedFile === path.resolve(argv.routes)) {
console.log( console.log(
chalk.gray(` ${argv.routes} has changed, reloading...`) chalk.gray(` ${argv.routes} has changed, reloading...`),
) )
server && server.destroy(() => start()) server && server.destroy(() => start())
} }

View File

@ -53,7 +53,7 @@ module.exports = function (source) {
if (typeof dataFn !== 'function') { if (typeof dataFn !== 'function') {
throw new Error( 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', { logger('dev', {
skip: (req) => skip: (req) =>
process.env.NODE_ENV === 'test' || req.path === '/favicon.ico', 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 // Remove foreign key suffix and pluralize it
// Example postId -> posts // Example postId -> posts
const refName = pluralize.plural( const refName = pluralize.plural(
key.replace(new RegExp(`${opts.foreignKeySuffix}$`), '') key.replace(new RegExp(`${opts.foreignKeySuffix}$`), ''),
) )
// Test if table exists // Test if table exists
if (db[refName]) { if (db[refName]) {

View File

@ -165,7 +165,7 @@ module.exports = (db, name, opts) => {
res.setHeader('X-Total-Count', chain.size()) res.setHeader('X-Total-Count', chain.size())
res.setHeader( res.setHeader(
'Access-Control-Expose-Headers', '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) { if (page.first) {
links.first = fullURL.replace( links.first = fullURL.replace(
`page=${page.current}`, `page=${page.current}`,
`page=${page.first}` `page=${page.first}`,
) )
} }
if (page.prev) { if (page.prev) {
links.prev = fullURL.replace( links.prev = fullURL.replace(
`page=${page.current}`, `page=${page.current}`,
`page=${page.prev}` `page=${page.prev}`,
) )
} }
if (page.next) { if (page.next) {
links.next = fullURL.replace( links.next = fullURL.replace(
`page=${page.current}`, `page=${page.current}`,
`page=${page.next}` `page=${page.next}`,
) )
} }
if (page.last) { if (page.last) {
links.last = fullURL.replace( links.last = fullURL.replace(
`page=${page.current}`, `page=${page.current}`,
`page=${page.last}` `page=${page.last}`,
) )
} }

View File

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