Skip to content

feat: Add require-store-callbacks-use-set-param rule #284

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

Conversation

baseballyama
Copy link
Member

resolve: #267

@changeset-bot
Copy link

changeset-bot bot commented Oct 30, 2022

🦋 Changeset detected

Latest commit: ec2d47d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-svelte Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@baseballyama baseballyama force-pushed the feat/require-store-callbacks-use-set-param branch from 88ee1e0 to 40ab9b2 Compare October 30, 2022 06:43
@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 30, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link
Member

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

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

Thank you for the PR that adds the rule!
I made some comments.

"writable",
])) {
const [_, fn] = node.arguments
if (!fn || fn.type !== "ArrowFunctionExpression") {
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be even better if we also check FunctionExpression.

Suggested change
if (!fn || fn.type !== "ArrowFunctionExpression") {
if (!fn || (fn.type !== "ArrowFunctionExpression" && fn.type !== "FunctionExpression")) {

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops! Sorry I fixed it.
ec2d47d

import { readable, writable, derived } from "svelte/store"

/** ✓ GOOD */
readable(false, (set) => set(true))
Copy link
Member

Choose a reason for hiding this comment

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

As far as I know it should return the stop function.
A rule doesn't have to check for it, but a GOOD example would be better if it was more correct.

Suggested change
readable(false, (set) => set(true))
readable(false, (set) => {
set(true)
return () => {/* stop */}
})

// refer: https://eslint.org/docs/latest/rules/no-unused-vars
readable(false, (set) => true)

writable(false, (set) => set(true))
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
writable(false, (set) => set(true))
writable(false, (set) => {
set(true)
return () => {/* stop */}
})

Copy link
Member Author

Choose a reason for hiding this comment

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

I updated.
a6686e4

And I added description about derived store.

Copy link
Member

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New rule: store callbacks must use set param
2 participants