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

Fixed some TypeScript Lint warnings. #1390

Closed
wants to merge 15 commits into from
Closed

Fixed some TypeScript Lint warnings. #1390

wants to merge 15 commits into from

Conversation

git-init-priyanshu
Copy link
Member

What kind of change does this PR introduce?
This pull request addresses some of the TypeScript lint warnings.

Issue Number:
#1201

Fixes #1201

Did you add tests for your changes?
No. I have tested it against the existing test cases.

Snapshots/Videos:
N/A

If relevant, did you update the documentation?
No

Summary
This PR fixes the following lint warnings:

  1. ban-ts-comment
  2. no-explicit-any
  3. no-inferrable-types
  4. no-non-null-asserted-optional-chain
  5. no-non-null-assertion
  6. no-var-requires

Does this PR introduce a breaking change?
No

Have you read the contributing guide?
Yes

@github-actions
Copy link

Our Pull Request Approval Process

We have these basic policies to make the approval process smoother for our volunteer team.

Testing Your Code

Please make sure your code passes all tests. Our test code coverage system will fail if these conditions occur:

  1. The overall code coverage drops below the target threshold of the repository
  2. Any file in the pull request has code coverage levels below the repository threshold
  3. Merge conflicts

The process helps maintain the overall reliability of the code base and is a prerequisite for getting your PR approved. Assigned reviewers regularly review the PR queue and tend to focus on PRs that are passing.

Reviewers

When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Congratulations on making your first PR! 🎊 If you haven't already, check out our Contributing Guidelines and PR Reporting Guidelines to ensure that you are following our guidelines for contributing and creating PR.

@codecov
Copy link

codecov bot commented Sep 22, 2023

Codecov Report

Attention: 69 lines in your changes are missing coverage. Please review.

Comparison is base (c0468a4) 98.17% compared to head (3228758) 97.62%.
Report is 101 commits behind head on develop.

Files Patch % Lines
src/utilities/PII/decryption.ts 0.00% 17 Missing ⚠️
src/resolvers/middleware/currentUserExists.ts 45.83% 13 Missing ⚠️
src/utilities/PII/encryption.ts 0.00% 13 Missing ⚠️
src/utilities/PII/isAuthorised.ts 0.00% 11 Missing ⚠️
...tilities/encodedVideoStorage/uploadEncodedVideo.ts 90.12% 8 Missing ⚠️
src/resolvers/Mutation/removeAdvertisement.ts 92.85% 2 Missing ⚠️
...c/resolvers/Query/postsByOrganizationConnection.ts 33.33% 2 Missing ⚠️
src/resolvers/Subscription/onPluginUpdate.ts 0.00% 2 Missing ⚠️
src/resolvers/Query/postsByOrganization.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1390      +/-   ##
===========================================
- Coverage    98.17%   97.62%   -0.56%     
===========================================
  Files          184      214      +30     
  Lines        10767    12950    +2183     
  Branches       835     1052     +217     
===========================================
+ Hits         10571    12643    +2072     
- Misses         186      292     +106     
- Partials        10       15       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@git-init-priyanshu
Copy link
Member Author

Hey @tasneemkoushar,
Can you please review my PR. Thanks.

@git-init-priyanshu
Copy link
Member Author

Hey @palisadoes can you review my PR please. Thanks.

@palisadoes
Copy link
Contributor

@tasneemkoushar Please review

@palisadoes palisadoes closed this Oct 13, 2023
@palisadoes palisadoes reopened this Oct 13, 2023
@palisadoes
Copy link
Contributor

@tasneemkoushar Please review

@github-actions
Copy link

This pull request did not get any activity in the past 10 days and will be closed in 180 days if no update occurs. Please verify it has no conflicts with the develop branch and rebase if needed. Mention it now if you need help or give permission to other people to finish your work.

@github-actions github-actions bot added the no-pr-activity No pull request activity label Oct 24, 2023
@palisadoes
Copy link
Contributor

@git-init-priyanshu Shouldn't you also be editing the .eslintrc.json file too? Ideally we should make the tests fail when the linting fails, this will help a lot with our code quality. I've added @EshaanAgg to provide his feedback.

@github-actions github-actions bot removed the no-pr-activity No pull request activity label Oct 28, 2023
@@ -48,7 +48,7 @@ export const createDirectChat: MutationResolvers["createDirectChat"] = async (
_id: args.data.organizationId,
}).lean();

await cacheOrganizations([organization!]);
if (organization) await cacheOrganizations([organization]);
Copy link
Contributor

Choose a reason for hiding this comment

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

You have added this if (organization) check in all of the caching statements to remove the use of the ! operator. Still, the same is unnecessary as it is guaranteed to exist, and thus the use of the ! operator. This change adds unnecessary verbosity to the code.
We should revert this change or find a more elegant way to deal with the same. What do you think @kb-0311?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok got it. I think I need to find a better way to remove the ! operator

Copy link
Member Author

Choose a reason for hiding this comment

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

Hey, for this can we do something like this?: we can check if we are getting id from the args and if not we can throw an error. So this will make sure that that the ids we are passing to the findOrganizationsInCache function will never be null.

Copy link
Contributor

@EshaanAgg EshaanAgg left a comment

Choose a reason for hiding this comment

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

Please also add all these rules to the linting config files so that husky and the workflows catch them.

@palisadoes
Copy link
Contributor

Please fix the conflicting file

@tasneemkoushar
Copy link
Contributor

@git-init-priyanshu can you resolve the conflicts?

@noman2002
Copy link
Member

@git-init-priyanshu Please fix the conflicting files.

@noman2002 noman2002 requested a review from EshaanAgg November 11, 2023 15:43
@git-init-priyanshu
Copy link
Member Author

I apologize for the inactivity. I have semester exams starting next week, so I won't have the time to work on this. Could you please grant me more time? Thank you.

@tasneemkoushar
Copy link
Contributor

@git-init-priyanshu you can do it after your exam. FYI some linting issues have been fixed by @parthiv360 . You can check that here in this PR. Please resolve conflicting files and try to fix linting issues which aren't covered in PR #1412 once your exam finishes.

@git-init-priyanshu
Copy link
Member Author

@git-init-priyanshu you can do it after your exam. FYI some linting issues have been fixed by @parthiv360 . You can check that here in this PR. Please resolve conflicting files and try to fix linting issues which aren't covered in PR #1412 once your exam finishes.

Yeah, sure.

@noman2002
Copy link
Member

@git-init-priyanshu Please fix the conflicting files.

@tasneemkoushar
Copy link
Contributor

@git-init-priyanshu any update on this PR

@git-init-priyanshu
Copy link
Member Author

@git-init-priyanshu any update on this PR

My exams just finished today, so I will be working on this now.

@git-init-priyanshu
Copy link
Member Author

@tasneemkoushar I have made the changes. Can you check now.

Copy link
Contributor

@EshaanAgg EshaanAgg left a comment

Choose a reason for hiding this comment

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

Needs minor changes.

@@ -190,7 +191,8 @@ describe("utilities -> imageAlreadyInDbCheck", () => {

try {
await imageAlreadyInDbCheck(null, testNewImagePath);
} catch (error: any) {
} catch (error: unknown) {
if (!(error instanceof ApplicationError)) return;
Copy link
Contributor

Choose a reason for hiding this comment

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

Make the test fail in such a case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Make the test fail in such a case.

if (!(error instanceof Error)) throw new Error;

Sorry for asking but will it work?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is not idiomatic.
Use Vitest error assertions instead.

@@ -32,7 +33,8 @@ describe("src -> utilities -> encodedImageStorage -> uploadEncodedImage", () =>
"NAAAAKElEQVQ4jWNgYGD4Twzu6FhFFGYYNXDUwGFpIAk2E4dHDRw1cDgaCAASFOffhEIO" +
"3gAAAABJRU5ErkJggg==";
await uploadEncodedImage(img, null);
} catch (error: any) {
} catch (error: unknown) {
if (!(error instanceof ApplicationError)) return;
Copy link
Contributor

Choose a reason for hiding this comment

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

Make the test fail here instead of returning.

@@ -50,7 +50,8 @@ describe("utilities -> adminCheck", () => {
testUser?._id,
testOrganization ?? ({} as InterfaceOrganization)
);
} catch (error: any) {
} catch (error: unknown) {
if (!(error instanceof Error)) return;
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

@git-init-priyanshu
Copy link
Member Author

git-init-priyanshu commented Dec 9, 2023

Hey @EshaanAgg can you please check now.

@EshaanAgg
Copy link
Contributor

Please fix the failing workflows.

@git-init-priyanshu
Copy link
Member Author

git-init-priyanshu commented Dec 14, 2023

Please fix the failing workflows.

can you check now

@palisadoes palisadoes requested a review from EshaanAgg December 15, 2023 05:40
@EshaanAgg
Copy link
Contributor

@git-init-priyanshu The tests are still failing.

Copy link
Contributor

@EshaanAgg EshaanAgg left a comment

Choose a reason for hiding this comment

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

The PR has the right spirit but needs work. Instead of trying to fix the lining warnings, please try to understand the intent behind using ! or ? and then write the resolvers accordingly. TypeScript and lining rules should help to enforce these patterns, not bother.

@@ -150,7 +150,7 @@ export const createPost: MutationResolvers["createPost"] = async (
}
);

await cacheOrganizations([updatedOrganizaiton!]);
if (updatedOrganizaiton) await cacheOrganizations([updatedOrganizaiton]);
Copy link
Contributor

Choose a reason for hiding this comment

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

In all such cases we are assured that the updatedOrganization would be not null due to the business logic. Thus this conditional is useless.

@@ -55,7 +55,7 @@ export const createPost: MutationResolvers["createPost"] = async (
_id: args.data.organizationId,
}).lean();

await cacheOrganizations([organization!]);
if (organization !== null) await cacheOrganizations([organization]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

@@ -42,7 +42,7 @@ export const removeMember: MutationResolvers["removeMember"] = async (
_id: args.data.organizationId,
}).lean();

await cacheOrganizations([organization!]);
if (organization !== null) await cacheOrganizations([organization]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto

updatedUser!.image = updatedUser?.image
? `${context.apiRootUrl}${updatedUser?.image}`
: null;
if (updatedUser)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

@palisadoes
Copy link
Contributor

@git-init-priyanshu

  1. You have made almost 40 commits to this PR without closing it.
  2. Something is wrong with your methodology or the original issue needs to be adjusted. We have a linting issue created to just check on the deltas which may be more appropriate.

Please close this PR and the issue if the issue above is a more suitable solution.

@git-init-priyanshu
Copy link
Member Author

I totally agree with you, sir. I was also losing motivation to work on this PR. I will review my methodology and make sure to work on this. If you have any specific suggestions or insights, I would welcome them to ensure that I can improve.

@palisadoes
Copy link
Contributor

  1. Thanks. I'll close this and the issue too.
  2. Focus on other issues that will reactivate your motivation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix Typescript Rules lint warnings
5 participants