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 full-size 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 full-size slide

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

    View full-size slide

  4. IDE-based search (VSCode Plugin)

    View full-size 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 full-size slide

  6. Search string:
    contributing lang:Markdown

    View full-size slide

  7. 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 full-size slide

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

    View full-size slide

  9. 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 full-size slide

  10. Search string:
    tailwindcss file:package.json

    View full-size slide

  11. 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 full-size slide

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

    View full-size slide

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

    View full-size slide

  14. 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 full-size slide

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

    View full-size slide

  16. 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 full-size slide

  17. Search string:
    symfont/process lang:JSON

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  20. 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 full-size slide

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

    View full-size slide

  22. 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 full-size slide

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

    View full-size slide

  24. 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 full-size slide

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

    View full-size slide

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

    View full-size slide