Giter Site home page Giter Site logo

moealsir / betty_fixer Goto Github PK

View Code? Open in Web Editor NEW
14.0 2.0 4.0 467 KB

Betty Fixer is a tool designed to automatically fix coding style issues in C files based on the Betty coding style guidelines. It performs corrections to ensure that the code complies with the Betty style, making it more readable and consistent.

Python 18.55% Shell 1.38% Perl 68.22% Roff 6.11% C 5.74%
alx alx-low-level-programming betty betty-coding-style betty-style coding-style holberton

betty_fixer's Introduction

Hi there ๐Ÿ‘‹

betty_fixer's People

Contributors

be-great avatar malazmuzamil98 avatar moealsir avatar younis-ahmed avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

betty_fixer's Issues

workflows/main.yml

#######################################

  • name: Run test script
    run: |
    # Include your specific testing commands here
    # For example, you might want to run a script that imports bettystyle and performs tests
    python your_test_script.py
    ######################################
    This part should be deleted. it's irrelevant

Duplication functions found in `betty_fixer` and `betty_handler` modules.

Summary:

Duplicate function found in betty_fixer and betty_handler modules.

Description:

While working on a different issue, I noticed that there is a function that is duplicated in both the betty_fixer and betty_handler modules. Though the interpreter will not raise errors and simply points to the recent object. This could lead to maintenance issues in the future and considered bad code.

Steps to Reproduce:

  1. Open the betty_fixer module.
    def other_handlers(file_path):
    errors_file_path = 'errors.txt'
    # Your logic code
    create_tasks_directory()
    # Pass file_path as a list to copy_files_to_tasks
    copy_files_to_tasks([file_path])
    modify_main_files([file_path])
    # Clean 'errors.txt' before extracting new errors
    clean_errors_file(errors_file_path)
    # Update Betty errors in errors.txt
    exctract_errors(file_path, errors_file_path)
    def create_tasks_directory():
    # Create tasks directory if not found
    if not os.path.exists("tasks"):
    os.makedirs("tasks")
    def copy_files_to_tasks(files):
    # Copy files to tasks directory
    for file_path in files:
    destination_path = os.path.join("tasks", os.path.basename(file_path))
    if not os.path.exists(destination_path):
    # Read the content of the file
    with open(file_path, 'r') as source_file:
    content = source_file.readlines()
    # Exclude lines starting with #include and ending with '.h"'
    filtered_content = [line for line in content if not line.strip().startswith("#include") or not line.strip().endswith('.h"')]
    # Write the modified content to the destination file
    with open(destination_path, 'w') as destination_file:
    destination_file.write(''.join(filtered_content))
    def modify_main_files(files):
    # Modify main files
    for file_path in files:
    # Read the content of the main file
    with open(file_path, 'r') as main_file:
    content = main_file.readlines()
    # Keep only lines with #include that end with '.h"'
    include_lines = [line.strip() for line in content if line.strip().startswith("#include") and line.strip().endswith('.h"')]
    # Write the modified content to the main file, adding an empty line at the end
    with open(file_path, 'w') as main_file:
    main_file.write('\n'.join(include_lines + [f'#include "tasks/{os.path.basename(file_path)}"\n']))
  2. Open the betty_handler module.
    def other_handler(file_path):
    create_tasks_directory()
    copy_files_to_tasks(file_path)
    modify_main_files(file_path)
    def create_tasks_directory():
    # Create tasks directory if not found
    if not os.path.exists("tasks"):
    os.makedirs("tasks")
    def copy_files_to_tasks(files):
    # Copy files to tasks directory
    for file_path in files:
    destination_path = os.path.join("tasks", os.path.basename(file_path))
    if not os.path.exists(destination_path):
    # Read the content of the file
    with open(file_path, 'r') as source_file:
    content = source_file.readlines()
    # Exclude lines starting with #include and ending with '.h"'
    filtered_content = [line for line in content if not line.strip().startswith("#include") or not line.strip().endswith('.h"')]
    # Write the modified content to the destination file
    with open(destination_path, 'w') as destination_file:
    destination_file.write(''.join(filtered_content))
    def modify_main_files(files):
    # Modify main files
    for file_path in files:
    # Read the content of the main file
    with open(file_path, 'r') as main_file:
    content = main_file.readlines()
    # Keep only lines with #include that end with '.h"'
    include_lines = [line.strip() for line in content if line.strip().startswith("#include") and line.strip().endswith('.h"')]
    # Write the modified content to the main file, adding an empty line at the end
    with open(file_path, 'w') as main_file:
    main_file.write('\n'.join(include_lines + [f'#include "tasks/{os.path.basename(file_path)}"\n']))

Expected Result:

Each function should be unique and not duplicated across different modules.

Actual Result:

The same function is present in both modules.

Suggested Fix:

We should refactor the code to remove the duplication. I can't see any differences on either implementations. Simple deletion should suffice.

Testing suite

Document Testing Suite Dependencies

Description

This is an extension of #5 that focuses on Testing Suite. To ensure cohesion through contributors, It is best document all the packages that the testing suite uses.

List of Packages

Here are the packages that we are currently using for the testing suite:

  1. unittest: This is a built-in Python module used for creating and running tests.
  2. pytest: It provides features like fixtures and parameterized testing that are not available in unittest.

Action Items

  • Review the list of packages and their uses.
  • Add any missing packages to the list.
  • Document the final list of packages in the project's README file.
  • ~80ยฑ Testing coverage

Codebase Formatting and Test Suite Proposal

Codebase Formatting and Test Suite Proposal

Hello @Moealsir @be-great @malazmuzamil98 ,

I recently forked this repository with the intention of contributing and noticed that the codebase lacks consistent formatting. Proper code formatting is crucial for readability and maintainability, especially for open-source projects where multiple contributors are involved.

I propose to implement a code to standardize format, such as PEP8 + docstring since we all are familiar with it, to ensure consistent code style across the project. This will help future contributors to read and understand the code more easily.

In addition to this, I noticed that the project does not have a test suite. Having a robust set of tests is important to ensure the stability of the project and prevent regressions when new changes are introduced. by integrating the tests into your CI pipeline we can ensure no bug get shipped into package with future PRs.

I would like to offer my assistance in setting up the code formatter and creating a test suite for the project. This will involve:

  1. Setting up the chosen code formatter and formatting the existing codebase which I already started.
  2. Writing unit tests for the existing functionality.
  3. Setting up a continuous integration service to run these tests automatically on every pull request.

Please let me know if you are interested in this proposal. I am ready to start working on this as soon as I get your approval.

Best Regards,
Younis

PEP8 and Docstring Formatting

Document PEP8 and docstring Formatting

Description

This is an extension of #5 proposal that focuses on migrating formats to PEP8 with pylint and Docstring. To ensure cohesion through contributions.

Why Pylint

  • pylint is a more comprehensive tool that checks for a wide range of issues, including coding standards, errors that could lead to bugs in runtime (like type errors), and code smells (like too many branches or lines in a function).
  • It can also check for adherence to a coding standard like PEP 8, but it also includes many other checks that go beyond style.
  • pylint includes features like checking the types of function arguments and return values, checking for unused variables or imports, and checking for cyclic imports.
  • It also provides a code rating based on the number and severity of issues found.

Objectives

  • Adding errors_logs directory
  • excluding errors_logs from distribution package
  • push code rating to ~9ยฑ overall [could improve in later PRs]
  • Skimming off as much error format as possible.
  • Add a linting Github action upon [push, pull request]

Format Analysis

Please be notified these reports are NOT comprehensive and merely scratching the surface but are a good place to start

autoprototype Module

79 statements analysed.

Statistics by type

type number old number difference %documented %badname
module 1 NC NC 0.00 0.00
class 0 NC NC 0 0
method 0 NC NC 0 0
function 11 NC NC 0.00 9.09

External dependencies

::

colorama (bettyfixer.autoprototype)

102 lines have been analyzed

Raw metrics

type number % previous difference
code 82 80.39 NC NC
docstring 0 0.00 NC NC
comment 5 4.90 NC NC
empty 15 14.71 NC NC

Duplication

now previous difference
nb duplicated lines 0 NC NC
percent duplicated lines 0.000 NC NC

Messages by category

type number previous difference
convention 29 NC NC
refactor 1 NC NC
warning 16 NC NC
error 0 NC NC

Messages

message id occurrences
missing-function-docstring 11
bad-indentation 11
line-too-long 5
trailing-whitespace 4
unused-import 2
unspecified-encoding 2
superfluous-parens 2
singleton-comparison 2
consider-using-f-string 2
wrong-import-order 1
no-else-return 1
missing-module-docstring 1
invalid-name 1
f-string-without-interpolation 1

Your code has been rated at 4.18/10

backup.py Module

9 statements analysed.

Statistics by type

type number old number difference %documented %badname
module 1 NC NC 0.00 0.00
class 0 NC NC 0 0
method 0 NC NC 0 0
function 1 NC NC 0.00 0.00

16 lines have been analyzed

Raw metrics

type number % previous difference
code 11 68.75 NC NC
docstring 0 0.00 NC NC
comment 1 6.25 NC NC
empty 4 25.00 NC NC

Duplication

now previous difference
nb duplicated lines 0 NC NC
percent duplicated lines 0.000 NC NC

Messages by category

type number previous difference
convention 5 NC NC
refactor 0 NC NC
warning 1 NC NC
error 0 NC NC

Messages

message id occurrences
trailing-whitespace 2
trailing-newlines 1
missing-module-docstring 1
missing-function-docstring 1
broad-exception-caught 1

Your code has been rated at 3.33/10

betty_fixer Module

210 statements analysed.

Statistics by type

type number old number difference %documented %badname
module 1 NC NC 0.00 0.00
class 0 NC NC 0 0
method 0 NC NC 0 0
function 22 NC NC 0.00 4.55

332 lines have been analyzed

Raw metrics

type number % previous difference
code 215 64.76 NC NC
docstring 1 0.30 NC NC
comment 50 15.06 NC NC
empty 66 19.88 NC NC

Duplication

now previous difference
nb duplicated lines 0 NC NC
percent duplicated lines 0.000 NC NC

Messages by category

type number previous difference
convention 34 NC NC
refactor 4 NC NC
warning 47 NC NC
error 0 NC NC

Messages

message id occurrences
missing-function-docstring 22
unspecified-encoding 21
redefined-outer-name 17
wildcard-import 4
unused-wildcard-import 4
line-too-long 4
trailing-whitespace 3
consider-using-with 2
unused-argument 1
too-many-nested-blocks 1
too-many-locals 1
superfluous-parens 1
singleton-comparison 1
missing-module-docstring 1
missing-final-newline 1
invalid-name 1

Your code has been rated at 5.95/10

betty_handler Module 33 statements analysed.

Statistics by type

type number old number difference %documented %badname
module 1 NC NC 0.00 0.00
class 0 NC NC 0 0
method 0 NC NC 0 0
function 4 NC NC 0.00 0.00

61 lines have been analyzed

Raw metrics

type number % previous difference
code 35 57.38 NC NC
docstring 0 0.00 NC NC
comment 13 21.31 NC NC
empty 13 21.31 NC NC

Duplication

now previous difference
nb duplicated lines 0 NC NC
percent duplicated lines 0.000 NC NC

Messages by category

type number previous difference
convention 8 NC NC
refactor 0 NC NC
warning 4 NC NC
error 0 NC NC

Messages

message id occurrences
unspecified-encoding 4
missing-function-docstring 4
line-too-long 3
missing-module-docstring 1


Your code has been rated at 6.36/10

errors_extractor Module

21 statements analysed.

Statistics by type

type number old number difference %documented %badname
module 1 NC NC 0.00 0.00
class 0 NC NC 0 0
method 0 NC NC 0 0
function 1 NC NC 0.00 0.00

39 lines have been analyzed

Raw metrics

type number % previous difference
code 23 58.97 NC NC
docstring 0 0.00 NC NC
comment 9 23.08 NC NC
empty 7 17.95 NC NC

Duplication

now previous difference
nb duplicated lines 0 NC NC
percent duplicated lines 0.000 NC NC

Messages by category

type number previous difference
convention 3 NC NC
refactor 1 NC NC
warning 6 NC NC
error 0 NC NC

Messages

message id occurrences
unspecified-encoding 3
redefined-outer-name 2
unnecessary-pass 1
missing-module-docstring 1
missing-function-docstring 1
invalid-name 1
consider-using-with 1


Your code has been rated at 5.24/10

extract_line **522 statements analysed.**

Statistics by type

type number old number difference %documented %badname
module 1 1 = 0.00 0.00
class 0 NC NC 0 0
method 0 NC NC 0 0
function 35 35 = 0.00 0.00

971 lines have been analyzed

Raw metrics

type number % previous difference
code 536 55.20 NC NC
docstring 16 1.65 NC NC
comment 206 21.22 NC NC
empty 213 21.94 NC NC

Duplication

now previous difference
nb duplicated lines 0 0 0
percent duplicated lines 0.000 0.000 =

Messages by category

type number previous difference
convention 82 82 82
refactor 5 5 5
warning 74 74 74
error 0 0 0

Messages

message id occurrences
unspecified-encoding 51
missing-function-docstring 35
trailing-whitespace 24
line-too-long 18
redefined-outer-name 10
f-string-without-interpolation 8
wrong-import-order 2
consider-using-in 2
broad-exception-caught 2
unused-variable 1
too-many-nested-blocks 1
too-many-branches 1
superfluous-parens 1
subprocess-run-check 1
missing-module-docstring 1
invalid-name 1
consider-using-with 1
bad-indentation 1

Your code has been rated at 6.92/10 (previous run: 6.92/10, +0.00)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.