UNPKG

@slippy-lint/slippy

Version:

A simple but powerful linter for Solidity

46 lines 1.45 kB
import { Query } from "@nomicfoundation/slang/cst"; import { ignoreLeadingTrivia } from "../slang/trivia.js"; const queries = [ ` [YulFunctionCallExpression operand: [YulExpression [YulPath ["eq"]]] arguments: [YulArguments [YulExpression] [Comma] [YulExpression [YulLiteral ["0"]]]] ] `, ` [YulFunctionCallExpression operand: [YulExpression [YulPath ["eq"]]] arguments: [YulArguments [YulExpression [YulLiteral ["0"]]] [Comma] [YulExpression]] ] `, ].map((query) => Query.create(query)); export const YulPreferIszero = { name: "yul-prefer-iszero", recommended: true, create: function () { return new YulPreferIszeroRule(this.name); }, }; class YulPreferIszeroRule { constructor(name) { this.name = name; } run({ file }) { const diagnostics = []; const cursor = file.createTreeCursor(); const matches = cursor.query(queries); for (const match of matches) { const matchCursor = match.root.spawn(); ignoreLeadingTrivia(matchCursor); diagnostics.push({ sourceId: file.id, rule: this.name, message: "Found 'eq' comparison to 0, use 'iszero' instead", line: matchCursor.textRange.start.line, column: matchCursor.textRange.start.column, }); } return diagnostics; } } //# sourceMappingURL=yul-prefer-iszero.js.map