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

Add jscs rule for function spacing #9708

Closed
wants to merge 5 commits into from

Conversation

hzoo
Copy link
Contributor

@hzoo hzoo commented Oct 21, 2014

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

it('should throw if model is not a Date object', function() {
compileInput('<input type="week" ng-model="secondWeek"/>');

expect(function() {
scope.$apply(function(){
Copy link
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
Copy link
Contributor Author

hzoo commented Oct 21, 2014

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

@caitp
Copy link
Contributor

caitp commented Oct 21, 2014

wunderbar~

@caitp
Copy link
Contributor

caitp commented Oct 21, 2014

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
Copy link
Contributor Author

hzoo commented Oct 21, 2014

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

@caitp
Copy link
Contributor

caitp commented Oct 21, 2014

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

@hzoo
Copy link
Contributor Author

hzoo commented Oct 21, 2014

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
Copy link
Contributor

caitp commented Oct 21, 2014

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
Copy link
Contributor Author

hzoo commented Oct 21, 2014

Oh I see what you mean.

@hzoo
Copy link
Contributor Author

hzoo commented Oct 21, 2014

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
Copy link
Contributor

caitp commented Oct 21, 2014

yeah pretty much

@hzoo
Copy link
Contributor Author

hzoo commented Oct 21, 2014

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
Copy link
Contributor

caitp commented Oct 22, 2014

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 force-pushed the add-jscs-rule-function-spacing branch from 74b23c8 to 5333736 Compare October 22, 2014 02:31
@hzoo
Copy link
Contributor Author

hzoo commented Oct 22, 2014

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?

@@ -91,7 +91,8 @@ function pluralExtractor(content, localeInfo) {
replace(/goog\.i18n\.pluralRules\.get_vf_/g, 'getVF').
replace(/goog\.i18n\.pluralRules\.get_wt_/g, 'getWT').
replace(/goog\.i18n\.pluralRules\.decimals_/g, 'getDecimals').
replace(/\n/g, '');
replace(/\n/g, '')
replace(/function \(n/,'function(n');
Copy link
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
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 force-pushed the add-jscs-rule-function-spacing branch from 7079822 to 88f1dd7 Compare October 22, 2014 12:00
@hzoo
Copy link
Contributor Author

hzoo commented Oct 22, 2014

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
Copy link
Contributor

caitp commented Oct 22, 2014

the build failure looks like a flake to me

@caitp
Copy link
Contributor

caitp commented Oct 22, 2014

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
Copy link
Contributor Author

hzoo commented Oct 22, 2014

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
Copy link
Contributor

caitp commented Oct 22, 2014

@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
Copy link
Contributor

caitp commented Oct 22, 2014

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

@caitp
Copy link
Contributor

caitp commented Oct 22, 2014

hzoo#1 there you go

@hzoo hzoo force-pushed the add-jscs-rule-function-spacing branch from 88f1dd7 to 3ef1523 Compare October 22, 2014 22:57
@hzoo
Copy link
Contributor Author

hzoo commented Oct 22, 2014

From this: 0eb2c2a#diff-4c51149c7932e91d0b490a8427472ab6L2706

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

@caitp

@hzoo hzoo force-pushed the add-jscs-rule-function-spacing branch from 3ef1523 to d2d18f0 Compare October 23, 2014 11:23
@hzoo
Copy link
Contributor Author

hzoo commented Oct 23, 2014

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
Copy link
Contributor Author

hzoo commented Oct 23, 2014

@caitp ah sorry accidentally closed

@caitp
Copy link
Contributor

caitp commented Oct 23, 2014

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
Copy link
Contributor

caitp commented Oct 23, 2014

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

@hzoo
Copy link
Contributor Author

hzoo commented Oct 23, 2014

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
Copy link
Contributor Author

hzoo commented Oct 23, 2014

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
Copy link
Contributor

caitp commented Oct 23, 2014

Closed by 40bbc98..d3b1f50

@caitp caitp closed this Oct 23, 2014
@caitp
Copy link
Contributor

caitp commented Oct 23, 2014

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

@hzoo
Copy link
Contributor Author

hzoo commented Oct 23, 2014

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

@caitp
Copy link
Contributor

caitp commented Oct 23, 2014

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