-
Notifications
You must be signed in to change notification settings - Fork 3
Conversation
Codecov Report
@@ Coverage Diff @@
## master #282 +/- ##
==========================================
+ Coverage 78.97% 79.50% +0.52%
==========================================
Files 6 6
Lines 195 200 +5
Branches 56 55 -1
==========================================
+ Hits 154 159 +5
Misses 21 21
Partials 20 20
Continue to review full report at Codecov.
|
@@ -24,7 +24,7 @@ export interface ClassicAddress { | |||
test: boolean | |||
} | |||
|
|||
abstract class Utils { | |||
const utils = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change from a class to an object that holds functions.
This is the proper fix for the no-extraneous-class rule. I did ask about using abstract classes for this problem, but the consensus seems to be to just use EcmaScript modules.
It's a little odd that we're exporting an object as opposed to the individual functions, but this keeps us consistent with the old way of exporting the class.
@@ -85,13 +85,13 @@ abstract class Utils { | |||
} | |||
|
|||
// Xpring Common JS's API takes a string|undefined while the underlying address library wants string|false. | |||
const shimTagParameter = tag !== undefined ? tag : false | |||
const shimTagParameter = tag ?? false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an ESLint rule against if(negative) {...} else {...}
, because there's usually a better way to write it (like here).
) {} | ||
public constructor(host: string, path: string) { | ||
this.host = host | ||
this.path = path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a rule that disallows declaring class properties in the constructor. I'm ok with disabling this rule for now, but since some properties might not be declarable in the constructor, it makes sense to be consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to use lint rules if that's what folks like doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only reason I could think of not liking this style is that you forget to assign a variable. However, this appears to not be the case, since the following errors:
public constructor(host: string, path: string) {
this.host = host
}
Yells taht I didn't initialize path.
return | ||
parsePayID(payID: string): PayIdComponents | undefined { | ||
if (!this.isASCII(payID)) { | ||
return undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The consistent-return rule requires being explicit with your return
statements if your function contains a return
statement that returns something other than undefined (like this function with return new PayIdComponents()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
woo. I actually prefer this.
* @param privateKey - The given private key for the wallet. | ||
* @param test - Whether the address is for use on a test network, defaults to `false`. | ||
*/ | ||
public constructor(publicKey: string, privateKey: string, test = false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the constructor because the member-ordering rule defines an order that class members should appear in (and constructors come before any methods).
@@ -162,13 +163,14 @@ describe('utils', function (): void { | |||
classicAddress!.address, | |||
'rU6K7V3Po4snVhBBaU29sesqs2qTQJWDw1', | |||
) | |||
assert.strictEqual(classicAddress!.tag, 12345) | |||
assert.strictEqual(classicAddress!.tag, tag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a variable for this to avoid the no-magic-numbers
rule. This seems reasonable because the GIVEN
comment includes the tag
"include": [ | ||
"src/**/*" | ||
] | ||
"include": ["src/**/*"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the src/types
directory to @types
. I think this is more conventional, but let me know if there's a strong reason to have custom declaration files in the src
directory.
I did this because I need to disable a rule for declaration files which I do for all files in @types/**/*.d.ts
right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, pending that it builds in Xpring4J and XpringKit. I'm verifying that now.
Verified this works in XpringKit and Xpring4J. I'm going to avoid merging anything so that you can get this PR landed cleanly and I'll rebase the upstream PRs for any issues. Are there further linter PRs to go or is everything enabled? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to actually hit approve.
There is probably one more linter PR to go. The big blocker here is that The only other violations are things like this:
So, if the |
Oh sweet. I'm pretty open to what you'd recommend as function length / parameter limits. I don't love it as an absolute heuristic, but I'm fine to try it out and see if it encourages me to have better behavior. |
Yeah, the config right now are just my best guesses. Super happy to amend them based on feedback, especially as we roll out this linting config to more projects. In general, my thinking is:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! I'm fine with all of these rules - I agree that the function complexity/length might be a bit more subjective, but I think everything here is objectively better. Only exception might be prohibiting parameter properties, which I don't think are too confusing. Though explicit really usually is better so I can get behind it.
High Level Overview of Change
member-ordering
for class membersContext of Change
3rd (and almost final) step of bringing
xpring-common-js
onto the new lint config.Type of Change
Test Plan
npm run test
is all still green.