mirror of
https://github.com/IT4Change/boilerplate-backend.git
synced 2025-12-13 10:25:49 +00:00
setup eslint
This commit is contained in:
parent
7af2c50e0e
commit
e660b7fe33
146
.eslintrc.json
Normal file
146
.eslintrc.json
Normal file
@ -0,0 +1,146 @@
|
||||
{
|
||||
"env": {
|
||||
"browser": true,
|
||||
"es2021": true
|
||||
},
|
||||
"extends": [
|
||||
"standard",
|
||||
"eslint:recommended",
|
||||
"plugin:@eslint-community/eslint-comments/recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:import/recommended",
|
||||
"plugin:import/typescript",
|
||||
"plugin:promise/recommended",
|
||||
"plugin:security/recommended"
|
||||
],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": "latest",
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"sourceType": "module"
|
||||
},
|
||||
"plugins": [
|
||||
"@typescript-eslint",
|
||||
"import",
|
||||
"promise",
|
||||
"security"
|
||||
],
|
||||
"settings": {
|
||||
"import/resolver": {
|
||||
"typescript": true,
|
||||
"node": true
|
||||
}
|
||||
},
|
||||
"rules": {
|
||||
"no-console": "error",
|
||||
"no-debugger": "error",
|
||||
"camelcase": "error",
|
||||
"indent": ["error", 2],
|
||||
"linebreak-style": ["error", "unix"],
|
||||
"semi": ["error", "never"],
|
||||
// Optional eslint-comments rule
|
||||
"@eslint-community/eslint-comments/no-unused-disable": "error",
|
||||
"@eslint-community/eslint-comments/disable-enable-pair": ["error", { "allowWholeFile": true }],
|
||||
// import
|
||||
"import/export": "error",
|
||||
"import/no-deprecated": "error",
|
||||
"import/no-empty-named-blocks": "error",
|
||||
"import/no-extraneous-dependencies": "error",
|
||||
"import/no-mutable-exports": "error",
|
||||
"import/no-unused-modules": "error",
|
||||
"import/no-named-as-default": "error",
|
||||
"import/no-named-as-default-member": "error",
|
||||
"import/no-amd": "error",
|
||||
"import/no-commonjs": "error",
|
||||
"import/no-import-module-exports": "error",
|
||||
"import/no-nodejs-modules": "off",
|
||||
"import/unambiguous": "off", // not compatible with scriptless vue files
|
||||
"import/default": "error",
|
||||
"import/named": "error",
|
||||
"import/namespace": "error",
|
||||
"import/no-absolute-path": "error",
|
||||
"import/no-cycle": "error",
|
||||
"import/no-dynamic-require": "error",
|
||||
"import/no-internal-modules": "off",
|
||||
"import/no-relative-packages": "error",
|
||||
"import/no-relative-parent-imports": [
|
||||
"error",
|
||||
{ "ignore": ["#[src,root,components,pages,assets,layouts,stores,plugins,context,types]/*"] }
|
||||
],
|
||||
"import/no-self-import": "error",
|
||||
"import/no-unresolved": "error",
|
||||
"import/no-useless-path-segments": "error",
|
||||
"import/no-webpack-loader-syntax": "error",
|
||||
"import/consistent-type-specifier-style": "error",
|
||||
"import/exports-last": "off",
|
||||
"import/extensions": [
|
||||
"error",
|
||||
"never",
|
||||
{
|
||||
"json": "always"
|
||||
}
|
||||
],
|
||||
"import/first": "error",
|
||||
"import/group-exports": "off",
|
||||
"import/newline-after-import": "error",
|
||||
"import/no-anonymous-default-export": "off", // todo - consider to enable again
|
||||
"import/no-default-export": "off", // incompatible with vite & vike
|
||||
"import/no-duplicates": "error",
|
||||
"import/no-named-default": "error",
|
||||
"import/no-namespace": "error",
|
||||
"import/no-unassigned-import": "error",
|
||||
"import/order": [
|
||||
"error",
|
||||
{
|
||||
"groups": ["builtin", "external", "internal", "parent", "sibling", "index", "object", "type"],
|
||||
"newlines-between": "always",
|
||||
"alphabetize": {
|
||||
"order": "asc", // sort in ascending order. Options: ["ignore", "asc", "desc"]
|
||||
"caseInsensitive": true // ignore case. Options: [true, false]
|
||||
},
|
||||
"distinctGroup": true
|
||||
}
|
||||
],
|
||||
"import/prefer-default-export": "off",
|
||||
// promise
|
||||
"promise/catch-or-return": "error",
|
||||
"promise/no-return-wrap": "error",
|
||||
"promise/param-names": "error",
|
||||
"promise/always-return": "error",
|
||||
"promise/no-native": "off",
|
||||
"promise/no-nesting": "warn",
|
||||
"promise/no-promise-in-callback": "warn",
|
||||
"promise/no-callback-in-promise": "warn",
|
||||
"promise/avoid-new": "warn",
|
||||
"promise/no-new-statics": "error",
|
||||
"promise/no-return-in-finally": "warn",
|
||||
"promise/valid-params": "warn",
|
||||
"promise/prefer-await-to-callbacks": "error",
|
||||
"promise/no-multiple-resolved": "error"
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["!*.json"],
|
||||
"plugins": ["prettier"],
|
||||
"extends": ["plugin:prettier/recommended"],
|
||||
"rules": {
|
||||
"prettier/prettier": "error"
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": ["*.json"],
|
||||
"plugins": ["json"],
|
||||
"extends": ["plugin:json/recommended-with-comments"]
|
||||
},
|
||||
{
|
||||
"files": ["*.[test,spec].[tj]s"],
|
||||
"plugins": ["vitest"],
|
||||
"extends": ["plugin:vitest/all"]
|
||||
},
|
||||
{
|
||||
"files": ["*.yaml", "*.yml"],
|
||||
"parser": "yaml-eslint-parser",
|
||||
"plugins": ["yml"],
|
||||
"extends": ["plugin:yml/prettier"]
|
||||
}
|
||||
]
|
||||
}
|
||||
2023
package-lock.json
generated
2023
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
11
package.json
11
package.json
@ -25,11 +25,22 @@
|
||||
"graphql": "^16.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint-community/eslint-plugin-eslint-comments": "^4.1.0",
|
||||
"@types/express": "^4.17.21",
|
||||
"@types/node": "^20.10.1",
|
||||
"@typescript-eslint/eslint-plugin": "^6.13.1",
|
||||
"@typescript-eslint/parser": "^6.13.1",
|
||||
"eslint": "^8.54.0",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"eslint-config-standard": "^17.1.0",
|
||||
"eslint-import-resolver-typescript": "^3.6.1",
|
||||
"eslint-plugin-import": "^2.29.0",
|
||||
"eslint-plugin-json": "^3.1.0",
|
||||
"eslint-plugin-prettier": "^5.0.1",
|
||||
"eslint-plugin-promise": "^6.1.1",
|
||||
"eslint-plugin-security": "^1.7.1",
|
||||
"eslint-plugin-vitest": "^0.3.10",
|
||||
"eslint-plugin-yml": "^1.10.0",
|
||||
"nodemon": "^3.0.1",
|
||||
"ts-node": "^10.9.1",
|
||||
"tsc": "^2.0.4",
|
||||
|
||||
34
src/index.ts
34
src/index.ts
@ -1,45 +1,45 @@
|
||||
import { ApolloServer, gql } from 'apollo-server-express'
|
||||
import express from 'express'
|
||||
import { ApolloServer, gql } from "apollo-server-express";
|
||||
import express from "express";
|
||||
|
||||
const typeDefs = gql`
|
||||
type Query {
|
||||
hello: String
|
||||
}
|
||||
`
|
||||
`;
|
||||
|
||||
const resolvers = {
|
||||
Query: {
|
||||
hello: () => 'Hello world!',
|
||||
hello: () => "Hello world!",
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
async function listen(port: number) {
|
||||
const app: any = express()
|
||||
const app: any = express();
|
||||
|
||||
const server = new ApolloServer({
|
||||
typeDefs,
|
||||
resolvers,
|
||||
})
|
||||
await server.start()
|
||||
});
|
||||
await server.start();
|
||||
|
||||
server.applyMiddleware({ app, path: '/' })
|
||||
server.applyMiddleware({ app, path: "/" });
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
app.listen(port).once('listening', resolve).once('error', reject)
|
||||
})
|
||||
app.listen(port).once("listening", resolve).once("error", reject);
|
||||
});
|
||||
}
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
await listen(4000)
|
||||
console.log('🚀 Server is ready at http://localhost:4000/graphql')
|
||||
await listen(4000);
|
||||
console.log("🚀 Server is ready at http://localhost:4000/graphql");
|
||||
} catch (err) {
|
||||
console.error('💀 Error starting the node server', err)
|
||||
console.error("💀 Error starting the node server", err);
|
||||
}
|
||||
}
|
||||
|
||||
void main().catch((e) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(e)
|
||||
throw e
|
||||
})
|
||||
console.error(e);
|
||||
throw e;
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user