Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
39d66c4
update to handle null expression and deploy to git
dannyvassallo Oct 14, 2021
7a9693f
forgot gitpkg
dannyvassallo Oct 14, 2021
445c1a2
testing fixer
dannyvassallo Oct 14, 2021
d0a895d
added version bump script
dannyvassallo Oct 14, 2021
89b40d6
0.0.5
dannyvassallo Oct 14, 2021
d82589f
oops
dannyvassallo Oct 14, 2021
69128d1
0.0.6
dannyvassallo Oct 14, 2021
9f54aa1
allow-empty
dannyvassallo Oct 14, 2021
8409b9e
0.0.7
dannyvassallo Oct 14, 2021
36cf834
version-bump
dannyvassallo Oct 14, 2021
5226112
bump version
dannyvassallo Oct 14, 2021
d5cec89
bump version
dannyvassallo Oct 14, 2021
53abc68
more version bump
dannyvassallo Oct 14, 2021
b9c62ef
0.0.8
dannyvassallo Oct 14, 2021
ef37ad7
version-bump
dannyvassallo Oct 14, 2021
e123320
again
dannyvassallo Oct 14, 2021
db238e8
0.0.9
dannyvassallo Oct 14, 2021
48923ae
version-bump
dannyvassallo Oct 14, 2021
b618934
rollback to 4
dannyvassallo Oct 14, 2021
5440fc9
rollback to 3
dannyvassallo Oct 14, 2021
0ac81a8
0.0.4
dannyvassallo Oct 14, 2021
bc7122e
version-bump
dannyvassallo Oct 14, 2021
cf7fb09
0.0.5
dannyvassallo Oct 14, 2021
e9702c4
0.0.6
dannyvassallo Oct 14, 2021
5521f2a
version-bump
dannyvassallo Oct 14, 2021
9802455
added fixable meta
dannyvassallo Oct 14, 2021
f6c3b68
devdep
dannyvassallo Oct 14, 2021
c62ef22
0.0.7
dannyvassallo Oct 14, 2021
065e8c9
version-bump
dannyvassallo Oct 14, 2021
6caf908
add fixable to each
dannyvassallo Oct 14, 2021
c52aea2
0.0.8
dannyvassallo Oct 14, 2021
7d673b9
version-bump
dannyvassallo Oct 14, 2021
328d8bf
0.0.9
dannyvassallo Oct 14, 2021
8fa03df
version-bump
dannyvassallo Oct 14, 2021
78b253e
testing
dannyvassallo Oct 15, 2021
3a2374d
added some autofixes for require-memo
dannyvassallo Oct 15, 2021
59ae0c3
added linking steps
dannyvassallo Oct 15, 2021
f83360d
moved normalizeIndent to utils and setup usememo spec
dannyvassallo Oct 15, 2021
b47445e
some autofixers working checking in to safely refactor
dannyvassallo Oct 18, 2021
50c0174
refactor fixer
dannyvassallo Oct 18, 2021
55328c7
handle usecallback
dannyvassallo Oct 18, 2021
6497b2a
accidentally committed a bunch of spaces
dannyvassallo Oct 18, 2021
57d24c4
commen out fixers and specs for now
dannyvassallo Oct 19, 2021
3c6152f
0.0.10
dannyvassallo Oct 19, 2021
e1e5e15
version-bump
dannyvassallo Oct 19, 2021
42b638c
rolled back fixers, have memo fixing but broken on one spec
dannyvassallo Oct 20, 2021
7dba0df
this is very hacky but it works
dannyvassallo Oct 20, 2021
a9347e3
updates
dannyvassallo Oct 28, 2021
c5c1cd7
0.0.11
dannyvassallo Oct 28, 2021
eb0a513
version-bump
dannyvassallo Oct 28, 2021
54307b9
comment tests back in
paulducsantos Nov 24, 2021
58feaf1
updated the usememo fixer for jsx
paulducsantos Nov 29, 2021
1a03e18
fix tests
TSMMark Nov 29, 2021
f0f7d99
memoized var name incr from 1
TSMMark Nov 29, 2021
92ba1cf
incr will resume from any point
TSMMark Nov 29, 2021
497d91c
Merge pull request #3 from Vydia/memoized-var-name-incr-from-1
paulducsantos Nov 29, 2021
1f13802
more fixer stuff
paulducsantos Dec 6, 2021
a3f382a
fix type
TSMMark Sep 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 83 additions & 24 deletions __tests__/require-memo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RuleTester } from "eslint";
import rule from "../require-memo";
import { normalizeIndent } from '../utils';

const ruleTester = new RuleTester({
parser: require.resolve("@typescript-eslint/parser"),
Expand All @@ -11,72 +12,130 @@ const ruleTester = new RuleTester({
ruleTester.run("memo", rule, {
valid: [
{
code: `const Component = React.memo(() => <div />)`,
code: normalizeIndent`
const Component = memo(() => <div />)
`,
},
{
code: `const Component = memo(() => <div />)`,
code: normalizeIndent`
const Component = memo(() => <div />)
`,
},
{
code: `const Component = memo(useRef(() => <div />))`,
code: normalizeIndent`
const Component = memo(useRef(() => <div />))
`,
},
{
code: `const Component = React.useRef(React.memo(() => <div />))`,
code: normalizeIndent`
const Component = useRef(memo(() => <div />))
`,
},
{
code: `const myFunction = () => <div />`,
code: normalizeIndent`
const myFunction = () => <div />
`,
},
{
code: `const myFunction = wrapper(() => <div />)`,
code: normalizeIndent`
const myFunction = wrapper(() => <div />)
`,
},
{
code: `const Component = React.memo(function() { return <div />; });`,
code: normalizeIndent`
const Component = memo(function() { return <div />; });
`,
},
{
code: `const Component = memo(function Component() { return <div />; });`,
code: normalizeIndent`
const Component = memo(function Component() { return <div />; });
`,
},
{
code: `const myFunction = () => <div />`,
code: normalizeIndent`
const myFunction = () => <div />
`,
},
{
code: `const myFunction = wrapper(() => <div />)`,
code: normalizeIndent`
const myFunction = wrapper(() => <div />)
`,
},
{
code: `function myFunction() { return <div />; }`,
code: normalizeIndent`
function myFunction() { return <div />; }
`,
},
{
code: `const myFunction = wrapper(function() { return <div /> })`,
code: normalizeIndent`
const myFunction = wrapper(function() { return <div /> })
`,
},
{
filename: "dir/myFunction.js",
parserOptions: { ecmaVersion: 6, sourceType: "module" },
code: `export default function() { return <div /> };`,
code: normalizeIndent`
export default function() { return <div /> };
`,
},
],
invalid: [
{
code: `const Component = () => <div />`,
code: `import { memo } from 'react'
const Component = () => <div />`,
errors: [{ messageId: "memo-required" }],
output: `import { memo } from 'react'
const Component = memo(() => <div />)`
},
{
code: `const Component = useRef(() => <div />)`,
code: `// @flow
import { map } from 'lodash'
const Component = useRef(() => <div />)`,
errors: [{ messageId: "memo-required" }],
},
{
code: `const Component = function Component() { return <div />; }`,
errors: [{ messageId: "memo-required" }],
},
{
code: `const Component = useRef(function() { return <div />; })`,
output: `// @flow
import { memo } from 'react'
import { map } from 'lodash'
const Component = memo(useRef(() => <div />))`
},
// {
// code: `const Component = function Component() { return <div />; }`,
// errors: [{ messageId: "memo-required" }],
// output: `import { memo } from 'react'
// const Component = memo(function Component() { return <div />; })`
// },
// {
// code: `const Component = useRef(function() { return <div />; })`,
// errors: [{ messageId: "memo-required" }],
// output: `import { memo } from 'react'
// const Component = useRef(memo(function() { return <div />; }))`
// },
{
code: `// @flow
import { map } from 'lodash'

console.warn('Hello World')
function Component() { return <div />; }`,
errors: [{ messageId: "memo-required" }],
output: `// @flow
import { memo } from 'react'
import { map } from 'lodash'

console.warn('Hello World')
memo(function Component() { return <div />; })`
},
{
code: `function Component() { return <div />; }`,
code: `import { memo } from 'react'

function Component() { return <div />; }`,
errors: [{ messageId: "memo-required" }],
output: `import { memo } from 'react'

memo(function Component() { return <div />; })`
},
// {
// filename: "dir/Component.js",
// parserOptions: { ecmaVersion: 6, sourceType: "module" },
// code: `export default function() { return <div /> };`,
// code: export default function() { return <div /> };,
// errors: [{ messageId: "memo-required" }],
// },
],
Expand Down
Loading