From d3ed8503bc3523a998f67b563af17dd0badfc408 Mon Sep 17 00:00:00 2001 From: GuyKh Date: Sun, 11 Oct 2020 16:29:57 +0300 Subject: [PATCH 1/2] Add Prettier, ESLint and Husky hooks --- .eslintrc.js | 39 ++ .prettierrc.js | 24 + package.json | 30 +- src/lib/index.tsx | 2 +- yarn.lock | 1708 ++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 1778 insertions(+), 25 deletions(-) create mode 100644 .eslintrc.js create mode 100644 .prettierrc.js diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..4126fac --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,39 @@ +module.exports = { + extends: [ + "airbnb-typescript", + "airbnb/hooks", + "plugin:@typescript-eslint/recommended", + "prettier", + "prettier/react", + "prettier/@typescript-eslint", + "plugin:prettier/recommended", + ], + plugins: ["react", "@typescript-eslint"], + env: { + browser: true, + es6: true, + }, + globals: { + Atomics: "readonly", + SharedArrayBuffer: "readonly", + }, + parser: "@typescript-eslint/parser", + parserOptions: { + ecmaFeatures: { + jsx: true, + }, + ecmaVersion: 2018, + sourceType: "module", + project: "./tsconfig.json", + }, + rules: { + "linebreak-style": "off", + "react/require-default-props": "off", + "prettier/prettier": [ + "error", + { + endOfLine: "auto", + }, + ], + }, +}; diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 0000000..3583622 --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,24 @@ +module.exports = { + "doubleQuote": true + /** + * printWidth: 80, + * tabWidth: 2, + * useTabs: false, + * semi: true, + * singleQuote: false, + * jsxSingleQuote: false, + * trailingComma: 'none', + * bracketSpacing: true, + * jsxBracketSameLine: false, + * arrowParens: 'avoid', + * rangeStart: 0, + * rangeEnd: Infinity, + * parser: undefined, + * filepath: undefined, + * requirePragma: false, + * insertPragma: false, + * proseWrap: 'preserve', + * htmlWhitespaceSensitivity: 'css', + * endOfLine: 'auto', + */ +}; diff --git a/package.json b/package.json index 35242b1..74e80c8 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,10 @@ "build": "babel src/lib --out-dir lib --out-file-extension .cjs.js --extensions '.ts,.tsx' && tsc", "demo:dev": "webpack-dev-server --mode development", "demo:prod": "webpack --mode production", - "prepublishOnly": "yarn build" + "prepublishOnly": "yarn build", + "format": "prettier --write src/lib/**/*.tsx", + "lint": "tsc --noEmit && eslint src/lib/**/*.tsx", + "lint:fix": "npm run lint -- --fix" }, "keywords": [ "copy email", @@ -30,8 +33,22 @@ "@babel/preset-typescript": "^7.10.4", "@types/react": "^16.9.43", "@types/react-dom": "^16.9.8", + "@typescript-eslint/eslint-plugin": "^4.4.0", + "@typescript-eslint/parser": "^4.4.0", + "babel-eslint": "^10.1.0", "css-loader": "^4.0.0", + "eslint": "^7.11.0", + "eslint-config-airbnb-typescript": "^11.0.0", + "eslint-config-prettier": "^6.12.0", + "eslint-plugin-import": "^2.22.1", + "eslint-plugin-jsx-a11y": "^6.3.1", + "eslint-plugin-prettier": "^3.1.4", + "eslint-plugin-react": "^7.21.4", + "eslint-plugin-react-hooks": "^4.1.2", "html-webpack-plugin": "^4.3.0", + "husky": "^4.3.0", + "lint-staged": "^10.4.0", + "prettier": "^2.1.2", "react": "^16.13.1", "react-dom": "^16.13.1", "source-map-loader": "^1.0.1", @@ -42,6 +59,17 @@ "webpack-cli": "^3.3.12", "webpack-dev-server": "^3.11.0" }, + "husky": { + "hooks": { + "pre-commit": "lint-staged" + } + }, + "lint-staged": { + "**/*.{js,jsx,css,ts,tsx}": [ + "npm run format", + "npm run lint" + ] + }, "repository": { "type": "git", "url": "https://github.com/devfolioco/react-copy-mailto" diff --git a/src/lib/index.tsx b/src/lib/index.tsx index 5313063..337b9ca 100644 --- a/src/lib/index.tsx +++ b/src/lib/index.tsx @@ -8,7 +8,7 @@ const copyToClipboard = (str: string) => { el.style.left = "-9999px"; // Move outside the screen to make it invisible document.body.appendChild(el); // Append the