Skip to content

Commit

Permalink
fix: issues reported by eslint-remote-tester (#60)
Browse files Browse the repository at this point in the history
* fix: issues reported by eslint-remote-tester
  • Loading branch information
DianaSuvorova authored Dec 14, 2020
1 parent df981f9 commit 65076e9
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rules/no-unused-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/useSelector-prefer-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
) {
Expand Down
9 changes: 9 additions & 0 deletions tests/code-sanity-samples.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = [
'expect(() => useSelector()).toThrow();',
`const rows = [];
function mapStateToProps(state, ownProps) {
for (const { value } of rows) {
}
}
`,
];
2 changes: 2 additions & 0 deletions tests/lib/rules/connect-prefer-minimum-two-arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)',
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/rules/connect-prefer-named-arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)',
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/rules/mapDispatchToProps-prefer-parameters-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) => {}',
Expand Down
3 changes: 3 additions & 0 deletions tests/lib/rules/mapDispatchToProps-prefer-shorthand.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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())},
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/rules/mapDispatchToProps-returns-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/rules/mapStateToProps-no-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/rules/mapStateToProps-prefer-hoisted.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -17,6 +18,7 @@ const ruleTester = new RuleTester({ parserOptions });

ruleTester.run('mapStateToProps-prefer-hoisted', rule, {
valid: [
...codeSamples,
`function mapStateToProps(state) {
return {};
}`,
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/rules/mapStateToProps-prefer-parameters-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) => {}',
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/rules/mapStateToProps-prefer-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) })',
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/rules/no-unused-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)};
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/rules/prefer-separate-component-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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')
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/rules/useSelector-prefer-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)',
Expand Down

0 comments on commit 65076e9

Please sign in to comment.