Skip to content

Commit

Permalink
Merge pull request #2 from Rulexec/style
Browse files Browse the repository at this point in the history
Big refactoring: eslint/strict typescript/tests
  • Loading branch information
Rulexec authored Nov 20, 2021
2 parents 8808c54 + b8672b5 commit 8a462ad
Show file tree
Hide file tree
Showing 160 changed files with 11,396 additions and 3,683 deletions.
3 changes: 2 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
TOKEN=123
MONGO=mongodb://localhost:27017/shieldy
MONGO=mongodb://user:password@localhost:27017/shieldy
WORKERS_COUNT=1
72 changes: 72 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const options = {
root: true,
env: {
node: true,
es6: true,
},
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
'linebreak-style': ['error', 'unix'],
'wrap-iife': ['error', 'inside'],
'no-constant-condition': ['error', {checkLoops: false}],
'no-restricted-syntax': ['error', 'BinaryExpression[operator="in"]'],
'semi': ['error', 'always'],
},

overrides: [
{
files: ['**/?(*.)+(spec|test).ts'],
plugins: ['jest'],
extends: ['plugin:jest/recommended'],
rules: {
'jest/expect-expect': 0,
},
},
],
};

const errorRules = [
'guard-for-in',
'no-extra-bind',
'no-extra-label',
'no-floating-decimal',
'no-lone-blocks',
'no-loop-func',
'no-new',
'no-new-wrappers',
'no-octal-escape',
'no-proto',
'no-return-assign',
'no-self-compare',
'no-sequences',
'no-unmodified-loop-condition',
'no-unused-expressions',
'no-useless-call',
'no-useless-return',
'require-await',
'no-label-var',
];

const warningRules = [
'block-scoped-var',
'dot-notation',
'radix',
// 'no-console',
'no-mixed-spaces-and-tabs',
];

errorRules.forEach(function (x) {
options.rules[x] = 'error';
});

warningRules.forEach(function (x) {
options.rules[x] = 'warn';
});

module.exports = options;
1 change: 0 additions & 1 deletion .github/FUNDING.yml

This file was deleted.

20 changes: 20 additions & 0 deletions .github/workflows/github-actions-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: PR checks
on:
pull_request:
types: [synchronize]
jobs:
PR-Checks:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v2
- name: Setup nodejs
uses: actions/setup-node@v2
with:
node-version: '12'
cache: 'yarn'
- name: Install dependencies
run: yarn install
- run: yarn run lint
- run: yarn run build-ts
- run: yarn run test
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run precommit
13 changes: 13 additions & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
semi: true

printWidth: 80

tabWidth: 2
useTabs: false

singleQuote: true
quoteProps: consistent
trailingComma: all

bracketSpacing: false
arrowParens: always
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.tabSize": 2
}
9 changes: 9 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- Move methods like `botRemoveEntryMessages` out of `src/database/mongo`
- Wrap all promises without `.catch(report)`
- Investigate mongodb reconnects
- Fix type hacks from `src/types/hacks`
- Get rid of custom `telegraf` dependency
- Migrate all telegraf's `.command`, `.action`, `.use` to methods from `appContext`
- Collect stats (at least requests per minute)
- Use external queue for telegram updates (for seamless updates)
- Write scripts for backup/restore
6 changes: 6 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
presets: [
['@babel/preset-env', { targets: { node: 'current' } }],
'@babel/preset-typescript',
],
}
16 changes: 16 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default {
clearMocks: true,
// collectCoverage: true,
// coverageDirectory: 'coverage',
// coverageProvider: 'v8',
roots: ['src'],
testMatch: ['**/?(*.)+(spec|test).[tj]s'],
testPathIgnorePatterns: ['/node_modules/'],
moduleNameMapper: {
'^@root/(.*)': '<rootDir>/src/$1',
'^@helpers/(.*)': '<rootDir>/src/helpers/$1',
'^@middlewares/(.*)': '<rootDir>/src/middlewares/$1',
'^@commands/(.*)': '<rootDir>/src/commands/$1',
'^@models/(.*)': '<rootDir>/src/models/$1',
},
}
41 changes: 35 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,66 @@
"start-kicker": "node --max-old-space-size=4000 dist/kickChecker.js",
"start-deleter": "node dist/messageDeleter.js",
"upload-translations": "node scripts/upload.js",
"download-translations": "node scripts/download.js && yarn prettier --single-quote --no-semi --write ./src/helpers/localizations.ts"
"download-translations": "node scripts/download.js && yarn prettier --single-quote --no-semi --write ./src/helpers/localizations.ts",
"lint": "eslint src",
"test": "jest",
"precommit": "pretty-quick --staged && lint-staged -v",
"prepare": "husky install"
},
"dependencies": {
"@typegoose/typegoose": "^7.4.7",
"@types/axios": "^0.14.0",
"@types/dotenv": "^8.2.0",
"@types/lodash": "^4.14.165",
"@types/mongoose": "^5.7.36",
"@types/node": "^14.11.10",
"axios": "^0.21.1",
"concurrently": "^5.3.0",
"dotenv": "^8.2.0",
"lodash": "^4.17.20",
"module-alias": "^2.2.2",
"mongoose": "^5.10.9",
"mongodb": "^4.0.1",
"sharp": "^0.26.3",
"svg-captcha": "^1.4.0",
"tall": "^3.1.0",
"telegraf": "git+https://github.com/backmeupplz/telegraf.git#ccef1dc6c811359d4d36667b57237bfba74841b1",
"telegram-typings": "^5.0.0",
"typescript": "^4.0.3"
"typescript": "^4.3.5"
},
"devDependencies": {
"@babel/core": "^7.15.5",
"@babel/preset-env": "^7.15.6",
"@babel/preset-typescript": "^7.15.0",
"@types/jest": "^26.0.24",
"@types/mongodb": "^3.6.20",
"@typescript-eslint/eslint-plugin": "^4.28.2",
"@typescript-eslint/parser": "^4.28.2",
"babel-jest": "^27.2.4",
"eslint": "^7.30.0",
"eslint-plugin-jest": "^24.4.0",
"flat": "^5.0.2",
"husky": "^7.0.1",
"jest": "^27.0.6",
"lint-staged": "^11.0.0",
"nodemon": "^2.0.5",
"prettier": "^2.1.2"
"prettier": "2.3.2",
"pretty-quick": "^3.1.1",
"ts-node": "^10.1.0",
"typegram": "^3.4.1"
},
"_moduleAliases": {
"@root": "dist",
"@commands": "dist/commands",
"@helpers": "dist/helpers",
"@middlewares": "dist/middlewares",
"@models": "dist/models"
},
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged && lint-staged"
}
},
"lint-staged": {
"*.+(js|ts)": [
"eslint"
]
}
}
Loading

0 comments on commit 8a462ad

Please sign in to comment.