Skip to content

Commit

Permalink
Merge branch 'release/0.4.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
hiukky committed Apr 5, 2022
2 parents 6c8ad30 + 6fd30af commit 6dc4b83
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/rules/sort/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ module.exports = {

case 'VariableDeclarator':
default:
return declaration.callee?.property || declaration.callee
return declaration?.callee?.property || declaration?.callee
}
})
.filter(Boolean)
Expand Down
85 changes: 83 additions & 2 deletions lib/rules/sort/sort.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Tester.run('hooks/sort', rule as unknown as Rule.RuleModule, {
console.log('Hello')
},[])
return <></>
return null
}
`,
parserOptions,
Expand All @@ -72,6 +72,8 @@ Tester.run('hooks/sort', rule as unknown as Rule.RuleModule, {
useEffect(() => {
document.title = 'Hello'
}, [])
return null
}
`,
parserOptions,
Expand All @@ -93,6 +95,8 @@ Tester.run('hooks/sort', rule as unknown as Rule.RuleModule, {
useEffect(() => {
document.title = 'Hello'
}, [])
return null
}
const ComponentB = () => {
Expand All @@ -107,6 +111,8 @@ Tester.run('hooks/sort', rule as unknown as Rule.RuleModule, {
useEffect(() => {
document.title = 'Hello'
}, [])
return null
}
export function ComponentC() {
Expand All @@ -121,6 +127,8 @@ Tester.run('hooks/sort', rule as unknown as Rule.RuleModule, {
useEffect(() => {
document.title = 'Hello'
}, [])
return null
}
export const ComponentD = () => {
Expand All @@ -135,6 +143,8 @@ Tester.run('hooks/sort', rule as unknown as Rule.RuleModule, {
useEffect(() => {
document.title = 'Hello'
}, [])
return null
}
`,
parserOptions,
Expand All @@ -154,13 +164,40 @@ Tester.run('hooks/sort', rule as unknown as Rule.RuleModule, {
useEffect(() => {
document.title = 'Hello'
}, [])
return null
}
`,
parserOptions,
options,
},
{
code: `
function ComponentA() {
const [todos, dispatch] = useReducer(todosReducer)
const [count, setCount] = useState(0)
const memoizedCallback = useCallback(() => {
doSomething(a, b);
},[a, b])
useEffect(() => {
document.title = 'Hello'
}, [])
return null
}
export default ComponentA
`,
parserOptions,
options,
},
{
code: `
var variableInitialized = null
function ComponentA() {
const [todos, dispatch] = useReducer(todosReducer)
Expand All @@ -173,6 +210,10 @@ Tester.run('hooks/sort', rule as unknown as Rule.RuleModule, {
useEffect(() => {
document.title = 'Hello'
}, [])
let uninitializedVariable
return null
}
export default ComponentA
Expand All @@ -196,6 +237,8 @@ Tester.run('hooks/sort', rule as unknown as Rule.RuleModule, {
const memoizedCallback = useCallback(() => {
doSomething(a, b)
}, [a, b])
return null
}
`,
errors: [
Expand All @@ -222,6 +265,8 @@ Tester.run('hooks/sort', rule as unknown as Rule.RuleModule, {
export function ComponentA() {
const [count, setCount] = useState(0)
const locale = useContext(LocaleContext)
return null
}
export function ComponentB() {
Expand All @@ -230,6 +275,8 @@ Tester.run('hooks/sort', rule as unknown as Rule.RuleModule, {
}, [])
const countRef = useRef(0)
return null
}
`,
errors: [
Expand Down Expand Up @@ -267,7 +314,41 @@ Tester.run('hooks/sort', rule as unknown as Rule.RuleModule, {
const [count, setCount] = React.useState(0)
return <></>
return null
}
`,
errors: [
{
message:
'Non-matching declaration order. useEffect comes after useState.',
},
{
message:
'Non-matching declaration order. useState comes before useEffect.',
},
],
parserOptions,
options,
},
{
code: `
import * as React from 'react'
import { useRef } from 'react'
var variableInitialized = null
export const ComponentA = () => {
React.useEffect(() => {
console.log('Hello')
},[])
const countRef = useRef(0)
const [count, setCount] = React.useState(0)
let uninitializedVariable
return null
}
`,
errors: [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-hooks",
"version": "0.4.2",
"version": "0.4.3",
"description": "A simple organizer for ordering hooks.",
"main": "dist/index.js",
"repository": {
Expand Down

0 comments on commit 6dc4b83

Please sign in to comment.