From 65076e939ca5b2392918806afaba5e8975b6a6a4 Mon Sep 17 00:00:00 2001 From: DianaSuvorova Date: Sun, 13 Dec 2020 17:02:27 -0800 Subject: [PATCH] fix: issues reported by eslint-remote-tester (#60) * fix: issues reported by eslint-remote-tester --- lib/rules/no-unused-prop-types.js | 2 +- lib/rules/useSelector-prefer-selectors.js | 2 +- tests/code-sanity-samples.js | 9 +++++++++ tests/lib/rules/connect-prefer-minimum-two-arguments.js | 2 ++ tests/lib/rules/connect-prefer-named-arguments.js | 2 ++ .../rules/mapDispatchToProps-prefer-parameters-names.js | 2 ++ tests/lib/rules/mapDispatchToProps-prefer-shorthand.js | 3 +++ tests/lib/rules/mapDispatchToProps-returns-object.js | 2 ++ tests/lib/rules/mapStateToProps-no-store.js | 2 ++ tests/lib/rules/mapStateToProps-prefer-hoisted.js | 2 ++ .../lib/rules/mapStateToProps-prefer-parameters-names.js | 2 ++ tests/lib/rules/mapStateToProps-prefer-selectors.js | 2 ++ tests/lib/rules/no-unused-prop-types.js | 2 ++ tests/lib/rules/prefer-separate-component-file.js | 2 ++ tests/lib/rules/useSelector-prefer-selectors.js | 2 ++ 15 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 tests/code-sanity-samples.js diff --git a/lib/rules/no-unused-prop-types.js b/lib/rules/no-unused-prop-types.js index be9f4d5..ae4f555 100644 --- a/lib/rules/no-unused-prop-types.js +++ b/lib/rules/no-unused-prop-types.js @@ -10,7 +10,7 @@ const belongsToReduxReact = (node, objectName, destrArg) => { const secondArgumentName = secondArgument && secondArgument.type === 'Identifier' && secondArgument.name; return (secondArgumentName === objectName // ownProps.myProp || destrArg === secondArgument // {myProp} in fn argument - || (destrArg && destrArg.parent.type === 'VariableDeclarator' && destrArg.parent.init.name === secondArgumentName) // const {myProp} = ownProps; + || (destrArg && destrArg.parent.type === 'VariableDeclarator' && destrArg.parent.init && destrArg.parent.init.name === secondArgumentName) // const {myProp} = ownProps; ); }; let isReactRedux = false; diff --git a/lib/rules/useSelector-prefer-selectors.js b/lib/rules/useSelector-prefer-selectors.js index 7521639..5a5ff75 100644 --- a/lib/rules/useSelector-prefer-selectors.js +++ b/lib/rules/useSelector-prefer-selectors.js @@ -28,7 +28,7 @@ module.exports = function (context) { ) { reportNoSelector(context, node); } else if ( - selector.type === 'Identifier' && + selector && selector.type === 'Identifier' && config.matching && !selector.name.match(new RegExp(config.matching)) ) { diff --git a/tests/code-sanity-samples.js b/tests/code-sanity-samples.js new file mode 100644 index 0000000..c8d8125 --- /dev/null +++ b/tests/code-sanity-samples.js @@ -0,0 +1,9 @@ +module.exports = [ + 'expect(() => useSelector()).toThrow();', + `const rows = []; + function mapStateToProps(state, ownProps) { + for (const { value } of rows) { + } + } + `, +]; diff --git a/tests/lib/rules/connect-prefer-minimum-two-arguments.js b/tests/lib/rules/connect-prefer-minimum-two-arguments.js index c42f12f..0a0b508 100644 --- a/tests/lib/rules/connect-prefer-minimum-two-arguments.js +++ b/tests/lib/rules/connect-prefer-minimum-two-arguments.js @@ -2,6 +2,7 @@ require('babel-eslint'); const rule = require('../../../lib/rules/connect-prefer-minimum-two-arguments'); const RuleTester = require('eslint').RuleTester; +const codeSamples = require('../../code-sanity-samples'); const parserOptions = { ecmaVersion: 6, @@ -15,6 +16,7 @@ const ruleTester = new RuleTester({ parserOptions }); ruleTester.run('connect-prefer-minimum-two-arguments', rule, { valid: [ + ...codeSamples, 'connect(mapStateToProps, mapDispatchToProps, mergeProps, options)(Component)', 'connect(mapStateToProps, mapDispatchToProps)(Component)', 'connect({prop1, prop2}, {action1, action2})(Component)', diff --git a/tests/lib/rules/connect-prefer-named-arguments.js b/tests/lib/rules/connect-prefer-named-arguments.js index e35abca..91d3661 100644 --- a/tests/lib/rules/connect-prefer-named-arguments.js +++ b/tests/lib/rules/connect-prefer-named-arguments.js @@ -2,6 +2,7 @@ require('babel-eslint'); const rule = require('../../../lib/rules/connect-prefer-named-arguments'); const RuleTester = require('eslint').RuleTester; +const codeSamples = require('../../code-sanity-samples'); const parserOptions = { ecmaVersion: 6, @@ -15,6 +16,7 @@ const ruleTester = new RuleTester({ parserOptions }); ruleTester.run('connect-prefer-named-arguments', rule, { valid: [ + ...codeSamples, 'export default connect(null, mapDispatchToProps)(TodoApp)', 'connect(mapStateToProps, mapDispatchToProps, mergeProps, options)(Component)', 'connect(mapStateToProps, mapDispatchToProps)(Component)', diff --git a/tests/lib/rules/mapDispatchToProps-prefer-parameters-names.js b/tests/lib/rules/mapDispatchToProps-prefer-parameters-names.js index cb8d324..bb5abaa 100644 --- a/tests/lib/rules/mapDispatchToProps-prefer-parameters-names.js +++ b/tests/lib/rules/mapDispatchToProps-prefer-parameters-names.js @@ -2,6 +2,7 @@ require('babel-eslint'); const rule = require('../../../lib/rules/mapDispatchToProps-prefer-parameters-names'); const RuleTester = require('eslint').RuleTester; +const codeSamples = require('../../code-sanity-samples'); const parserOptions = { ecmaVersion: 6, @@ -15,6 +16,7 @@ const ruleTester = new RuleTester({ parserOptions }); ruleTester.run('mapDispatchToProps-prefer-parameters-names', rule, { valid: [ + ...codeSamples, 'const mapDispatchToProps = (dispatch, ownProps) => {}', 'const mapDispatchToProps = (dispatch, {prop1, prop2}) => {}', 'const mapDispatchToProps = (dispatch) => {}', diff --git a/tests/lib/rules/mapDispatchToProps-prefer-shorthand.js b/tests/lib/rules/mapDispatchToProps-prefer-shorthand.js index 037776f..ae3fe16 100644 --- a/tests/lib/rules/mapDispatchToProps-prefer-shorthand.js +++ b/tests/lib/rules/mapDispatchToProps-prefer-shorthand.js @@ -2,6 +2,8 @@ require('babel-eslint'); const rule = require('../../../lib/rules/mapDispatchToProps-prefer-shorthand'); const RuleTester = require('eslint').RuleTester; +const codeSamples = require('../../code-sanity-samples'); + const parserOptions = { ecmaVersion: 6, @@ -15,6 +17,7 @@ const ruleTester = new RuleTester({ parserOptions }); ruleTester.run('mapDispatchToProps-prefer-shorthand', rule, { valid: [ + ...codeSamples, 'function mapDispatchToProps () {return {action}}', `const mapDispatchToProps = dispatch => ({ onDoSomething: function() {return dispatch(toDo())}, diff --git a/tests/lib/rules/mapDispatchToProps-returns-object.js b/tests/lib/rules/mapDispatchToProps-returns-object.js index d505a82..fd25e38 100644 --- a/tests/lib/rules/mapDispatchToProps-returns-object.js +++ b/tests/lib/rules/mapDispatchToProps-returns-object.js @@ -2,6 +2,7 @@ require('babel-eslint'); const rule = require('../../../lib/rules/mapDispatchToProps-returns-object'); const RuleTester = require('eslint').RuleTester; +const codeSamples = require('../../code-sanity-samples'); const parserOptions = { ecmaVersion: 6, @@ -15,6 +16,7 @@ const ruleTester = new RuleTester({ parserOptions }); ruleTester.run('mapDispatchToProps-returns-object', rule, { valid: [ + ...codeSamples, 'const mapDispatchToProps = {}', 'const mapDispatchToProps = null', 'const mapDispatchToProps = actionsMap', diff --git a/tests/lib/rules/mapStateToProps-no-store.js b/tests/lib/rules/mapStateToProps-no-store.js index ab859b3..14ce331 100644 --- a/tests/lib/rules/mapStateToProps-no-store.js +++ b/tests/lib/rules/mapStateToProps-no-store.js @@ -2,6 +2,7 @@ require('babel-eslint'); const rule = require('../../../lib/rules/mapStateToProps-no-store'); const RuleTester = require('eslint').RuleTester; +const codeSamples = require('../../code-sanity-samples'); const parserOptions = { ecmaVersion: 6, @@ -15,6 +16,7 @@ const ruleTester = new RuleTester({ parserOptions }); ruleTester.run('mapStateToProps-no-store', rule, { valid: [ + ...codeSamples, ` const mapStateToProps = state => ({ ...getSomeStateFromASelector(state), showDefaultHeader: showDefaultHeader(state), diff --git a/tests/lib/rules/mapStateToProps-prefer-hoisted.js b/tests/lib/rules/mapStateToProps-prefer-hoisted.js index a0765b6..77c773c 100644 --- a/tests/lib/rules/mapStateToProps-prefer-hoisted.js +++ b/tests/lib/rules/mapStateToProps-prefer-hoisted.js @@ -2,6 +2,7 @@ require('babel-eslint'); const rule = require('../../../lib/rules/mapStateToProps-prefer-hoisted'); const RuleTester = require('eslint').RuleTester; +const codeSamples = require('../../code-sanity-samples'); const parserOptions = { ecmaVersion: 6, @@ -17,6 +18,7 @@ const ruleTester = new RuleTester({ parserOptions }); ruleTester.run('mapStateToProps-prefer-hoisted', rule, { valid: [ + ...codeSamples, `function mapStateToProps(state) { return {}; }`, diff --git a/tests/lib/rules/mapStateToProps-prefer-parameters-names.js b/tests/lib/rules/mapStateToProps-prefer-parameters-names.js index eaa062e..667d3e3 100644 --- a/tests/lib/rules/mapStateToProps-prefer-parameters-names.js +++ b/tests/lib/rules/mapStateToProps-prefer-parameters-names.js @@ -2,6 +2,7 @@ require('babel-eslint'); const rule = require('../../../lib/rules/mapStateToProps-prefer-parameters-names'); const RuleTester = require('eslint').RuleTester; +const codeSamples = require('../../code-sanity-samples'); const parserOptions = { ecmaVersion: 6, @@ -15,6 +16,7 @@ const ruleTester = new RuleTester({ parserOptions }); ruleTester.run('mapStateToProps-prefer-parameters-names', rule, { valid: [ + ...codeSamples, 'const mapStateToProps = ({prop1, prop2}, {ownProp1, ownProp2}) => {}', 'const mapStateToProps = (state, ownProps) => {}', 'const mapStateToProps = (state) => {}', diff --git a/tests/lib/rules/mapStateToProps-prefer-selectors.js b/tests/lib/rules/mapStateToProps-prefer-selectors.js index 1fbf90f..8ca3278 100644 --- a/tests/lib/rules/mapStateToProps-prefer-selectors.js +++ b/tests/lib/rules/mapStateToProps-prefer-selectors.js @@ -2,6 +2,7 @@ require('babel-eslint'); const rule = require('../../../lib/rules/mapStateToProps-prefer-selectors'); const RuleTester = require('eslint').RuleTester; +const codeSamples = require('../../code-sanity-samples'); const parserOptions = { ecmaVersion: 6, @@ -15,6 +16,7 @@ const ruleTester = new RuleTester({ parserOptions }); ruleTester.run('mapStateToProps-prefer-selectors', rule, { valid: [ + ...codeSamples, 'const mapStateToProps = (state) => 1', 'const mapStateToProps = (state) => ({})', 'const mapStateToProps = (state) => ({ x: xSelector(state) })', diff --git a/tests/lib/rules/no-unused-prop-types.js b/tests/lib/rules/no-unused-prop-types.js index 2e129de..b42b96b 100644 --- a/tests/lib/rules/no-unused-prop-types.js +++ b/tests/lib/rules/no-unused-prop-types.js @@ -2,6 +2,7 @@ require('babel-eslint'); const rule = require('../../../lib/rules/no-unused-prop-types'); const RuleTester = require('eslint').RuleTester; +const codeSamples = require('../../code-sanity-samples'); const parserOptions = { ecmaVersion: 6, @@ -17,6 +18,7 @@ const ruleTester = new RuleTester({ parserOptions }); ruleTester.run('no-unused-prop-types', rule, { valid: [ + ...codeSamples, `export const mapStateToProps = (state, ownProps) => { const { myProp } = ownProps; return { myData: getMyData(state, myProp)}; diff --git a/tests/lib/rules/prefer-separate-component-file.js b/tests/lib/rules/prefer-separate-component-file.js index 3e01f48..8bb6b4b 100644 --- a/tests/lib/rules/prefer-separate-component-file.js +++ b/tests/lib/rules/prefer-separate-component-file.js @@ -2,6 +2,7 @@ require('babel-eslint'); const rule = require('../../../lib/rules/prefer-separate-component-file'); const RuleTester = require('eslint').RuleTester; +const codeSamples = require('../../code-sanity-samples'); const parserOptions = { ecmaVersion: 6, @@ -15,6 +16,7 @@ const ruleTester = new RuleTester({ parserOptions }); ruleTester.run('prefer-separate-component-file', rule, { valid: [ + ...codeSamples, ` import Component from './component'; connect(mapStateToProps, mapDispatchToProps)(Component)`, `const Component = require('./component') diff --git a/tests/lib/rules/useSelector-prefer-selectors.js b/tests/lib/rules/useSelector-prefer-selectors.js index ae5a1b5..90a0584 100644 --- a/tests/lib/rules/useSelector-prefer-selectors.js +++ b/tests/lib/rules/useSelector-prefer-selectors.js @@ -2,6 +2,7 @@ require('babel-eslint'); const rule = require('../../../lib/rules/useSelector-prefer-selectors'); const RuleTester = require('eslint').RuleTester; +const codeSamples = require('../../code-sanity-samples'); const parserOptions = { ecmaVersion: 6, @@ -15,6 +16,7 @@ const ruleTester = new RuleTester({ parserOptions }); ruleTester.run('useSelector-prefer-selectors', rule, { valid: [ + ...codeSamples, 'const property = useSelector(xSelector)', { code: 'const property = useSelector(xSelector)',