Skip to content

Commit

Permalink
Fix issue with file matching and linting invalid files
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertOstermann committed Mar 23, 2023
1 parent c6cec6a commit 2864460
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/features/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class LinterProvider implements Linter {
return provider;
}

public process(lines: string[]): FileDiagnostic[] {
public process(lines: string[], documentPath: string): FileDiagnostic[] {
const editor = vscode.window.activeTextEditor;
const diagnostics: FileDiagnostic[] = [];

Expand Down Expand Up @@ -51,7 +51,7 @@ export default class LinterProvider implements Linter {

if (editor) {
const editorPath = Utilities.normalizePath(editor.document.fileName);
if (editorPath.includes(path) || path === "stdin") {
if (editorPath.includes(documentPath) || path === "stdin") {
range = editor.document.getWordRangeAtPosition(violationPosition) || range;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/features/providers/formatter/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export class FormattingProvider {
const workingDirectory = Configuration.workingDirectory(rootPath);
const textEdits: vscode.TextEdit[] = [];

if (workingDirectory?.includes("${")) {
return [];
}

Utilities.appendHyphenatedLine();
Utilities.outputChannel.appendLine(`Format triggered for ${filePath}`);

Expand Down
14 changes: 10 additions & 4 deletions src/features/providers/linter/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ export default class LintingProvider {
return;
}

if (workingDirectory?.includes("${")) {
return;
}

const args: string[] = [...Configuration.lintFileArguments()];
const options: CommandOptions = { filePath: filePath };

Expand Down Expand Up @@ -149,21 +153,23 @@ export default class LintingProvider {

let fileDiagnostics: FileDiagnostic[] = [];
if (result.lines?.length > 0) {
fileDiagnostics = this.linter.process(result.lines);
fileDiagnostics = this.linter.process(result.lines, filePath);

if (fileDiagnostics.length === 0 && document) {
this.diagnosticCollection.set(document.uri, []);
return;
}

fileDiagnostics.forEach(async (fileDiagnostic) => {
const filePath = document ? Utilities.normalizePath(document.fileName) : undefined;

try {
if (document && fileDiagnostic.filePath === "stdin") {
this.diagnosticCollection.set(document.uri, fileDiagnostic.diagnostics);
return;
}
const fileGlob = "**/" + fileDiagnostic.filePath;
const files = await vscode.workspace.findFiles(fileGlob, undefined, 1);
const file = files.length > 0 ? files[0].fsPath : Utilities.normalizePath(fileDiagnostic.filePath);

const file = filePath ? filePath : Utilities.normalizePath(fileDiagnostic.filePath);
if (file) {
const uri = vscode.Uri.file(file);
this.diagnosticCollection.set(uri, fileDiagnostic.diagnostics);
Expand Down
2 changes: 1 addition & 1 deletion src/features/providers/linter/types/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import FileDiagnostic from "./fileDiagnostic";

export default interface Linter {
languageId: Array<string>,
process: (output: string[]) => FileDiagnostic[];
process: (lines: string[], filePath: string) => FileDiagnostic[];
}
4 changes: 2 additions & 2 deletions test/.sqlfluff
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[sqlfluff]
dialect = postgres

[sqlfluff:rules:L010]
[sqlfluff:rules:capitalisation.keywords]
capitalisation_policy = upper

[sqlfluff:rules:L014]
[sqlfluff:rules:capitalisation.identifiers]
extended_capitalisation_policy = lower
1 change: 1 addition & 0 deletions test/target/suite/test_sql/bad.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT a from a_table;

0 comments on commit 2864460

Please sign in to comment.