Browse Source

fix deps/eslintconfig

main
eiknat 11 months ago
parent
commit
2e09f52e8c
  1. 1
      .eslintignore
  2. 21
      .eslintrc.js
  3. 20
      .eslintrc.json
  4. 6
      package.json
  5. 4
      src/category/category.controller.ts
  6. 2
      src/category/category.model.ts
  7. 4
      src/comment/comment.controller.ts
  8. 2
      src/comment/comment.model.ts
  9. 8
      src/community/community.controller.ts
  10. 2
      src/community/community.model.ts
  11. 2
      src/post/post.controller.ts
  12. 2
      src/post/post.model.ts
  13. 8
      src/private-message/private-message.controller.ts
  14. 4
      src/private-message/private-message.model.ts
  15. 2
      src/site/site.controller.ts
  16. 2
      src/site/site.model.ts
  17. 8
      src/user/models/user.model.ts
  18. 18
      src/user/user.controller.ts
  19. 6
      src/user/user.service.ts
  20. 2
      tsconfig.json

1
.eslintignore

@ -1 +1,2 @@
/.*
**/database/migrations/snapshots/*.ts

21
.eslintrc.js

@ -1,21 +0,0 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
tsconfigRootDir: __dirname,
project: 'tsconfig.json',
},
plugins: [
'@typescript-eslint',
],
extends: [
'airbnb-typescript/base',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
],
rules: {
'radix': ['error', 'as-needed'],
'max-len': [2, {'code': 120, 'tabWidth': 2, 'ignoreUrls': true}],
'no-trailing-spaces': [2, { 'skipBlankLines': true }],
'arrow-body-style': 'off'
}
};

20
.eslintrc.json

@ -0,0 +1,20 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
"plugins": [
"@typescript-eslint"
],
"extends": [
"airbnb-typescript/base",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking"
],
"rules": {
"radix": ["error", "as-needed"],
"max-len": [2, {"code": 120, "tabWidth": 2, "ignoreUrls": true}],
"no-trailing-spaces": [2, { "skipBlankLines": true }],
"arrow-body-style": ["error", "always"]
}
}

6
package.json

@ -21,17 +21,17 @@
"@types/node": "^14.14.6",
"@typescript-eslint/eslint-plugin": "^4.7.0",
"@typescript-eslint/parser": "^4.7.0",
"cross-env": "^7.0.2",
"eslint-config-airbnb-typescript": "^12.0.0",
"eslint-plugin-import": "^2.22.1",
"eslint": "^7.13.0",
"nodemon": "^2.0.6",
"ts-node": "^9.0.0",
"typescript": "^4.0.5"
},
"dependencies": {
"cross-env": "^7.0.2",
"dayjs": "^1.9.5",
"dotenv": "^8.2.0",
"eslint-config-airbnb-typescript": "^12.0.0",
"eslint-plugin-import": "^2.22.1",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"knex": "^0.21.10",

4
src/category/category.controller.ts

@ -3,4 +3,6 @@
import { Request, Response } from 'express';
import { getCategoryList } from './category.model';
export const getCategories = async (req: Request, res: Response) => res.json({ categories: await getCategoryList() });
export const getCategories = async (req: Request, res: Response) => {
return res.json({ categories: await getCategoryList() });
};

2
src/category/category.model.ts

@ -5,4 +5,4 @@ export interface Category {
name: string;
}
export const getCategoryList = async (): Promise<Category[]> => knex<Category>('category');
export const getCategoryList = async (): Promise<Category[]> => { return knex<Category>('category'); };

4
src/comment/comment.controller.ts

@ -3,4 +3,6 @@
import { Request, Response } from 'express';
import { getCommentList } from './comment.model';
export const getComments = async (_req: Request, res: Response) => res.json({ comments: await getCommentList() });
export const getComments = async (_req: Request, res: Response) => {
return res.json({ comments: await getCommentList() });
};

2
src/comment/comment.model.ts

@ -15,4 +15,4 @@ export interface Comment {
local: boolean;
}
export const getCommentList = async (): Promise<Comment[]> => knex<Comment>('comment');
export const getCommentList = async (): Promise<Comment[]> => { return knex<Comment>('comment'); };

8
src/community/community.controller.ts

@ -3,6 +3,8 @@
import { Request, Response } from 'express';
import { getCommunityList } from './community.model';
export const getCommunities = async (_req: Request, res: Response) => res.json({
communities: await getCommunityList(),
});
export const getCommunities = async (_req: Request, res: Response) => {
return res.json({
communities: await getCommunityList(),
});
};

2
src/community/community.model.ts

@ -21,4 +21,4 @@ export interface Community {
banner?: string;
}
export const getCommunityList = async (): Promise<Community[]> => knex<Community>('community');
export const getCommunityList = async (): Promise<Community[]> => { return knex<Community>('community'); };

2
src/post/post.controller.ts

@ -3,4 +3,4 @@
import { Request, Response } from 'express';
import { getPostList } from './post.model';
export const getPosts = async (req: Request, res: Response) => res.json({ posts: await getPostList() });
export const getPosts = async (req: Request, res: Response) => { return res.json({ posts: await getPostList() }); };

2
src/post/post.model.ts

@ -23,4 +23,4 @@ export interface Post {
featured: boolean;
}
export const getPostList = async (): Promise<Post[]> => knex<Post>('post');
export const getPostList = async (): Promise<Post[]> => { return knex<Post>('post'); };

8
src/private-message/private-message.controller.ts

@ -3,6 +3,8 @@
import { Request, Response } from 'express';
import { getPrivateMessageList } from './private-message.model';
export const getPrivateMessages = async (req: Request, res: Response) => res.json({
privateMessages: await getPrivateMessageList(),
});
export const getPrivateMessages = async (req: Request, res: Response) => {
return res.json({
privateMessages: await getPrivateMessageList(),
});
};

4
src/private-message/private-message.model.ts

@ -13,4 +13,6 @@ export interface PrivateMessage {
local: boolean;
}
export const getPrivateMessageList = async (): Promise<PrivateMessage[]> => knex<PrivateMessage>('private_message');
export const getPrivateMessageList = async (): Promise<PrivateMessage[]> => {
return knex<PrivateMessage>('private_message');
};

2
src/site/site.controller.ts

@ -3,4 +3,4 @@
import { Request, Response } from 'express';
import { getSiteDetail } from './site.model';
export const getSite = async (req: Request, res: Response) => res.json({ site: await getSiteDetail() });
export const getSite = async (req: Request, res: Response) => { return res.json({ site: await getSiteDetail() }); };

2
src/site/site.model.ts

@ -15,4 +15,4 @@ export interface Site {
banner?: string;
}
export const getSiteDetail = async (): Promise<Site|undefined> => knex<Site>('site').first();
export const getSiteDetail = async (): Promise<Site|undefined> => { return knex<Site>('site').first(); };

8
src/user/models/user.model.ts

@ -38,9 +38,11 @@ export interface User {
inbox_disabled: boolean;
}
export const getUserList = (): Promise<User[]> => knex<User>('user_');
export const getUserList = (): Promise<User[]> => { return knex<User>('user_'); };
export const getUserById = (userId: number): Promise<User|undefined> => knex<User>('user_').where('id', userId).first();
export const getUserById = (userId: number): Promise<User|undefined> => {
return knex<User>('user_').where('id', userId).first();
};
export interface UserView {
readonly id: User['id'];
@ -120,7 +122,7 @@ export const getUserView = async (
});
if (omitEmail) {
return users.map((u: UserView) => ({ ...u, email: '' }));
return users.map((u: UserView) => { return { ...u, email: '' }; });
}
return users;
};

18
src/user/user.controller.ts

@ -6,7 +6,7 @@ import { requireAdminOrMod, requireUserToken } from '../middleware/user.middlewa
const router = Router();
router.get('/', async (req: Request, res: Response) => res.json({ users: await getUserList() }));
router.get('/', async (req: Request, res: Response) => { return res.json({ users: await getUserList() }); });
// This just makes a token for testing for now
router.get('/login', async (req: Request, res: Response) => {
@ -14,13 +14,17 @@ router.get('/login', async (req: Request, res: Response) => {
return res.json({ jwt });
});
router.get('/auth-test', requireUserToken, async (req: Request, res: Response) => res.json({
users: await getUserList(),
}));
router.get('/auth-test', requireUserToken, async (req: Request, res: Response) => {
return res.json({
users: await getUserList(),
});
});
router.get('/:userId', requireAdminOrMod, async (req: Request, res: Response) => res.json({
user: await getUserSecure(parseInt(req.params.userId)),
}));
router.get('/:userId', requireAdminOrMod, async (req: Request, res: Response) => {
return res.json({
user: await getUserSecure(parseInt(req.params.userId)),
});
});
// eslint-disable-next-line import/prefer-default-export
export const UserRoutes = router;

6
src/user/user.service.ts

@ -1,10 +1,10 @@
import { getUserView, UserView } from './models/user.model';
export const getSiteAdmins = (): Promise<UserView[]> => getUserView({ admin: true }, true);
export const getSiteAdmins = (): Promise<UserView[]> => { return getUserView({ admin: true }, true); };
export const getSiteMods = (): Promise<UserView[]> => getUserView({ sitemod: true }, true);
export const getSiteMods = (): Promise<UserView[]> => { return getUserView({ sitemod: true }, true); };
export const getBanned = (): Promise<UserView[]> => getUserView({ banned: true }, true);
export const getBanned = (): Promise<UserView[]> => { return getUserView({ banned: true }, true); };
export const getUserSecure = async (userId: UserView['id']): Promise<UserView> => {
const userList = await getUserView({ id: userId }, true);

2
tsconfig.json

@ -4,7 +4,7 @@
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es2019", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"target": "es2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */

Loading…
Cancel
Save