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

Clarification for Inline Comments #1506

Open
Zamiell opened this issue Jul 26, 2017 · 4 comments
Open

Clarification for Inline Comments #1506

Zamiell opened this issue Jul 26, 2017 · 4 comments

Comments

@Zamiell
Copy link

Zamiell commented Jul 26, 2017

Thanks for the excellent style guide!

One thing that is not explicitly defined by the guide is inline comments. Can a section on this topic be added to the "Comments" section block, please?

For example,

let foo = 145; // This is modified below in the "baz()" function

Is this a legal line in the airbnb style?

And the follow-up question: if it is not legal, then I assume that the correct fix to have it be moved above, like this?

// This is modified below in the "baz()" function
let foo = 145;

Yet another follow-up question: if inline comments are legal, then what is the correct fix for in-line comments that make the line extend past 100 character? Like the following:

// This is a comment describing the following block of variable initializations
let foo = 123; // used in various contexts, but mostly for soccer games, basketball, and football games
let bar = 456; // used only for horse races; it is explicitly reset at the beginning of the "endRace()" function
let baz = 789; // used only for car races; it will be overwritten once we reach the "oilChange()" function

If it were moved above, it would overlap with the block comment header. So then does it make the most sense to move them down to the next line, like this?

// This is a comment describing the following block of variable initializations
let foo = 123;
// used in various contexts, but mostly for soccer games, basketball, and football games
let bar = 456;
// used only for horse races; it is explicitly reset at the beginning of the "endRace()" function
let baz = 789;
// used only for car races; it will be overwritten once we reach the "oilChange()" function
@ljharb
Copy link
Collaborator

ljharb commented Jul 26, 2017

Both are allowed.

As for length, I'm not sure if we ignore line length for comments in the config or not, but I'd say both "use whatever makes the most sense to you", and also "if lots of comments are required, rearchitect the code so fewer are needed".

@Zamiell
Copy link
Author

Zamiell commented Nov 10, 2017

Can this information actually be added to the style guide?

@ljharb
Copy link
Collaborator

ljharb commented Nov 11, 2017

A PR that adds it would be appreciated!

@sharma62

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants