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

Fix bug where encoding setting in .sqlfluff file was not being respected #3170

Conversation

barrywhart
Copy link
Member

@barrywhart barrywhart commented Apr 24, 2022

Brief summary of the change made

Fixes #3157

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.

@@ -1256,44 +1256,40 @@ def test_encoding(encoding_in, encoding_out):
)


def test_cli_pass_on_correct_encoding_argument():
Copy link
Member Author

Choose a reason for hiding this comment

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

Replaced two tests that were testing the --encoding command-line parameter with a single parametrized test which does the same but also tests setting encoding in the .sqlfluff config file.

@@ -247,7 +247,7 @@ def core_options(f: Callable) -> Callable:
)(f)
f = click.option(
"--encoding",
default="autodetect",
default=None,
Copy link
Member Author

Choose a reason for hiding this comment

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

Providing an explicit default value of "autodetect" was causing any setting in .sqlfluff to be overridden by the command-line value. (You'll note that elsewhere in this file, command-line options that override .sqlfluff values already had a default value of None.)

@codecov
Copy link

codecov bot commented Apr 24, 2022

Codecov Report

Merging #3170 (52b6163) into main (6c026c7) will not change coverage.
The diff coverage is n/a.

@@            Coverage Diff            @@
##              main     #3170   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          166       166           
  Lines        12341     12341           
=========================================
  Hits         12341     12341           
Impacted Files Coverage Δ
src/sqlfluff/cli/commands.py 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 6c026c7...52b6163. Read the comment docs.

Comment on lines +1262 to +1265
("utf-8", "command-line", False),
("utf-8-SIG", "command-line", True),
("utf-8", "config-file", False),
("utf-8-SIG", "config-file", True),
Copy link
Member

Choose a reason for hiding this comment

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

For completeness we could add the following, as capitalisation seems to be irrelevant:

Suggested change
("utf-8", "command-line", False),
("utf-8-SIG", "command-line", True),
("utf-8", "config-file", False),
("utf-8-SIG", "config-file", True),
("utf-8", "command-line", False),
("UTF-8", "command-line", False),
("utf-8-sig", "command-line", True),
("UTF-8-SIG", "command-line", True),
("utf-8-SIG", "command-line", True),
("utf-8", "config-file", False),
("UTF-8", "config-file", False),
("utf-8-sig", "config-file", True),
("UTF-8-SIG", "config-file", True),
("utf-8-SIG", "config-file", True),

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense, but I think I'll omit it for now, as encoding is something SQLFluff doesn't really process, it mainly relies on the chardet package and Python built-ins like file, etc.

@barrywhart barrywhart merged commit 3793f35 into sqlfluff:main Apr 25, 2022
@tunetheweb tunetheweb changed the title Fix bug where "encoding" setting in .sqlfluff file was not being respected Fix bug where encoding setting in .sqlfluff file was not being respected May 3, 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.

Commented dash character converted to non utf-8 character
2 participants