Skip to content

Commit

Permalink
feat: update eslint config (#20)
Browse files Browse the repository at this point in the history
This is based on the linting rules recently added to threads-native-ui.
Use `--resolve-plugins-relative-to node_modules/@threads/tsconfig`
when invoking the lint command from the app repo.

BREAKING CHANGE: lint rules are stricter than before - linting may break on existing projects.
  • Loading branch information
alephyud authored Sep 25, 2020
1 parent ad3b417 commit 1909e1d
Show file tree
Hide file tree
Showing 3 changed files with 219 additions and 40 deletions.
48 changes: 45 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ module.exports = {
* Turns off all TypeScript rules that are unnecessary or might conflict with Prettier.
*/
'prettier/@typescript-eslint',
/**
* Adds React-related rules.
*/
'plugin:react/recommended',
/**
* Adds React hooks-related rules.
*/
'plugin:react-hooks/recommended',
],
/**
* An ESLint parser which leverages TypeScript ESTree to allow for ESLint to lint TypeScript source code.
Expand All @@ -36,7 +44,7 @@ module.exports = {
jsx: true,
},
},
plugins: ['@typescript-eslint', 'import', 'jsdoc'],
plugins: ['@typescript-eslint', 'import', 'jsdoc', '@babel'],
rules: {
/**
* Require that member overloads be consecutive
Expand All @@ -60,6 +68,10 @@ module.exports = {
Object: 'Avoid using the `Object` type. Did you mean `object`?',
Function:
'Avoid using the `Function` type. Prefer a specific function type, like `() => void`.',
/*
* Allow use of '{}' - we use it to define React components with no properties
*/
'{}': false,
},
},
],
Expand Down Expand Up @@ -201,7 +213,7 @@ module.exports = {
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: ['**/__tests__/**/*'],
devDependencies: ['**/__tests__/**/*', '**/__story__/**/*', '**/fixtures/**/*'],
optionalDependencies: false,
},
],
Expand Down Expand Up @@ -290,8 +302,13 @@ module.exports = {
'no-fallthrough': 'error',
/**
* Disallow this keywords outside of classes or class-like objects.
*
* We use class fields in our class components, which is an ES proposal.
* Eslint generates false positives for no-invalid-this in this case -
* we need to use the babel plugin, which checks them correctly.
*/
'no-invalid-this': 'error',
'no-invalid-this': 'off',
'@babel/no-invalid-this': 'error',
/**
* Disallow Primitive Wrapper Instances
*/
Expand Down Expand Up @@ -364,5 +381,30 @@ module.exports = {
* Require calls to isNaN() when checking for NaN
*/
'use-isnan': 'error',

// React-specific rule overrides

/**
* We use TypeScript - we don't use dynamic prop type checks
*/
'react/prop-types': 'off',
/**
* We use anonymous functions for components - having displayNames would be good,
* but we don't want to change the entire code base
*/
'react/display-name': 'off',
/**
* Enable ' in unescaped entities - it's safe and escaping it makes adding copy harder
*/
'react/no-unescaped-entities': [
'error',
{
forbid: ['>', '}', '"'],
},
],
/**
* Make exhaustive deps mandatory
*/
'react-hooks/exhaustive-deps': 'error',
},
};
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"license": "MIT",
"keywords": [
"tslint",
"eslint",
"typescript",
"prettier",
"commitlint",
Expand All @@ -27,6 +28,9 @@
"release": "semantic-release"
},
"dependencies": {
"@babel/eslint-plugin": "^7.11.5",
"eslint-plugin-react": "^7.20.6",
"eslint-plugin-react-hooks": "^4.1.2",
"@commitlint/config-conventional": "^8.0.0",
"@typescript-eslint/eslint-plugin": "^3.6.0",
"@typescript-eslint/parser": "^3.6.0",
Expand Down
Loading

0 comments on commit 1909e1d

Please sign in to comment.