npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@codeque/cli

v0.5.1

Published

Multiline code search for every language. Structural code search for JavaScript, TypeScript, HTML and CSS

Downloads

42

Readme


What is CodeQue?

CodeQue is semantic code search engine that understands the code syntax.

It matches code structurally which makes it excellent for more complex queries.

Query language offers wildcards, partial matching and ignores code formatting.

Structural code search is available for JavaScript, TypesScript, HTML, CSS, Python, Lua and more soon.

Text code search with handy wildcards is available for every language and covers common regex search use cases.

Integrations

CodeQue is available as:

Coming soon

CodeQue will be soon available as:

  • Duplicated code identification
  • Batch code refactoring
  • Advanced ESLint rule creator

CLI tool 🔥

CodeQue CLI is a complementary tool that can be used for

  • Searching code patterns right from terminal including headless environments
  • Building scripts to assert that some code patterns exist or not exist
  • Enhancing git hooks to avoid committing or pushing unwanted code

Installation 👇

yarn global add @codeque/cli

Usage 🕵️

Run codeque to start CLI query editor.

codeque

Type query and hit ctrl+s to run your first search!

CodeQue CLI features:

  • four search modes
  • search by file dependency
  • search by files changed since last commit
  • clickable file links with code position (CMD + pointer click)
  • case insensitive search
  • API to use codeque as restricted code pattern guard

Find out how to use wildcards and discover search modes in codeque docs!

Use cases 🧑‍💻

In first place it's code search, so you can use it to search any code (as long as it is TypeScript or JavaScript - more languages in future).

Here are some use cases where CodeQue shines ✨

Search duplicated code 🍣

Once you spot some code pattern in more than one place, you can just copy and search for it.

You will find all occurrences and you will be bale to get rid of repetition forever!

Search API usage 🧰

I love using CodeQue to look for specific function or React hook usage. It's faster than looking for API into docs.

This a typical query that you can use to find usage of some React hook.

const $$$ = useMyHook();

Assertions ☔

You can use CLI to ensure that some bad code patterns will not be introduced into the codebase.

It's not that handy as ESLint (an CodeQue ESLint plugin is commit soon!), but at least you will not waste time for implementing custom plugins!

Use this to ensure there are no skipped tests in the codebase:

codeque --query "$$.skip()" "$$.only()" --invertExitCode

Flag --invertExitCode will revert default behavior of exit codes, and return non zero exit code when matches would be found.

Git hooks 🪝

I use codeque with text mode for my pre-commit hook.

text mode is faster than other modes, because it's regexp based.

I want to ensure there will be no console.logs, todos, and skipped tests introduced in my commit.

.git/hooks/pre-commit content

#!/bin/sh

codeque --git --query '$$.only(' '$$.skip(' 'console.log(' '// todo' --mode text --invertExitCode --caseInsensitive

if [ $? -ge 1 ] ; then
  echo '🛑 Found restricted code. Terminating.'
  exit 1
fi

CLI reference 📖

Root command codeque

Opens interactive terminal editor to type query and performs structural code search in current working directory. Alternatively performs search based on query provided as an param or query file.

Usage

codeque [options]

Options

  • -m, --mode [mode] - Search mode: exact, include, include-with-order, text (optional)
  • -r, --root [root] - Root directory for search (default: process.cwd()) (optional)
  • -e, --entry [entry] - Entry point to determine search files list based on it's imports (excluding nodeˍmodules) (optional)
  • -i, --caseInsensitive - Perform search with case insensitive mode (optional)
  • -l, --limit [limit] - Limit of results count to display (optional)
  • -q, --query [query...] - Inline search query(s) (optional)
  • -qp, --queryPath [queryPath...] - Path to file(s) with search query(s) (optional)
  • -g, --git - Search in files changed since last git commit (optional)
  • -iec, --invertExitCode - Return non-zero exit code if matches are found. Useful for creating assertions (optional)
  • -v, --version - Print CLI version (optional)
  • -pfl, --printFilesList - Print list of searched files (optional)
  • -ogi, --omitGitIgnore - Search files regardless .gitignore settings (optional)
  • -ae, --allExtensions - Search in all file extensions. Useful for text search mode. (optional)

Support and feedback

Feel free to use Github Issues to

  • ask for help with writing a query
  • report a bug or doubt
  • suggest feature or improvement