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

Mixing arrow function properties with methods #49

Open
the-owl opened this issue Feb 9, 2019 · 12 comments
Open

Mixing arrow function properties with methods #49

the-owl opened this issue Feb 9, 2019 · 12 comments

Comments

@the-owl
Copy link

the-owl commented Feb 9, 2019

I haven't found a way to treat methods and arrow function properties as a single group. Is this currently possible? I'd like to treat arrow function properties as methods and sort them alphabetically together, like this:

class A {
  a = () => {}

  b () {}

  c = () => {}

  d () {}
}
@bryanrsmith
Copy link
Owner

bryanrsmith commented Feb 10, 2019

I think you're right. There isn't currently a way to define a group whose matches are unordered. I imagine this could be useful for React components, where methods are often converted to arrow function properties to avoid binding issues.

This is almost it, except it requires methods to come before properties

groups: {
	methodOrFuncProperty: [
		{ type: 'method' },
		{ type: 'property', propertyType: 'ArrowFunctionExpression' },
	],
},

There is a sort option on a matcher, but maybe we could move it up to the group level?

groups: {
	methodOrFuncProperty: {
		rules: [
			{ type: 'method' },
			{ type: 'property', propertyType: 'ArrowFunctionExpression' },
		],
		sort: 'none',
	},
},

@the-owl
Copy link
Author

the-owl commented Mar 8, 2019

There is a sort option on a matcher, but maybe we could move it up to the group level?

groups: {
	methodOrFuncProperty: {
		rules: [
			{ type: 'method' },
			{ type: 'property', propertyType: 'ArrowFunctionExpression' },
		],
		sort: 'none',
	},
},

Yes, this will solve the problem! I can try to implement this feature and send a PR.

@nsisodiya
Copy link

Thanks

@nsisodiya
Copy link

@bryanrsmith - I am confused, above config will work or proposed?
Please let us know what is the right config if we want to mix (arrow functions and methods) and then sort both together.

@bryanrsmith
Copy link
Owner

No, it's is not currently supported. I was proposing that the sort option be supported at the group level to enable this functionality. PRs welcome!

@nsisodiya
Copy link

@bryanrsmith - may you guide me, I can try for a PR.

@kazlauskis
Copy link

You can already wrap the arrow functions with methods, which allows to keep the methods and the arrow props in the same place. I am not sure why this works but it does for me.

"order": [
            "[static-properties]",
            "[static-methods]",
            "[properties]",
            "constructor",
            "[methods]",
            {
              "type": "property",
              "propertyType": "ArrowFunctionExpression"
            },
            "[methods]"
 ],

@piranna
Copy link

piranna commented May 8, 2023

Any update on this? I'm also interested. Maybe instead of rules, we can reuse the groups, so we don't need to define them again, as far as we prevent loops it will be fine.

@bryanrsmith
Copy link
Owner

No updates. I haven't personally used this plugin in a long time, as classes are not a language feature I use much any more. I'm happy to review PRs, but I'm not very motivated to put any effort into new features myself. Sounds like a plan has been proposed earlier in the thread, so feel free to take a stab at it.

@piranna
Copy link

piranna commented May 10, 2023

classes are not a language feature I use much any more

Just curious, what pattern are you using now? Functional programming? Split of data and procedures?

@bryanrsmith
Copy link
Owner

Yep. I do a lot of React work, and my class use dropped off pretty hard when React introduced hooks in 2019.

@piranna
Copy link

piranna commented May 10, 2023

Ok, make sense. Personally I think hooks were an error, I still prefer classes, but if they are useful to you, that's fine :-)

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

No branches or pull requests

5 participants