Commit de2c6903 authored by Mickaël Bourgier's avatar Mickaël Bourgier
Browse files

🚨 Configure ESLint with Typescript

parent 46959b90
......@@ -6,6 +6,8 @@
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:jest/recommended",
"plugin:react/recommended"
],
......@@ -23,18 +25,36 @@
"rules": {
"react/prop-types": "off"
}
},
{
"files": ["**/*.js"],
"rules": {
"@typescript-eslint/explicit-function-return-type": "off"
}
},
{
"files": ["**/*.ts", "**/*.tsx"],
"rules": {
"react/prop-types": "off"
}
}
],
"parser": "babel-eslint",
"parser": "@typescript-eslint/parser",
"parserOptions": {
"sourceType": "module"
},
"plugins": [
"jest"
"jest",
"@typescript-eslint"
],
"rules": {
"no-alert": "error",
"no-console": "error",
"no-unused-vars": ["error", {
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-unused-vars": ["error", {
"ignoreRestSiblings": true
}],
"no-alert": "error",
"no-console": "error",
"no-unused-vars": "off",
"react/no-unescaped-entities": 0
},
"settings": {
......
......@@ -25,6 +25,7 @@ class ComponentDoc extends Component {
const {
description = '',
props = {},
// eslint-disable-next-line @typescript-eslint/no-var-requires
} = require(`!!react-docgen!@webalt/react/${name}/${name}`);
const longDescription = description.replace(/^@summary .+$/m, '');
......
......@@ -22,6 +22,7 @@ class Home extends Component {
...components.map((name) => {
const {
description,
// eslint-disable-next-line @typescript-eslint/no-var-requires
} = require(`!!react-docgen!@webalt/react/${name}/${name}`);
let shortDescription = '';
......
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path');
const parseJs = require('react-docgen').parse;
......
......@@ -32,7 +32,7 @@
"dev": "WEBPACK_TARGET=docs yarn docs:dev",
"docs:build": "rm -rf docs/dist && NODE_ENV=production WEBPACK_TARGET=docs webpack",
"docs:dev": "webpack-dev-server --hot",
"lint": "eslint ./docs ./src",
"lint": "eslint './docs/**/*.{js,ts,tsx}' './src/**/*.{js,ts,tsx}'",
"prepublishOnly": "yarn prettier && yarn lint && yarn build",
"prettier": "prettier --write './src/**/*.js' './docs/**/*.js'",
"prettier:check": "prettier --check './src/**/*.js' './docs/**/*.js'",
......@@ -63,8 +63,9 @@
"@testing-library/react": "^10.0.4",
"@types/react": "^16.9.34",
"@types/react-dom": "^16.9.7",
"@typescript-eslint/eslint-plugin": "^2.31.0",
"@typescript-eslint/parser": "^2.31.0",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^26.0.0",
"babel-loader": "^8.0.5",
"codemirror": "^5.42.0",
......
......@@ -106,7 +106,7 @@ export interface BoxProps {
/**
* @summary Boîte stylisée en fonction des couleurs du thème
*/
export const Box = (props: BoxProps) => {
export const Box: React.FC<BoxProps> = (props) => {
const {
classes,
className: classNameProps,
......
......@@ -43,21 +43,14 @@ function Modal({
setPrevOpen(props.open);
}
useEffect(() => {
document.addEventListener('keydown', handleKeyDown);
return () => {
document.removeEventListener('keydown', handleKeyDown);
};
}, []);
useEffect(() => {
document.addEventListener('mousedown', handleClickOutside, false);
return () => {
document.removeEventListener('mousedown', handleClickOutside, false);
};
}, []);
const exit = (e) => {
if (props.onClose) {
props.onClose(e);
if (!getHasTransition(props)) {
setExited(true);
}
}
};
const handleKeyDown = (e) => {
if (e.key === 'Escape' || e.key === 'Esc' || e.keyCode === 27) {
......@@ -78,6 +71,22 @@ function Modal({
exit(e);
};
useEffect(() => {
document.addEventListener('keydown', handleKeyDown);
return () => {
document.removeEventListener('keydown', handleKeyDown);
};
}, []);
useEffect(() => {
document.addEventListener('mousedown', handleClickOutside, false);
return () => {
document.removeEventListener('mousedown', handleClickOutside, false);
};
}, []);
const hasTransition = getHasTransition(props);
const handleExited = () => {
......@@ -90,15 +99,6 @@ function Modal({
}
};
const exit = (e) => {
if (props.onClose) {
props.onClose(e);
if (!getHasTransition(props)) {
setExited(true);
}
}
};
const childProps = {};
if (hasTransition) {
......
......@@ -41,6 +41,7 @@ describe('@webalt/react', () => {
it('must export all components', () => {
const files = glob.sync(path.join(__dirname, './[A-Z]*/index.js'));
// eslint-disable-next-line @typescript-eslint/no-var-requires
const index = require('./index');
const regex = /([^/]+)\/index\.js$/;
......
......@@ -285,7 +285,7 @@
chalk "^2.0.0"
js-tokens "^4.0.0"
"@babel/parser@^7.1.0", "@babel/parser@^7.7.0", "@babel/parser@^7.7.5", "@babel/parser@^7.8.6", "@babel/parser@^7.9.6":
"@babel/parser@^7.1.0", "@babel/parser@^7.7.5", "@babel/parser@^7.8.6", "@babel/parser@^7.9.6":
version "7.9.6"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.9.6.tgz#3b1bbb30dabe600cd72db58720998376ff653bc7"
integrity sha512-AoeIEJn8vt+d/6+PXDRPaksYhnlbMIiejioBZvvMQsOjW/JYK6k/0dKnvvP3EhK5GfMBWDPtrxRtegWdAcdq9Q==
......@@ -862,7 +862,7 @@
"@babel/parser" "^7.8.6"
"@babel/types" "^7.8.6"
"@babel/traverse@^7.1.0", "@babel/traverse@^7.7.0", "@babel/traverse@^7.7.4", "@babel/traverse@^7.8.3", "@babel/traverse@^7.9.6":
"@babel/traverse@^7.1.0", "@babel/traverse@^7.7.4", "@babel/traverse@^7.8.3", "@babel/traverse@^7.9.6":
version "7.9.6"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.9.6.tgz#5540d7577697bf619cc57b92aa0f1c231a94f442"
integrity sha512-b3rAHSjbxy6VEAvlxM8OV/0X4XrG72zoxme6q1MOoe2vd0bEc+TwayhuC1+Dfgqh1QEG+pj7atQqvUprHIccsg==
......@@ -877,7 +877,7 @@
globals "^11.1.0"
lodash "^4.17.13"
"@babel/types@^7.0.0", "@babel/types@^7.3.0", "@babel/types@^7.3.3", "@babel/types@^7.4.4", "@babel/types@^7.7.0", "@babel/types@^7.8.3", "@babel/types@^7.8.6", "@babel/types@^7.9.0", "@babel/types@^7.9.5", "@babel/types@^7.9.6":
"@babel/types@^7.0.0", "@babel/types@^7.3.0", "@babel/types@^7.3.3", "@babel/types@^7.4.4", "@babel/types@^7.8.3", "@babel/types@^7.8.6", "@babel/types@^7.9.0", "@babel/types@^7.9.5", "@babel/types@^7.9.6":
version "7.9.6"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.9.6.tgz#2c5502b427251e9de1bd2dff95add646d95cc9f7"
integrity sha512-qxXzvBO//jO9ZnoasKF1uJzHd2+M6Q2ZPIVfnFps8JJvXy0ZBbwbNOmE6SGIY5XOY6d1Bo5lb9d9RJ8nv3WSeA==
......@@ -1182,6 +1182,11 @@
resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0"
integrity sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==
"@types/eslint-visitor-keys@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d"
integrity sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag==
"@types/events@*":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7"
......@@ -1359,7 +1364,17 @@
dependencies:
"@types/yargs-parser" "*"
"@typescript-eslint/experimental-utils@^2.5.0":
"@typescript-eslint/eslint-plugin@^2.31.0":
version "2.31.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.31.0.tgz#942c921fec5e200b79593c71fafb1e3f57aa2e36"
integrity sha512-iIC0Pb8qDaoit+m80Ln/aaeu9zKQdOLF4SHcGLarSeY1gurW6aU4JsOPMjKQwXlw70MvWKZQc6S2NamA8SJ/gg==
dependencies:
"@typescript-eslint/experimental-utils" "2.31.0"
functional-red-black-tree "^1.0.1"
regexpp "^3.0.0"
tsutils "^3.17.1"
"@typescript-eslint/experimental-utils@2.31.0", "@typescript-eslint/experimental-utils@^2.5.0":
version "2.31.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.31.0.tgz#a9ec514bf7fd5e5e82bc10dcb6a86d58baae9508"
integrity sha512-MI6IWkutLYQYTQgZ48IVnRXmLR/0Q6oAyJgiOror74arUMh7EWjJkADfirZhRsUMHeLJ85U2iySDwHTSnNi9vA==
......@@ -1369,6 +1384,16 @@
eslint-scope "^5.0.0"
eslint-utils "^2.0.0"
"@typescript-eslint/parser@^2.31.0":
version "2.31.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-2.31.0.tgz#beddd4e8efe64995108b229b2862cd5752d40d6f"
integrity sha512-uph+w6xUOlyV2DLSC6o+fBDzZ5i7+3/TxAsH4h3eC64tlga57oMb96vVlXoMwjR/nN+xyWlsnxtbDkB46M2EPQ==
dependencies:
"@types/eslint-visitor-keys" "^1.0.0"
"@typescript-eslint/experimental-utils" "2.31.0"
"@typescript-eslint/typescript-estree" "2.31.0"
eslint-visitor-keys "^1.1.0"
"@typescript-eslint/typescript-estree@2.31.0":
version "2.31.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.31.0.tgz#ac536c2d46672aa1f27ba0ec2140d53670635cfd"
......@@ -1833,18 +1858,6 @@ babel-core@^7.0.0-bridge.0:
resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-7.0.0-bridge.0.tgz#95a492ddd90f9b4e9a4a1da14eb335b87b634ece"
integrity sha512-poPX9mZH/5CSanm50Q+1toVci6pv5KSRv/5TWCwtzQS5XEwn40BcCrgIeMFWP9CKKIniKXNxoIOnOq4VVlGXhg==
babel-eslint@^10.0.1:
version "10.1.0"
resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-10.1.0.tgz#6968e568a910b78fb3779cdd8b6ac2f479943232"
integrity sha512-ifWaTHQ0ce+448CYop8AdrQiBsGrnC+bMgfyKFdi6EsPLTAWG+QfyDeM6OH+FmWnKvEq5NnBMLvlBUPKQZoDSg==
dependencies:
"@babel/code-frame" "^7.0.0"
"@babel/parser" "^7.7.0"
"@babel/traverse" "^7.7.0"
"@babel/types" "^7.7.0"
eslint-visitor-keys "^1.0.0"
resolve "^1.12.0"
babel-jest@^26.0.0:
version "26.0.0"
resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-26.0.0.tgz#fa2adcff5313bd89bdf200bfa674fa4babd4f602"
......@@ -3345,7 +3358,7 @@ eslint-utils@^2.0.0:
dependencies:
eslint-visitor-keys "^1.1.0"
eslint-visitor-keys@^1.0.0, eslint-visitor-keys@^1.1.0:
eslint-visitor-keys@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.1.0.tgz#e2a82cea84ff246ad6fb57f9bde5b46621459ec2"
integrity sha512-8y9YjtM1JBJU/A9Kc+SbaOV4y29sSWckBwMHa+FGtVj5gN/sbnKDf6xJUl+8g7FAij9LVaP8C24DUiH/f/2Z9A==
......@@ -7221,6 +7234,11 @@ regexpp@^2.0.1:
resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-2.0.1.tgz#8d19d31cf632482b589049f8281f93dbcba4d07f"
integrity sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw==
regexpp@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.1.0.tgz#206d0ad0a5648cffbdb8ae46438f3dc51c9f78e2"
integrity sha512-ZOIzd8yVsQQA7j8GCSlPGXwg5PfmA1mrq0JP4nGhh54LaKN3xdai/vHUDu74pKwV8OxseMS65u2NImosQcSD0Q==
regexpu-core@^4.7.0:
version "4.7.0"
resolved "https://registry.yarnpkg.com/regexpu-core/-/regexpu-core-4.7.0.tgz#fcbf458c50431b0bb7b45d6967b8192d91f3d938"
......@@ -7411,7 +7429,7 @@ resolve-url@^0.2.1:
resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a"
integrity sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo=
resolve@^1.10.0, resolve@^1.12.0, resolve@^1.15.1, resolve@^1.17.0, resolve@^1.3.2:
resolve@^1.10.0, resolve@^1.15.1, resolve@^1.17.0, resolve@^1.3.2:
version "1.17.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.17.0.tgz#b25941b54968231cc2d1bb76a79cb7f2c0bf8444"
integrity sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment