
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@asbjorn/eslint-plugin-groq
Advanced tools
Unofficial eslint
plugin for GROQ queries.
npm install @asbjorn/eslint-plugin-groq
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]`;
{
"plugins": ["@asbjorn/groq"],
"rules": {
"@asbjorn/groq/no-syntax-errors": "error",
"@asbjorn/groq/no-template-expressions": "error"
}
}
Or:
{
"extends": ["plugin:@asbjorn/groq/recommended"]
}
groq
from other librariesBy 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"] }
]
}
}
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.
// 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} == {]`;
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).
// 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}]`;
2.0.0
groq-js@0.2.0
groq
from peerDependenciesgroqs
option to no-syntax-errors
and no-template-expressions
rules to support a growing number of groq
proxies@nuxtjs/sanity
. Users of @nuxtjs/sanity
must now configure this per rule instead:{
"@asbjorn/groq/no-syntax-errors": ["error", { "groqs": ["@nuxtjs/sanity"] }],
"@asbjorn/groq/no-template-expressions": [
"error",
{ "groqs": ["@nuxtjs/sanity"] }
]
}
FAQs
Eslint plugin for GROQ queries
We found that @asbjorn/eslint-plugin-groq demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.