### Install diff-cover Development Version Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Clone the repository, navigate to the directory, and install the development version using poetry. ```bash git clone https://github.com/Bachmann1234/diff-cover.git cd diff-cover poetry install poetry shell ``` -------------------------------- ### Install diff-cover Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Install the latest release of diff-cover using pip. ```bash pip install diff-cover ``` -------------------------------- ### Install Project Dependencies with Poetry Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Install all project dependencies managed by Poetry. This command also sets up a virtual environment for the project. ```bash poetry install ``` -------------------------------- ### Example Snippet 1 Source: https://github.com/bachmann1234/diff_cover/blob/main/diff_cover/templates/snippet_content.txt This is an example of a terminal snippet. ```python def greet(name): print(f"Hello, {name}!") greet("World") ``` -------------------------------- ### Install Poetry Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Install Poetry, a dependency management and packaging tool for Python projects, using pip. ```bash pip install poetry ``` -------------------------------- ### Diff Coverage Report Example Source: https://github.com/bachmann1234/diff_cover/blob/main/tests/fixtures/add_markdown_report.md An example of a diff coverage report for the file 'test_src.txt', showing missing lines and coverage percentage. ```text 1 test 1 ! 2 test 2 3 test 3 ! 4 test 4 5 test 5 ! 6 test 6 7 test 7 ! 8 test 8 9 test 9 ! 10 test 10 ``` -------------------------------- ### Example Snippet 2 Source: https://github.com/bachmann1234/diff_cover/blob/main/diff_cover/templates/snippet_content.txt Another example of a terminal snippet. ```python def add(a, b): return a + b result = add(5, 3) print(f"The sum is: {result}") ``` -------------------------------- ### Example Snippet 3 Source: https://github.com/bachmann1234/diff_cover/blob/main/diff_cover/templates/snippet_content.txt A simple Python function example. ```python def multiply(x, y): return x * y product = multiply(4, 6) print(f"The product is: {product}") ``` -------------------------------- ### Example diff-quality Plugin Implementation Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst A simplified example of a Python plugin for diff-quality. It defines a reporter class that implements the necessary methods to report violations and is registered using the @diff_cover_hookimpl decorator. ```python from diff_cover.hook import hookimpl as diff_cover_hookimpl from diff_cover.violationsreporters.base import BaseViolationReporter, Violation class SQLFluffViolationReporter(BaseViolationReporter): supported_extensions = ['sql'] def __init__(self): super(SQLFluffViolationReporter, self).__init__('sqlfluff') def violations(self, src_path): return [ Violation(violation.line_number, violation.description) for violation in get_linter().get_violations(src_path) ] def measured_lines(self, src_path): return None @staticmethod def installed(): return True @diff_cover_hookimpl def diff_cover_report_quality(): return SQLFluffViolationReporter() ``` -------------------------------- ### TOML Configuration for Diff Cover and Diff Quality Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Example TOML configuration for diff-cover and diff-quality. Option names are command-line equivalents with dashes replaced by underscores. Lists are used for options that can be specified multiple times. ```toml [tool.diff_cover] compare_branch = "origin/feature" quiet = true [tool.diff_quality] compare_branch = "origin/feature" ignore_staged = true ``` -------------------------------- ### Example C++ Code Snippet Source: https://github.com/bachmann1234/diff_cover/blob/main/tests/fixtures/snippet_list3.md A basic C++ code snippet demonstrating printf statements and function structure. This snippet is part of a larger program, indicated by the line numbers and comments. ```cpp 8 // this is line 8 9 printf("Test2"); 10 11 // this is line 11 ! 12 printf("Test"); 13 } 14 15 int main() 16 { ``` -------------------------------- ### Example of Duplicate Code Function Source: https://github.com/bachmann1234/diff_cover/blob/main/tests/fixtures/pylint_dupe.txt This Python function, `selection_sort`, is identified as having duplicate code. The warning indicates that similar logic exists in another file. ```python def selection_sort(to_sort): """ The greatest sorting algorithm? """ new_list = [] final_size = len(to_sort) while len(new_list) < final_size: candidate_index = 0 for index in xrange(len(to_sort)): if to_sort[index] <= to_sort[candidate_index]: candidate_index = index new_list.append(to_sort.pop(candidate_index)) return new_list ``` -------------------------------- ### Python Calculator Class Definition Source: https://github.com/bachmann1234/diff_cover/blob/main/tests/fixtures/git_diff_python.txt Defines a Calculator class with methods for arithmetic operations and number processing. This serves as a base for coverage examples. ```python from typing import List, Callable class Calculator: def add(self, a: float, b: float) -> float: """Function coverage example""" return a + b def divide(self, a: float, b: float) -> float: """Branch coverage example""" if b == 0: raise ValueError("Division by zero") return a / b def process_numbers(self, numbers: List[float], processor: Callable[[float], float] = None) -> List[float]: """Lambda function coverage example""" if processor is None: processor = lambda x: x * 2 return list(map(processor, numbers)) def get_grade(self, score: float) -> str: """Line and branch coverage example""" if score < 0 or score > 100: raise ValueError("Invalid score") if score >= 90: return "A" elif score >= 80: return "B" elif score >= 70: return "C" else: return "F" ``` -------------------------------- ### TypeScript Calculator Class Definition Source: https://github.com/bachmann1234/diff_cover/blob/main/tests/fixtures/git_diff_typescript.txt Defines a Calculator class with methods for addition, division, number processing, and grading. Use this class for basic arithmetic and conditional logic examples. ```typescript export class Calculator { // Function coverage add(a: number, b: number): number { return a + b; } // Branch coverage divide(a: number, b: number): number { if (b === 0) { throw new Error("Division by zero"); } return a / b; } // Anonymous function coverage processNumbers( numbers: number[], processor: (n: number) => number = (n) => n * 2 ): number[] { return numbers.map(processor); } // Line and branch coverage getGrade(score: number): string { if (score < 0 || score > 100) { throw new Error("Invalid score"); } if (score >= 90) { return "A"; } else if (score >= 80) { return "B"; } else if (score >= 70) { return "C"; } else { return "F"; } } } ``` -------------------------------- ### Define Entry Point for diff-quality Plugin Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Configure the setup.py file of a Python package to register a diff-quality plugin. The entry point must be named 'diff_cover' and follow the format 'TOOL_NAME = YOUR_PACKAGE.PLUGIN_MODULE'. ```python setup( ... entry_points={ 'diff_cover': [ 'sqlfluff = sqlfluff.diff_quality_plugin' ], }, ... ) ``` -------------------------------- ### Specify Configuration File Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Use --config-file or -c to specify options in a configuration file. Currently, only TOML files are supported. ```bash diff-cover coverage.xml --config-file myconfig.toml diff-quality --violations=pycodestyle --config-file myconfig.toml ``` -------------------------------- ### Run diff-quality with Options Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Pass additional options to the underlying linter using the --options flag. Options should be quoted. ```bash diff-quality --violations=pycodestyle --options="--exclude='*/migrations*' --statistics" pycodestyle_report.txt ``` -------------------------------- ### C++ Hello World Source: https://github.com/bachmann1234/diff_cover/blob/main/tests/fixtures/snippet_list2.md This snippet shows a minimal C++ program. It includes the iostream library for input/output operations and the main function, which is the entry point of the program. The std::cout object is used to print the string 'Hello World!' to the standard output stream. ```cpp #include int main() { std::cout << "Hello World!"; return 0; } ``` -------------------------------- ### Run diff-cover for Coverage Analysis Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Execute diff-cover with the generated coverage.xml file to compare against the git diff and print the diff coverage report to the console. ```bash diff-cover coverage.xml ``` -------------------------------- ### Run diff-quality with Pycodestyle Report Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Use a generated pycodestyle report when running diff-quality. The report must be piped to a file first. ```bash pycodestyle > pycodestyle_report.txt diff-quality --violations=pycodestyle pycodestyle_report.txt ``` -------------------------------- ### Run diff-cover with Diff File Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Use a generated diff file as input for diff-cover instead of a branch name. ```bash diff-cover coverage.xml --diff-file=diff.txt ``` -------------------------------- ### Enable Float Percentages Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Use the --total-percent-float flag to display coverage/quality percentages with up to two decimal places. ```bash diff-cover coverage.xml --total-percent-float ``` ```bash diff-quality --violations=pycodestyle --total-percent-float ``` -------------------------------- ### Compare Branch with diff-cover Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Specify a different compare branch for diff-cover. Defaults to origin/main. ```bash diff-cover coverage.xml --compare-branch=origin/release ``` -------------------------------- ### Run diff-quality with Multiple Reports Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Accepts multiple pylint reports for analysis. Ensure reports are correctly named and located. ```bash diff-quality --violations=pylint report_1.txt report_2.txt ``` -------------------------------- ### Generate diff-cover Reports in Different Formats Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Generate diff-cover reports in HTML, JSON, or Markdown formats by specifying the desired format and output file. ```bash diff-cover coverage.xml --format html:report.html ``` ```bash diff-cover coverage.xml --format json:report.json ``` ```bash diff-cover coverage.xml --format markdown:report.md ``` ```bash diff-cover coverage.xml --format html:report.html,markdown:report.md ``` -------------------------------- ### Displaying Source File Quality Report Source: https://github.com/bachmann1234/diff_cover/blob/main/diff_cover/templates/html_quality_report.html Iterates through source files in the diff, displaying coverage percentage and line violations if coverage is less than 100%. Includes a fallback for files with 100% coverage. ```html {% if src_stats %} {% for src_path, stats in src_stats|dictsort %} {% if stats.percent_covered < 100 %} Source File Diff Quality (%) Lines in violation {{ src_path }} {{ stats.percent_covered|round(1) }}% {% for line, message in stats.violations %}* {{ line }}: {{ message }} {% endfor %} {% else %} {% endif %} {% endfor %} {{ src_path }} 100%   * **Total**: {{ total_num_lines }} {% trans count=total_num_lines %}line{% pluralize %}lines{% endtrans %} * **Violation**: {{ total_num_violations }} {% trans count=total_num_violations %}line{% pluralize %}lines{% endtrans %} * **% Quality**: {{ total_percent_covered }}% {% else %} No lines with quality information in this diff. {% endif %} ``` -------------------------------- ### Run diff-quality with Pylint Report Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Use the generated pylint report when running diff-quality. Ensure the report is generated in a compatible format. ```bash diff-quality --violations=pylint pylint_report.txt ``` -------------------------------- ### Generate diff-quality Reports in Different Formats Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Generate diff-quality reports in HTML, JSON, or Markdown formats by specifying the format and output file, along with the violations tool. ```bash diff-quality --violations= --format html:report.html ``` ```bash diff-quality --violations= --format json:report.json ``` ```bash diff-quality --violations= --format markdown:report.md ``` ```bash diff-quality --violations= --format html:report.html,markdown:report.md ``` -------------------------------- ### Pass Pre-generated Quality Reports to diff-quality Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Pass an already generated quality report file (e.g., from pylint) to diff-quality for efficiency, instead of letting diff-quality re-run the checker. ```bash # For pylint < 1.0 pylint -f parseable > pylint_report.txt # For pylint >= 1.0 pylint --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" > pylint_report.txt ``` -------------------------------- ### Include Paths with Diff Quality Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Include specific files or paths using the --include option with glob patterns. Options should be wrapped in double quotes and are relative to the git directory. ```bash diff-quality --violations=pycodestyle --include "project/foo/**" ``` -------------------------------- ### Combined Coverage Report from Multiple XML Files Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Generate a combined coverage report by providing multiple XML coverage files as arguments to diff-cover. A line is considered covered if it's covered in any of the reports. ```bash diff-cover coverage1.xml coverage2.xml ``` -------------------------------- ### Run diff-quality for Quality Reports Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Use diff-quality to generate quality reports on diff lines by specifying the violations tool. Supported tools include pycodestyle, pyflakes, flake8, pylint, etc. ```bash diff-quality --violations= ``` -------------------------------- ### Specify Source Directories for Jacoco Coverage Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Provide one or more source directories for diff-cover to map Jacoco coverage data back to source files. Defaults to src/main/java and src/test/java. ```bash diff-cover coverage.xml --src-roots src/main/java src/test/java ``` -------------------------------- ### Python File Coverage Report Source: https://github.com/bachmann1234/diff_cover/blob/main/tests/fixtures/html_report_two_snippets.html Displays coverage statistics for Python files, including percentage and missing lines. ```text Source File Diff Coverage (%) Missing Lines file1.py 66.7% 10-11 subdir/file2.py 66.7% 10-11 ``` -------------------------------- ### Python Hello World with Unknown Variable Source: https://github.com/bachmann1234/diff_cover/blob/main/tests/fixtures/git_diff_violations_two_files.txt This snippet shows a modification to a Python file that introduces an undefined variable, likely causing an error. ```diff diff --git a/hello.py b/hello.py index b732142..b2ba069 100644 --- a/hello.py +++ b/hello.py @@ -1 +1,2 @@ print "hello" +print unknown_var ``` -------------------------------- ### Generate HTML Report with Covered Lines Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Generate an HTML report and highlight both covered and uncovered lines using --html-report and --show-covered flags. ```bash diff-cover coverage.xml --html-report report.html --show-covered ``` -------------------------------- ### Python Snippet with Unicode Characters Source: https://github.com/bachmann1234/diff_cover/blob/main/tests/fixtures/html_report_two_snippets.html Shows a source code snippet from a Python file, demonstrating handling of Unicode characters. ```python Snippet with ስ 芒 unicode ``` -------------------------------- ### Troubleshooting: Fetch Remote Main Branch Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Solution for 'fatal: ambiguous argument' error when running diff-cover in Travis CI. Fetch the remote main branch before running diff-cover. ```bash git fetch origin master:refs/remotes/origin/main ``` -------------------------------- ### Set Fail Under Threshold Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Use the --fail-under parameter to set a threshold for coverage/quality percentage. A non-zero status code is returned if the score is below this threshold. ```bash diff-cover coverage.xml --fail-under=80 ``` ```bash diff-quality --violations=pycodestyle --fail-under=80 ``` -------------------------------- ### Enable Quiet Mode Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Enable quiet mode using the -q or --quiet flag to suppress informational messages and only show errors and failures. ```bash diff-cover coverage.xml -q ``` ```bash diff-quality --violations=pycodestyle -q ``` -------------------------------- ### Include Untracked Files Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Use the --include-untracked flag to include untracked files in the analysis. By default, untracked files are ignored. ```bash diff-cover coverage.xml --include-untracked ``` -------------------------------- ### Generate Coverage Report with pytest-cov Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Run your test suite and generate an XML coverage report using pytest-cov. This creates a coverage.xml file. ```bash pytest --cov --cov-report=xml ``` -------------------------------- ### Calculator Class Methods in C++ Source: https://github.com/bachmann1234/diff_cover/blob/main/tests/fixtures/git_diff_cpp.txt Provides the implementation for addition, division, number processing, and grade calculation within the Calculator class. ```cpp #include "calculator.h" double Calculator::add(double a, double b) { return a + b; } double Calculator::divide(double a, double b) { if (b == 0) { throw std::invalid_argument("Division by zero"); } return a / b; } std::vector Calculator::processNumbers(const std::vector& numbers, std::function processor) { if (!processor) { processor = [](double x) { return x * 2; }; } std::vector result; result.reserve(numbers.size()); for (const auto& num : numbers) { result.push_back(processor(num)); } return result; } std::string Calculator::getGrade(double score) { if (score < 0 || score > 100) { throw std::invalid_argument("Invalid score"); } if (score >= 90) { return "A"; } else if (score >= 80) { return "B"; } else if (score >= 70) { return "C"; } else { return "F"; } } ``` -------------------------------- ### Calculator Class Methods Source: https://github.com/bachmann1234/diff_cover/blob/main/tests/fixtures/git_diff_cpp_functions.txt Implements basic arithmetic operations and a number processing utility for the Calculator class. ```cpp #include "calculator.h" double Calculator::add(double a, double b) { return a + b; } double Calculator::divide(double a, double b) { if (b == 0) { throw std::invalid_argument("Division by zero"); } return a / b; } std::vector Calculator::processNumbers(const std::vector& numbers, std::function processor) { std::vector result; for (const auto& num : numbers) { result.push_back(processor(num)); } return result; } ``` -------------------------------- ### Python Hi World with Unknown Variable Source: https://github.com/bachmann1234/diff_cover/blob/main/tests/fixtures/git_diff_violations_two_files.txt This snippet illustrates a change in another Python file, also introducing an undefined variable. ```diff diff --git a/hi.py b/hi.py index bae1109..151d05d 100644 --- a/hi.py +++ b/hi.py @@ -1 +1,2 @@ print "hi" +print unknown_var ``` -------------------------------- ### Specify Report Root Path for Diff Quality Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Use --report-root-path to specify the root path when generating a quality tool report if it was run from a different directory than the current working directory. ```bash diff-quality --violations=pycodestyle --report-root-path=path/to/root ``` -------------------------------- ### Add DoSomethingNew Method in C# Source: https://github.com/bachmann1234/diff_cover/blob/main/tests/fixtures/git_diff_dotnet.txt This snippet shows the addition of a new static method `DoSomethingNew` to a C# class. This method takes two integers and returns their sum. It's a common pattern for extending class functionality. ```csharp namespace SampleApp { class Program { static void Main(string[] args) { try { // Some existing code } catch (Exception ex) { Console.WriteLine(ex.Message); } } public static int DoSomethingNew(int a,int b) { return a + b; } } } ``` -------------------------------- ### Source Snippet Name Styling Source: https://github.com/bachmann1234/diff_cover/blob/main/diff_cover/templates/snippet_style.html Sets the font weight to bold for source snippet names. ```css .src-name { font-weight: bold; } ``` -------------------------------- ### Python Function with Missing Docstrings and Unused Variable Source: https://github.com/bachmann1234/diff_cover/blob/main/tests/fixtures/pylint_violations_report.html This Python code snippet demonstrates a function with a missing module docstring and a function with a missing docstring. It also includes an unused variable, which would be flagged by Pylint. ```python def func_1(apple, my_list): if apple<10: # Do something my_list.append(apple) return my_list[1:] """A less messy function""" for char in spongebob: if char in squarepants: return char unused=1 return None ``` -------------------------------- ### Generate HTML Report with External CSS Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Embeds HTML report styles inline by default. Use --external-css-file to write the CSS into a separate file instead. ```bash diff-cover coverage.xml --html-report report.html --external-css-file report.css diff-quality --violations=pycodestyle --html-report report.html --external-css-file report.css ``` -------------------------------- ### Expand Coverage Report for Multi-line Statements Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Use --expand-coverage-report as a workaround for multi-line statements not being analyzed by diff-cover. Adds lines not in coverage reports with the same hits as the previously reported line. ```bash diff-cover coverage.xml --expand-coverage-report ``` -------------------------------- ### Show Uncovered Lines Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Use the --show-uncovered flag to display individual lines that lack coverage on the console report. ```bash diff-cover coverage.xml --show-uncovered ``` -------------------------------- ### Exclude Paths Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Exclude specific files or paths using the --exclude option with fnmatch patterns. This applies to both diff-cover and diff-quality. ```bash diff-cover coverage.xml --exclude setup.py ``` ```bash diff-quality --violations=pycodestyle --exclude setup.py ``` -------------------------------- ### Generate Git Diff File Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Generate a diff file between two branches or a branch and a commit using git diff. This file can then be used with diff-cover. ```bash git diff main..feature > diff.txt ``` ```bash git diff A..feature > diff.txt ``` -------------------------------- ### Specify Diff Range Notation Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Use --diff-range-notation to specify the git diff range notation. Defaults to '...' (changes on the current branch since it diverged from the compare branch). Use '..' for all differences between the two branches. ```bash diff-cover coverage.xml --diff-range-notation=.. diff-quality --violations=pycodestyle --diff-range-notation=.. ``` -------------------------------- ### Ignore Git Staged/Unstaged Files Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Use --ignore-staged or --ignore-unstaged flags to exclude files with specific git statuses from the analysis. ```bash diff-cover coverage.xml --ignore-staged ``` ```bash diff-quality --violations=pycodestyle --ignore-unstaged ``` -------------------------------- ### Configure Git Blame Ignore Revisions Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Configure Git to ignore specific commits when running 'git blame'. This is useful for ignoring commits that reformatted the entire codebase. ```bash git config blame.ignoreRevsFile .git-blame-ignore-revs ``` -------------------------------- ### Default Snippet Margin Source: https://github.com/bachmann1234/diff_cover/blob/main/diff_cover/templates/snippet_style.html Applies a top margin of 2em to source snippets when snippet styling is enabled. ```css .src-snippet { margin-top: 2em; } ``` -------------------------------- ### New Python Function func_2 Source: https://github.com/bachmann1234/diff_cover/blob/main/tests/fixtures/git_diff_violations.txt This snippet introduces a new Python function, `func_2`, which iterates through a string to find a character present in another string. It includes a docstring explaining its purpose and an unused variable. ```python def func_2(spongebob, squarepants): """A less messy function""" for char in spongebob: if char in squarepants: return char unused=1 return None ``` -------------------------------- ### Snippet Container Borders Source: https://github.com/bachmann1234/diff_cover/blob/main/diff_cover/templates/snippet_style.html Adds top and bottom borders to the snippet container for visual separation. ```css .snippets { border-top: 1px solid #bdbdbd; border-bottom: 1px solid #bdbdbd; } ``` -------------------------------- ### Ignore Whitespace Changes in Diff Source: https://github.com/bachmann1234/diff_cover/blob/main/README.rst Use --ignore-whitespace to ignore any and all whitespace changes when computing the diff. ```bash diff-cover coverage.xml --ignore-whitespace diff-quality --violations=pycodestyle --ignore-whitespace ``` -------------------------------- ### Modified Python Function func_1 Source: https://github.com/bachmann1234/diff_cover/blob/main/tests/fixtures/git_diff_violations.txt This snippet shows a modified version of the `func_1` Python function. The changes include minor whitespace adjustments and a slight alteration in the conditional logic. ```python def func_1(apple,my_list): if apple< 10: # Do something my_list.append(apple) return my_list[1:] ``` -------------------------------- ### Lua Multiplication Function Source: https://github.com/bachmann1234/diff_cover/blob/main/tests/fixtures/git_diff_lua.txt Adds a multiplication function to the maths module. Use this for multiplying two numbers. ```lua function maths.mult(a,b) return a * b end ``` -------------------------------- ### Duplicate Code Warning in Pylint Source: https://github.com/bachmann1234/diff_cover/blob/main/tests/fixtures/pylint_dupe.txt Pylint identifies similar lines of code across different files. This snippet shows the warning message format and the specific files and line numbers involved. ```text filetwo.py:1: [R0801(duplicate-code), ] Similar lines in 2 files ==fileone:3 ==filetwo:3 ``` -------------------------------- ### Python Code with pycodestyle Violations Source: https://github.com/bachmann1234/diff_cover/blob/main/tests/fixtures/pycodestyle_violations_report_external_css.html This Python code snippet contains several pycodestyle violations, including missing whitespace around operators and incorrect blank line spacing. It is used to demonstrate the reporting of code quality issues. ```python def func_1(apple, my_list): if apple<10: # Do something my_list.append(apple) return my_list[1:] def func_2(spongebob, squarepants): """A less messy function""" for char in spongebob: if char in squarepants: return char unused=1 return None ``` -------------------------------- ### TypeScript Calculator Class Definition Source: https://github.com/bachmann1234/diff_cover/blob/main/tests/fixtures/git_diff_typescript_branches.txt Defines a Calculator class with static methods for division and grading. Use the divide method with caution due to potential division by zero errors. The getGrade method maps numerical scores to letter grades. ```typescript export class Calculator { static divide(a: number, b: number): number { if (b === 0) { throw new Error('Division by zero'); } return a / b; } static getGrade(score: number): string { if (score >= 90) { return 'A'; } else if (score >= 80) { return 'B'; } else if (score >= 70) { return 'C'; } else if (score >= 60) { return 'D'; } else { return 'F'; } } } ``` -------------------------------- ### Python Selection Sort Function Source: https://github.com/bachmann1234/diff_cover/blob/main/tests/fixtures/git_diff_code_dupe.txt Implements the selection sort algorithm to sort a list. This function iteratively finds the minimum element from the unsorted part and appends it to the new list. ```python """ Fileone """ def selection_sort(to_sort): """ The greatest sorting algorithm? """ new_list = [] final_size = len(to_sort) while len(new_list) < final_size: candidate_index = 0 for index in xrange(len(to_sort)): if to_sort[index] <= to_sort[candidate_index]: candidate_index = index new_list.append(to_sort.pop(candidate_index)) return new_list ``` -------------------------------- ### Lua Subtraction Function Source: https://github.com/bachmann1234/diff_cover/blob/main/tests/fixtures/git_diff_lua.txt Defines a function to subtract two numbers. This is part of the core arithmetic operations. ```lua function maths.subber(a, b) return a - b end ``` -------------------------------- ### Python Code with Unused Variable Violation Source: https://github.com/bachmann1234/diff_cover/blob/main/tests/fixtures/pyflakes_violations_report.html This Python code snippet demonstrates a common pyflakes violation: a local variable 'unused' is assigned a value but never used. This can indicate dead code or potential logic errors. ```Python """A less messy function""" for char in spongebob: if char in squarepants: return char unused=1 return None ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.