mirror of
https://github.com/denoland/deno.git
synced 2025-02-01 12:16:11 -05:00
WIP
This commit is contained in:
parent
19baadf319
commit
280d10e801
20 changed files with 2218 additions and 1284 deletions
1060
cli/js/40_lint.js
1060
cli/js/40_lint.js
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -74,9 +74,9 @@ impl PluginRunner {
|
||||||
let (tx_req, rx_req) = channel(10);
|
let (tx_req, rx_req) = channel(10);
|
||||||
let (tx_res, rx_res) = channel(10);
|
let (tx_res, rx_res) = channel(10);
|
||||||
|
|
||||||
log::info!("spawning thread");
|
log::debug!("spawning thread");
|
||||||
let join_handle = std::thread::spawn(move || {
|
let join_handle = std::thread::spawn(move || {
|
||||||
log::info!("PluginRunner thread spawned");
|
log::debug!("PluginRunner thread spawned");
|
||||||
let start = std::time::Instant::now();
|
let start = std::time::Instant::now();
|
||||||
let fut = async move {
|
let fut = async move {
|
||||||
let mut flags = Flags::default();
|
let mut flags = Flags::default();
|
||||||
|
@ -110,7 +110,7 @@ impl PluginRunner {
|
||||||
let mut worker = worker.into_main_worker();
|
let mut worker = worker.into_main_worker();
|
||||||
let runtime = &mut worker.js_runtime;
|
let runtime = &mut worker.js_runtime;
|
||||||
|
|
||||||
log::info!("before loaded");
|
log::debug!("before loaded");
|
||||||
|
|
||||||
let obj_result = runtime.lazy_load_es_module_with_code(
|
let obj_result = runtime.lazy_load_es_module_with_code(
|
||||||
"ext:cli/lint.js",
|
"ext:cli/lint.js",
|
||||||
|
@ -125,7 +125,7 @@ impl PluginRunner {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
log::info!("After plugin loaded, capturing exports");
|
log::debug!("After plugin loaded, capturing exports");
|
||||||
let (install_plugin_fn, run_plugins_for_file_fn) = {
|
let (install_plugin_fn, run_plugins_for_file_fn) = {
|
||||||
let scope = &mut runtime.handle_scope();
|
let scope = &mut runtime.handle_scope();
|
||||||
let module_exports: v8::Local<v8::Object> =
|
let module_exports: v8::Local<v8::Object> =
|
||||||
|
@ -163,9 +163,9 @@ impl PluginRunner {
|
||||||
rx: rx_req,
|
rx: rx_req,
|
||||||
};
|
};
|
||||||
// TODO(bartlomieju): send "host ready" message to the proxy
|
// TODO(bartlomieju): send "host ready" message to the proxy
|
||||||
log::info!("running host loop");
|
log::debug!("running host loop");
|
||||||
runner.run_loop().await?;
|
runner.run_loop().await?;
|
||||||
log::info!(
|
log::debug!(
|
||||||
"PluginRunner thread finished, took {:?}",
|
"PluginRunner thread finished, took {:?}",
|
||||||
std::time::Instant::now() - start
|
std::time::Instant::now() - start
|
||||||
);
|
);
|
||||||
|
@ -175,7 +175,7 @@ impl PluginRunner {
|
||||||
tokio_util::create_and_run_current_thread(fut)
|
tokio_util::create_and_run_current_thread(fut)
|
||||||
});
|
});
|
||||||
|
|
||||||
log::info!("is thread finished {}", join_handle.is_finished());
|
log::debug!("is thread finished {}", join_handle.is_finished());
|
||||||
let proxy = PluginRunnerProxy {
|
let proxy = PluginRunnerProxy {
|
||||||
tx: tx_req,
|
tx: tx_req,
|
||||||
rx: Arc::new(tokio::sync::Mutex::new(rx_res)),
|
rx: Arc::new(tokio::sync::Mutex::new(rx_res)),
|
||||||
|
@ -335,7 +335,7 @@ impl PluginRunnerProxy {
|
||||||
.send(PluginRunnerRequest::LoadPlugins(plugin_specifiers))
|
.send(PluginRunnerRequest::LoadPlugins(plugin_specifiers))
|
||||||
.await?;
|
.await?;
|
||||||
let mut rx = self.rx.lock().await;
|
let mut rx = self.rx.lock().await;
|
||||||
log::info!("receiving load plugins");
|
log::debug!("receiving load plugins");
|
||||||
if let Some(val) = rx.recv().await {
|
if let Some(val) = rx.recv().await {
|
||||||
let PluginRunnerResponse::LoadPlugin(result) = val else {
|
let PluginRunnerResponse::LoadPlugin(result) = val else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
|
|
9
cli/tsc/dts/lib.deno.ns.d.ts
vendored
9
cli/tsc/dts/lib.deno.ns.d.ts
vendored
|
@ -6394,6 +6394,11 @@ declare namespace Deno {
|
||||||
expressions: Expression[];
|
expressions: Expression[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ParenthesisExpression extends BaseNode {
|
||||||
|
type: "ParenthesisExpression";
|
||||||
|
expression: Expression;
|
||||||
|
}
|
||||||
|
|
||||||
export interface Super extends BaseNode {
|
export interface Super extends BaseNode {
|
||||||
type: "Super";
|
type: "Super";
|
||||||
}
|
}
|
||||||
|
@ -6472,6 +6477,7 @@ declare namespace Deno {
|
||||||
| MetaProperty
|
| MetaProperty
|
||||||
| NewExpression
|
| NewExpression
|
||||||
| ObjectExpression
|
| ObjectExpression
|
||||||
|
| ParenthesisExpression
|
||||||
| StaticBlock
|
| StaticBlock
|
||||||
| SequenceExpression
|
| SequenceExpression
|
||||||
| Super
|
| Super
|
||||||
|
@ -7026,7 +7032,8 @@ declare namespace Deno {
|
||||||
TemplateLiteral?(node: TemplateLiteral): void;
|
TemplateLiteral?(node: TemplateLiteral): void;
|
||||||
|
|
||||||
// Literals
|
// Literals
|
||||||
BooleanLiteral?(node: BooleanLiteral): void;
|
BooleanLiteral?(node: BigIntLiteral): void;
|
||||||
|
BigIntLiteral?(node: BooleanLiteral): void;
|
||||||
NullLiteral?(node: NullLiteral): void;
|
NullLiteral?(node: NullLiteral): void;
|
||||||
NumericLiteral?(node: NumericLiteral): void;
|
NumericLiteral?(node: NumericLiteral): void;
|
||||||
RegExpLiteral?(node: RegExpLiteral): void;
|
RegExpLiteral?(node: RegExpLiteral): void;
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
{
|
|
||||||
"lint": {
|
|
||||||
"plugins": [
|
|
||||||
"./plugin.ts"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
0
lint.md
Normal file
0
lint.md
Normal file
24
tests/specs/lint/plugins_ast/__test__.jsonc
Normal file
24
tests/specs/lint/plugins_ast/__test__.jsonc
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
{
|
||||||
|
"tests": {
|
||||||
|
"program": {
|
||||||
|
"cwd": "./program",
|
||||||
|
"args": "lint --plugins=./plugin.ts source.ts",
|
||||||
|
"output": "program/log.out"
|
||||||
|
},
|
||||||
|
"statements": {
|
||||||
|
"cwd": "./statements",
|
||||||
|
"args": "lint --config=./statements/deno.json source.ts",
|
||||||
|
"output": "statement/log.out"
|
||||||
|
},
|
||||||
|
"expressions": {
|
||||||
|
"cwd": "./expressions",
|
||||||
|
"args": "lint --plugins=./plugin.ts source.ts",
|
||||||
|
"output": "expressions/log.out"
|
||||||
|
},
|
||||||
|
"literals": {
|
||||||
|
"cwd": "./literals",
|
||||||
|
"args": "lint --plugins=./plugin.ts source.ts",
|
||||||
|
"output": "literals/log.out"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
tests/specs/lint/plugins_ast/expressions/log.out
Normal file
27
tests/specs/lint/plugins_ast/expressions/log.out
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
CallExpression {
|
||||||
|
type: "CallExpression",
|
||||||
|
range: [ 9, 14 ],
|
||||||
|
optional: false
|
||||||
|
}
|
||||||
|
CallExpression {
|
||||||
|
type: "CallExpression",
|
||||||
|
range: [ 16, 25 ],
|
||||||
|
optional: false
|
||||||
|
}
|
||||||
|
CallExpression {
|
||||||
|
type: "CallExpression",
|
||||||
|
range: [ 27, 41 ],
|
||||||
|
optional: false
|
||||||
|
}
|
||||||
|
MemberExpression {
|
||||||
|
type: "MemberExpression",
|
||||||
|
range: [ 83, 86 ],
|
||||||
|
optional: false,
|
||||||
|
computed: false
|
||||||
|
}
|
||||||
|
MemberExpression {
|
||||||
|
type: "MemberExpression",
|
||||||
|
range: [ 88, 94 ],
|
||||||
|
optional: false,
|
||||||
|
computed: true
|
||||||
|
}
|
17
tests/specs/lint/plugins_ast/expressions/plugin.ts
Normal file
17
tests/specs/lint/plugins_ast/expressions/plugin.ts
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
export default {
|
||||||
|
name: "ast_plugin",
|
||||||
|
rules: {
|
||||||
|
ast: {
|
||||||
|
create() {
|
||||||
|
return {
|
||||||
|
CallExpression(node) {
|
||||||
|
console.log(node);
|
||||||
|
},
|
||||||
|
MemberExpression(node) {
|
||||||
|
console.log(node);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} satisfies Deno.LintPlugin;
|
9
tests/specs/lint/plugins_ast/expressions/source.ts
Normal file
9
tests/specs/lint/plugins_ast/expressions/source.ts
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
// Call
|
||||||
|
foo();
|
||||||
|
foo(1, 2);
|
||||||
|
foo(1, ...bar);
|
||||||
|
// FIXME foo?.(1);
|
||||||
|
|
||||||
|
// MemberExpression
|
||||||
|
a.b;
|
||||||
|
a["b"];
|
44
tests/specs/lint/plugins_ast/literals/log.out
Normal file
44
tests/specs/lint/plugins_ast/literals/log.out
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
StringLiteral {
|
||||||
|
type: "StringLiteral",
|
||||||
|
range: [ 1, 8 ],
|
||||||
|
value: "foo\n"
|
||||||
|
}
|
||||||
|
StringLiteral {
|
||||||
|
type: "StringLiteral",
|
||||||
|
range: [ 10, 16 ],
|
||||||
|
value: 'bar"'
|
||||||
|
}
|
||||||
|
NumericLiteral { type: "NumericLiteral", range: [ 18, 19 ], value: 2 }
|
||||||
|
NumericLiteral {
|
||||||
|
type: "NumericLiteral",
|
||||||
|
range: [ 21, 24 ],
|
||||||
|
value: 2.3
|
||||||
|
}
|
||||||
|
NumericLiteral { type: "NumericLiteral", range: [ 26, 31 ], value: 0 }
|
||||||
|
BooleanLiteral {
|
||||||
|
type: "BooleanLiteral",
|
||||||
|
range: [ 33, 37 ],
|
||||||
|
value: true
|
||||||
|
}
|
||||||
|
BooleanLiteral {
|
||||||
|
type: "BooleanLiteral",
|
||||||
|
range: [ 39, 44 ],
|
||||||
|
value: false
|
||||||
|
}
|
||||||
|
NullLiteral { type: "NullLiteral", range: [ 46, 50 ], value: null }
|
||||||
|
RegExpLiteral {
|
||||||
|
type: "RegExpLiteral",
|
||||||
|
range: [ 52, 56 ],
|
||||||
|
pattern: "a",
|
||||||
|
flags: "g"
|
||||||
|
}
|
||||||
|
RegExpLiteral {
|
||||||
|
type: "RegExpLiteral",
|
||||||
|
range: [ 58, 65 ],
|
||||||
|
pattern: "[/g]",
|
||||||
|
flags: "m"
|
||||||
|
}
|
||||||
|
BigIntLiteral { type: "BigIntLiteral", range: [ 67, 69 ], value: 1n }
|
||||||
|
ArrayExpression { type: "ArrayExpression", range: [ 82, 91 ] }
|
||||||
|
ArrayExpression { type: "ArrayExpression", range: [ 93, 104 ] }
|
||||||
|
ArrayExpression { type: "ArrayExpression", range: [ 106, 114 ] }
|
35
tests/specs/lint/plugins_ast/literals/plugin.ts
Normal file
35
tests/specs/lint/plugins_ast/literals/plugin.ts
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
export default {
|
||||||
|
name: "ast_plugin",
|
||||||
|
rules: {
|
||||||
|
ast: {
|
||||||
|
create() {
|
||||||
|
return {
|
||||||
|
ArrayExpression(node) {
|
||||||
|
console.log(node);
|
||||||
|
},
|
||||||
|
BooleanLiteral(node) {
|
||||||
|
console.log(node);
|
||||||
|
},
|
||||||
|
BigIntLiteral(node) {
|
||||||
|
console.log(node);
|
||||||
|
},
|
||||||
|
NullLiteral(node) {
|
||||||
|
console.log(node);
|
||||||
|
},
|
||||||
|
NumericLiteral(node) {
|
||||||
|
console.log(node);
|
||||||
|
},
|
||||||
|
ObjectExpression(node) {
|
||||||
|
console.log(node);
|
||||||
|
},
|
||||||
|
RegExpLiteral(node) {
|
||||||
|
console.log(node);
|
||||||
|
},
|
||||||
|
StringLiteral(node) {
|
||||||
|
console.log(node);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} satisfies Deno.LintPlugin;
|
30
tests/specs/lint/plugins_ast/literals/source.ts
Normal file
30
tests/specs/lint/plugins_ast/literals/source.ts
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
"foo\n";
|
||||||
|
'bar"';
|
||||||
|
2;
|
||||||
|
2.3;
|
||||||
|
0b000;
|
||||||
|
true;
|
||||||
|
false;
|
||||||
|
null;
|
||||||
|
/a/g;
|
||||||
|
/[/g]/m;
|
||||||
|
1n;
|
||||||
|
|
||||||
|
// arrays
|
||||||
|
[1, 2, 3];
|
||||||
|
[1, ...foo];
|
||||||
|
[1, , 3];
|
||||||
|
|
||||||
|
// objects
|
||||||
|
a = {};
|
||||||
|
a = { foo };
|
||||||
|
a = { foo: 1 };
|
||||||
|
a = { ["foo\n"]: 1, 1: 2, "baz": 3 };
|
||||||
|
a = {
|
||||||
|
get foo() {
|
||||||
|
return 1;
|
||||||
|
},
|
||||||
|
set foo(a) {
|
||||||
|
2;
|
||||||
|
},
|
||||||
|
};
|
1
tests/specs/lint/plugins_ast/program/log.out
Normal file
1
tests/specs/lint/plugins_ast/program/log.out
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Program { type: "Program", range: [ 1, 1 ], sourceType: "script" }
|
14
tests/specs/lint/plugins_ast/program/plugin.ts
Normal file
14
tests/specs/lint/plugins_ast/program/plugin.ts
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
export default {
|
||||||
|
name: "ast_plugin",
|
||||||
|
rules: {
|
||||||
|
ast: {
|
||||||
|
create() {
|
||||||
|
return {
|
||||||
|
Program(node) {
|
||||||
|
console.log(node);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} satisfies Deno.LintPlugin;
|
0
tests/specs/lint/plugins_ast/program/source.ts
Normal file
0
tests/specs/lint/plugins_ast/program/source.ts
Normal file
8
tests/specs/lint/plugins_ast/statements/deno.json
Normal file
8
tests/specs/lint/plugins_ast/statements/deno.json
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"lint": {
|
||||||
|
"plugins": ["./plugin.ts"],
|
||||||
|
"rules": {
|
||||||
|
"exclude": ["no-debugger"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
2
tests/specs/lint/plugins_ast/statements/log.out
Normal file
2
tests/specs/lint/plugins_ast/statements/log.out
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
BreakStatement { type: "BreakStatement", range: [ 19, 25 ] }
|
||||||
|
BreakStatement { type: "BreakStatement", range: [ 54, 66 ] }
|
20
tests/specs/lint/plugins_ast/statements/plugin.ts
Normal file
20
tests/specs/lint/plugins_ast/statements/plugin.ts
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
export default {
|
||||||
|
name: "ast_plugin",
|
||||||
|
rules: {
|
||||||
|
ast: {
|
||||||
|
create() {
|
||||||
|
return {
|
||||||
|
BreakStatement(node) {
|
||||||
|
console.log(node);
|
||||||
|
},
|
||||||
|
ContinueStatement(node) {
|
||||||
|
console.log(node);
|
||||||
|
},
|
||||||
|
ReturnStatement(node) {
|
||||||
|
console.log(node);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} satisfies Deno.LintPlugin;
|
28
tests/specs/lint/plugins_ast/statements/source.ts
Normal file
28
tests/specs/lint/plugins_ast/statements/source.ts
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
// Break
|
||||||
|
while (false) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
outer: while (false) {
|
||||||
|
break outer;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Continue
|
||||||
|
while (false) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
outer: while (false) {
|
||||||
|
continue outer;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debugger
|
||||||
|
debugger;
|
||||||
|
|
||||||
|
// Return
|
||||||
|
(() => {
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
(() => {
|
||||||
|
return 1;
|
||||||
|
});
|
Loading…
Add table
Reference in a new issue