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

JavaScript - wrong regex for Function followed by one space vs. Function followed by no space #62

Open
tkrotoff opened this issue Nov 24, 2015 · 0 comments

Comments

@tkrotoff
Copy link
Contributor

See https://github.com/outsideris/popularconvention/blob/master/src/parser/js-parser.coffee#L136

onespace = /function(\s+.)*\s+\(/
nospace = /function(\s+.)*\(/

These regex check for function() vs function () without a function name, not for function foo () vs function foo() like advertised.

Either the regex are wrong or the documentation is.

Ideal would be to check for function() vs function () and also for function foo () vs function foo()

Tests:

var onespace = /function(\s+.)*\s+\(/;
'function foo () {'.match(onespace); // => null
'function foo() {'.match(onespace);  // => null
'function () {'.match(onespace);     // => ["function (", undefined]
'function() {'.match(onespace);      // => null

var nospace = /function(\s+.)*\(/;
'function foo () {'.match(nospace); // => null
'function foo() {'.match(nospace);  // => null
'function () {'.match(nospace);     // => null
'function() {'.match(nospace);      // => ["function(", undefined]
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

1 participant