UNPKG

@slippy-lint/slippy

Version:

A simple but powerful linter for Solidity

50 lines 1.45 kB
import { ignoreLeadingTrivia } from "../slang/trivia.js"; import { Query } from "@nomicfoundation/slang/cst"; const TRANSFER_QUERY = Query.create(` [FunctionCallExpression operand: [Expression [MemberAccessExpression member: ["transfer"] ] ] ]`); const SEND_QUERY = Query.create(` [FunctionCallExpression operand: [Expression [MemberAccessExpression member: ["send"] ] ] ]`); export const NoSend = { name: "no-send", recommended: true, create: function () { return new NoSendRule(this.name); }, }; class NoSendRule { constructor(name) { this.name = name; } run({ file }) { const results = []; const cursor = file.createTreeCursor(); const matches = cursor.query([TRANSFER_QUERY, SEND_QUERY]); for (const match of matches) { const textRangeCursor = match.root.spawn(); ignoreLeadingTrivia(textRangeCursor); const textRange = textRangeCursor.textRange; const method = match.queryIndex === 0 ? "transfer" : "send"; results.push({ rule: this.name, sourceId: file.id, line: textRange.start.line, column: textRange.start.column, message: `Avoid using '.${method}(amount)'. Use '.call{value: amount}("")' instead.`, }); } return results; } } //# sourceMappingURL=no-send.js.map