diff --git a/.husky/pre-commit b/.husky/pre-commit
index e6feac5b..74a0ba51 100755
--- a/.husky/pre-commit
+++ b/.husky/pre-commit
@@ -1,4 +1,5 @@
#!/bin/sh
. "$(dirname $0)/_/husky.sh"
-npm test
\ No newline at end of file
+npm test
+npm run lint
\ No newline at end of file
diff --git a/__tests__/cli/index.js b/__tests__/cli/index.js
index 0414b9c4..a7f54cc7 100644
--- a/__tests__/cli/index.js
+++ b/__tests__/cli/index.js
@@ -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
diff --git a/__tests__/server/mixins.js b/__tests__/server/mixins.js
index 0fe2ab83..694ed0b0 100644
--- a/__tests__/server/mixins.js
+++ b/__tests__/server/mixins.js
@@ -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
)
})
})
diff --git a/package.json b/package.json
index 24d8ab67..07669d93 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "json-server",
- "version": "0.17.3",
+ "version": "0.17.4",
"description": "Get a full fake REST API with zero coding in less than 30 seconds",
"main": "./lib/server/index.js",
"bin": "./lib/cli/bin.js",
@@ -17,7 +17,7 @@
"build": "babel src -d lib",
"toc": "markdown-toc -i README.md",
"postversion": "git push && git push --tags",
- "prepublish": "npm test && npm run build"
+ "prepublish": "npm lint & npm test && npm run build"
},
"dependencies": {
"body-parser": "^1.19.0",
diff --git a/public/script.js b/public/script.js
index 9506a8e4..53da7f79 100644
--- a/public/script.js
+++ b/public/script.js
@@ -15,7 +15,7 @@ function ResourceList({ db }) {
ResourceItem({
name,
length: Array.isArray(db[name]) && db[name].length,
- }),
+ })
)
.join('')}
@@ -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 }) {
`
${rule} |
⇢ ${customRoutes[rule]} |
-
`,
+ `
)
.join('')}
@@ -72,5 +72,5 @@ window
(customRoutes) =>
(document.getElementById('custom-routes').innerHTML = CustomRoutesBlock({
customRoutes,
- })),
+ }))
)
diff --git a/src/cli/run.js b/src/cli/run.js
index c4238f47..2e45b8f8 100644
--- a/src/cli/run.js
+++ b/src/cli/run.js
@@ -42,7 +42,7 @@ function createApp(db, routes, middlewares, argv) {
const router = jsonServer.router(
db,
- foreignKeySuffix ? { foreignKeySuffix } : undefined,
+ foreignKeySuffix ? { foreignKeySuffix } : undefined
)
const defaultsOpts = {
@@ -141,8 +141,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)
@@ -156,8 +156,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
@@ -174,7 +174,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`
)
}
})
@@ -217,7 +217,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())
}
@@ -234,7 +234,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())
}
diff --git a/src/cli/utils/load.js b/src/cli/utils/load.js
index 2c095c8c..d1f8ec87 100644
--- a/src/cli/utils/load.js
+++ b/src/cli/utils/load.js
@@ -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.'
)
}
diff --git a/src/server/defaults.js b/src/server/defaults.js
index d4cd55df..a0a8b7a7 100644
--- a/src/server/defaults.js
+++ b/src/server/defaults.js
@@ -40,7 +40,7 @@ module.exports = function (opts) {
logger('dev', {
skip: (req) =>
process.env.NODE_ENV === 'test' || req.path === '/favicon.ico',
- }),
+ })
)
}
diff --git a/src/server/mixins.js b/src/server/mixins.js
index e99ce288..482c1231 100644
--- a/src/server/mixins.js
+++ b/src/server/mixins.js
@@ -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]) {
diff --git a/src/server/router/plural.js b/src/server/router/plural.js
index 0e73dc39..b3695d9e 100644
--- a/src/server/router/plural.js
+++ b/src/server/router/plural.js
@@ -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}`
)
}
diff --git a/src/server/router/validate-data.js b/src/server/router/validate-data.js
index b4f112a3..5fc4bfeb 100644
--- a/src/server/router/validate-data.js
+++ b/src/server/router/validate-data.js
@@ -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.`
)
}
}