sqlfluff icon indicating copy to clipboard operation
sqlfluff copied to clipboard

.sqlfluffignore is case-sensitive

Open mhahn-ts opened this issue 2 years ago • 3 comments

Search before asking

  • [X] I searched the issues and found no similar issues.

What Happened

.sqlfluffignore only ignores files when the full path is an exact case-sensitive match. The actual linter, however, does a case-insensitive search when finding which file to lint. image

Expected Behaviour

I would expect the linter to ignore all 3 commands in my example.

Observed Behaviour

The linter ignored the file when the command contained the exact case-sensitive match. The linter linted the file when the command contained just a case-insensitive match on the file path.

How to reproduce

  • Create a new project folder.
  • In that folder, create a .sqlfluff
[sqlfluff]
dialect = tsql
  • Also create a .sqlfluffignore
database/skip.sql
  • Create a database folder.
  • In the database folder, create a skip.sql
select a, b, c from tab where id = 1
  • Run this command: sqlfluff lint "C:/dev/SQLFluffTesting/database/skip.sql"
  • This command properly skips the file.
  • Run this command: sqlfluff lint "c:/dev/SQLFluffTesting/database/skip.sql"
  • This command lints the file.

Dialect

tsql, but this issue should be unrelated to dialect.

Version

sqlfluff, version 1.4.5 Python 3.10.4

Configuration

.sqlfluffignore

database/skip.sql

.sqlfluff

[sqlfluff]
dialect = tsql

Are you willing to work on and submit a PR to address the issue?

  • [X] Yes I am willing to submit a PR!

Code of Conduct

mhahn-ts avatar Aug 23 '23 15:08 mhahn-ts

Is there anyone working in this already?

mahimairaja avatar Sep 16 '23 03:09 mahimairaja

I haven't started on it yet.

mhahn-ts avatar Sep 18 '23 12:09 mhahn-ts

I've been taking a look at this and I think I've worked out what's going on.

See this SO post for some more details: https://stackoverflow.com/questions/6710511/case-sensitive-path-comparison-in-python

In short, python is slightly unhelpful when it comes to path case-sensitivity. Windows & MacOS are case-insensitive on paths - linux is case sensitive. Depending on whether the path matching routines are delegated to the OS or not controls how the case sensitivity is applied.

There are some similar weird effects when it comes to gitignore files (which is what we've modelled the sqlfluffignore file off) as documented here: https://www.hanselman.com/blog/git-is-casesensitive-and-your-filesystem-may-not-be-weird-folder-merging-on-windows

What that means is that currently the ignore file is being consistently case sensitive on all platforms, but that the file paths are inconsistently handled across platforms to sometimes be case sensitive and sometimes not.

This means on some systems, it would matter whether or not the ignore file was case-sensitive, and therefore if we enable it to be insensitive that would need to be a configuration value somewhere.

Anyone with suggestions on how to do this neatly and be fairly consistent cross platform would be very well received.

alanmcruickshank avatar Aug 08 '24 23:08 alanmcruickshank