@asbjorn/eslint-plugin-groq (英语)
非正式 eslint 用于 加纳 查询.
npm install @asbjorn/eslint-plugin-groq
所需资源
此插件使用 groq 以识别 GROQ 标记的模板文字,默认情况下不会报告任何不使用此软件包的查询.
如果您使用 groq 从不同的图书馆,例如 @nuxtjs/sanity 或者说 next-sanity,见下文配置.
// 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]`;
配置
{
"plugins": ["@asbjorn/groq"],
"rules": {
"@asbjorn/groq/no-syntax-errors": "error",
"@asbjorn/groq/no-template-expressions": "error"
}
}
或者说:
{
"extends": ["plugin:@asbjorn/groq/recommended"]
}
使用 groq 其他图书馆
默认情况下,这些 eslint 规则只检查使用 GROQ 函数导出到 groq npm 软件包. 如果您使用不同库中的 GROQ, 例如 @nuxtjs/sanity 或者说 next-sanity,您可以通过一组包名来配置规则 :
{
"plugins": ["@asbjorn/groq"],
"rules": {
"@asbjorn/groq/no-syntax-errors": [
"error",
{ "groqs": ["@nuxtjs/sanity"] }
],
"@asbjorn/groq/no-template-expressions": [
"error",
{ "groqs": ["@nuxtjs/sanity"] }
]
}
}
规则
无语法错误
报告 GROQ 查询中与导出函数标记的任何语法错误 groq。请注意,包含表达式的模板字元不会被擦去,因为解析表达式非常难以可靠地进行。 如果要特别安全,请结合 no-template-expressions 规则.
未结案
// Syntax error in tagged query
import groq from "groq";
groq`*[_type == { ]`;
// Syntax error (not imported as `groq`)
import hello from "groq";
hello`*[_type == { ]`;
通过案件
// 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} == {]`;
无模板表达式
报告 GROQ 查询中与导出函数标记的任何表达式 groq。这一规则之所以存在,是因为 no-syntax-errors 规则对包含表达式的任何查询进行保释(见该规则的说明).
未结案
// Template expression
import groq from "groq";
groq`*[_type == ${type}]`;
// Template expression (not imported as 'groq')
import hello from "groq";
hello`*[_type == ${type}]`;
通过案件
// 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}]`;