documentation icon indicating copy to clipboard operation
documentation copied to clipboard

add documentation how to use the annontation bear as a dependency

Open hwmrocker opened this issue 9 years ago • 10 comments

I don't have the time to do it myself, but i want to give you what i build during the pycon.

from coalib.bears.LocalBear import LocalBear
from bears.general.AnnotationBear import AnnotationBear
from collections import deque
from coalib.results.Diff import Diff
from coalib.results.Result import RESULT_SEVERITY, Result


class UpperCaseBear(LocalBear):

    BEAR_DEPS = {AnnotationBear}

    def run(self, filename, file, dependency_results):
        results = dependency_results[AnnotationBear.name]
        strings = deque()

        for result in results:
            if result.start.line == result.end.line:
                # we only support single line strings
                strings.extend(result.contents["strings"])
        if not strings:
            return
        next_str = strings.popleft()

        for line_number, line in enumerate(file, start=1):
            if line_number < next_str.start.line:
                continue
            while next_str.start.line == line_number:
                s, e = next_str.start.column - 1, next_str.end.column
                word = line[s:e]
                if word.upper() != word:
                    diff = Diff(file)
                    diff.change_line(
                        line_number,
                        line,
                        line[:s] + word.upper() + line[e:])
                    diffs = {filename: diff}
                    yield Result.from_values(
                        origin=self,
                        message="change to upper",
                        file=filename,
                        line=line_number,
                        column=s,
                        end_line=line_number,
                        end_column=e,
                        severity=RESULT_SEVERITY.INFO,
                        diffs=diffs)
                if not strings:
                    break
                next_str = strings.popleft()

hwmrocker avatar Nov 04 '16 09:11 hwmrocker

it makes all your strings upper case?

sils avatar Nov 04 '16 09:11 sils

didn't you work on this quoting thing or was that someone else? What is not working, what could have gone better?

sils avatar Nov 04 '16 09:11 sils

yes, i wanted to the strings quotation stuff, but there are still some open questions when i need to consider.

  • other languages like c use ' for single chars and " for strings
  • how are strings like r'test\foo', b'bla', u'täst' or s'test' treated?
  • how to add a sane language specific config

this code gives you the single line words including the quotes. But i didn't check if the annotation bear consider the string type (r,u,s,b) as part of the string or not.

hwmrocker avatar Nov 04 '16 09:11 hwmrocker

I'm pretty sure it just ignores rusb and such

sils avatar Nov 04 '16 09:11 sils

in this case, this needed to be checked in the bear if we are processing python code

hwmrocker avatar Nov 04 '16 09:11 hwmrocker

this mght be interesting to @underyx

sils avatar Nov 04 '16 12:11 sils

we probably want to just link to the quotation bear and make a minimal example

sils avatar Nov 14 '16 14:11 sils

quotation bear PR: https://github.com/coala/coala-bears/pull/992/

sils avatar Nov 14 '16 14:11 sils

is this still needed now that we have quotes bear or?

Adrianzatreanu avatar Feb 02 '17 17:02 Adrianzatreanu

we still need docs for the annotationbear but it shouldn't be in this repo but rather right in the doc comment of the bears

Sincerely,

Lasse Schuirmann

[email protected] http://coala.io/ - http://viperdev.io/ - http://gitmate.com/

On 2 February 2017 at 18:29, Zatreanu Adrian-Gabriel < [email protected]> wrote:

is this still needed now that we have quotes bear or?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/coala/documentation/issues/272#issuecomment-277024683, or mute the thread https://github.com/notifications/unsubscribe-auth/AFc6KNeeDlAFwW_wvQoyN2FtfpjACAJFks5rYhJygaJpZM4KpV0P .

sils avatar Feb 02 '17 20:02 sils