mirror of
https://github.com/denoland/deno.git
synced 2025-03-11 22:59:41 -04:00

This PR adds a part of the `SourceCode` API in eslint (see https://eslint.org/docs/latest/extend/custom-rules#applying-fixes) . It's used to get the text of the current node, etc.
28 lines
727 B
TypeScript
28 lines
727 B
TypeScript
export default {
|
|
name: "test-plugin",
|
|
rules: {
|
|
"my-rule": {
|
|
create(context) {
|
|
return {
|
|
VariableDeclarator(node) {
|
|
console.log(`Source:`);
|
|
console.log(context.sourceCode.getText());
|
|
|
|
console.log(`Source VariableDeclarator:`);
|
|
console.log(context.sourceCode.getText(node));
|
|
console.log();
|
|
|
|
console.log(`Ancestors:`);
|
|
console.log(
|
|
context.sourceCode.getAncestors(node).map((node) => node.type),
|
|
);
|
|
console.log();
|
|
|
|
console.log(`Ast:`);
|
|
console.log(context.sourceCode.ast.type);
|
|
},
|
|
};
|
|
},
|
|
},
|
|
},
|
|
} satisfies Deno.lint.Plugin;
|