From e831743132e167e85dbf9ee7f3d638517f7c6272 Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Wed, 10 Jul 2019 03:46:50 -0700 Subject: [PATCH] Harden lint rules Summary: Taking another stab at adding some lint rules to make it harder to shoot yourself in the foot. Hopefully nothing too controversial. Preferring spread and rest should lead is more readable and there's no downside when using ES6. The "useless" rules are just things like renaming imports to the original name which should only happen during refactors. Reviewed By: jknoxville Differential Revision: D16180453 fbshipit-source-id: 1cf6851b7726c0aee953ec7cf7dd6fa0aca32253 --- .eslintrc.js | 8 ++++++++ src/dispatcher/plugins.js | 2 +- src/plugins/databases/index.js | 4 ++-- static/globalTestSetup.js | 4 ++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 06824da09..2cbf93753 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -23,10 +23,18 @@ module.exports = { 'consistent-return': 0, 'no-var': 2, 'prefer-const': [2, {destructuring: 'all'}], + 'prefer-spread': 1, + 'prefer-rest-params': 1, 'max-len': 0, // lets prettier take care of this indent: 0, // lets prettier take care of this 'no-console': 0, // we're setting window.console in App.js + 'no-multi-spaces': 2, 'prefer-promise-reject-errors': 1, + 'no-extra-boolean-cast': 2, + 'no-extra-semi': 2, + 'no-unsafe-negation': 2, + 'no-useless-computed-key': 2, + 'no-useless-rename': 2, // additional rules for this project 'header/header': [2, 'block', {pattern}], diff --git a/src/dispatcher/plugins.js b/src/dispatcher/plugins.js index 5f6e5532d..7ebe66e34 100644 --- a/src/dispatcher/plugins.js +++ b/src/dispatcher/plugins.js @@ -155,7 +155,7 @@ export const requirePlugin = ( if (plugin.default) { plugin = plugin.default; } - if (!plugin.prototype instanceof FlipperBasePlugin) { + if (!(plugin.prototype instanceof FlipperBasePlugin)) { throw new Error(`Plugin ${plugin.name} is not a FlipperBasePlugin`); } diff --git a/src/plugins/databases/index.js b/src/plugins/databases/index.js index 7497e5119..60d1add10 100644 --- a/src/plugins/databases/index.js +++ b/src/plugins/databases/index.js @@ -276,7 +276,7 @@ class PageInfo extends Component< onSubmit(e: SyntheticKeyboardEvent<>) { if (e.key === 'Enter') { - const rowNumber = parseInt(this.state.inputValue); + const rowNumber = parseInt(this.state.inputValue, 10); console.log(rowNumber); this.props.onChange(rowNumber - 1, this.props.count); this.setState({isOpen: false}); @@ -297,7 +297,7 @@ class PageInfo extends Component<
{this.state.isOpen ? (