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

Add Python language support and fix processors intialization #5

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

Dectinc
Copy link

@Dectinc Dectinc commented Oct 28, 2019

Feature:

  • general comment block filter and Python multiline docstrings filter
  • sharp("#") comment filter for Python
  • Python processor

Update:

  • move filters to another package named filters

Fix:

  • processor initialization

filters was a class property of FilterProcessorBase and not re-defined in subclassess. In each subclass, some filters were appended to this class property, led to all subclasses shared the class property from their base class but using their own.

`filters` 是基类 `FilterProcessorBase` 的一个类属性, 但是并没有在各子类中重新定义,
而是在子类的初始化方法中添加元素;而且子类均没有调用基类的初始化方法。
这导致每一个子类最终的 `filter` 属性都包含所有被添加过的 filter,与预期行为应该是不一致的。

originally

class FileProcessorBase(object):
    """ Base class for file processors. The processor for each lanuage should inherit from this class.
    """
    expected_extensions = []
    filters = []

    def __init__(self):
        # by default, processors of all languages will always starts with a blank line filter
        self.filters.append(BlankLineFilter())
        return

class JsProcessor(FileProcessorBase):
    expected_extensions = ['.js', '.jsx', '.vue']
    expected_extensions = ['.js', '.jsx', '.vue', '.wpy']

    def __init__(self):
        self.filters.append(BlankLineFilter())
        self.filters.append(CStyleCommentBlockFilter())
        self.filters.append(DoubleSlashCommentFilter())
        return

fixed

class FileProcessorBase(object):
    """ Base class for file processors. The processor for each lanuage should inherit from this class.
    """
    expected_extensions = []

    def __init__(self):
        # by default, processors of all languages will always starts with a blank line filter
        self.filters = []
        self.filters.append(BlankLineFilter())
        return

class JsProcessor(FileProcessorBase):
    expected_extensions = ['.js', '.jsx', '.vue', '.wpy']

    def __init__(self):
        super().__init__()
        self.filters.append(CStyleCommentBlockFilter())
        self.filters.append(DoubleSlashCommentFilter())

@huandzh
Copy link

huandzh commented Dec 2, 2020

Hi, @Dectinc. Thanks for your contribution.

But it fails when comments start with just a line-break. See fix in PR Dectinc#1.

Would you kindly merge it into this PR if it is possible.

Python comments started with line-break will not be removed
@Dectinc
Copy link
Author

Dectinc commented Dec 2, 2020

Hi, @Dectinc. Thanks for your contribution.

But it fails when comments start with just a line-break. See fix in PR Dectinc#1.

Would you kindly merge it into this PR if it is possible.

Thanks, merged.

@huandzh
Copy link

huandzh commented Dec 3, 2020

Thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants