mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 04:52:26 -05:00
comment out type decls, capture more fns
This commit is contained in:
parent
a1e590dc66
commit
3588e75c6c
4 changed files with 100 additions and 23 deletions
|
@ -7,6 +7,10 @@ const {
|
|||
op_lint_report,
|
||||
} = core.ops;
|
||||
|
||||
const state = {
|
||||
plugins: {},
|
||||
};
|
||||
|
||||
export class Context {
|
||||
id;
|
||||
|
||||
|
@ -18,6 +22,7 @@ export class Context {
|
|||
}
|
||||
|
||||
source() {
|
||||
// TODO(bartlomieju): cache it on the state - it won't change between files, but callers can mutate it.
|
||||
return op_lint_get_source();
|
||||
}
|
||||
|
||||
|
@ -46,6 +51,43 @@ export class Context {
|
|||
}
|
||||
}
|
||||
|
||||
export function installPlugins(plugins) {
|
||||
state.plugins = plugins;
|
||||
}
|
||||
|
||||
export function runPluginsForFile(fileName, serializedAst) {
|
||||
const ast = JSON.parse(serializedAst, (key, value) => {
|
||||
if (key === "ctxt") {
|
||||
return undefined;
|
||||
}
|
||||
return value;
|
||||
});
|
||||
|
||||
for (const plugin of state.plugins) {
|
||||
runRulesFromPlugin(plugin, fileName, ast);
|
||||
}
|
||||
}
|
||||
|
||||
function runRulesFromPlugin(plugin, fileName, ast) {
|
||||
for (const ruleName of Object.keys(plugin)) {
|
||||
const rule = plugin[ruleName];
|
||||
|
||||
if (typeof rule.create !== "function") {
|
||||
throw new Error("Rule's `create` property must be a function");
|
||||
}
|
||||
|
||||
// TODO(bartlomieju): can context be created less often, maybe once per plugin or even once per `runRulesForFile` invocation?
|
||||
const id = `${plugin.name}/${ruleName};`;
|
||||
const ctx = new Context(id, fileName);
|
||||
const visitor = rule.create(ctx);
|
||||
traverse(ast, visitor);
|
||||
|
||||
if (typeof rule.destroy === "function") {
|
||||
rule.destroy(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function runPluginRule(fileName, pluginName, ruleName, serializedAst) {
|
||||
const id = `${pluginName}/${ruleName}`;
|
||||
|
||||
|
|
|
@ -68,6 +68,8 @@ pub struct PluginRunnerProxy {
|
|||
pub struct PluginRunner {
|
||||
worker: MainWorker,
|
||||
run_plugin_rule_fn: v8::Global<v8::Function>,
|
||||
install_plugins_fn: v8::Global<v8::Function>,
|
||||
run_plugins_for_file_fn: v8::Global<v8::Function>,
|
||||
tx: Sender<PluginRunnerResponse>,
|
||||
rx: Receiver<PluginRunnerRequest>,
|
||||
}
|
||||
|
@ -127,19 +129,50 @@ impl PluginRunner {
|
|||
}
|
||||
};
|
||||
|
||||
let run_plugin_rule_fn = {
|
||||
let (install_plugins_fn, run_plugins_for_file_fn, run_plugin_rule_fn) = {
|
||||
let scope = &mut runtime.handle_scope();
|
||||
let fn_name = v8::String::new(scope, "runPluginRule").unwrap();
|
||||
let obj_local: v8::Local<v8::Object> =
|
||||
let module_exports: v8::Local<v8::Object> =
|
||||
v8::Local::new(scope, obj).try_into().unwrap();
|
||||
let run_fn_val = obj_local.get(scope, fn_name.into()).unwrap();
|
||||
let run_fn: v8::Local<v8::Function> = run_fn_val.try_into().unwrap();
|
||||
v8::Global::new(scope, run_fn)
|
||||
|
||||
// TODO(bartlomieju): use v8::OneByteConst and `v8_static_strings!` macro from `deno_core`.
|
||||
let run_plugin_rule_fn_name =
|
||||
v8::String::new(scope, "runPluginRule").unwrap();
|
||||
let run_plugin_rule_fn_val = module_exports
|
||||
.get(scope, run_plugin_rule_fn_name.into())
|
||||
.unwrap();
|
||||
let run_plugin_rule_fn: v8::Local<v8::Function> =
|
||||
run_plugin_rule_fn_val.try_into().unwrap();
|
||||
|
||||
// TODO(bartlomieju): use v8::OneByteConst and `v8_static_strings!` macro from `deno_core`.
|
||||
let install_plugins_fn_name =
|
||||
v8::String::new(scope, "installPlugins").unwrap();
|
||||
let install_plugins_fn_val = module_exports
|
||||
.get(scope, install_plugins_fn_name.into())
|
||||
.unwrap();
|
||||
let install_plugins_fn: v8::Local<v8::Function> =
|
||||
install_plugins_fn_val.try_into().unwrap();
|
||||
|
||||
// TODO(bartlomieju): use v8::OneByteConst and `v8_static_strings!` macro from `deno_core`.
|
||||
let run_plugins_for_file_fn_name =
|
||||
v8::String::new(scope, "runPluginRule").unwrap();
|
||||
let run_plugins_for_file_fn_val = module_exports
|
||||
.get(scope, run_plugins_for_file_fn_name.into())
|
||||
.unwrap();
|
||||
let run_plugins_for_file_fn: v8::Local<v8::Function> =
|
||||
run_plugins_for_file_fn_val.try_into().unwrap();
|
||||
|
||||
(
|
||||
v8::Global::new(scope, run_plugin_rule_fn),
|
||||
v8::Global::new(scope, install_plugins_fn),
|
||||
v8::Global::new(scope, run_plugins_for_file_fn),
|
||||
)
|
||||
};
|
||||
|
||||
let runner = Self {
|
||||
worker,
|
||||
run_plugin_rule_fn,
|
||||
install_plugins_fn,
|
||||
run_plugins_for_file_fn,
|
||||
tx: tx_res,
|
||||
rx: rx_req,
|
||||
};
|
||||
|
|
30
cli/tsc/dts/lib.deno.ns.d.ts
vendored
30
cli/tsc/dts/lib.deno.ns.d.ts
vendored
|
@ -6161,21 +6161,21 @@ declare namespace Deno {
|
|||
|
||||
export {}; // only export exports
|
||||
|
||||
export interface LintRuleContext {
|
||||
report(
|
||||
data: { span: { start: number; end: number }; message: string },
|
||||
): void;
|
||||
source(): string;
|
||||
}
|
||||
// export interface LintRuleContext {
|
||||
// report(
|
||||
// data: { span: { start: number; end: number }; message: string },
|
||||
// ): void;
|
||||
// source(): string;
|
||||
// }
|
||||
|
||||
export interface LintRule {
|
||||
// TODO(bartlomieju): proper return type
|
||||
create(context: LintRuleContext);
|
||||
destroy?(context: LintRuleContext): void;
|
||||
}
|
||||
// export interface LintRule {
|
||||
// // TODO(bartlomieju): proper return type
|
||||
// create(context: LintRuleContext);
|
||||
// destroy?(context: LintRuleContext): void;
|
||||
// }
|
||||
|
||||
export interface LintPlugin {
|
||||
name: string;
|
||||
rules: Record<string, LintRule>;
|
||||
}
|
||||
// export interface LintPlugin {
|
||||
// name: string;
|
||||
// rules: Record<string, LintRule>;
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -62,9 +62,11 @@ export default {
|
|||
[RULE1_NAME]: rule,
|
||||
"jsx-style-string": {
|
||||
create(context) {
|
||||
console.log("context", context);
|
||||
return {
|
||||
VariableDeclaration(node) {
|
||||
console.log("INTERFAcE", { ...node, parent: null });
|
||||
console.log("node", node);
|
||||
// console.log("INTERFAcE", { ...node, parent: null });
|
||||
},
|
||||
JSXAttribute(node) {
|
||||
if (
|
||||
|
@ -82,7 +84,7 @@ export default {
|
|||
},
|
||||
"jest/no-identical-title": {
|
||||
create(context) {
|
||||
console.log(context.source());
|
||||
// console.log(context.source());
|
||||
const seen = new Set();
|
||||
return {
|
||||
CallExpression(node) {
|
||||
|
|
Loading…
Add table
Reference in a new issue