Skip to content

Commit

Permalink
feat: Handle Typescript files in eslint and babel configs
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
- upgrade from eslint 5 to eslint 8
- upgrade prettier from 1 to 2
- you'll need to run --fix to fix lint issues after
the upgrade. Few errors are not auto fixable, you
can // disable-next-line if needed
  • Loading branch information
acezard committed Dec 2, 2021
1 parent 8fa16be commit fe658ed
Show file tree
Hide file tree
Showing 9 changed files with 1,890 additions and 458 deletions.
3 changes: 3 additions & 0 deletions .tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./packages/eslint-config-cozy-app/.tsconfig.json"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"scripts": {
"build:doc:react": "styleguidist build --config docs/styleguidist.config.js",
"deploy:doc": "git-directory-deploy --directory docs/build/ --branch gh-pages",
"lint": "eslint --ext js,jsx .",
"lint": "eslint --ext js,jsx,ts,tsx .",
"lint:md": "remark . -o",
"test": "lerna run --concurrency 1 test",
"build": "lerna run --parallel build",
Expand Down
1 change: 1 addition & 0 deletions packages/babel-preset-cozy-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ const mkConfig = (api, options) => {
}

config.presets = [
require.resolve('@babel/preset-typescript'),
[require.resolve('@babel/preset-env'), presetEnvOptions],
// if (P)React app
!node && react ? require.resolve('@babel/preset-react') : null
Expand Down
21 changes: 12 additions & 9 deletions packages/babel-preset-cozy-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@
"validate.js"
],
"dependencies": {
"@babel/core": "^7.12.3",
"@babel/helper-plugin-utils": "^7.10.4",
"@babel/plugin-proposal-class-properties": "^7.12.1",
"@babel/plugin-proposal-object-rest-spread": "^7.12.1",
"@babel/plugin-transform-runtime": "^7.12.1",
"@babel/preset-env": "^7.12.1",
"@babel/preset-react": "^7.12.5",
"@babel/runtime": "^7.12.5",
"@babel/core": "^7.16.0",
"@babel/eslint-parser": "^7.16.3",
"@babel/helper-plugin-utils": "^7.14.5",
"@babel/plugin-proposal-class-properties": "^7.16.0",
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
"@babel/plugin-transform-runtime": "^7.16.4",
"@babel/preset-env": "^7.16.4",
"@babel/preset-react": "^7.16.0",
"@babel/preset-typescript": "^7.16.0",
"@babel/runtime": "^7.16.3",
"browserslist-config-cozy": "^0.4.0",
"lodash": "^4.17.19"
"lodash": "^4.17.21",
"typescript": "^4.5.2"
}
}
20 changes: 20 additions & 0 deletions packages/eslint-config-cozy-app/.tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"baseUrl": "./src",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"jsx": "react",
"lib": ["dom", "dom.iterable", "esnext"],
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"noFallthroughCasesInSwitch": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"target": "es5",
"strict": true
}
}
2 changes: 1 addition & 1 deletion packages/eslint-config-cozy-app/basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module.exports = {
plugins: ['prettier'],
extends: ['eslint:recommended', 'eslint-config-prettier'],
parser: 'babel-eslint',
parser: '@babel/eslint-parser',
env: {
browser: true,
jest: true,
Expand Down
19 changes: 11 additions & 8 deletions packages/eslint-config-cozy-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
"vue.js"
],
"dependencies": {
"babel-eslint": "10.0.1",
"eslint": "5.16.0",
"eslint-config-prettier": "4.3.0",
"eslint-plugin-prettier": "3.1.2",
"eslint-plugin-react": "7.24.0",
"eslint-plugin-react-hooks": "2.3.0",
"eslint-plugin-vue": "5.2.3",
"prettier": "1.18.2"
"@babel/eslint-parser": "^7.16.3",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"eslint": "^8.3.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.27.1",
"eslint-plugin-react-hooks": "^4.3.0",
"eslint-plugin-vue": "^8.1.1",
"prettier": "^2.4.1",
"typescript": "^4.5.2"
}
}
25 changes: 23 additions & 2 deletions packages/eslint-config-cozy-app/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@ module.exports = {
rules: Object.assign({}, basics.rules, {
'react/prop-types': 'off',
'react-hooks/rules-of-hooks': 'error',
'react-hooks/exhaustive-deps': 'warn'
})
'react-hooks/exhaustive-deps': 'warn',
}),
overrides: [
{
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
],

files: ['**/*.ts', '**/*.tsx'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: ['./.tsconfig.json'],
},
plugins: ['@typescript-eslint'],
rules: {
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/explicit-function-return-type': 'error',
},
},
],
}

0 comments on commit fe658ed

Please sign in to comment.