diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f064ebbf01..ea5b0eb7254 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Note: Can be used with `megalinter/megalinter@beta` in your GitHub Action mega-l - Allow to provide CI_ACTION_RUN_URL to build hlink for GitHub Comments reporter messages ([[#1341](https://github.com/megalinter/megalinter/issues/1341)) - Display plugin URL in MegaLinter output logs ([[#1340](https://github.com/megalinter/megalinter/issues/1340)) - Fix public glibc public key download + - Fix `no override and no default toolchain set` when lint rust with clippy via github-action ([#975](https://github.com/megalinter/megalinter/issues/975)) - Doc - Add instructions to upload artifacts when using MegaLinter with Jenkins diff --git a/megalinter/descriptors/rust.megalinter-descriptor.yml b/megalinter/descriptors/rust.megalinter-descriptor.yml index 3ed1143598b..c74e7dea4d2 100644 --- a/megalinter/descriptors/rust.megalinter-descriptor.yml +++ b/megalinter/descriptors/rust.megalinter-descriptor.yml @@ -10,7 +10,8 @@ install: - ENV PATH="/root/.cargo/bin:${PATH}" linters: # CLIPPY - - linter_name: clippy + - class: ClippyLinter + linter_name: clippy linter_url: https://github.com/rust-lang/rust-clippy linter_rules_url: https://rust-lang.github.io/rust-clippy/stable/index.html linter_rules_configuration_url: https://github.com/rust-lang/rust-clippy#configuration diff --git a/megalinter/linters/ClippyLinter.py b/megalinter/linters/ClippyLinter.py new file mode 100644 index 00000000000..37bf44755a0 --- /dev/null +++ b/megalinter/linters/ClippyLinter.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +""" +Use Clippy to lint rust files +""" +import logging +import os + +import megalinter + + +class ClippyLinter(megalinter.Linter): + + # To execute before linting files + def before_lint_files(self): + # Build pre-command + if not os.path.isfile(os.path.expandvars("${HOME}/.rustup/settings.toml")): + rustup_init_command = "rustup default stable" + if self.pre_commands is None: + self.pre_commands = [] + # Add to pre-commands + logging.debug("clippy before_lint_files: " + rustup_init_command) + self.pre_commands.append({ + "command": rustup_init_command, + "cwd": self.workspace + })