Skip to content

graphql() false positive #1097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
developer239 opened this issue Mar 1, 2017 · 1 comment · Fixed by #1338
Closed

graphql() false positive #1097

developer239 opened this issue Mar 1, 2017 · 1 comment · Fixed by #1338

Comments

@developer239
Copy link

Tell us about your environment

  • ESLint Version: "^3.15.0"
  • Node Version: "v7.5.0"
  • npm Version: "4.1.2"

What parser (default, Babel-ESLint, etc.) are you using?

"webpack": "^2.2.1",
"babel-eslint": "^7.1.1",

What did you do? Please include the actual source code causing the issue.

import React from 'react'
import { Link } from 'react-router'
import { graphql } from 'react-apollo'
import { connect } from 'react-redux'
import { Grid, Alert, PageHeader } from 'react-bootstrap'

import Spinner from 'components/common/Spinner'
import { queryPostDetail } from '../../qql'


export const PostsBaseContainer = ({ data }) => {
  if (data.loading) {
    return (
      <Grid>
        <Spinner />
      </Grid>
    )
  }

  if (data.error) {
    return (
      <Grid>
        <Alert bsStyle="danger">
          <strong>Error!</strong> Fetching data from GraphQl server was not successful.
        </Alert>
      </Grid>
    )
  }

  return (
    <Grid>
      <PageHeader>
        {data.Post.title}
        <Link to={`/posts/${data.Post.id}/edit`}>
          <small>[edit]</small>
        </Link>
      </PageHeader>
      <p>{data.Post.text}</p>
    </Grid>
  )
}

PostsBaseContainer.propTypes = {
  data: React.PropTypes.shape({
    loading: React.PropTypes.bool,
    error: React.PropTypes.object,
    Post: React.PropTypes.shape({
      id: React.PropTypes.string.isRequired,
      title: React.PropTypes.string.isRequired,
      text: React.PropTypes.string.isRequired,
    }),
  }).isRequired,
  params: React.PropTypes.shape({
    postId: React.PropTypes.string.isRequired,
  }).isRequired,
}

const mapStateToProps = () => ({})
const mapDispatchToProps = () => ({})

const PostsBaseContainerWithQueries = graphql(queryPostDetail, {
  options: ownProps => ({
    variables: {
      id: ownProps.params.postId,
    },
  }),
})(PostsBaseContainer)


export default connect(mapStateToProps, mapDispatchToProps)(PostsBaseContainerWithQueries)


What did you expect to happen?

Eslint should not find any errors in the code.

What actually happened? Please include the actual, raw output from ESLint.

image

@DianaSuvorova
Copy link
Contributor

@developer239, I think the plugin acts correctly here. params.propId is not used in PostsBaseContainer. It is used in connect(mapStateToProps, mapDispatchToProps)(PostsBaseContainerWithQueries) component. You may want to configure that prop type on that one instead. I have created a PR with both correct and incorrect props configurations.

ljharb added a commit that referenced this issue Aug 2, 2017
[no-unused-prop-types] graphql issue #1097
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants