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

linter bear adds newline at end of file in process_output #6083

Open
surgura opened this issue Oct 11, 2019 · 3 comments · May be fixed by #6170
Open

linter bear adds newline at end of file in process_output #6083

surgura opened this issue Oct 11, 2019 · 3 comments · May be fixed by #6170
Assignees

Comments

@surgura
Copy link

surgura commented Oct 11, 2019

Overview Description

A custom bear and providing your own process_output does not result in the correct file parameter, when the file in question does not end in a newline; the newline is added by the linter class.

This is problematic for a bear that adds a newline at the end of a file.

Steps to Reproduce

  1. Create a bear that prints the provided file contents and also the actual file contents
from coalib.bearlib.abstractions.Linter import linter

@linter(executable='echo', # we use echo to print some random output to force usage of process_output
        output_format=None
        )

class TestBear:
    @staticmethod
    def create_arguments(filename, file, config_file):
        return ["asd"]

    def process_output(self, output, filename=None, file=None):
        contents = ""
        with open(filename) as f:
            for line in f.readlines():
                contents += line
        print("---------")
        print(repr(contents))
        print("---------")
        print(file)            
        print("---------")
  1. Create a file that ends without newline
    printf asd > test.txt

  2. Run the bear and compare

coala -b TestBear -d . -f ./test.txt -I

Actual Results

Executing section cli...
---------
'asd'
---------
('asd\n',)
---------

As you you can see there is an additional newline.

Expected Results

Executing section cli...
---------
'asd'
---------
('asd',)
---------

Reproducibility

Every time

Additional Information:

Actually having the newline in the file results in the output:

Executing section cli...
---------
'asd\n'
---------
('asd\n',)
---------

The newline seems to only be added if there is none present.

@surgura surgura changed the title linter bear adds newline in process_output linter bear adds newline at end of file in process_output Oct 11, 2019
@duddu-coder
Copy link

I'm sending a PR on this one.

@MaskedCarrot
Copy link

hello, I want to work on this issue. But I am new to open source. I have worked in a couple of difficulty/newcomer issue would this be an appropriate issue for me to work on?

@surgura
Copy link
Author

surgura commented Oct 16, 2019

hello, I want to work on this issue. But I am new to open source. I have worked in a couple of difficulty/newcomer issue would this be an appropriate issue for me to work on?

If @duddu-coder is working on this, it seems weird to me to work on the same issue, right?

PrasanthChettri added a commit to PrasanthChettri/coala that referenced this issue Jun 4, 2021
Previously a new line was appened at the end of the last line of the file even,
made it so that coala checks first if a new line is present
at the end of the file before appending the last line

Closes coala#6083
PrasanthChettri added a commit to PrasanthChettri/coala that referenced this issue Jun 4, 2021
Previously a newline was appened at EOF,
made it so that coala checks first if a new line is present
at the end of the file before appending the last line

Closes coala#6083
@PrasanthChettri PrasanthChettri linked a pull request Jun 4, 2021 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants