Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Add jscs rule for function spacing - #9708

Closed
hzoo wants to merge 5 commits into
angular:masterfrom
hzoo:add-jscs-rule-function-spacing
Closed

hzoo wants to merge 5 commits into
angular:masterfrom
hzoo:add-jscs-rule-function-spacing

Conversation

@hzoo

@hzoo hzoo commented Oct 21, 2014

Copy link
Copy Markdown
Contributor

Add rule disallowSpacesInFunctionDeclaration beforeOpeningRoundBrace.

function a() {

};

Add rule disallowSpacesInNamedFunctionExpression beforeOpeningRoundBrace.

var a = function a() {

}

Add rule requireSpacesInFunction beforeOpeningCurlyBrace. Applies to all types of functions.

Didn't include spacing for round brace for anonymous functions yet.
Checking only anonymous function expressions: for function (e), got 1121 times.
Checking only anonymous function expressions: for function(e), got 9159 times.

cc: @caitp @petebacondarwin

Comment thread test/ng/directive/inputSpec.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM --- although I'd still like the function () vs function() inconsistency fixed :< can wait for another CL.

@rodyhaddad rodyhaddad added this to the 1.3.x milestone Oct 21, 2014
@hzoo

hzoo commented Oct 21, 2014

Copy link
Copy Markdown
Contributor Author

Ok added a new commit for 'function()`. That was a lot haha. @caitp

@caitp

caitp commented Oct 21, 2014

Copy link
Copy Markdown
Contributor

wunderbar~

@caitp

caitp commented Oct 21, 2014

Copy link
Copy Markdown
Contributor

Hah, changing the generated locale files... did you also change the JS in the locale files generator scripts? (i cant tell because the diff is too big)

@hzoo

hzoo commented Oct 21, 2014

Copy link
Copy Markdown
Contributor Author

Not sure which ones are the generator scripts? src/ng/locale.js?, or everything in i18n/?

@caitp

caitp commented Oct 21, 2014

Copy link
Copy Markdown
Contributor

under the i18n directory and subdirectories (stuff like this https://github.com/angular/angular.js/blob/master/i18n/src/closureI18nExtractor.js#L173-L197)

@hzoo

hzoo commented Oct 21, 2014

Copy link
Copy Markdown
Contributor Author

Ok I'l have to do that since grunt jscs only runs under src/ and test/.

In the Gruntfile, src: ['src/**/*.js', 'test/**/*.js']

So we'll probably want to add i18n/ in and maybe some other stuff?

Although after doing that, there will probably be a lot of other changes that have to be made since jscs was never run on that folder.

@caitp

caitp commented Oct 21, 2014

Copy link
Copy Markdown
Contributor

well it's generated code, so most of it is within string literals. The problem is that it will overwrite all the changes to src/ngLocale that you did when it's run again, and those files will start failing the linting

@hzoo

hzoo commented Oct 21, 2014

Copy link
Copy Markdown
Contributor Author

Oh I see what you mean.

@hzoo

hzoo commented Oct 21, 2014

Copy link
Copy Markdown
Contributor Author

So I'l remove all changes to any src/ngLocale files.
Then look through the string literals / fix the styling there and keep testing till the generated ngLocale files pass?

@caitp

caitp commented Oct 21, 2014

Copy link
Copy Markdown
Contributor

yeah pretty much

@hzoo

hzoo commented Oct 21, 2014

Copy link
Copy Markdown
Contributor Author

Hmm looks like I'm having some problems with running the generator. Not sure if i'm doing something weird.

I tried running ./i18n/generate.sh and got:

Created directory "../src/ngLocale/"
Processing currency and number symbols ...
Processing datetime symbols ...

angular.js/node_modules/q/q.js:126
throw e;
^
Error: ENOENT, open 'angular.js/i18n/src/../closure/datetimeSymbols.js'


But yeah, only one style change is needed for the generated files at line 113: "pluralCat": function (n, opt_precision)

looks like L89: var temp = goog.i18n.pluralRules.select.toString(). creates:

function (n) {
  if (n >= 0 && n < 2) {
    return goog.i18n.pluralRules.Keyword.ONE;
  }
  return goog.i18n.pluralRules.Keyword.OTHER;
}

which has that space (I guess that's the toString() default)

even though all the functions in i18n/closure/pluralRules are function(n) and not function (n)

@caitp

caitp commented Oct 22, 2014

Copy link
Copy Markdown
Contributor

it looks like the file is in the tree as datetimesymbols.js rather than datetimeSymbols.js --- I guess we all have case-insensitive file systems for some reason :x (apparently my mac's fs is case insensitive currently. huh.) --- easy patch to write, and that's worth fixing anyways. Why not change that over in the PR in a separate commit? I'll give it an LGTM

@hzoo

hzoo commented Oct 22, 2014

Copy link
Copy Markdown
Contributor Author

Ok renamed it and generate.sh ran!

I added replace('function (n','function(n'); to the string which fixed it for all the generated files except for

src/ngLocale/angular-locale_en-dsrt-us.js
src/ngLocale/angular-locale_en-dsrt.js
src/ngLocale/angular-locale_ms-bn.js
src/ngLocale/angular-locale_ms-my.js

and not sure why..

looking at https://github.com/angular/angular.js/tree/master/src/ngLocale - it looks like those 4 aren't generated based on the last commit that regenerated the locale files?

Comment thread i18n/src/closureI18nExtractor.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't there be a space between arguments ? ;)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Haha yeah good catch. I think that the validateParameterSeparator rule seems to only check for function (a, b, c) { and we need to use disallowSpaceBeforeBinaryOperators and requireSpaceAfterBinaryOperators with , to check for spaces between arguments for actual function calls like 'asdf'.replace(a, b).

Although should I be running jscs on the other files too? Since now it's only checking files under 'src' and 'test'

@hzoo

hzoo commented Oct 22, 2014

Copy link
Copy Markdown
Contributor Author

I pushed a commit that fixed the js in the generated scripts except the 4 mentioned above so I did those manually. Still need to figure out why those 4 aren't being created and why the build is failing though.

@caitp

caitp commented Oct 22, 2014

Copy link
Copy Markdown
Contributor

the build failure looks like a flake to me

@caitp

caitp commented Oct 22, 2014

Copy link
Copy Markdown
Contributor

if those files aren't being created, it's possible the closure build is out of date, or maybe some locales were removed from closure. run the closure update script and maybe clear out src/ngLocale's js files

@hzoo

hzoo commented Oct 22, 2014

Copy link
Copy Markdown
Contributor Author

Ok, after clearing src/ngLocale and running update-closure.sh, closure/currencySymbols.js was updated but the 4 locales aren't updated (still have the function ()).

Yeah the last time angular-locale_en-dsrt-us.js, angular-locale_en-dsrt.js,
angular-locale_ms-bn.js,angular-locale_ms-my.js were updated were ~ a year ago while the other files were a month ago.

Also there aren't references to those locales in the /closure/datetimeSymbolsExt.js and /closure/numberSymbolsExt.js files unlike the rest. So I guess like you said they were removed or weren't added in?

@caitp

caitp commented Oct 22, 2014

Copy link
Copy Markdown
Contributor

@eltacodeldiablo see caitp#1 --- when I run with those fixes (some of them are just extra) and do grep 'function (' -r src/ngLocale, I get no output. So it should work

@caitp

caitp commented Oct 22, 2014

Copy link
Copy Markdown
Contributor

err -- I think I opened that PR wrong lol. Hang on.

@caitp

caitp commented Oct 22, 2014

Copy link
Copy Markdown
Contributor

@hzoo

hzoo commented Oct 22, 2014

Copy link
Copy Markdown
Contributor Author

From this: 0eb2c2a#diff-4c51149c7932e91d0b490a8427472ab6L2706

it looks like those 4 files are being used anymore so I removed them.

@caitp

hzoo added 3 commits October 23, 2014 07:20
This rule enforces a space after the curly brace
for function declarations, anonymous function expressions,
and named function expressions.
@hzoo

hzoo commented Oct 23, 2014

Copy link
Copy Markdown
Contributor Author

Oh ok I was able to rebase on top of master (also amended the commit message since it was the wrong rule to AnonymousFunctionExpression)

@hzoo hzoo closed this Oct 23, 2014
@hzoo
hzoo deleted the add-jscs-rule-function-spacing branch October 23, 2014 11:25
@hzoo
hzoo restored the add-jscs-rule-function-spacing branch October 23, 2014 11:25
@hzoo hzoo reopened this Oct 23, 2014
@hzoo

hzoo commented Oct 23, 2014

Copy link
Copy Markdown
Contributor Author

@caitp ah sorry accidentally closed

@caitp

caitp commented Oct 23, 2014

Copy link
Copy Markdown
Contributor

it looks like those 4 files are being used anymore so I removed them.

Hmm --- so I guess if we aren't claiming to support those anymore, it's fine to get rid of them... but I feel like people will file bugs about that :(

Well, lets worry about it later, I guess.

@caitp

caitp commented Oct 23, 2014

Copy link
Copy Markdown
Contributor

Looks good to me, although I'd rather the re-generated files were in a separate commit than the jscs fix

@hzoo

hzoo commented Oct 23, 2014

Copy link
Copy Markdown
Contributor Author

ok so you want the locale file changes in a separate commit? What about the ones in /i18n? Yeah doing a lot of different stuff this commit like updating i18n/closure/currencySymbols.js
and renaming i18n/closure/{datetimesymbols.js → datetimeSymbols.js}

@hzoo

hzoo commented Oct 23, 2014

Copy link
Copy Markdown
Contributor Author

Well at least for ms-bn it was removed in commit 6382e21 so I don't know how it came back.

For en-dsrt-us it looks like another commit replaced it with en_dg
For ms-my, ms_Latn_MY

@caitp

caitp commented Oct 23, 2014

Copy link
Copy Markdown
Contributor

Closed by 40bbc98..d3b1f50

@caitp caitp closed this Oct 23, 2014
@caitp

caitp commented Oct 23, 2014

Copy link
Copy Markdown
Contributor

hopefully nobody wants to revert these arbitrary style rules we've added ;-;

@hzoo

hzoo commented Oct 23, 2014

Copy link
Copy Markdown
Contributor Author

xp I think the last one for anonymous functions might be annoying to some folk. Although the code was 90% function() for anonymous.

@caitp

caitp commented Oct 23, 2014

Copy link
Copy Markdown
Contributor

they will learn to deal with it :>

@hzoo
hzoo deleted the add-jscs-rule-function-spacing branch October 25, 2014 03:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants