






















UPDATE 2025/3/5: The Lint Rules Contest is over!
We received a bunch of great submissions (and some cheeky playful ones that made us smile)! Your lint plugins ranged from solving personal needs, to porting rules from ESLint, and more. Some notable ones to call out:
@armaanas/no-empty-function: A
simple rule that warns on any empty functions@sakgoyal/use-nullish: enforces the
use of Nullish Coalescing operator instead of ternary operators@0fficersally/fresh-island-naming-lint-plugin:
requires all Fresh island names to use the suffix “Island”@danteasc4/ban-enum: replaces any
TypeScript enums with type unions@aireone/deno-lint-curly: a
minimal re-implementation of ESLint rule,
curly@tyler/no-this-plugin: warns against
any usage of this@prosto/nullish: a set of lint rules to
enforce treating null and undefined values the same wayPlus, many more!
Thank you all again and we’ll be shipping the stickers out shortly!
In Deno 2.2, we’ve added the ability to
extend deno lint with a new plugin system.
While deno lint currently
has 123 built-in rules, the new plugin system
means that anyone can create new lint rules. (For comparison,
ESLint has 310 rules.)
To encourage more deno lint rules, we’re kicking off a contest to invite you
to write and publish new lint rules to JSR until Tuesday, March 4th, 6pm PT.
To reward you for your effort, every participant will receive a free, random
assortment of Deno stickers!
Read on to learn more about how to participate:
To show you how to write a new lint rule, we’ll create a plugin that reports an
error if you name a variable foo:
deno.json
{ "lint": { "plugins": ["./my-plugin.ts"] } }
my-plugin.ts
const plugin: Deno.lint.Plugin = { name: "my-lint-plugin", rules: { "my-lint-rule": { create(context) { return { VariableDeclarator(node) { if (node.id.type === "Identifier" && node.id.name === "foo") { context.report({ node, message: "Use more descriptive name than `foo`", }); } }, }; }, }, }, }; export default plugin;
main.js
const foo = "foo"; console.log(foo);
$ deno lint main.js error[my-lint-plugin/my-lint-rule]: Use more descriptive name than`foo` --> /dev/main.js:1:7 | 1 | const foo = "foo"; | ^^^^^^^^^^^ Found 1 problem Checked 1 file
In addition to a visitor based API, you can also use CSS-like selectors for targeting specific nodes. Let’s rewrite above rule, using the selector syntax.
my-plugin.ts
const plugin: Deno.lint.Plugin = { name: "my-lint-plugin", rules: { "my-lint-rule": { create(context) { return { 'VariableDeclarator[id.name="foo"]'(node) { context.report({ node, message: "Use more descriptive name than `foo`", }); }, }; }, }, }, }; export default plugin;
To see this in action, check out this one minute video demo:
For more information,
check out the deno lint plugin API in our Deno docs.
For starters, there are many popular rules from ESlint that have yet to be implemented in Deno:
{}
usage for all control blocks (if/else/for/etc.), even if optionalTo see more examples of lint rules, here is the ESLint GitHub repo.
For ideas and inspiration for lint rules that might not exist yet, check out this GitHub issue (Warning: this issue may be a bit stale, so tread with caution).
And just a reminder, if you do end up borrowing code from ESLint, please remember to give credit and provide the license!
Lint plugins can be authored in TypeScript, and Deno provides full type
declarations out-of-the-box under
the Deno.lint namespace.
To publish your plugin to JSR, update your deno.json so the exports points
to your plugin:
deno.json
{ "lint": { "plugins": ["./my-plugin.ts"] }, "name": "@lambtron/andys-lint-rule", "version": "0.3.0", "license": "MIT", "exports": "./my-plugin.ts" }
Then, run deno publish (or npx jsr publish), and it’ll appear on JSR.
For a full, end-to-end example, check out Andy’s Lint Rule.
Consuming lint plugins from JSR (or npm) is simple. You can use the specifier
directly in lint.plugins in your deno.json:
deno.json
{ "lint": { "plugins": [ "./my-plugin.ts", "jsr:@my-scope/lint-plugin", "npm:@my-scope/other-plugin" ] } }
Anyone who submits a deno lint rule to JSR will win free assortment of Deno
stickers!

In order to be eligible to receive your stickers, please fill out this form with key details of your lint rule and shipping information.
We will be accepting submissions until Tuesday, March 4th, 6pm PT.
If you want to participate but don’t have any ideas, come join our Discord, where we’ll discuss lint rule ideas, answer any questions, and get you setup writing your lint rules!
We look forward to seeing what lint rules you create!
Get technical support, share your project, or simply say hi on Twitter, Discord, BlueSky, and Mastodon.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。