Upgrade to Pro — share decks privately, control downloads, hide ads and more …

10 Code Search Tricks for Open Source

Erika Heidi
February 10, 2022

10 Code Search Tricks for Open Source

Learn how to leverage Sourcegraph code search to improve onboarding and productivity in the context of open source software.

Talk presented at JSWorld Online on February 10, 2022.

Erika Heidi

February 10, 2022
Tweet

More Decks by Erika Heidi

Other Decks in Technology

Transcript

  1. 10 Code Search Tricks
    for Open Source
    Using Sourcegraph to improve onboarding and
    productivity in the context of OSS
    JSWorld Online 2021

    View Slide

  2. Sourcegraph Code Search
    ● Search across millions of indexed open source repositories
    ○ doesn't require an account
    ● Search across your public and private repositories
    ○ requires an account to sync your repos from multiple code hosts
    ● Other options: Self hosted
    ○ free up to 10 users

    View Slide

  3. Browser-based search (sourcegraph.com/search)

    View Slide

  4. IDE-based search (VSCode Plugin)

    View Slide

  5. 1. Find projects that
    welcome contributors
    Use case: you want to find a welcoming open source project to
    contribute to (ex: for Hacktoberfest)

    View Slide

  6. Search string:
    contributing lang:Markdown

    View Slide

  7. View Slide

  8. View Slide

  9. 2. Find welcoming projects
    in language or framework
    Use case: you want to find a welcoming open source project in your
    language or framework of choice to contribute to

    View Slide

  10. Search string:
    contributing lang:Markdown
    repohasfile:"^composer.json$" patterntype:regexp

    View Slide

  11. View Slide

  12. 3. Find projects relying on
    specific dependencies
    Use case: you want to find out which projects are relying on a library
    you wrote, and how they're using it

    View Slide

  13. Search string:
    tailwindcss file:package.json

    View Slide

  14. View Slide

  15. 4. Find how an object is used
    across multiple repositories
    Use case: you want to use an undocumented function or method from
    an open source project and would like to see usage examples

    View Slide

  16. Search string:
    repo:^github\.com/minicli/.* new TableHelper
    lang:PHP

    View Slide

  17. View Slide

  18. Search string:
    repo:^github\.com/minicli/.*
    getPrinter()->out(...,...) patterntype:structural

    View Slide

  19. View Slide

  20. 5. Find exposed keys and
    secrets across repositories
    Use case: you want to check if any of your repositories contains
    exposed keys and secrets that were committed by mistake

    View Slide

  21. Search string:
    repo:^github\.com/sourcegraph/.*
    (key|secret|token)-[\w+]{32,} patterntype:regexp

    View Slide

  22. 6. Find usage of compromised
    dependencies
    Use case: you find out about a compromised package and want to
    check if the malicious code is included in any of your repositories

    View Slide

  23. Search string:
    symfont/process lang:JSON

    View Slide

  24. View Slide

  25. 7. Audit an organization for
    outdated dependencies
    Use case: you want to check across repositories for dependencies with
    a specific version

    View Slide

  26. Search string:
    file:package.json lodash 4.17.19
    patterntype:regexp

    View Slide

  27. 8. Find code that is not up to
    language standards
    Use case: you want to audit one or multiple repositories for code that is
    not up to predefined standards and best practices

    View Slide

  28. Search string:
    lang:PHP ^if([(...)]) patterntype:regexp

    View Slide

  29. View Slide

  30. 9. Search for recent changes in
    large or multiple projects
    Use case: you want to be on top of any new functionality or bug
    patches in a project you rely on

    View Slide

  31. Search string:
    repo:^github\.com/laravel/laravel$ type:commit
    after:lastweek

    View Slide

  32. View Slide

  33. 10. Find deprecated function
    calls across repositories
    Use case: you need to update a project to a newer version of a
    framework or language, but there might be breaking changes

    View Slide

  34. Search string:
    mhash(...) lang:PHP select:content
    patterntype:structural

    View Slide

  35. View Slide

  36. Thank You!
    Questions?
    Twitter: @erikaheidi
    E-mail: [email protected]
    https://sourcegraph.com

    View Slide