2025-01-01 04:12:39 +09:00
|
|
|
// Copyright 2018-2025 the Deno authors. MIT license.
|
2024-01-31 22:39:56 +01:00
|
|
|
|
feat(lint): add JavaScript plugin support (#27203)
This commit adds an unstable lint plugin API.
Plugins are specified in the `deno.json` file under
`lint.plugins` option like so:
```
{
"lint": {
"plugins": [
"./plugins/my-plugin.ts",
"jsr:@deno/lint-plugin1",
"npm:@deno/lint-plugin2"
]
}
}
```
The API is considered unstable and might be subject
to changes in the future.
Plugin API was modelled after ESLint API for the
most part, but there are no guarantees for compatibility.
The AST format exposed to plugins is closely modelled
after the AST that `typescript-eslint` uses.
Lint plugins use the visitor pattern and can add
diagnostics like so:
```
export default {
name: "lint-plugin",
rules: {
"plugin-rule": {
create(context) {
return {
Identifier(node) {
if (node.name === "a") {
context.report({
node,
message: "should be b",
fix(fixer) {
return fixer.replaceText(node, "_b");
},
});
}
},
};
},
},
},
} satisfies Deno.lint.Plugin;
```
Besides reporting errors (diagnostics) plugins can provide
automatic fixes that use text replacement to apply changes.
---------
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
Co-authored-by: David Sherret <dsherret@gmail.com>
2025-02-05 16:59:24 +01:00
|
|
|
const EXPECTED_OP_COUNT = 14;
|
2024-01-31 22:39:56 +01:00
|
|
|
|
|
|
|
Deno.test(function checkExposedOps() {
|
|
|
|
// @ts-ignore TS doesn't allow to index with symbol
|
|
|
|
const core = Deno[Deno.internal].core;
|
|
|
|
const opNames = Object.keys(core.ops);
|
|
|
|
|
|
|
|
if (opNames.length !== EXPECTED_OP_COUNT) {
|
|
|
|
throw new Error(
|
|
|
|
`Expected ${EXPECTED_OP_COUNT} ops, but got ${opNames.length}:\n${
|
|
|
|
opNames.join("\n")
|
|
|
|
}`,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|