From c4e0655aed3357ec6ee449ae9838cc53276421af Mon Sep 17 00:00:00 2001 From: Rachid OUBRAIM Date: Thu, 14 Jan 2021 00:06:05 +0100 Subject: [PATCH] #3 Migrate to ESlint and code formatting using prettier and huskey --- .eslintrc.js | 16 ++++++++++++++++ .huskyrc | 6 ++++++ .lintstagedrc | 5 +++++ .prettierrc | 7 ++++++- package.json | 13 +++++++++---- tslint.json | 6 ------ 6 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 .eslintrc.js create mode 100644 .huskyrc create mode 100644 .lintstagedrc delete mode 100644 tslint.json diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..d1506bb --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,16 @@ +module.exports = { + parser: '@typescript-eslint/parser', + parserOptions: { + ecmaVersion: 2020, + sourceType: 'module', + }, + extends: [ + 'plugin:@typescript-eslint/recommended', + 'prettier/@typescript-eslint', + 'plugin:prettier/recommended', + ], + rules: { + // Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs + // e.g. "@typescript-eslint/explicit-function-return-type": "off", + }, +}; diff --git a/.huskyrc b/.huskyrc new file mode 100644 index 0000000..4a70657 --- /dev/null +++ b/.huskyrc @@ -0,0 +1,6 @@ +{ + "hooks": { + "pre-commit": "lint-staged", + "pre-push":"npm run test" + } +} \ No newline at end of file diff --git a/.lintstagedrc b/.lintstagedrc new file mode 100644 index 0000000..66c6b4c --- /dev/null +++ b/.lintstagedrc @@ -0,0 +1,5 @@ +{ + "*.ts": [ + "eslint --fix" + ] +} \ No newline at end of file diff --git a/.prettierrc b/.prettierrc index dc2fb82..651a3a7 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,3 +1,8 @@ { - "singleQuote": true + "singleQuote": true, + "printWidth": 100, + "tabWidth": 2, + "semi": true, + "trailingComma":"all", + "arrowParens": "avoid" } \ No newline at end of file diff --git a/package.json b/package.json index 5e195a3..34a15e3 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "main": "jmap-client-ts.js", "scripts": { "build": "tsc", - "format": "prettier --write \"src/**/*.ts\"", - "lint": "tslint -p tsconfig.json", + "lint": "eslint 'src/**/*.ts'", + "lint:fix": "npm run lint --quiet --fix", "test": "mocha -r ts-node/register -r jsdom-global/register **/*.spec.ts", "prepare": "npm run build", "prePublish": "npm run build" @@ -34,14 +34,19 @@ "devDependencies": { "@types/chai": "4.1.3", "@types/mocha": "8.0.3", + "@typescript-eslint/eslint-plugin": "^4.13.0", + "@typescript-eslint/parser": "^4.13.0", "chai": "4.2.0", + "eslint": "^7.17.0", + "eslint-config-prettier": "^7.1.0", + "eslint-plugin-prettier": "^3.3.1", + "husky": "^4.3.7", "jsdom": "16.4.0", "jsdom-global": "3.0.2", + "lint-staged": "^10.5.3", "mocha": "8.1.3", "prettier": "2.1.2", "ts-node": "9.0.0", - "tslint": "6.1.3", - "tslint-config-prettier": "1.18.0", "typescript": "4.0.3" } } diff --git a/tslint.json b/tslint.json deleted file mode 100644 index 45f18b1..0000000 --- a/tslint.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": ["tslint:recommended", "tslint-config-prettier"] , - "rules": { - "object-literal-sort-keys": false - } -}