From 67d236f7cfb336d9258a51e8282c6f9021d5e4b8 Mon Sep 17 00:00:00 2001 From: reemuru Date: Sat, 18 Sep 2021 21:40:47 -0500 Subject: [PATCH] add eslint and editorconfig This commit adds a simple editorconfig generated via VSCode and .eslintrc.json configuration created with 'npx eslint --init'. The rules are react-specific typescript recommnedations with the Airbnb style guide. Linting can be performed by running 'npm run lint' or fix possible errors with 'npm run eslintfix'. These commands are located in the pacakge.json 'scripts' configuration. Place file extensions and directories to be ignored in .eslintignore. --- .editorconfig | 12 ++++++++++++ .eslintignore | 3 +++ .eslintrc.json | 42 ++++++++++++++++++++++++++++++++++++++++++ package.json | 19 ++++++++++++------- 4 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 .editorconfig create mode 100644 .eslintignore create mode 100644 .eslintrc.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..c1322dc7 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = false +insert_final_newline = false \ No newline at end of file diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000..53d15037 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +*.css +*.svg +*.png \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 00000000..bce38da6 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,42 @@ +{ + "env": { + "browser": true, + "es2021": true + }, + "extends": [ + "plugin:@typescript-eslint/recommended", + "plugin:react/recommended", + "airbnb" + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaFeatures": { + "jsx": true + }, + "ecmaVersion": 12, + "sourceType": "module" + }, + "plugins": [ + "react", + "react-hooks", + "@typescript-eslint" + ], + "rules": { + "no-use-before-define": "off", + "@typescript-eslint/no-use-before-define": ["error"], + "react/jsx-filename-extension": [ "warn", {"extensions": [".tsx"]}], + "import/extensions": ["error","ignorePackages",{"ts": "never", "tsx": "never" }], + "@typescript-eslint/explicit-function-return-type": ["error",{"allowExpressions": true}], + "no-shadow": "off", "@typescript-eslint/no-shadow": ["error"], + "max-len": ["warn", { "code": 80 }], + "react-hooks/rules-of-hooks": "error", + "react-hooks/exhaustive-deps": "warn", + "import/prefer-default-export": "off", + "react/prop-types": "off" + }, + "settings": { + "import/resolver": { + "typescript": {} + } + } +} \ No newline at end of file diff --git a/package.json b/package.json index 907e1c6c..d0d2d742 100644 --- a/package.json +++ b/package.json @@ -22,13 +22,9 @@ "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", - "eject": "react-scripts eject" - }, - "eslintConfig": { - "extends": [ - "react-app", - "react-app/jest" - ] + "eject": "react-scripts eject", + "lint": "eslint src/*", + "eslintfix": "eslint src/* --fix" }, "browserslist": { "production": [ @@ -43,6 +39,15 @@ ] }, "devDependencies": { + "@typescript-eslint/eslint-plugin": "^4.31.1", + "@typescript-eslint/parser": "^4.31.1", + "eslint": "^7.32.0", + "eslint-config-airbnb": "^18.2.1", + "eslint-import-resolver-typescript": "^2.5.0", + "eslint-plugin-import": "^2.24.2", + "eslint-plugin-jsx-a11y": "^6.4.1", + "eslint-plugin-react": "^7.25.2", + "eslint-plugin-react-hooks": "^4.2.0", "monero-javascript": "^0.5.5" } }