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 ignore_words_regex configuration option #3098

Merged
merged 17 commits into from
Apr 15, 2022

Conversation

dmohns
Copy link
Contributor

@dmohns dmohns commented Apr 14, 2022

Brief summary of the change made

Fixes #3089

I added this to all rules that are based on L010, but this does not cover all rules that have the ignore_words option.

Are there any other side effects of this change that we should be aware of?

Pull Request checklist

  • Please confirm you have completed any of the necessary steps below.

  • Included test cases to demonstrate any code changes, which may be one or more of the following:

    • .yml rule test cases in test/fixtures/rules/std_rule_cases.
    • .sql/.yml parser test cases in test/fixtures/dialects (note YML files can be auto generated with tox -e generate-fixture-yml).
    • Full autofix test cases in test/fixtures/linter/autofix.
    • Other.
  • Added appropriate documentation for the change.

  • Created GitHub issues for any relevant followup/future enhancements if appropriate.

@codecov
Copy link

codecov bot commented Apr 14, 2022

Codecov Report

Merging #3098 (f096ca8) into main (aa704c4) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main     #3098   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          164       164           
  Lines        12168     12184   +16     
=========================================
+ Hits         12168     12184   +16     
Impacted Files Coverage Δ
src/sqlfluff/core/rules/config_info.py 100.00% <ø> (ø)
src/sqlfluff/rules/L014.py 100.00% <ø> (ø)
src/sqlfluff/rules/L030.py 100.00% <ø> (ø)
src/sqlfluff/rules/L063.py 100.00% <ø> (ø)
src/sqlfluff/rules/L010.py 100.00% <100.00%> (ø)
src/sqlfluff/rules/L029.py 100.00% <100.00%> (ø)
src/sqlfluff/rules/L057.py 100.00% <100.00%> (ø)
src/sqlfluff/rules/L059.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update aa704c4...f096ca8. Read the comment docs.

@tunetheweb
Copy link
Member

I added this to all rules that are based on L010, but this does not cover all rules that have the ignore_words option.

I think this is confusing, and think we should ensure it's available everywhere ignore_words is. It's a little extra work, but not too much.

src/sqlfluff/rules/L010.py Outdated Show resolved Hide resolved
@dmohns
Copy link
Contributor Author

dmohns commented Apr 14, 2022

While working on writing the tests I stumbled upon one small thing.

I am using regex.match() to apply the regex. However, maybe the way match works is unintuitive to users not too familiar with Python internals.

For example

>>> print(regex.match("hash$", "aliashash"))
None
>>> print(regex.match("^alias", "aliashash"))
<regex.Match object; span=(0, 5), match='alias'>

Would it be more suitable to use regex.search here?

@tunetheweb
Copy link
Member

regex.search seems more sensible to me, but not a python expert here.

@barrywhart @WittierDinosaur any thoughts or concerns here?

Obviously there is a risk of someone slowing down SQLFluff with a really complex regex, but I think given it will only be applied to small identifiers, and that this is configured by the user, I'm OK with that. I presume python does exit early if it's not set, in code like this and won't actually execute the regex in this instance?:

        if self.ignore_words_regex and regex.match(
            self.ignore_words_regex, context.segment.raw
        ):

Copy link
Member

@tunetheweb tunetheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Would still be good to get @barrywhart and @WittierDinosaur 's view if they get a chance so won't merge yet.

@tunetheweb
Copy link
Member

This good to merge now?

Copy link
Member

@barrywhart barrywhart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@tunetheweb tunetheweb merged commit fccae14 into sqlfluff:main Apr 15, 2022
@tunetheweb tunetheweb changed the title L010: Add ignore_words_regex configuration option Add ignore_words_regex configuration option Apr 19, 2022
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.

Provide more flexible way of defining ignore_words for rules
3 participants