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

Document and finalize standardized code formatting #389

Closed
7 of 9 tasks
sashadev-sky opened this issue Aug 20, 2019 · 21 comments · Fixed by #742
Closed
7 of 9 tasks

Document and finalize standardized code formatting #389

sashadev-sky opened this issue Aug 20, 2019 · 21 comments · Fixed by #742

Comments

@sashadev-sky
Copy link
Member

sashadev-sky commented Aug 20, 2019

as a follow up to #378, I wanted to confirm some straggling syntaxes still not sure about, and also just document our code syntax in a wiki maybe (eventually we can make a contributing.md)

So far the standard we will implement is:

  • 2 space indent
  • single quotes
  • space in blocks, no space in objects
Yep. Makes sense. You see, { return; } qualifies as code, or more specifically a block of code that runs (executes one line per session by the intepreter), whereas { deselect: true } is not the same but an object, and is interpreted in one go, unlike some block of code, hence the rules for both differ.
  • column limit: 80 recommended. No column limit on comments but be reasonable
  • No space before parentheses: function() {}
  • no comma after var declaration style
  • trailing commas for objects
  • camelCase variables

Pending:

  • comment syntax
@sashadev-sky
Copy link
Member Author

@rexagod I was curious about:

    if (!this._moved) {
      return;
    }

Sometimes we will see the above syntax, sometimes we will see:

    if (!this._moved) { return; }

Is there a linter we can add that keeps it on the same line unless the line goes over length limit, and in that case goes to a new line? Is this something we want? Also what is the current line length limit that is set?

@sashadev-sky
Copy link
Member Author

Ok I added 3 configs:

        "curly": ["error", "multi-line"],
        "brace-style": ["error", "1tbs", { "allowSingleLine": true }],
        "block-spacing": ["error", "always"],

that basically allow if (!this._moved) { return; } in terms of having the return on the same line and spaces in between the braces and the return.

It does not allow spaces in between objects still: so map.fire('singleclick', {deselect: true}); is ok but map.fire('singleclick', { deselect: true }); is not.

let me know what you think!

@rexagod
Copy link
Member

rexagod commented Aug 21, 2019

Yep. Makes sense. You see, { return; } qualifies as code, or more specifically a block of code that runs (executes one line per session by the intepreter), whereas { deselect: true } is not the same but an object, and is interpreted in one go, unlike some block of code, hence the rules for both differ.

Maybe https://eslint.org/docs/rules/object-curly-spacing could help here?

@sashadev-sky
Copy link
Member Author

what are your thoughts on the var? (last point). Google says no to the one declaration followed by comma syntax. I kind of like how it looks compared to doing something like what we currently have:

rotateBy: function(angle) {
    var map = this._map;
    var center = map.project(this.getCenter());
    var corners = {0: '', 1: '', 2: '', 3: ''};
    var i;
    var p;
    var q;

    for (i = 0; i < 4; i++) {
      p = map.project(this.getCorner(i)).subtract(center);
      q = L.point(
          Math.cos(angle) * p.x - Math.sin(angle) * p.y,
          Math.sin(angle) * p.x + Math.cos(angle) * p.y
      );
      corners[i] = map.unproject(q.add(center));
    }

    this.setCorners(corners);

    // window.angle = L.TrigUtil.radiansToDegrees(angle);

    this.rotation -= L.TrigUtil.radiansToDegrees(angle);

    return this;
  },

I thought also it was pretty standard to do that in ES6, like with object destructuring too for ex. honestly just curious

@sashadev-sky
Copy link
Member Author

@rexagod prepared to get this serious about our style guide?

This Style Guide uses RFC 2119 terminology when using the phrases must, must not, should, should not, and may. The terms prefer and avoid correspond to should and should not, respectively. Imperative and declarative statements are prescriptive and correspond to must.

@rexagod
Copy link
Member

rexagod commented Aug 23, 2019

Haha. I am, but the question is, will the first timers be okay with this standard? Also, I agree with the no comma after var declaration style, looks more cleaner to me. So +1 for that!

@sashadev-sky
Copy link
Member Author

@rexagod the block of vars look cleaner to you you’re saying?

I felt the opposite, but I can see your perspective too and functionally it is actually cleaner. So +1 from me too

@sashadev-sky
Copy link
Member Author

@rexagod up next: trailing commas? We don't do that at all, but I'm kinda with it. Makes sense functionally. Thoughts?

@sashadev-sky
Copy link
Member Author

@jywarren looping in

@rexagod
Copy link
Member

rexagod commented Aug 23, 2019

Trailing commas? Sorry, can you provide an example of those?

@sashadev-sky
Copy link
Member Author

like commas on the last key value pairs in objects and after the last method in the class. Even though nothing follows it. Makes it easier to add new methods

@rexagod
Copy link
Member

rexagod commented Aug 23, 2019

Oh. Those! Yeah they definitely do, all good from me!

@sashadev-sky
Copy link
Member Author

sashadev-sky commented Aug 24, 2019

@rexagod ok then:
Leaflet always puts a space before parentheses in function declarations like function () { }

Do you have any opinions on this one? I kinda think function() { } is more standard right?

@rexagod
Copy link
Member

rexagod commented Aug 24, 2019 via email

@jywarren
Copy link
Member

jywarren commented Aug 27, 2019 via email

@sashadev-sky
Copy link
Member Author

@jywarren I think you wrote the function without a space and said thats better for debugging but then said space should be required? Sorry can you clarify

@jywarren
Copy link
Member

jywarren commented Aug 28, 2019 via email

@rexagod
Copy link
Member

rexagod commented Aug 28, 2019

I'm all +1 for named functions as well, they are way more distinguishable in the error stack trace, hence better debugging!

@rexagod
Copy link
Member

rexagod commented Aug 28, 2019

Okay so it seems we'll be going ahead with no spaces, right?

@sashadev-sky
Copy link
Member Author

@rexagod yes!

@sashadev-sky
Copy link
Member Author

sashadev-sky commented Aug 29, 2019

@rexagod @jywarren ok i think this is last! Comments -
should we say

// this one is for a one-liner on its own line
return exampleCode; /* this one is for a one-liner that is inline with the code */
/**
 * this is a multi-line comment block
 * it is integrated with JSDoc - JSDoc comment snippet is suggested after typing `/**`
 * guessing its personal config but if we start using JSDoc later, can suggest ppl integrate that
 */
// this is fine too
// for multi-line comments

I don't mind left behind TODO comments. CodeCov threw an error on my PR in MK for this yesterday so just saying..

I set Max Length for comments to be ignored: "max-len": ["warn", { "ignoreComments": true }]
Agree / Disagree? Should we compromise for instead a more lenient max length for comments or does this just really not matter? I just don't like the way comments will span over more lines and take up more space following the current max length of 80.

For JSDoc commenting, for now maybe lets hold off on that until we get our code standard and then reopen the issue later as part of a 'standardizing documentation' discussion?

  • "valid-jsdoc": 2 is in .eslintrc.js but has been deprecated as of ESLint v5.10.0 (we are on 6.1.0) so either way lets change to "valid-jsdoc": 0?
  • getting errors for eslint(require-jsdoc) even though its also deprecated and not even included under rules in .eslintrc.js. So let's add `"require-jsdoc": 0?
  • eslint-plugin-jsdoc suggested by eslint instead in deprecation notice. we can install when decide we want to start jsdocing?

@sashadev-sky sashadev-sky mentioned this issue Sep 4, 2019
5 tasks
@sashadev-sky sashadev-sky mentioned this issue Sep 2, 2020
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants