diff --git a/packages/eslint-config-typescript-react/.eslintrc.js b/packages/eslint-config-typescript-react/.eslintrc.js new file mode 100644 index 0000000..f2d97d6 --- /dev/null +++ b/packages/eslint-config-typescript-react/.eslintrc.js @@ -0,0 +1,55 @@ +const config = { + env: { + browser: true, + es6: true, + node: true, + }, + root: true, + parser: '@typescript-eslint/parser', + plugins: ['@typescript-eslint', 'import', 'jsx-a11y', 'jest', 'react-hooks'], + extends: [ + 'eslint:recommended', + 'plugin:react/recommended', + 'plugin:@typescript-eslint/eslint-recommended', + 'plugin:@typescript-eslint/recommended', + 'prettier', + 'prettier/react', + 'prettier/@typescript-eslint', + 'plugin:import/typescript', + ], + rules: { + '@typescript-eslint/explicit-function-return-type': 'off', + '@typescript-eslint/no-var-requires': 'off', + 'import/no-default-export': 'error', + 'import/no-deprecated': 'warn', + 'import/order': [ + 'error', + { + pathGroupsExcludedImportTypes: ['builtin'], + groups: [ + 'builtin', + 'external', + 'internal', + 'unknown', + 'parent', + 'sibling', + 'index', + ], + 'newlines-between': 'always', + alphabetize: { order: 'asc' }, + }, + ], + 'import/prefer-default-export': 'off', + 'react-hooks/exhaustive-deps': 'warn', + 'react/prop-types': 'off', + 'react/react-in-jsx-scope': 'off', + }, + settings: { + 'import/ignore': ['node_modules'], + react: { + version: 'detect', + }, + }, +} + +module.exports = config diff --git a/packages/eslint-config-typescript-react/README.md b/packages/eslint-config-typescript-react/README.md new file mode 100644 index 0000000..27289f8 --- /dev/null +++ b/packages/eslint-config-typescript-react/README.md @@ -0,0 +1,5 @@ +# @jdp-dev/eslint-config + +My shareable [ESLint](https://eslint.org/) config for +[TypeScript](https://www.typescriptlang.org/) [React](https://reactjs.org/) +projects. diff --git a/packages/eslint-config-typescript-react/__tests__/index.js b/packages/eslint-config-typescript-react/__tests__/index.js new file mode 100644 index 0000000..e5a1d6f --- /dev/null +++ b/packages/eslint-config-typescript-react/__tests__/index.js @@ -0,0 +1,6 @@ +const test = require('tape') + +test('entry point parses', (t) => { + t.doesNotThrow(() => require('..'), 'index does not throw') + t.end() +}) diff --git a/packages/eslint-config-typescript-react/__tests__/validate-config.js b/packages/eslint-config-typescript-react/__tests__/validate-config.js new file mode 100644 index 0000000..ac27b2a --- /dev/null +++ b/packages/eslint-config-typescript-react/__tests__/validate-config.js @@ -0,0 +1,20 @@ +const eslint = require('eslint') +const test = require('tape') + +test('load config in eslint to validate all rule syntax is correct', (t) => { + const cli = new eslint.CLIEngine({ + useEslintrc: false, + configFile: 'index.js', + }) + + const code = ` + const Hello = ({ name }: { name: string }) => { + return
Hello, {name}!
+ } +` + + const result = cli.executeOnText(code) + + t.equal(result.errorCount, 0) + t.end() +}) diff --git a/packages/eslint-config-typescript-react/index.js b/packages/eslint-config-typescript-react/index.js new file mode 100644 index 0000000..69285fe --- /dev/null +++ b/packages/eslint-config-typescript-react/index.js @@ -0,0 +1 @@ +module.exports = require('./.eslintrc.js') diff --git a/packages/eslint-config-typescript-react/package.json b/packages/eslint-config-typescript-react/package.json new file mode 100644 index 0000000..1d6de66 --- /dev/null +++ b/packages/eslint-config-typescript-react/package.json @@ -0,0 +1,50 @@ +{ + "name": "@jdp-dev/eslint-config-typescript-react", + "version": "0.0.3", + "description": "My shareable ESLint config for TypeScript React projects.", + "private": false, + "homepage": "https://github.com/john-d-pelingo/jdp-scripts", + "author": { + "email": "johndarrylpelingo@gmail.com", + "name": "John Darryl Pelingo", + "url": "https://johndpelingo.com" + }, + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/john-d-pelingo/jdp-scripts", + "directory": "packages/eslint-config" + }, + "bugs": { + "url": "https://github.com/john-d-pelingo/jdp-scripts/issues" + }, + "main": "index.js", + "scripts": { + "lint": "eslint . --config=.eslintrc.js", + "test": "npm run lint && tape __tests__/*.js" + }, + "peerDependencies": { + "@typescript-eslint/eslint-plugin": "^4.9.0", + "@typescript-eslint/parser": "^4.9.0", + "eslint": "^7.14.0", + "eslint-plugin-import": "^2.22.1", + "eslint-plugin-jsx-a11y": "^6.4.1", + "eslint-plugin-react": "^7.21.5", + "eslint-plugin-react-hooks": "^4.2.0", + "react": "^17.0.1", + "typescript": "^4.1.2" + }, + "dependencies": { + "@typescript-eslint/eslint-plugin": "^4.9.0", + "@typescript-eslint/parser": "^4.9.0", + "eslint": "^7.14.0", + "eslint-config-airbnb-typescript": "^12.0.0", + "eslint-config-prettier": "^6.15.0", + "eslint-plugin-import": "^2.22.1", + "eslint-plugin-jsx-a11y": "^6.4.1", + "eslint-plugin-react": "^7.21.5", + "eslint-plugin-react-hooks": "^4.2.0", + "react": "^17.0.1", + "typescript": "^4.1.2" + } +} diff --git a/yarn.lock b/yarn.lock index 5dcc392..954d3a3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -249,7 +249,7 @@ semver "^7.3.2" tsutils "^3.17.1" -"@typescript-eslint/experimental-utils@4.9.0", "@typescript-eslint/experimental-utils@^4.0.1": +"@typescript-eslint/experimental-utils@4.9.0": version "4.9.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.9.0.tgz#23a296b85d243afba24e75a43fd55aceda5141f0" integrity sha512-0p8GnDWB3R2oGhmRXlEnCvYOtaBCijtA5uBfH5GxQKsukdSQyI4opC4NGTUb88CagsoNQ4rb/hId2JuMbzWKFQ== @@ -1278,13 +1278,6 @@ eslint-plugin-import@^2.22.1: resolve "^1.17.0" tsconfig-paths "^3.9.0" -eslint-plugin-jest@^24.1.3: - version "24.1.3" - resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-24.1.3.tgz#fa3db864f06c5623ff43485ca6c0e8fc5fe8ba0c" - integrity sha512-dNGGjzuEzCE3d5EPZQ/QGtmlMotqnYWD/QpCZ1UuZlrMAdhG5rldh0N0haCvhGnUkSeuORS5VNROwF9Hrgn3Lg== - dependencies: - "@typescript-eslint/experimental-utils" "^4.0.1" - eslint-plugin-jsx-a11y@^6.4.1: version "6.4.1" resolved "https://registry.yarnpkg.com/eslint-plugin-jsx-a11y/-/eslint-plugin-jsx-a11y-6.4.1.tgz#a2d84caa49756942f42f1ffab9002436391718fd"