-
Notifications
You must be signed in to change notification settings - Fork 581
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
Rust Clippy #1467
base: master
Are you sure you want to change the base?
Rust Clippy #1467
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ environment: | |
# /E:ON and /V:ON options are not enabled in the batch script intepreter | ||
# See: http://stackoverflow.com/a/13751649/163740 | ||
CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\.ci\\run_with_env.cmd" | ||
RUST_TOOLCHAIN: "nightly-2017-07-20-x86_64-pc-windows-msvc" | ||
|
||
matrix: | ||
- PYTHON: "C:\\Python34" | ||
|
@@ -20,6 +21,13 @@ cache: | |
- "C:\\Users\\appveyor\\AppData\\Local\\coala-bears\\coala-bears" | ||
- "C:\\Users\\appveyor\\AppData\\Roaming\\nltk_data" | ||
|
||
# Workaround Appveyor bug: | ||
# http://help.appveyor.com/discussions/problems/7115-curl-cant-download-files-through-ssl | ||
init: | ||
- ps: > | ||
Disable-NetFirewallRule | ||
-DisplayName 'Core Networking - Group Policy (LSASS-Out)' | ||
|
||
branches: | ||
except: | ||
- /^sils\/.*/ | ||
|
@@ -49,6 +57,26 @@ install: | |
- "npm config set loglevel warn" | ||
- "npm install" | ||
|
||
- "curl -sSf -o rustup-init.exe https://win.rustup.rs/" | ||
- "rustup-init.exe -y --default-toolchain=%RUST_TOOLCHAIN%" | ||
# Normally, we shouldn't need the toolchain lib directory in our PATH | ||
# https://github.com/rust-lang-nursery/rustup.rs/issues/876 | ||
# This is actually the sole reason that we really | ||
# need the RUST_TOOLCHAIN variable. | ||
- "set PATH=%PATH%;C:\\Users\\appveyor\\.cargo\\bin" | ||
# Start ignoring YAMLLintBear | ||
# because of the line length; plitting up these paths would become unreadable | ||
- "set PATH=%PATH%;C:\\Users\\appveyor\\.rustup\\toolchains\\%RUST_TOOLCHAIN%\\bin" | ||
- "set PATH=%PATH%;C:\\Users\\appveyor\\.rustup\\toolchains\\%RUST_TOOLCHAIN%\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" | ||
# Stop ignoring YAMLLintBear | ||
- "cargo install clippy --vers 0.0.144" | ||
|
||
# Print rust and cargo parameters for quick debugging. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you still need this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I put it there because it might get in handy in the future, when things start to break on the CI because of me :'-) |
||
- where rustc cargo | ||
- rustc -vV | ||
- cargo -vV | ||
- cargo clippy -V | ||
|
||
build: false # Not a C# project, build stuff at the test step instead. | ||
|
||
test_script: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ htmlcov | |
*.egg-info | ||
.coverage.* | ||
src | ||
!tests/rust/test_*/src | ||
site | ||
.zanata-cache | ||
*.exe | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,8 @@ coala-bears | |
----------- | ||
|
||
coala-bears is a Python package containing all the bears that are officially | ||
supported by coala. It features more than **78 bears** covering | ||
**54 languages**. Here is a `generated list <https://github.com/coala/bear-docs/>`_ | ||
supported by coala. It features more than **79 bears** covering | ||
**55 languages**. Here is a `generated list <https://github.com/coala/bear-docs/>`_ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/coala/bear-docs/#supported-languages-64 according to the generated docs we have 64 languages. I think this might have to be updated seperately, the number of bears was never updated since a longer while There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd just get rid of hard coded statistics honestly. |
||
that contains information about each bear, such as the languages it supports and | ||
what fixes it can apply to your code. | ||
|
||
|
@@ -69,35 +69,35 @@ To see what coala can do for your language, run: | |
+----------------------------+----------------------------+----------------------------+ | ||
| Languages coala provides algorithms for | | ||
+============================+============================+============================+ | ||
| C | Latex | SQL | | ||
| C | Latex | sh & bash scripts | | ||
+----------------------------+----------------------------+----------------------------+ | ||
| C++ | Lua | Stylus | | ||
| C++ | Lua | SQL | | ||
+----------------------------+----------------------------+----------------------------+ | ||
| C# | Markdown | Swift | | ||
| C# | Markdown | Stylus | | ||
+----------------------------+----------------------------+----------------------------+ | ||
| CMake | Matlab/Octave | TypeScript | | ||
| CMake | Matlab/Octave | Swift | | ||
+----------------------------+----------------------------+----------------------------+ | ||
| CoffeeScript | Natural Language (English) | Verilog | | ||
| CoffeeScript | Natural Language (English) | Typescript | | ||
+----------------------------+----------------------------+----------------------------+ | ||
| CSS | Perl | VHDL | | ||
| CSS | Perl | Verilog | | ||
+----------------------------+----------------------------+----------------------------+ | ||
| Dart | PHP | Vimscript | | ||
| Dart | PHP | VHDL | | ||
+----------------------------+----------------------------+----------------------------+ | ||
| Fortran | Python 2 | XML | | ||
| Fortran | Python 2 | Vimscript | | ||
+----------------------------+----------------------------+----------------------------+ | ||
| Go | Python 3 | YAML | | ||
| Go | Python 3 | XML | | ||
+----------------------------+----------------------------+----------------------------+ | ||
| Haskell | R | | | ||
| Haskell | R | YAML | | ||
+----------------------------+----------------------------+----------------------------+ | ||
| HTML | reStructured Text | | | ||
+----------------------------+----------------------------+----------------------------+ | ||
| Java | Ruby | | | ||
+----------------------------+----------------------------+----------------------------+ | ||
| JavaScript | Scala | | | ||
| JavaScript | Rust | | | ||
+----------------------------+----------------------------+----------------------------+ | ||
| JSP | SCSS | | | ||
| JSP | Scala | | | ||
+----------------------------+----------------------------+----------------------------+ | ||
| Julia | sh & bash scripts | | | ||
| Julia | SCSS | | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh damn just inserting a new language requires 1000 line-changes in the readme :P seems like we can't avoid this when using this kind of layout :P There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't you guys add all these languages? Never noticed? :P There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we split it off to be a separate file that is generated? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we even updating the number of bears for new bears? Most new bears change this, the one I have seen merged atleast There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right ... either we are generating this table, or we need to check it somehow, or ... kill it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall I undo this for now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep it until #1609 is solved. |
||
+----------------------------+----------------------------+----------------------------+ | ||
|
||
The number of bears grows every day! If you want to see any particular | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import json | ||
import os | ||
|
||
from coalib.bearlib.abstractions.Linter import linter | ||
from coalib.results.Result import Result | ||
from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY | ||
from dependency_management.requirements.CargoRequirement import ( | ||
CargoRequirement) | ||
|
||
|
||
@linter(executable='cargo', | ||
global_bear=True, | ||
use_stdout=False, | ||
use_stderr=True) | ||
class RustClippyLintBear: | ||
LANGUAGES = {'Rust'} | ||
AUTHORS = {'The coala developers'} | ||
AUTHORS_EMAILS = {'coala-devel@googlegroups.com'} | ||
LICENSE = 'AGPL-3.0' | ||
CAN_DETECT = { | ||
'Formatting', | ||
'Unused Code', | ||
'Syntax', | ||
'Unreachable Code', | ||
'Smell', | ||
'Code Simplification', | ||
} | ||
EXECUTABLE = 'cargo.exe' if os.name == 'nt' else 'cargo' | ||
REQUIREMENTS = { | ||
CargoRequirement('clippy') | ||
} | ||
SEVERITY_MAP = { | ||
'warning': RESULT_SEVERITY.NORMAL, | ||
'error': RESULT_SEVERITY.MAJOR, | ||
} | ||
|
||
@staticmethod | ||
def create_arguments(config_file): | ||
args = ('clippy', '--quiet', '--color', 'never', | ||
'--', '-Z', 'unstable-options', | ||
'--error-format', 'json', | ||
'--test') | ||
return args | ||
|
||
def process_output(self, output, filename, file): | ||
# Rust outputs \n's, instead of the system default. | ||
for line in output.split('\n'): | ||
if not line: | ||
continue | ||
# cargo still outputs some text, even when in quiet mode, | ||
# when a project does not build. We skip this, as the | ||
# real reason will be reported on another line. | ||
if line.startswith('To learn more, run the command again'): | ||
continue | ||
yield self.new_result(json.loads(line)) | ||
|
||
def new_result(self, issue): | ||
span = issue['spans'][0] | ||
return Result.from_values( | ||
origin=self.__class__.__name__, | ||
message=issue['message'], | ||
file=span['file_name'], | ||
line=span['line_start'], | ||
end_line=span['line_end'], | ||
column=span['column_start'], | ||
end_column=span['column_end'], | ||
severity=self.SEVERITY_MAP[issue['level']]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target | ||
Cargo.lock |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import unittest | ||
import os | ||
from queue import Queue | ||
from shutil import which | ||
from unittest.case import skipIf | ||
|
||
from coalib.settings.Section import Section | ||
|
||
from bears.rust.RustClippyLintBear import RustClippyLintBear | ||
|
||
|
||
@skipIf(which('cargo') is None, 'Cargo is not installed') | ||
class RustClippyLintBearTest(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.section = Section('name') | ||
self.queue = Queue() | ||
self.file_dict = {} | ||
self.uut = RustClippyLintBear(self.file_dict, self.section, self.queue) | ||
|
||
def change_directory(self, directory_name): | ||
test_path = os.path.abspath(os.path.join(os.path.dirname(__file__), | ||
directory_name)) | ||
os.chdir(test_path) | ||
|
||
def set_config_dir(self, directory): | ||
# Work around https://github.com/coala/coala/issues/3867 | ||
test_path = os.path.abspath(os.path.join( | ||
os.path.dirname(__file__), directory)) | ||
self.uut.get_config_dir = lambda *args, **kwargs: test_path | ||
|
||
def test_ok_source(self): | ||
self.set_config_dir('test_ok') | ||
results = list(self.uut.run()) | ||
self.assertTrue(len(results) == 0) | ||
|
||
def test_bad_source(self): | ||
self.set_config_dir('test_bad') | ||
results = list(self.uut.run()) | ||
self.assertTrue(len(results) >= 3) | ||
|
||
def test_error_source(self): | ||
self.set_config_dir('test_error') | ||
results = list(self.uut.run()) | ||
self.assertTrue(len(results) == 1) | ||
|
||
result = results[0] | ||
print(result) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. darn, spotted a print statement, I wanted to ack this! |
||
self.assertTrue(result.message == 'mismatched types') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[package] | ||
name = "coala_test_files" | ||
version = "0.1.0" | ||
|
||
[dependencies] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// This function should trigger unused code (warning level) | ||
fn testssss() { | ||
// This comparison should trigger a `deny` level lint | ||
let mut x: f64 = 0.0; | ||
if x == std::f64::NAN { | ||
} | ||
x += 1.; // Triggers allow style lint | ||
println!("{}", x); | ||
} | ||
|
||
|
||
// We test whether bad code is found in (unit) tests | ||
#[cfg(test)] | ||
mod tests { | ||
#[test] | ||
fn it_works() { | ||
let x = Some(1u8); | ||
// This match triggers a `warning` level lint | ||
match x { | ||
Some(y) => println!("{:?}", y), | ||
_ => () | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[package] | ||
name = "coala_test_files" | ||
version = "0.1.0" | ||
|
||
[dependencies] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fn main() { | ||
// This does not compile. Message is 'mismatched types' | ||
let a: i32 = ""; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[package] | ||
name = "coala_test_files" | ||
version = "0.1.0" | ||
|
||
[dependencies] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#[test] | ||
fn it_works() { | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect this could also be improved using yaml lint splitting
>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I honestly wouldn't split them up. @sils and I seem to have agreed on that.