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

Linting the wrong file #88

Closed
ferdyh opened this issue Mar 22, 2023 · 6 comments
Closed

Linting the wrong file #88

ferdyh opened this issue Mar 22, 2023 · 6 comments

Comments

@ferdyh
Copy link

ferdyh commented Mar 22, 2023

When I run the linter (jinja or dbt) on a project file, the right command is executed, with the right relative path. However, when the command finishes the wrong file is linted. So for example:

models/datamart_a/model.sql (file i created and is used while executing sqlfluff)
target/compiled/projectname/models/datamart_a/model.sql (is linted / shown in Problems tab)

Can't seem to find any setting relating to this problem.

@alanmcruickshank
Copy link
Member

Can you confirm whether this is just an issue of displaying the wrong file name, or whether you're getting unexpected linting errors as a result?

In the background the dbt templater does use the compiled file as part of the input, so I'm not totally suprised that this is happening. It definitely should not be happening if you're using the jinja templater however.

@ferdyh
Copy link
Author

ferdyh commented Mar 22, 2023

When I open the file in the target folder (the one that actually linted), then most of the linting is in the wrong place. It takes a few seconds while sqlfluff is run on the file in the target folder and everything is in order again. So, to answer your question, yes, unexpected linting errors.

All in all it looks a bit random. Sometimes (rarely) it picks the right file. Most of the times its one from the target/compiled or target/run folder.

I first thought it had something todo with the 'sqlfluff.format.enabled = true' setting, however that was just lucky first try.

@ferdyh
Copy link
Author

ferdyh commented Mar 23, 2023

Correct me if i'm wrong, but it looks like the fileGlob for lookup up the file will match any matching part of the path, as long as the end is similar. In my case this is true.

const fileGlob = "**/" + fileDiagnostic.filePath;

**/{filePath} will match all of the cases;
so **/models/datamart_a/model.sql will match:

  • target/compiled/projectname/models/datamart_a/model.sql
  • target/run/projectname/models/datamart_a/model.sql

and on this line results are limited to 1:

const files = await vscode.workspace.findFiles(fileGlob, undefined, 1);

This would explain the randomness of the results. I'd expect a full match on the path here.

@RobertOstermann
Copy link
Contributor

@ferdyh I believe you are correct. I struggled to recreate this unless I switched to the other file while the linting was being processed, which was weird. Either way, definitely a bug. Should be fixed later today in the next version

@RobertOstermann
Copy link
Contributor

@ferdyh Please update to v2.2.5 and let us know if that solves the issue.

@ferdyh
Copy link
Author

ferdyh commented Mar 23, 2023

@RobertOstermann That looks better, thanks!

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

No branches or pull requests

3 participants