hardis:project:lint
Description
Command Behavior
Applies syntactic analysis (linting) to your repository sources using Mega-Linter, ensuring code quality and adherence to coding standards.
This command integrates Mega-Linter, a comprehensive linter orchestrator, into your Salesforce DX project. It helps identify and fix code style violations, potential bugs, and other issues across various file types relevant to Salesforce development.
Key functionalities:
- Automated Linting: Runs a suite of linters configured for Salesforce projects.
- Fixing Issues (
--fixflag): Automatically attempts to fix detected linting issues, saving manual effort. - Configuration Management: If
.mega-linter.ymlis not found, it guides you through the initial setup of Mega-Linter, prompting for the Salesforce flavor. - CI/CD Integration: Designed to be used in CI/CD pipelines to enforce code quality gates.
Technical explanations
The command's technical implementation involves:
- Mega-Linter Integration: It runs Mega-Linter by spawning
npx mega-linter-runner, so the runner is only downloaded when the command is used. - Configuration Check: Before running, it checks for the presence of
.mega-linter.yml. If not found and not in a CI environment, it initiates an interactive setup process usingnpx mega-linter-runner --install. - Linter Execution: It calls
npx mega-linter-runnerwith thesalesforceflavor and the--fixflag (if provided). - Exit Code Handling: The
process.exitCodeis set based on the Mega-Linter's exit status, allowing CI/CD pipelines to react to linting failures. - User Feedback: Provides clear messages about the success or failure of the linting process.
Agent Mode
Supports non-interactive execution with --agent:
sf hardis:project:lint --agent
In agent mode, all interactive prompts are skipped and default values are used.
Parameters
| Name | Type | Description | Default | Required | Options |
|---|---|---|---|---|---|
| agent | boolean | Run in non-interactive mode for agents and automation | |||
| debug -d |
boolean | Activate debug mode (more logs) | |||
| fix -f |
boolean | Apply linters fixes | |||
| flags-dir | option | undefined | |||
| json | boolean | Format output as json. | |||
| skipauth | boolean | Skip authentication check when a default username is required | |||
| target-org -o |
option | undefined | |||
| websocket | option | Websocket host:port for VsCode SFDX Hardis UI integration |
Examples
$ sf hardis:project:lint
$ sf hardis:project:lint --agent
$ sf hardis:project:lint --fix