@asbjorn/eslint-plugin-groq

中文文档
2.0.0发布于 2021/12/01MITCommonJS近 30 天下载 1870

Eslint plugin for GROQ queries

原始使用文档
文档目录6 节
  1. Requirements
  2. Configuration
  3. Using groq from other libraries
  4. Rules
  5. no-syntax-errors
  6. no-template-expressions

@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}]`;

版本与发布记录

@asbjorn/eslint-plugin-groq 共发布 5 个版本,首次发布于 2019/10/29;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.0latest2021/12/014 年前
1.0.02020/10/146 年前
0.1.22019/10/297 年前
0.1.12019/10/297 年前
0.1.02019/10/297 年前

关于 @asbjorn/eslint-plugin-groq 的常见问题

@asbjorn/eslint-plugin-groq 是什么?

Eslint plugin for GROQ queries

如何安装 @asbjorn/eslint-plugin-groq?

在项目目录运行 npm install @asbjorn/eslint-plugin-groq,或使用 pnpm add / yarn add / bun add。

@asbjorn/eslint-plugin-groq 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/asbjorn__eslint-plugin-groq 是否存在。

@asbjorn/eslint-plugin-groq 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@asbjorn/eslint-plugin-groq 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=10.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@asbjorn/eslint-plugin-groq 可以商用吗?

@asbjorn/eslint-plugin-groq 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@asbjorn/eslint-plugin-groq 的下载量有多少?

根据 npm 官方下载统计,@asbjorn/eslint-plugin-groq 在 2026/10/07 – 2026/11/05 这 30 天内被下载 1,870 次,日均约 62 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@asbjorn/eslint-plugin-groq 还在维护吗?

最新版本 2.0.0 发布于 2021/12/01(4 年前);至今共发布 5 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/10/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。