Skip to content
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

Eslint plugin react hooks #67

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
node_modules
package-lock.json
yarn.lock
Comment on lines +1 to +3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
node_modules
package-lock.json
yarn.lock
node_modules

Instead of adding lock files to the gitignore I think it's better to add an .npmrc file with package-lock=false in it. Otherwise people will be using a lock-file locally, it just won't be synchronised...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you, seems the owner of this PR doesn't know about programming.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a better solution would be to agree to use just one package manager to develop this and add it to a contributions or requirements section of the readme.

P.D: this PR just turned 1 year old 🥳

20 changes: 20 additions & 0 deletions TestComponent.jsx
@@ -0,0 +1,20 @@
import React, { useEffect, useState } from 'react'
import { string } from 'prop-types'

const Component = ({ someProp }) => {
const [state, setState] = useState()

useEffect(() => {
if (someProp) {
setState(someProp)
}
}, [someProp])

return <h1>{state}</h1>
}

Component.propTypes = {
someProp: string
}

export default Component
7 changes: 5 additions & 2 deletions eslintrc.json
Expand Up @@ -14,7 +14,8 @@
},

"plugins": [
"react"
"react",
"react-hooks"
],

"rules": {
Expand All @@ -27,6 +28,8 @@
"react/no-unknown-property": "error",
"react/no-unused-prop-types": "error",
"react/prop-types": "error",
"react/react-in-jsx-scope": "error"
"react/react-in-jsx-scope": "error",
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "error"
}
}
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -13,6 +13,7 @@
"devDependencies": {
"eslint": "^7.12.1",
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-react-hooks": "^4.2.0",
"tape": "^5.0.1"
},
"homepage": "https://github.com/feross/eslint-config-standard-react",
Expand Down
17 changes: 8 additions & 9 deletions test/validate-config.js
@@ -1,16 +1,15 @@
const eslint = require('eslint')
const { ESLint } = require('eslint')
const test = require('tape')
const config = require('../eslintrc.json')
const path = require('path')

test('load config in eslint to validate all rule syntax is correct', function (t) {
const CLIEngine = eslint.CLIEngine

const cli = new CLIEngine({
test('load config in eslint to validate all rule syntax is correct', async function (t) {
const eslint = new ESLint({
useEslintrc: false,
configFile: 'eslintrc.json'
baseConfig: config
})
const results = await eslint.lintFiles(path.resolve(__dirname, '../TestComponent.jsx'))

const code = 'var foo = 1\nvar bar = function () {}\nbar(foo)\n'

t.equal(cli.executeOnText(code).errorCount, 0)
t.equal(results[0].errorCount, 0)
t.end()
})