Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix no override and no default toolchain set when lint rust #1385

Merged
merged 1 commit into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion megalinter/descriptors/rust.megalinter-descriptor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions megalinter/linters/ClippyLinter.py
Original file line number Diff line number Diff line change
@@ -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
})