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

Over-restrictive regex for function definitions? #37

Open
mekhami opened this issue May 28, 2020 · 2 comments
Open

Over-restrictive regex for function definitions? #37

mekhami opened this issue May 28, 2020 · 2 comments
Labels

Comments

@mekhami
Copy link

mekhami commented May 28, 2020

In the regex for function definitions (specifically looked at arrow functions but could also apply to others, didn't look):

--regex-javascript=/^[ \t]*var[ \t]\{1,\}\([a-z_$][A-Za-z0-9_$]\{1,\}\)[ \t]*=.\{1,\}=>/\1/F,Function,Functions/b
--regex-javascript=/^[ \t]*let[ \t]\{1,\}\([a-z_$][A-Za-z0-9_$]\{1,\}\)[ \t]*=.\{1,\}=>/\1/F,Function,Functions/b
--regex-javascript=/^[ \t]*const[ \t]\{1,\}\([a-z_$][A-Za-z0-9_$]\{1,\}\)[ \t]*=.\{1,\}=>/\1/F,Function,Functions/b

Why does the first character of the function need to be lower cased? I specifically have a React component definition:

const MyModal = ({ prop1, prop2 }) => {

}

export default MyModal

This definition is skipped because of the capital case component function name.

@romainl romainl added the bug label May 28, 2020
@romainl
Copy link
Owner

romainl commented May 28, 2020

I know. I have a local fix for that but it is not complete and fully tested so I've been sitting on it for a while. Thank you for reminding me!

romainl added a commit that referenced this issue May 29, 2020
The "Class" kind covered both the old constructor-based style and the
new class-based style. Since the old style is indistinguishable from
a regular function definition I used casing to decide if it was
a "Class" or a "Function".

That was pretty short-sighted.

Old style constructor-based definition are now demoted to the "Function"
kind.
@romainl
Copy link
Owner

romainl commented May 29, 2020

@mekhami, the last commit should fix the issue.

FWIW: old school constructor-based "class" definitions are indistinguishable from plain function definition except for the convention of starting the name with an uppercase character. That's what lead me to that short-sighted casing restriction. Now, old school "class" definitions are just considered as functions.

romainl added a commit that referenced this issue May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants