Skip to content

Instantly share code, notes, and snippets.

@rocky
Created November 23, 2018 13:08
Show Gist options
  • Save rocky/8dd07dd31c97ccdc2e4225bb36463543 to your computer and use it in GitHub Desktop.
Save rocky/8dd07dd31c97ccdc2e4225bb36463543 to your computer and use it in GitHub Desktop.
Maru AntlR and solc AST for SWC-100
const parser = require("solidity-parser-antlr");
import { IssuePointer } from "../maru/issue";
import { Plugin } from '../maru/plugin';
import SolFile from "../maru/sol_file";
import PluginConfig from "../maru/plugin_config";
let DefaultVisibilityFunction: Plugin;
DefaultVisibilityFunction = function (sol_file: SolFile, plugin_config: PluginConfig): IssuePointer[] {
const issuePointers: IssuePointer[] = [];
for (const f of sol_file.getContractFunctions()) {
if (f.visibility.match(/default/)) {
issuePointers.push(new IssuePointer(plugin_config.swcID, plugin_config.descriptionShort[0], f.location));
}
}
return issuePointers;
};
exports.DefaultVisibilityFunction = DefaultVisibilityFunction;
// Rules involving the solc FunctionDefinition AST node
"use strict";
import { Issue, Severity } from '../issue';
function defaultVisibilityFunctionViolation(node: any, issues: Issue[]): boolean {
if (node.attributes.visibility === "default") {
const mess = `Function ${node.attributes.name} visibility is not set and defaults to "public".`;
const issue = new Issue(node.src, "SWC-100", Severity.Warning, mess);
issues.push(issue);
return true;
}
return false;
}
// Register violation functions
exports.register = (): any[] => {
return [defaultVisibilityFunctionViolation];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment