Skip to content

Commit

Permalink
✅ TS-aware eslint + in CI
Browse files Browse the repository at this point in the history
* Use @typescript-eslint/parser
* Add npm/yarn scripts: prettier check and eslint on all files
* Run all of this in CI (along with eslintrc checker)
* Use typescript parser only for ts{x,} files
* Fix test & cypress sub-configs
* Fix .test.js + off explicit-function-return-type
  • Loading branch information
lajarre committed May 5, 2020
1 parent d98c570 commit 291b5ff
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 334 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
90 changes: 90 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
module.exports = {
root: true,
parser: "babel-eslint",
parserOptions: {
"ecmaFeatures": {
"jsx": true
}
},
env: {
"browser": true,
"commonjs": true,
"es6": true,
},
globals: {
"process": false
},
plugins: [
"react",
"react-hooks"
],
rules: {
"quotes": [
1,
"single",
{
"avoidEscape": true
}
],
"no-console": 1,
"no-restricted-globals": [
2,
"length"
],
"no-global-assign": 0,
"no-unsafe-negation": 0,
"react/prop-types": 0,
"react/jsx-no-target-blank": 0,
"react/no-unescaped-entities": 0,
"react/display-name": 1,
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn"
},
settings: {
"react": {
"version": "detect"
}
},
overrides: [
{
files: [ "**/*.{ts,tsx}" ],
parser: "@typescript-eslint/parser",
parserOptions: {
"ecmaFeatures": {
"jsx": true
},
"tsconfigRootDir": __dirname,
"project": [ "./tsconfig.json" ]
},
plugins: [ "@typescript-eslint" ],
rules: {
"@typescript-eslint/no-empty-function": 0,
"@typescript-eslint/no-use-before-define": 0,
"@typescript-eslint/member-delimiter-style": [2, {
multiline: {
delimiter: "none"
}
}],
"@typescript-eslint/explicit-function-return-type": 0
},
extends: [
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking"
]
},
{
files: [ "**/*.test.js" ],
env: {
mocha: true
}
}
],
extends: [
"eslint:recommended",
"plugin:react/recommended",
"prettier",
"prettier/react",
"prettier/@typescript-eslint"
]
}
44 changes: 0 additions & 44 deletions .eslintrc.yaml

This file was deleted.

1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.eslintrc.js
15 changes: 11 additions & 4 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,22 @@ commands:
- run: CYPRESS_baseUrl=<< parameters.base_url >> yarn run cypress run --record --key 21660df5-36a5-4c49-b23d-801799b0c759 --env language=<< parameters.language >> --config integrationFolder=cypress/integration/<< parameters.integration_folder >>

jobs:
lint:
docker:
- image: node:12.16.1-buster
steps:
- install
- run: |
yarn eslintrc-check
yarn eslint-check --quiet
yarn prettier-check
type-check:
docker:
- image: node:12.16.1-buster
steps:
- install
- run: |
yarn run type-check
yarn type-check
i18n-check:
docker:
- image: node:12.16.1-buster
Expand All @@ -53,7 +62,6 @@ jobs:
git config --global core.quotepath false
yarn test
yarn test-regressions
end-to-end-test:
docker:
- image: cypress/base:12.16.1
Expand All @@ -73,7 +81,6 @@ jobs:
- cypress:
base_url: http://localhost:5002
integration_folder: publi.codes

bundlesize-test:
docker:
- image: cypress/base:12.16.1
Expand All @@ -84,7 +91,6 @@ jobs:
- run: |
yarn run simple-compile
yarn test-bundlesize
production-end-to-end-test:
docker:
- image: cypress/base:12.16.1
Expand Down Expand Up @@ -113,6 +119,7 @@ workflows:
version: 2
test:
jobs:
- lint
- type-check
- i18n-check
- unit-test
Expand Down
3 changes: 2 additions & 1 deletion cypress/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ globals:
cy: false
Cypress: false
expect: false
parser: esprima
env:
mocha: true
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@
"compile": "yarn run webpack --config source/webpack.prod.js && yarn run webpack --config source/webpack.prod.legacyBrowser.js",
"simple-compile": "yarn run webpack --config source/webpack.prod.js",
"stats": "webpack --config source/webpack.prod.js --profile --json > stats.json",
"eslint-check": "eslint --print-config .eslintrc | eslint-config-prettier-check",
"eslint": "LIST=`git diff --cached --name-only --diff-filter=AMR HEAD | grep .*\\.js | grep -v json`; if [ \"$LIST\" ]; then eslint $LIST; fi",
"eslintrc-check": "eslint --print-config .eslintrc.js | eslint-config-prettier-check",
"eslint-check": "eslint . --ext .js,.jsx,.ts,.tsx",
"prettier-check": "prettier --check \"{source,test,cypress}/**/*.{js,jsx,ts,tsx}\"",
"lint": "yarn eslintrc-check && yarn eslint-check && yarn prettier-check",
"type-check": "tsc --noEmit",
"externalize": "node source/scripts/externalize.js",
"analyze-bundle": "ANALYZE_BUNDLE=1 yarn run compile",
"heroku-postbuild": "yarn install --production=false && yarn compile",
"pretest": "LIST=`git diff --name-only --diff-filter=AMR HEAD^..HEAD | grep .*\\.js | grep -v json`; if [ \"$LIST\" ]; then eslint $LIST; fi",
"start": "node source/server.js",
"test-inversions": "yarn test-watch --grep 'inversions'",
"test-meca": "yarn test-watch --grep 'Mécanismes'",
Expand All @@ -89,7 +91,6 @@
"test-units": "mocha-webpack --webpack-config source/webpack.test.js --require source-map-support/register --include componentTestSetup.js --require mock-local-storage --require test/helpers/browser.js test/units.test.js",
"test-regressions": "jest",
"test-bundlesize": "bundlesize",
"type-check": "tsc --noEmit",
"compile-lib": "yarn webpack --config source/webpack.lib.js",
"compile-dev": "FR_SITE='http://localhost:5000${path}' EN_SITE='http://localhost:5001${path}' yarn run compile",
"i18n:rules:check": "node source/scripts/i18n/check-missing-rule-translation.js",
Expand Down Expand Up @@ -141,6 +142,8 @@
"@types/webpack-bundle-analyzer": "^2.13.3",
"@types/webpack-env": "^1.14.1",
"@types/workbox-webpack-plugin": "^5.1.0",
"@typescript-eslint/eslint-plugin": "^2.29.0",
"@typescript-eslint/parser": "^2.29.0",
"akh": "^3.1.2",
"autoprefixer": "^9.3.1",
"babel-eslint": "^11.0.0-beta.0",
Expand All @@ -161,7 +164,7 @@
"dotenv": "=8.1.0",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"eslint": "^6.5.1",
"eslint": "^6.8.0",
"eslint-config-prettier": "^4.0.0",
"eslint-plugin-react": "^7.12.4",
"eslint-plugin-react-hooks": "^2.0.1",
Expand Down
Loading

0 comments on commit 291b5ff

Please sign in to comment.