Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

noUnusedVariableRule should apply the ignorePattern to imports #3187

Merged
merged 1 commit into from Sep 26, 2017

Conversation

brandf
Copy link
Contributor

@brandf brandf commented Aug 30, 2017

I have a import that I need to ignore (custom reactNamespace), however ignore-pattern is not applied to imports.

PR checklist

Overview of change:

applies the importPattern to importNames (in addition to the existing behavior)

Is there anything you'd like reviewers to focus on?

not sure if importName.text is the correct thing to test against, but it seems to work.

@palantirtech
Copy link
Member

Thanks for your interest in palantir/tslint, @brandf! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request.

@brandf
Copy link
Contributor Author

brandf commented Aug 30, 2017

I'm happy to add tests/doc changes, but will need some direction on getting setup to run them. I just did a quick 'fork and edit this file' on github.

@ajafff
Copy link
Contributor

ajafff commented Aug 31, 2017

ignorePattern may be undefined. That needs to be handled.
The easier fix would be moving the block at line 134 above line 119.

Regarding documentation: docs are generated from the metadata in the rule. That means you can simply replace line 41 with

Variable names and imports that match the pattern will be ignored.

Regarding tests: you can add a test case in test/rules/no-unused-variable/ignore-pattern/var.ts.lint

To test this locally, you need to

  • yarn install inside your local clone of the repository (or npm install if you don't have yarn installed)
  • edit the rule and the tests
  • npm run verify will compile, run the linter and the tests afterwards
  • if everything is fine, commit and push as usual

@brandf
Copy link
Contributor Author

brandf commented Sep 8, 2017

Sorry for the delay on this, I will follow up with ajafff's suggestions soon. In laws are in town, so not a lot of time atm ;-)

@brandf
Copy link
Contributor Author

brandf commented Sep 22, 2017

@ajafff, apologies again for the delay on this. The latest includes the easier fix, docs updated, test case, and tests passing.

@brandf
Copy link
Contributor Author

brandf commented Sep 22, 2017

Container 3 in circleci is failing - I can repro it locally with:

npm run clean && yarn compile && yarn add typescript@next && yarn test

...but I'm not sure how to fix it. It looks like the error message is different in typescript@next:

                                           ~~~~              ['args' is declared but its value is never read.]
                                           ~~~~              ['args' is declared but never used.]

@brandf
Copy link
Contributor Author

brandf commented Sep 22, 2017

After looking at other PR's, the CI failure appears to be unrelated to my change. It's just a coincidence that it was failing in the rule I modified :-/

For example, same failure here:
#3238

@ajafff
Copy link
Contributor

ajafff commented Sep 22, 2017

Please merge master into your branch to fix the CI failures

I'm not able to turn this rule on for my project because we use tsx with a custom namespace.  The namespace must be imported, but the sugar'ed code doesn't use it.  I tried applying the ignore-pattern to this namespace and it didn't work without this change.

adding a test case, doc fix, and easier fix that ajafff suggested
@brandf
Copy link
Contributor Author

brandf commented Sep 23, 2017

Should be all set - green CI after rebasing

@brandf
Copy link
Contributor Author

brandf commented Sep 26, 2017

@adidahiya, you can remove the 'waiting on author' tag. Should be good to merge.

@ajafff ajafff merged commit 5650f87 into palantir:master Sep 26, 2017
@ajafff
Copy link
Contributor

ajafff commented Sep 26, 2017

Thanks @brandf

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

Successfully merging this pull request may close these issues.

None yet

4 participants