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

@asbjorn/eslint-plugin-groq

v2.0.0

Published

Eslint plugin for GROQ queries

Downloads

9,979

Readme

@asbjorn/eslint-plugin-groq

Unofficial eslint plugin for GROQ queries.

npm install @asbjorn/eslint-plugin-groq

Requirements

This plugin uses groq to identify GROQ tagged template literals, and by default will not report anything for queries that don't use this package.

If you use groq from a different library, such as @nuxtjs/sanity or next-sanity, see below for configuration.

// Will not be linted:
const query = "*[_type == 'movies'][0..10]";

// Will be linted:
import groq from "groq";
const query = groq`*[_type == 'movies'][0..10]`;

// Will also be linted:
import anything from "groq";
const query = anything`*[_type == 'movies'][0..10]`;

Configuration

{
  "plugins": ["@asbjorn/groq"],
  "rules": {
    "@asbjorn/groq/no-syntax-errors": "error",
    "@asbjorn/groq/no-template-expressions": "error"
  }
}

Or:

{
  "extends": ["plugin:@asbjorn/groq/recommended"]
}

Using groq from other libraries

By default these eslint rules only check queries using the GROQ function exported from the groq npm package. If you use GROQ from a different library, such as @nuxtjs/sanity or next-sanity, you can pass an array of package names as config to the rules:

{
  "plugins": ["@asbjorn/groq"],
  "rules": {
    "@asbjorn/groq/no-syntax-errors": [
      "error",
      { "groqs": ["@nuxtjs/sanity"] }
    ],
    "@asbjorn/groq/no-template-expressions": [
      "error",
      { "groqs": ["@nuxtjs/sanity"] }
    ]
  }
}

Rules

no-syntax-errors

Reports any syntax errors in GROQ queries tagged with the function exported from groq. Note that template literals that contain expressions will not be linted because resolving the expressions is very hard to do reliably. If you want to be extra safe, use this rule in combination with the no-template-expressions rule.

Failing cases

// Syntax error in tagged query
import groq from "groq";
groq`*[_type == { ]`;

// Syntax error (not imported as `groq`)
import hello from "groq";
hello`*[_type == { ]`;

Passing cases

// Non-tagged query with syntax error
`*[_type == {]`;

// Valid, tagged query
import groq from "groq";
groq`*[_type == 'movie']`;

// Query with syntax error tagged with `groq` not imported from `"groq"`
import groq from "somewhere";
groq`*[_type == {]`;

// Query with syntax error and template expression
import groq from "groq";
groq`*[_${expression} == {]`;

no-template-expressions

Reports any expressions in GROQ queries tagged with the function exported from groq. This rule exists because the no-syntax-errors rule bails on any query that contains expressions (see the description for that rule).

Failing cases

// Template expression
import groq from "groq";
groq`*[_type == ${type}]`;

// Template expression (not imported as 'groq')
import hello from "groq";
hello`*[_type == ${type}]`;

Passing cases

// Tagged query without expressions
import groq from "groq";
groq`*[_type == 'movie']`;

// Non-tagged query with expression
`*[_type == ${type}]`;

// Query with expression tagged with `groq` not imported from `"groq"`
import groq from "somewhere";
groq`*[_type == ${type}]`;