-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
style(eslint): apply specified code style changes #138
style(eslint): apply specified code style changes #138
Conversation
Signed-off-by: Derek Lewis <[email protected]>
Alright, so we already have some good feedback to work with on this PR. It seems to have made many corrections but would have been introducing an antipattern that we do not currently lint for with our local tooling: Use of a banned type detected JS-0296
|
src/index.ts
Outdated
@@ -84,10 +83,10 @@ interface ITargetSourceDepth { | |||
*/ | |||
export function deepMerge(target: Object, source: Object, depth = 10): Object { | |||
// Keep track of seen objects to detect recursive references. | |||
const seen: Array<Object> = []; | |||
const seen: Object[] = []; |
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 have started to collect some research on the topic at https://github.com/openinf/util-object/wiki/Type-Annotation-for-JavaScript-Objects, which we'll be incorporating as part of our style guide. Once I have settled on our preference, i'll be sure to make the update here.
/cc @septs as this would be another guideline to be added to our JS authoring guide (and enforced via our standard) ^^
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.
Object
-> object
Number
-> number
String
-> string
BigInt
-> bigint
Symbol
-> symbol
Boolean
-> boolean
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.
Object
->object
For this one, that would seem alright, but it would be very loose as it would simply mean any non-nullish value. Wonder what you think about the TypeScript Record
utility type?
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 don't like that it is called the same as Record
from the TC39 proposal, seeing as how they have different semantics iiuc. The TypeScript Record
utility type isn't an immutable object afaik, so mixing that in our codebase is a bit annoying imo.
src/index.ts
Outdated
} | ||
return obj; | ||
return object; |
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.
return object; | |
return { ...opt_initial }; |
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.
That might work; need to double-check, but just so that we're on the same page, this is what we are referred to when we say that it returns a "map-like object":
https://github.com/google/closure-compiler/wiki/A-word-about-the-type-Object#map-like-objects
src/index.ts
Outdated
} else { | ||
return undefined; | ||
} | ||
export function ownProperty( |
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 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 believe the Reflect.get
static method would also be able to access any inherited properties (e.g., from the base Object
superclass — all the properties from the constructor would be included), which i think we'd like to avoid.
For security purposes, i believe only having access to all enumerable own properties would be safer and more efficient iiuc.
src/index.ts
Outdated
@@ -160,14 +159,14 @@ export function objectsEqualShallow( | |||
* @template T,R | |||
*/ | |||
export function memo<T, P extends keyof T>( |
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 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.
Yeah, i knew about that proposal, but am not yet sure how it relates to this function. Is the difference that this is Object memo and that would be Function memo?
/cc @js-choi
spread props don't trigger getters on the target object Refs: https://babeljs.io/docs/en/assumptions#setspreadproperties Co-authored-by: septs <[email protected]> Signed-off-by: Derek Lewis <[email protected]>
Signed-off-by: Derek Lewis <[email protected]>
Signed-off-by: Derek Lewis <[email protected]>
Signed-off-by: Derek Lewis <[email protected]>
Signed-off-by: Derek Lewis <[email protected]>
Signed-off-by: Derek Lewis <[email protected]>
Signed-off-by: Derek Lewis <[email protected]>
Signed-off-by: Derek Lewis <[email protected]>
Signed-off-by: Derek Lewis <[email protected]>
Signed-off-by: Derek Lewis <[email protected]>
Signed-off-by: Derek Lewis <[email protected]>
Signed-off-by: Derek Lewis <[email protected]>
Signed-off-by: Derek Lewis <[email protected]>
Signed-off-by: Derek Lewis <[email protected]>
Signed-off-by: Derek Lewis <[email protected]>
Signed-off-by: Derek Lewis <[email protected]>
Signed-off-by: Derek Lewis <[email protected]>
Signed-off-by: Derek Lewis <[email protected]>
Signed-off-by: Derek Lewis <[email protected]>
Signed-off-by: Derek Lewis <[email protected]>
Cool, we finally got a green CI 🎉 |
Signed-off-by: Derek Lewis <[email protected]>
Oh dang, the TypeScript Compiler just type-checked the file and found some nits 😅 Refs: https://github.com/openinf/util-object/actions/runs/3261462228/jobs/5356396292 |
Signed-off-by: Derek Lewis <[email protected]>
Having trouble interpreting the TS typecheck error in CI rn, but am going to land it as-is since it's blocking a lot of other project-critical work and will likely take longer to resolve than would be worthwhile at this point. We'll be circling back to this shortly and obviously will have to resolve it before release. |
I have made a comment pertaining to a change that we have made here. See: 34fdb2a#r87092905 |
Refs: https://babeljs.io/docs/en/assumptions#setspreadproperties Fixes: #141 Fixes: #139 PR-URL: #138 Reviewed-by: septs <[email protected]> Reviewed-by: Derek Lewis <[email protected]> Signed-off-by: Derek Lewis <[email protected]> Co-authored-by: Derek Lewis <[email protected]> Co-authored-by: septs <[email protected]>
This PR separates the code style changes proposed by @ignoreintuition in #133.
Although recognized as desirable, they would be beyond the scope of the specific feature we are working on in that workstream; breaking them out here so as not to derail would be preferable.