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

Adding ESLint #12

Merged
merged 3 commits into from Mar 29, 2023
Merged

Adding ESLint #12

merged 3 commits into from Mar 29, 2023

Conversation

evert
Copy link
Collaborator

@evert evert commented Mar 20, 2023

I split this PR in 3 commits:

  1. The rules
  2. The changes eslint was able to automatically do.
  3. Manual changes I had to make to remove the final errors (mostly unused variables)

Happy to make changes to the rules if there's anything you don't like about the style it decided on, and also happy to elaborate on why I made certain choices. Some are obviously stylistic, but there's also a few that help reduce bugs.

@evert evert added the enhancement New feature or request label Mar 20, 2023
@evert evert requested a review from mattbishop March 20, 2023 19:37
@evert evert self-assigned this Mar 20, 2023
"avoidEscape": true
}
],
"semi": ["error", "never"],
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only change I made from my standard ruleset =)

Copy link
Contributor

@mattbishop mattbishop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me think on this a bit, and let me know your thoughts. Most of these are just long-standing preferences, but I am open to convincing of better ways.

@@ -22,8 +22,11 @@
"@types/chai": "4.3.4",
"@types/mocha": "10.0.1",
"@types/node": "18.14.0",
"@typescript-eslint/eslint-plugin": "^5.56.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's your opinion on hats (^)? I've never liked them as I am not certain what versions I am using, and I have to trust authors to follow semver.

Copy link
Collaborator Author

@evert evert Mar 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly that's why we have package-lock. It's purpose really is exactly this, and also so we can go back later and be really sure we're testing with the version that was checked in.

So package-lock.json gives us stable unchanging dependencies, and package.json gives us information on what we could probably safely upgrade to, but it doesn't happen by default.

import {downloadAndValidateLedger} from "../../lib/download"
import {TokenAwareCommand} from "../../lib/token-command"
import { initClient } from '../../lib/client';
import {Flags} from '@oclif/core'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

' vs " - my take, I use ' for JS files and " for TS as it reminds me of Java (type systems). I am half-seriously thinking of switching to ` for everything, but haven't made that change.

@@ -27,7 +26,7 @@ describe('ledger:download', async () => {
expect(req.headers.get('Authorization')).to.equal(`Bearer ${testToken}`)
const path = new URL(req.url).pathname
switch(path) {
case '/ledgers/download' :
case '/ledgers/download' : {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really? That looks so bizarre in a case statement!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know why I don't like it. The closure doesn't do anything. One still has to break out of the case. Typescript needs better method pattern matching or something.

Copy link
Collaborator Author

@evert evert Mar 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the reason eslint wants this is a pretty specific reason, it's because const was used inside the body of the 'case'.

I don't love this syntax either but it is one of those bug-preventing things. You may have noticed I only did it for this case, but not for the others (because it's the only one that defines a new variable).

Here's the eslint docs on this rule:

https://eslint.org/docs/latest/rules/no-case-declarations

We can still disable it though, let me know! I super don't care about this rule because the kind of the bug it prevents is pretty subtle.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for digging into these rules.

@mattbishop
Copy link
Contributor

Looks good, merge when ready.

@evert evert merged commit 4391b3f into main Mar 29, 2023
2 checks passed
@evert evert deleted the eslint branch May 3, 2023 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants