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

feat(eslint-plugin): add extension rule init-declarations #1814

Merged

Conversation

anikethsaha
Copy link
Contributor

fixes #1811

  • init-declarations
  • added tests for declaring of typed variables
  • docs

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @anikethsaha!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day.

@anikethsaha
Copy link
Contributor Author

@bradzacher messageIds is simply extending string and that is causing error for test file's messaged of invalid cases. Any workaround.? Is it ok to change the type in ruletester to string instead of extending it .

similar for errors.type

@bradzacher bradzacher added awaiting response Issues waiting for a reply from the OP or another party enhancement: new base rule extension New base rule extension required to handle a TS specific case labels Mar 27, 2020
@bradzacher
Copy link
Member

bradzacher commented Mar 29, 2020

make sure you validate your code locally and fix the errors.

https://github.com/typescript-eslint/typescript-eslint/blob/master/CONTRIBUTING.md#validating-your-changes

@codecov
Copy link

codecov bot commented Apr 1, 2020

Codecov Report

Merging #1814 into master will decrease coverage by 0.02%.
The diff coverage is 81.25%.

@@            Coverage Diff             @@
##           master    #1814      +/-   ##
==========================================
- Coverage   94.38%   94.36%   -0.03%     
==========================================
  Files         165      166       +1     
  Lines        7592     7608      +16     
  Branches     2178     2185       +7     
==========================================
+ Hits         7166     7179      +13     
  Misses        183      183              
- Partials      243      246       +3     
Flag Coverage Δ
#unittest 94.36% <81.25%> (-0.03%) ⬇️
Impacted Files Coverage Δ
...kages/eslint-plugin/src/rules/init-declarations.ts 81.25% <81.25%> (ø)

@anikethsaha
Copy link
Contributor Author

@bradzacher looks like there is some auth issue, I cant push to this branch after reading

image

@bradzacher
Copy link
Member

Make sure your local is up to date with the remote before pushing, or try force pushing if you want to overwrite the remote.

@anikethsaha
Copy link
Contributor Author

anikethsaha commented Apr 1, 2020

I did rebase and after that its coming. Its up to date with upstream

@anikethsaha
Copy link
Contributor Author

anikethsaha commented Apr 6, 2020

@bradzacher I did add some more tests but the diff coverage is still the same as before adding them
any suggestion ?

@bradzacher
Copy link
Member

https://codecov.io/gh/typescript-eslint/typescript-eslint/pull/1814/diff

The lines marked with yellow are branches that haven't been tested.

I.e. looking at your code + tests, you've got code that handles module declarations, but no tests for it.

@anikethsaha
Copy link
Contributor Author

anikethsaha commented Apr 8, 2020

image

@bradzacher I don't know how to particularly test those lines. I did add some test cases to cover those conditions.

@bradzacher
Copy link
Member

bradzacher commented Apr 8, 2020

I don't know how to particularly test those lines.

In codecov, yellow means that one branch of a conditional check has been tested, but not the other branch.

So looking at the code in question:

if (
  node.parent?.type === AST_NODE_TYPES.TSModuleBlock &&
  node.parent?.parent?.type === AST_NODE_TYPES.TSModuleDeclaration &&
  node.parent?.parent?.declare
) {
  return;
}

What is this if statement doing? What is it guarding against?
Compare it with your tests - which of the two branches are you testing, and which are you not?

(this is not me trying to be snarky here - I'm trying to drop a hint without giving you the answer 😄)


Another thing I see you doing in your code a lot is you're using unnecessary optional chains ?..
The typescript types are all correct - so you only need do use an optional chain if the field is nullish. Codecov has no way to understand this though - it just sees an optional chain as a branch that needs to be tested.

eg you've got if (node?.declare) { return }, but node is never nullish, so the ?. is unnecessary.

@anikethsaha
Copy link
Contributor Author

(this is not me trying to be snarky here - I'm trying to drop a hint without giving you the answer 😄)

😅

I will give another try 👍

@anikethsaha
Copy link
Contributor Author

@bradzacher
I did add some tests for those if statements in the latest commits
ed71f47

de1544f

07950f6

anything missing, a hint would be great

@bradzacher
Copy link
Member

Those test are sufficient - the reason codecov is reporting lower is because of the optional chain.
The parent is never nullable, so there's no way to test that branch - just ignore it. Your coverage is sufficient.

The branch target isn't a hard merge blocker. It's a guideline to help ensure people do enough tests and help me review that the tests cover the cases.

@bradzacher bradzacher removed the awaiting response Issues waiting for a reply from the OP or another party label Apr 10, 2020
@anikethsaha
Copy link
Contributor Author

the reason codecov is reporting lower is because of the optional chain.

I doubted that. idk even codecov supports the optional chaining or not

The branch target isn't a hard merge blocker. It's a guideline to help ensure people do enough tests and help me review that the tests cover the cases.

cool, 👍

@bradzacher bradzacher changed the title feat(eslint-plugin): added init-declarations support feat(eslint-plugin): add extension rule init-declarations Apr 20, 2020
bradzacher
bradzacher previously approved these changes Apr 20, 2020
Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

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

LGTM - thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: new base rule extension New base rule extension required to handle a TS specific case
Projects
None yet
2 participants