Project code style

39 views
Skip to first unread message

sainaen

unread,
May 8, 2013, 7:47:39 PM5/8/13
to vimiu...@googlegroups.com
“Follow the style already present in the file”, said in CONTRIBUTING.md, but there are some inconsistencies in existing code.

For example we could omit curly brackets and commas in object literals in CoffeeScript, and so you do omit them:

    @keyToCommandRegistry[key] =
      command: command
      isBackgroundCommand: @availableCommands[command].isBackgroundCommand
      passCountToFunction: @availableCommands[command].passCountToFunction
      noRepeat: @availableCommands[command].noRepeat

…some times.

        rect = {
          top: imgClientRects[0].top + coords[1],
          left: imgClientRects[0].left + coords[0],
          right: imgClientRects[0].left + coords[2],
          bottom: imgClientRects[0].top + coords[3],
          width: coords[2] - coords[0],
          height: coords[3] - coords[1]
        }


Also we could omit parentheses when calling a function with a few arguments, and so you do that:

    chrome.tabs.query {}, (tabs) =>
      results = tabs.filter (tab) -> RankingUtils.matches(queryTerms, tab.url, tab.title)

…some times.

  chrome.tabs.query({ windowId: chrome.windows.WINDOW_ID_CURRENT, active: true },
    (tabs) -> updateActiveState(tabs[0].id))

That's of course not such a big deal (as long as it works), but anyway what code style should I follow if I want to make a few pull requests more? :)

Or, maybe, there is some reason to write it so, that I missed?

Phil Crosby

unread,
May 9, 2013, 2:01:22 AM5/9/13
to vimiu...@googlegroups.com
Vimium has had many contributors and a coffeescript port a year ago, and as a result the style isn't completely consistent throughout.

In general, this style guideline has good recommendations; we should add that as a reference to the README. The only difference we have from the guide is the use of 110 character lines instead of 80.

Regarding object literals, without braces and commas is preferred.

Regarding parentheses in function invocation, as the style guide indicates, we should try to optimize for readability. That means omitting the parentheses by default and adding them in if it makes the structure of the call clearer.

Indeed, in the example you provided would be improved if the map was converted to coffeescript style, the arguments provided one per line, and the parentheses removed.

If a particular case of inconsistent style is bothering you, please feel free to submit a PR to fix the file so it's consistent throughout. Just try not to mix unrelated style cleanups to new functionality in the same PR.



--
You received this message because you are subscribed to the Google Groups "vimium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vimium-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Phil Crosby

unread,
May 9, 2013, 2:05:29 AM5/9/13
to vimiu...@googlegroups.com
I've updated CONTRIBUTING.md with a link to that style guide.

sainaen

unread,
May 10, 2013, 1:59:47 PM5/10/13
to vimiu...@googlegroups.com
Oh, I see. Thank you, for your answer.

I think I'll try to work on code style consistency at this weekend, but I don't want to promise anything.

Четвер, 9 травня 2013 р. 09:01:22 UTC+3 користувач Phil Crosby написав:
Reply all
Reply to author
Forward
0 new messages