How duaraghav8/ethlint works
Project type and purpose
• This is a Node.js–based CLI tool (linter) called Ethlint (formerly Solium). Its purpose is to parse, analyze, and optionally auto-fix Solidity smart‐contract code for style and security issues.
File structure
• Top‐level:
• bin/solium.js – CLI entrypoint
• lib/ – core implementation, organized into modules:
◦ cli-utils – helpers to parse CLI flags, read config ignore files
◦ solium.js – orchestrates the lint run
◦ rule-context.js, rules.js – manage rule execution context and rule definitions
◦ autofix/ – pipeline to collect and merge code fixes
◦ reporters/ – format output (pretty, gcc)
◦ utils/ – AST utilities, config inspection, file system, JS helpers, plugin loader
• config/ – JSON schemas & built-in rulesets (recommended, all)
• docs/ – documentation build files
• test/ – unit + integration tests covering every module/rule
• snap, .travis.yml – packaging & CI
Key insights from the README
• The tool reads a project’s .soliumrc.json (config + rules/plugins/extensions) and .soliumignore.
• It offers commands: init, lint, fix.
• It resolves a set of rules (style + security), applies them to an AST of the source files, and reports/fixes violations.
a. Main components
1. CLI Layer
• bin/solium.js
• Parses command‐line options (–init, –fix, –d, –f)
2. Configuration Manager
• lib/cli-utils (default ignore & rc handling)
• lib/utils/config-inspector.js
• config/schemas & rulesets
3. File System & Source Loader
• lib/utils/fs-utils.js
• Reads Solidity source files, applies ignore globs
4. Parser & AST Builder
• (Third‐party parser) invoked by lib/utils/ast-utils.js
5. Rule Engine
• lib/rules.js: loads built-in + plugin rules via rule-loader.js
• lib/rule-context.js: provides context & AST node traversal helpers
• Executes each rule on AST nodes
6. Autofix Pipeline (optional)
• lib/autofix/source-code-fixer.js
• merge-fixer-packets.js / rule-fixer.js
7. Reporters
• lib/reporters/pretty.js and gcc.js
• Format and output lint messages
8. Plugin System
• config/schemas/plugin.js
• lib/utils/plugin-loader (dynamic rule extensions)
b. Interactions & data flow
1. User invokes CLI → CLI Layer
2. CLI reads config & ignore → Configuration Manager
3. File paths feed into File System → Source Loader
4. Each file → Parser → AST
5. AST + active rules → Rule Engine → violation reports + fixer packets
6. If --fix → Autofix Pipeline applies changes back to files
7. Reporters format final output to console or files
c. Architectural patterns & principles
• Modular design: each concern separated (CLI, config, parsing, rules, autofix, reporting)
• Plugin architecture: dynamic rule loading via schemas and rule‐loader
• Pipeline pattern: linting and autofix organized as linear processing steps
• Schema validation: configs and rulesets validated via JSON schemas
d. Key technologies
• Node.js (CommonJS modules)
• ESLint-style plugin/rule conventions
• JSON schema for configurations
• External Solidity parser (e.g., solparse) invoked within ast-utils