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

style(eslint): apply specified code style changes #138

Merged
merged 27 commits into from
Oct 17, 2022

Conversation

DerekNonGeneric
Copy link
Member

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.

Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is>
@DerekNonGeneric
Copy link
Member Author

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

Don't use Object as a type

https://deepsource.io/gh/openinf/util-object/run/0db33e3f-7492-4a1c-bbf1-68a2271cdf54/javascript/JS-0296?listindex=0

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[] = [];
Copy link
Member Author

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) ^^

Copy link
Contributor

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

Copy link
Member Author

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?

Copy link
Member Author

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return object;
return { ...opt_initial };

Copy link
Member Author

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 Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
src/index.ts Outdated
} else {
return undefined;
}
export function ownProperty(
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

@DerekNonGeneric DerekNonGeneric Oct 16, 2022

Choose a reason for hiding this comment

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

see https://mdn.io/relect-get

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>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

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 <github@septs.pw>
Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is>
src/index.ts Outdated Show resolved Hide resolved
Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is>
src/index.ts Outdated Show resolved Hide resolved
Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is>
src/index.ts Outdated Show resolved Hide resolved
Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is>
src/index.ts Outdated Show resolved Hide resolved
Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is>
src/index.ts Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is>
src/index.ts Outdated Show resolved Hide resolved
Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is>
src/index.ts Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is>
Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is>
Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is>
Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is>
Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is>
Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is>
Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is>
src/index.ts Outdated Show resolved Hide resolved
Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is>
src/index.ts Outdated Show resolved Hide resolved
Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is>
src/index.ts Outdated Show resolved Hide resolved
Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is>
src/index.ts Outdated Show resolved Hide resolved
Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is>
src/index.ts Outdated Show resolved Hide resolved
Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is>
src/index.ts Outdated Show resolved Hide resolved
Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is>
@DerekNonGeneric
Copy link
Member Author

Cool, we finally got a green CI 🎉

Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is>
@DerekNonGeneric
Copy link
Member Author

DerekNonGeneric commented Oct 17, 2022

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 <DerekNonGeneric@inf.is>
@DerekNonGeneric
Copy link
Member Author

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.

@DerekNonGeneric
Copy link
Member Author

DerekNonGeneric commented Oct 18, 2022

I have made a comment pertaining to a change that we have made here.

See: 34fdb2a#r87092905

DerekNonGeneric added a commit that referenced this pull request Nov 3, 2022
Refs: https://babeljs.io/docs/en/assumptions#setspreadproperties

Fixes: #141
Fixes: #139

PR-URL: #138
Reviewed-by: septs <github@septs.pw>
Reviewed-by: Derek Lewis <DerekNonGeneric@inf.is>
Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is>
Co-authored-by: Derek Lewis <DerekNonGeneric@inf.is>
Co-authored-by: septs <github@septs.pw>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants