-
Notifications
You must be signed in to change notification settings - Fork 21
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
Enforce code style? #83
Comments
This is what these two options could look like:
I separated the ESLint branch commits by fixing each rule in turn, but the fixes would be squashed into a single commit for a pull request. Dealing with manually ensuring the format is correct is way more annoying than just letting Prettier do it automatically on every editor save. I included Prettier editor configurations for both VS Code and WebStorm. Prettier can also take care of markdown files and code inside of markdown files. |
I'm in favour of this 👍 I would go with Prettier, as it to me doesn't make sense to go against the recommendations from TypeScript. @carlhoerberg do you have any opinions on this? |
Breaking up |
Not really excited about 1300 more lines in the code base.. but on my phone and cant make a just assessment yet. |
There's a couple options I can think of, Get the comment back onto the function call:closeOk.setUint32(j, 4) // frameSize
j += 4 Use a postfix increment function and object and get it all back on one line:let j = new Position(0) // position in outgoing frame
// and
closeOk.setUint32(j.poInc(4), 4) // frameSize elsewhere: export class Position {
public position: number
constructor(initialPosition = 0) {
this.position = initialPosition
}
/** Post increment by offset, returning position before incrementing. */
poInc(offset = 1) {
const p = this.position
this.position += offset
return p
}
} Ignore sections of code
|
As I have been making contributions, I try to match the surrounding code style, but sometimes add semicolons, or get the single-quote/double-quote different.
Prettier would make it easy to enforce a single code style for everyone.
There are currently 423 single-quotes and 870 double-quotes in the source files.
Likewise, there are 428 semicolons, but mostly in multi-statement lines like these:
The biggest change is that Prettier will force the statements above onto separate lines.
Considering the above, these are the options that could be used:
With
"semi": false
, that runs into a potential linting issue because Prettier is trying to prevent a potential ASI failure with changes like this:ESLint will complain about unnecessary semicolons (but can be disabled with
eslint-config-prettier
)... Maybe semicolons are fine after all?Alternatively ESLint could be used to enforce a coding style, starting with the semi and quotes rules. The full list of rules that would need to be configured is extensive.
Using linters for formatting is not really recommended, including by ESLint.
The text was updated successfully, but these errors were encountered: