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

Add GitHub shorthand for URL rewrites #128

Merged
merged 1 commit into from
Apr 25, 2017
Merged

Conversation

gabro
Copy link
Collaborator

@gabro gabro commented Apr 25, 2017

Closes #125

First working draft. I've setup some integration tests but they fail because the file referenced is not there. Not sure whether these tests make sense, or whether we should just unit test the shorthand expansion. Anyway, the FileNotFound exception shows a correct value, so 🎉.

@olafurpg take a look and let me know what you think!

@gabro
Copy link
Collaborator Author

gabro commented Apr 25, 2017

Hu, also, I haven't ran scalafmt on the patch yet, so the CI is probably going to complain about that too.

@gabro
Copy link
Collaborator Author

gabro commented Apr 25, 2017

Ok, I've run scalafmt, that part should be ok now

Copy link
Contributor

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

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

Thank you for this contribution! Looks great besides the test suite location and that we don't need to do the whole DiffTest part ^^

@@ -20,4 +20,37 @@ class URLConfiguration
|
""".stripMargin
DiffTest("url", code, "UrlRewrite.stat").foreach(runDiffTest)

val githubURL =
"github:scalacenter/scalafix/1.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, I just realised that we of course just want to unit test this feature. One integration test for the actual http request should be enough. We can create a new tests suite named GitHubUrlRewriteTest inside scalafix-tests/src/test/scala/...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yep, I realized it while writing it as well. I'll add a unit test and remove this.

|rewrites = [
| "$githubURL"
|]
|<<< NOWRAP GitHub shorthand
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we only need to test the String => URL expansion, there's no need to test this.

@gabro
Copy link
Collaborator Author

gabro commented Apr 25, 2017

@olafurpg done! I've force-pushed the version of the tests, no more integration tests, just unit tests checking the shorthand expansion.

import org.scalatest.{FunSuiteLike, Matchers}
import metaconfig.Conf

class GitHubUrlRewriteSuite extends FunSuiteLike with Matchers {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've used FunSuiteLike directly since no scalafix-specific features are needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great!

Copy link
Contributor

@olafurpg olafurpg 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 for the fruitful discussion. I will merge when the CI is green.

import org.scalatest.{FunSuiteLike, Matchers}
import metaconfig.Conf

class GitHubUrlRewriteSuite extends FunSuiteLike with Matchers {
Copy link
Contributor

Choose a reason for hiding this comment

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

Great!

@olafurpg olafurpg merged commit 10af7b2 into scalacenter:master Apr 25, 2017
@gabro
Copy link
Collaborator Author

gabro commented Apr 25, 2017

🎉

val normVersion = version.replaceAll("[^\\d]", "_")
val fileName = s"${repo.toLowerCase.capitalize}_$normVersion.scala"
new URL(
s"https://github.com/$org/$repo/blob/$sha/scalafix-rewrites/src/main/scala/$repo/scalafix/$fileName")
Copy link
Contributor

Choose a reason for hiding this comment

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

I just realized that repo can contain non-alphanumerical characters like - which are unsupported in package names. What do you think @gabro about doing a replaceAll("[^a-zA-Z0-9]", "_")?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right, tracking it here: #131

I'll fix it soon.

bjaglin pushed a commit to liancheng/scalafix that referenced this pull request May 23, 2023
bjaglin pushed a commit to liancheng/scalafix that referenced this pull request May 23, 2023
bjaglin pushed a commit to liancheng/scalafix that referenced this pull request May 23, 2023
bjaglin pushed a commit to liancheng/scalafix that referenced this pull request May 23, 2023
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.

2 participants