Replies: 7 comments 10 replies
-
Should this go directly into oxc_linter or a new crate? |
Beta Was this translation helpful? Give feedback.
-
Do we want to support multifile queries in a single query? subquestion: do we want to support also querying the package.json? |
Beta Was this translation helpful? Give feedback.
-
Idea: Oxc as a background service, where trustfall queries into it. Or some kind of reverse dependency infrastructure - This plugin system dependents on Oxc. |
Beta Was this translation helpful? Give feedback.
-
Those pictures don't really do it justice. Here are some queries with descriptions. Feel free to ask any questions. BAD_ASSIGN_IN_CONDITION from deepscanquery {
File {
ast_node {
... on IfStatementOrTernary {
test {
# unwraps parens, because there will always be parens around a ternary with an assignment otherwise
# it's a constant condition
# NOTE: If we want to allow paren'd if statements, we'd have to split this into two queries,
# one for IfStatement and one for Ternary
inner_expr {
... on AssignmentExpression {
span {
span_start: start @output
span_end: end @output
}
}
}
}
}
}
}
}
} BAD_BITWISE_OPERATOR from deepscanquery {
File {
# x & x.???
ast_node {
... on BinaryExpression {
left {
... on Identifier {
name @tag
}
}
operator {
is_bitwise @filter(op: "=", value: ["$true"])
}
right {
... on FieldAccessOnObject {
final_assignment {
... on Identifier {
name @filter(op: "=", value: ["%name"])
}
}
}
}
span {
span_start: start @output
span_end: end @output
}
}
}
}
} query {
File {
# x |= ??? will be flagged when
# the ??? isn't a NumberLiteral ie... 1, 2, 19
# the ??? isn't 1 << 19 or 1 >> 19 or any bitwise operation where both sides are numbers
ast_node {
... on AssignmentExpression {
operator {
is_bitwise @filter(op: "=", value: ["$true"])
}
# this basically says don't allow any expressions where the right is something like `19`, or any number
right @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
... on NumberLiteral {
# needed here because we can't have a no field used coercion,
# but we don't actually need span->start
span {
start
}
}
}
# this says don't allow any expressions where the right is something like `1 << 12`, `1 | 12`, or any bitwise expression
right @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
... on BinaryExpression {
operator {
is_bitwise @filter(op: "=", value: ["$true"])
}
both_sides @fold @transform(op: "count") @filter(op: "=", value: ["$two"]) {
... on NumberLiteral {
# needed here because we can't have a no field used coercion,
# but we don't actually need span->start
span {
start
}
}
}
}
}
span {
span_start: start @output
span_end: end @output
}
}
}
}
} no_async_promise_execs from eslintquery {
File {
ast_node {
... on NewExpression {
callee {
... on Identifier {
name @filter(op: "=", value: ["$Promise"])
}
}
arguments {
... on ExpressionArgument {
inner_expr {
... on Function {
is_async @filter(op: "=", value: ["$true"])
span {
span_start: start @output
span_end: end @output
}
}
}
}
}
}
}
}
} |
Beta Was this translation helpful? Give feedback.
-
@u9g How much performance overhead are we adding here? |
Beta Was this translation helpful? Give feedback.
-
@u9g Can you do a quick survey and see if these typical eslint plugins can be ported to Trustfall. If so, how much effort for writing these plugins, and how much effort for supporting all the features? |
Beta Was this translation helpful? Give feedback.
-
Case for no-restricted-syntax https://github.com/vuejs/core/blob/9f8e98af891f456cc8cc9019a31704e5534d1f08/.eslintrc.cjs#L21-L30 |
Beta Was this translation helpful? Give feedback.
-
Note
Update: We decided to stop exploring this approach and is going to try with AST transfer instead.
From @u9g based on https://github.com/obi1kenobi/trustfall. The query is a subset of GraphQL.
Examples:
BAD_ASSIGN_IN_CONDITION from deepscan
BAD_BITWISE_OPERATOR from deepscan
no_async_promise_execs from eslint
code-declare-service-brand
code-no-look-behind-regex
args:
vscode-dts-literal-or-types
code-no-test-only
args:
vscode-dts-cancellation
args:
vscode-dts-string-type-literals
vscode-dts-use-thenable
vscode-dts-create-func
args:
vscode-dts-provider-naming
args:
vscode-dts-interface-naming
To note:
Beta Was this translation helpful? Give feedback.
All reactions