Skip to content

Commit

Permalink
Fix ESLint config
Browse files Browse the repository at this point in the history
- Fix config so eslint checks all files in the project when run.
- Add a library to check testing library common issues.
- Fix typescript config issues when running eslint.
  • Loading branch information
maurobender committed Sep 30, 2022
1 parent c99d952 commit 70cd644
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 63 deletions.
174 changes: 121 additions & 53 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
module.exports = {
'root': true,
'env': {
'browser': true,
'es2021': true,
'jest': true
},
'extends': [
'airbnb-base',
'plugin:@typescript-eslint/recommended'
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
'plugin:jest/recommended',
'plugin:testing-library/react'
],
'parser': '@typescript-eslint/parser',
'plugins': [ '@typescript-eslint' ],
'plugins': [ '@typescript-eslint', 'jest', 'react', 'testing-library' ],
'parserOptions': {
'ecmaVersion': 12,
'sourceType': 'module'
Expand All @@ -24,23 +26,83 @@ module.exports = {
'alwaysTryTypes': true,
'project': './tsconfig.json'
}
},
'react': {
'version': 'detect'
}
},
'overrides': [
{
'files': [ 'src/*.ts' ],
'files': [ 'src/**/*.ts', 'src/**/*.tsx' ],
'parserOptions': {
'project': './tsconfig.json'
},
'excludedFiles': '*.js',
'extends': [
'plugin:@typescript-eslint/recommended-requiring-type-checking'
]
],
'rules': {
'@typescript-eslint/no-unsafe-assignment': 'off'
}
},
{
'files': [ 'tests/**/*.ts' ],
'parserOptions': {
'project': './tsconfig.tests.json'
},
'excludedFiles': '*.js',
'extends': [
'plugin:@typescript-eslint/recommended-requiring-type-checking'
],
'rules': {
'@typescript-eslint/no-unsafe-assignment': 'off'
}
},
{
'files': [ 'example/src/**/*.ts', 'example/src/**/*.tsx' ],
'parserOptions': {
'project': './example/tsconfig.json'
},
'excludedFiles': '*.js',
'extends': [
'plugin:@typescript-eslint/recommended-requiring-type-checking'
],
'rules': {
'@typescript-eslint/no-unsafe-assignment': 'off'
}
},
{
'files': [ 'web_example/src/**/*.ts', 'web_example/src/**/*.tsx' ],
'parserOptions': {
'project': './web_example/tsconfig.json'
},
'excludedFiles': '*.js',
'extends': [
'plugin:@typescript-eslint/recommended-requiring-type-checking'
],
'rules': {
'@typescript-eslint/no-unsafe-assignment': 'off'
}
},
{
'files': [ 'docs/src/**/*.ts', 'docs/src/**/*.tsx' ],
'parserOptions': {
'project': './docs/tsconfig.json'
},
'excludedFiles': '*.js',
'extends': [
'plugin:@typescript-eslint/recommended-requiring-type-checking'
],
'rules': {
'@typescript-eslint/no-unsafe-assignment': 'off',
'react/jsx-filename-extension': [ 1, { extensions: [ '.ts', '.tsx', '.js', '.jsx' ] } ]
}
},
{
'files': [ 'example/**/*', 'web_example/**/*', 'docs/**/*' ],
'rules': {
'import/no-extraneous-dependencies': 'off'
'import/no-extraneous-dependencies': 'off',
'no-alert': 'off'
}
},
{
Expand All @@ -54,16 +116,13 @@ module.exports = {
{
'files': [ 'tests/**/*' ],
'rules': {
'@typescript-eslint/no-var-requires': 'off'
'@typescript-eslint/no-var-requires': 'off',
'react/jsx-filename-extension': 'off'
}
}
],
'ignorePatterns': [ 'dist/**/*' ],
'ignorePatterns': [ 'build/**/*', 'node_modules/**/*', 'android/**/*', 'ios/**/*' ],
'rules': {
'no-shadow': 'off',
'@typescript-eslint/no-shadow': [ 'error' ],
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': [ 'error' ],
'import/extensions': [
'error',
'ignorePackages',
Expand All @@ -74,55 +133,27 @@ module.exports = {
'tsx': 'never'
}
],
'no-tabs': 'off',
'indent': [
'error',
'tab'
],
'comma-dangle': [
'error',
'never'
],
'import/prefer-default-export': 'off',
'space-in-parens': [
'error',
'always'
],
'array-bracket-spacing': [
'import/no-dynamic-require': 0,
'import/no-extraneous-dependencies': [
'error',
'always'
{ 'devDependencies': true }
],
'import/no-named-as-default': 'off',
'no-tabs': [ 'error', { allowIndentationTabs: true } ],
'indent': [ 'error', 'tab' ],
'comma-dangle': [ 'error', 'never' ],
'space-in-parens': [ 'error', 'always' ],
'array-bracket-spacing': [ 'error', 'always' ],
'no-underscore-dangle': [
'error',
{
'allowAfterThis': true
}
],
'computed-property-spacing': [
'error',
'always'
],
'quote-props': [
'error',
'consistent'
],
'import/no-dynamic-require': 0,
'import/no-extraneous-dependencies': [
'error',
{
'devDependencies': true
}
{ 'allowAfterThis': true }
],
'computed-property-spacing': [ 'error', 'always' ],
'quote-props': [ 'error', 'consistent' ],
'prefer-const': 'off',
'no-param-reassign': 'off',
'import/no-named-as-default': 'off',
'function-paren-newline': 'off',
'no-restricted-imports': [
'error',
{
'patterns': [ '@material-ui/*/*/*', '!@material-ui/core/test-utils/*' ]
}
],
'arrow-parens': [
2,
'as-needed',
Expand All @@ -132,6 +163,43 @@ module.exports = {
'error',
'always',
{ 'exceptAfterSingleLine': true }
]
],
// Typescript
'no-shadow': 'off',
'@typescript-eslint/no-shadow': [ 'error' ],
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': [ 'error' ],
'@typescript-eslint/type-annotation-spacing': [
'error',
{
before: false,
after: true,
overrides: { arrow: { before: true, after: true } }
}
],
'@typescript-eslint/no-unsafe-assignment': 'off',
// Jest
'jest/expect-expect': [
'error',
{ assertFunctionNames: [ 'expect' ] }
],
'jest/no-disabled-tests': 'error',
'jest/no-focused-tests': 'error',
'jest/no-identical-title': 'error',
'jest/prefer-to-have-length': 'error',
'jest/valid-expect': 'error',
// Testing library
'testing-library/prefer-screen-queries': 'off',
// JSX
'react/jsx-indent': 'off',
'react/jsx-indent-props': [ 2, 'tab' ],
'react/jsx-filename-extension': [ 1, { extensions: [ '.ts', '.tsx' ] } ],
'react/function-component-definition': [ 2, {
namedComponents: 'arrow-function',
unnamedComponents: 'arrow-function'
} ],
'react/jsx-props-no-spreading': 'off',
'react/prop-types': 'off',
'react/require-default-props': 'off'
}
};
29 changes: 29 additions & 0 deletions example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"compilerOptions": {
"paths": {
"@amalgama/react-native-ui-kit": ["../src"]
},
"jsx": "react-native",
"lib": ["esnext", "dom"],
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"esModuleInterop": true,
"importsNotUsedAsValues": "error",
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noImplicitUseStrict": false,
"noStrictGenericChecks": false,
"noUnusedLocals": true,
"allowSyntheticDefaultImports": true,
"noUnusedParameters": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "esnext"
},
"include": ["src"],
"exclude": ["node_modules", "build"]
}
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"eslint-import-resolver-typescript": "^2.7.1",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-testing-library": "^5.7.0",
"husky": "^6.0.0",
"jest": "^26.0.1",
"jest-junit": "^13.2.0",
Expand Down Expand Up @@ -115,6 +116,9 @@
"testMatch": [
"<rootDir>/tests/**/?(*.)(spec|test).(js|ts|jsx|tsx)"
],
"transform": {
"^.+\\.[jt]sx?$": "babel-jest"
},
"modulePathIgnorePatterns": [
"<rootDir>/example/node_modules",
"<rootDir>/dist/"
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
"strict": true,
"target": "esnext"
},
"include": [ "src" ],
"exclude": ["node_modules", "tests"]
}
7 changes: 7 additions & 0 deletions tsconfig.tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

{
"extends": "./tsconfig",
"include": [ "src", "tests" ],
"exclude": ["node_modules"]
}

3 changes: 2 additions & 1 deletion web_example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
},
"resolutions": {
"@types/react": "17.0.2",
"@types/react-dom": "17.0.2"
"@types/react-dom": "17.0.2",
"@types/react-native": "0.65"
},
"browserslist": {
"production": [
Expand Down
12 changes: 6 additions & 6 deletions web_example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1913,14 +1913,14 @@
"@types/react" "*"
"@types/react-native" "*"

"@types/react-native@*":
version "0.69.2"
resolved "https://registry.yarnpkg.com/@types/react-native/-/react-native-0.69.2.tgz#cf6fe8c909093833579ff5956bc645d6e77de426"
integrity sha512-AVdWv4B8/++T5QQdnpveb2OVqD+0i8SOoT63ZRD+lNtQIYxzDak91V0k6olthy+H261d4t/MRBC1cfX1Rwsb6A==
"@types/react-native@*", "@types/[email protected]":
version "0.65.26"
resolved "https://registry.yarnpkg.com/@types/react-native/-/react-native-0.65.26.tgz#a1dc5a3a983d47eb61226a05221b2f7fd637539f"
integrity sha512-o/YpCvmLLH5uf89d9IiCXMRWEp0flIHBq7lVJq1najoF1aZgaAtmzdJhqPUcqxaetJNShnWMoajxL2dv7yjQJg==
dependencies:
"@types/react" "*"
"@types/react" "^17"

"@types/react@*", "@types/[email protected]":
"@types/react@*", "@types/[email protected]", "@types/react@^17":
version "17.0.2"
resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.2.tgz#3de24c4efef902dd9795a49c75f760cbe4f7a5a8"
integrity sha512-Xt40xQsrkdvjn1EyWe1Bc0dJLcil/9x2vAuW7ya+PuQip4UYUaXyhzWmAbwRsdMgwOFHpfp7/FFZebDU6Y8VHA==
Expand Down
Loading

0 comments on commit 70cd644

Please sign in to comment.