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

create eslint-plugin-xstate package #221

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

with-heart
Copy link
Contributor

Hi all! This draft PR contains the start of the eslint-plugin-xstate package and will eventually resolve #216.

Currently this PR contains implementations for a few rules:

  • avoid-context-spread
  • no-cond
  • no-emitted-from
  • no-factory-context-arg
  • require-object-context
  • require-parameterized-actions-params
  • require-parameterized-guards-params

Having briefly talked to @Andarist about it, I'm not entirely sure an eslint plugin/config makes sense for his vision of XState tooling. It's possible that these rules (and others listed in the issue) would be more useful if implemented as part of the VSCode extension rather than in eslint.

At the very least, this has been a fun exploration of custom eslint rules for me and might give us a sense of the type of logic we'd need to implement similar functionality in the extension.

@changeset-bot
Copy link

changeset-bot bot commented Sep 21, 2022

⚠️ No Changeset found

Latest commit: 2dfb6d7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Comment on lines +90 to +93
"@typescript-eslint/parser": "^5.37.0",
"concurrently": "6.2.0",
"esbuild": "^0.14.48",
"eslint": "^7.26.0",
"eslint": "^8.0.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have the config in .eslintrc.js commented out so updating these doesn't affect anything

Comment on lines +17 to +31
"devDependencies": {
"@typescript-eslint/parser": "^5.37.0",
"eslint": "^8.0.0",
"typescript": "^4.3.5"
},
"peerDependencies": {
"@typescript-eslint/parser": "^5.0.0",
"eslint": "^6.0.0 || ^7.0.0 || ^8.0.0",
"typescript": "*"
},
"peerDependenciesMeta": {
"typescript": {
"optional": true
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not entirely sure these dependencies are correct if we end up publishing this package. I somewhat copied the dependencies setup from @typescript-eslint/eslint-plugin, but they also don't have any of these as devDependencies which yarn whined about 🤷

ruleTester.run("avoid-context-spread", rule, {
valid: [
{
code: outdent`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using outdent allows the code blocks to be displayed correctly in test output. Not sure if there's a better way to handle that but without it, the indentation was a mess.

@with-heart
Copy link
Contributor Author

Would love to have a discussion on eslint vs. other ways to implement.

My ultimate goal in playing with this stuff was to use it as the basis for a v5 codemod that automatically migrates codebases (as much as possible, anyway). Perhaps it'd be better to just start with that, or figure out ways to implement this type of stuff through the extension instead of eslint?

@davidkpiano
Copy link
Member

Would love to have a discussion on eslint vs. other ways to implement.

My ultimate goal in playing with this stuff was to use it as the basis for a v5 codemod that automatically migrates codebases (as much as possible, anyway). Perhaps it'd be better to just start with that, or figure out ways to implement this type of stuff through the extension instead of eslint?

I would say eslint is preferable.

@EightArmCode
Copy link

Someone already wrote an eslint-plugin-xstate FWIW

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.

create eslint config and plugin for v5
3 participants