fix: actually used Prettier in ESLint

This commit is contained in:
Roberto Tonino 2021-04-03 19:43:40 +02:00
parent e3a0a996fe
commit db7e07bd1d
10 changed files with 78 additions and 80 deletions

View File

@ -1,6 +1,7 @@
--- ---
extends: extends:
- "@nuxtjs" - "@nuxtjs"
- plugin:prettier/recommended
plugins: plugins:
- "@typescript-eslint" - "@typescript-eslint"
parserOptions: parserOptions:

View File

@ -25,7 +25,7 @@
"@typescript-eslint/eslint-plugin": "4.20.0", "@typescript-eslint/eslint-plugin": "4.20.0",
"@typescript-eslint/parser": "4.20.0", "@typescript-eslint/parser": "4.20.0",
"eslint": "7.23.0", "eslint": "7.23.0",
"eslint-config-prettier": "8.1.0", "eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "3.3.1", "eslint-plugin-prettier": "3.3.1",
"nodemon": "2.0.7", "nodemon": "2.0.7",
"prettier": "2.2.1", "prettier": "2.2.1",

View File

@ -5,18 +5,18 @@ import { Port } from '../types'
* *
* @since 0.0.0 * @since 0.0.0
*/ */
export function normalizePort (portString:string): Port { export function normalizePort(portString: string): Port {
const port = parseInt(portString, 10) const port = parseInt(portString, 10)
if (isNaN(port)) { if (isNaN(port)) {
// named pipe // named pipe
return portString return portString
} }
if (port >= 0) { if (port >= 0) {
// port number // port number
return port return port
} }
return false return false
} }

View File

@ -6,30 +6,28 @@ import type { Debugger } from 'debug'
* *
* @since 0.0.0 * @since 0.0.0
*/ */
export function getErrorCb (port: number | string | boolean) { export function getErrorCb(port: number | string | boolean) {
return (error: any) => { return (error: any) => {
if (error.syscall !== 'listen') { if (error.syscall !== 'listen') {
throw error throw error
} }
const bind = typeof port === 'string' const bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port
? 'Pipe ' + port
: 'Port ' + port
// handle specific listen errors with friendly messages // handle specific listen errors with friendly messages
switch (error.code) { switch (error.code) {
case 'EACCES': { case 'EACCES': {
console.error(bind + ' requires elevated privileges') console.error(bind + ' requires elevated privileges')
process.exit(1) process.exit(1)
} }
case 'EADDRINUSE': { case 'EADDRINUSE': {
console.error(bind + ' is already in use') console.error(bind + ' is already in use')
process.exit(1) process.exit(1)
} }
default: default:
throw error throw error
} }
} }
} }
/** /**
@ -37,15 +35,13 @@ export function getErrorCb (port: number | string | boolean) {
* *
* @since 0.0.0 * @since 0.0.0
*/ */
export function getListeningCb (server: http.Server, debug: Debugger) { export function getListeningCb(server: http.Server, debug: Debugger) {
return () => { return () => {
const addr = server.address() const addr = server.address()
if (addr) { if (addr) {
const bind = typeof addr === 'string' const bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port
? 'pipe ' + addr debug('Listening on ' + bind)
: 'port ' + addr.port }
debug('Listening on ' + bind) }
}
}
} }

View File

@ -4,10 +4,10 @@ import express from 'express'
import cookieParser from 'cookie-parser' import cookieParser from 'cookie-parser'
import { WEBUI_DIR } from './helpers/paths' import { WEBUI_DIR } from './helpers/paths'
export function registerMiddlewares (app: Application) { export function registerMiddlewares(app: Application) {
app.use(logger('dev')) app.use(logger('dev'))
app.use(express.json()) app.use(express.json())
app.use(express.urlencoded({ extended: false })) app.use(express.urlencoded({ extended: false }))
app.use(cookieParser()) app.use(cookieParser())
app.use(express.static(WEBUI_DIR)) app.use(express.static(WEBUI_DIR))
} }

View File

@ -3,7 +3,7 @@ import { ApiHandler } from '../../../types'
const path: ApiHandler['path'] = '/sample' const path: ApiHandler['path'] = '/sample'
const handler: ApiHandler['handler'] = (_, res) => { const handler: ApiHandler['handler'] = (_, res) => {
res.send('Mandi') res.send('Mandi')
} }
const apiHandler: ApiHandler = { path, handler } const apiHandler: ApiHandler = { path, handler }

View File

@ -1,11 +1,12 @@
import { Application } from 'express' import type { Application } from 'express'
import { ApiHandler } from '../../types' import type { ApiHandler } from '../../types'
import getEndpoints from './get' import getEndpoints from './get'
import deleteEndpoints from './delete' import deleteEndpoints from './delete'
import postEndpoints from './post' import postEndpoints from './post'
import patchEndpoints from './patch' import patchEndpoints from './patch'
const prependApiPath = (path:string) => `/api${path}` const prependApiPath = (path: string) => `/api${path}`
interface Method { interface Method {
method: string method: string
@ -13,29 +14,29 @@ interface Method {
} }
const methods: Method[] = [ const methods: Method[] = [
{ {
method: 'get', method: 'get',
endpoints: getEndpoints endpoints: getEndpoints
}, },
{ {
method: 'delete', method: 'delete',
endpoints: deleteEndpoints endpoints: deleteEndpoints
}, },
{ {
method: 'post', method: 'post',
endpoints: postEndpoints endpoints: postEndpoints
}, },
{ {
method: 'patch', method: 'patch',
endpoints: patchEndpoints endpoints: patchEndpoints
} }
] ]
export function registerApis (app: Application) { export function registerApis(app: Application) {
methods.forEach(({ method, endpoints }) => { methods.forEach(({ method, endpoints }) => {
endpoints.forEach((endpoint) => { endpoints.forEach(endpoint => {
// @ts-ignore // @ts-ignore
app[method](prependApiPath(endpoint.path), endpoint.handler) app[method](prependApiPath(endpoint.path), endpoint.handler)
}) })
}) })
} }

View File

@ -8,7 +8,7 @@ const router = express.Router()
* @since 0.0.0 * @since 0.0.0
*/ */
router.get('/', (_, res) => { router.get('/', (_, res) => {
res.render('index', { title: 'Express' }) res.render('index', { title: 'Express' })
}) })
export default router export default router

View File

@ -8,7 +8,7 @@ const router = express.Router()
* @since 0.0.0 * @since 0.0.0
*/ */
router.get('/', (_, res) => { router.get('/', (_, res) => {
res.send('respond with a resource') res.send('respond with a resource')
}) })
export default router export default router

View File

@ -1116,7 +1116,7 @@ escape-string-regexp@^1.0.5:
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ= integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=
eslint-config-prettier@8.1.0: eslint-config-prettier@^8.1.0:
version "8.1.0" version "8.1.0"
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-8.1.0.tgz#4ef1eaf97afe5176e6a75ddfb57c335121abc5a6" resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-8.1.0.tgz#4ef1eaf97afe5176e6a75ddfb57c335121abc5a6"
integrity sha512-oKMhGv3ihGbCIimCAjqkdzx2Q+jthoqnXSP+d86M9tptwugycmTFdVR4IpLgq2c4SHifbwO90z2fQ8/Aio73yw== integrity sha512-oKMhGv3ihGbCIimCAjqkdzx2Q+jthoqnXSP+d86M9tptwugycmTFdVR4IpLgq2c4SHifbwO90z2fQ8/Aio73yw==