Skip to content

Commit

Permalink
Merge branch 'master' into bhart-add_sqlfluff_format
Browse files Browse the repository at this point in the history
  • Loading branch information
Barry Hart committed Mar 19, 2024
2 parents 8219043 + 35238c5 commit 9b159ff
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 43 deletions.
20 changes: 11 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,24 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Install Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: 16.x
node-version: 20.x
- run: npm install
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.7
python-version: 3.8
- name: Install sqlfluff
run: pip install sqlfluff
- name: Run tests
uses: GabrielBB/xvfb-action@v1.2
with:
run: npm test
- name: Run Tests (Linux)
run: xvfb-run -a npm test
if: runner.os == 'Linux'
- name: Run Tests (Non-Linux)
run: npm test
if: runner.os != 'Linux'
- name: Publish
if: success() && startsWith(github.ref, 'refs/tags/') && matrix.os == 'ubuntu-latest'
run: npm run deploy
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -54,7 +54,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -68,4 +68,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to the "sqlfluff" extension will be documented in this file.

## [3.0.0] - 2024-03-13

- Update for sqlfluff version 3.0.0.
- Add Vertica dialect.
- Removed `--force` from `fix` as it is the default for >= 3.0.0.

## [2.4.4] - 2023-09-12

- Switch DBT Osmosis to DBT Core Interface. Thanks to BAntonellini's [Pull Request](https://github.com/sqlfluff/vscode-sqlfluff/pull/111)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ DBT setup requires these settings to lint and format the document.

### Format file

By default you will be able use SQLFluff fix your file by formatting. Same as calling `sqlfluff fix --force <path>`
By default you will be able use SQLFluff fix your file by formatting. Same as calling `sqlfluff fix <path>`

![plugin configuration](./media/format_config.gif)

Expand Down
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vscode-sqlfluff",
"displayName": "sqlfluff",
"version": "2.4.4",
"version": "3.0.0",
"description": "A linter and auto-formatter for SQLfluff, a popular linting tool for SQL and dbt.",
"publisher": "dorzey",
"icon": "images/icon.png",
Expand Down Expand Up @@ -127,8 +127,7 @@
"exasol",
"greenplum",
"hive",
"materializ",
"e",
"materialize",
"mysql",
"oracle",
"postgres",
Expand All @@ -138,7 +137,8 @@
"sparksql",
"sqlite",
"teradata",
"tsql"
"tsql",
"vertica"
],
"default": "",
"description": "The dialect of SQL to lint."
Expand Down Expand Up @@ -259,7 +259,7 @@
"sqlfluff.format.arguments": {
"type": "array",
"default": [],
"markdownDescription": "This is useful for setting extra arguments for the `sqlfluff fix` command."
"markdownDescription": "This is useful for setting extra arguments for the `sqlfluff fix` command. Include `--force` if running sqlfluff < 3.0.0."
},
"sqlfluff.format.enabled": {
"type": "boolean",
Expand Down Expand Up @@ -432,7 +432,6 @@
"node-fetch": "^2.6.7"
},
"devDependencies": {
"@types/glob": "^8.1.0",
"@types/mocha": "^10.0.1",
"@types/node": "^20.4.2",
"@types/node-fetch": "^2.6.4",
Expand All @@ -449,8 +448,8 @@
"glob": "^10.3.3",
"mocha": "^10.2.0",
"typescript": "^5.1.6",
"vsce": "^2.15.0",
"vscode-dts": "^0.3.3",
"vscode-test": "^1.6.1"
"@vscode/vsce": "^2.15.0",
"@vscode/dts": "^0.4.0",
"@vscode/test-electron": "^2.3.9"
}
}
2 changes: 1 addition & 1 deletion src/features/helper/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ export default class Configuration {
}

public static formatFileArguments(): string[] {
const extraArguments = [...this.fixArguments(), "--force"];
const extraArguments = [...this.fixArguments()];

return extraArguments;
}
Expand Down
10 changes: 6 additions & 4 deletions src/features/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ export default class LinterProvider implements Linter {

filePath.violations.forEach((violation: Violation) => {
const path = filePath.filepath;
const line = violation.line_no - 1 > 0 ? violation.line_no - 1 : 0;
const character = violation.line_pos - 1 > 0 ? violation.line_pos - 1 : 0;
const violationPosition = new vscode.Position(line, character);
let range = new vscode.Range(line, character, line, character);
const start_line_no = Math.max(0, (violation.line_no ?? violation.start_line_no ?? 1) - 1);
const start_line_pos = Math.max(0, (violation.line_pos ?? violation.start_line_pos ?? 1) - 1);
const end_line_no = Math.max(0, (violation.line_no ?? violation.end_line_no ?? 1) - 1);
const end_line_pos = Math.max(0, (violation.line_pos ?? violation.end_line_pos ?? 1) - 1);
const violationPosition = new vscode.Position(start_line_no, start_line_pos);
let range = new vscode.Range(start_line_no, start_line_pos, end_line_no, end_line_pos);

if (editor) {
const editorPath = Utilities.normalizePath(editor.document.fileName);
Expand Down
8 changes: 6 additions & 2 deletions src/features/providers/linter/types/violation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
export default interface Violation {
line_no: number,
line_pos: number,
line_no?: number,
line_pos?: number,
start_line_no?: number,
start_line_pos?: number,
end_line_no?: number,
end_line_pos?: number,
description: string,
code: string,
}
6 changes: 4 additions & 2 deletions test/runTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { runTests } from "@vscode/test-electron";
import * as path from "path";
import { runTests } from "vscode-test";

const main = async () => {
try {
Expand All @@ -11,8 +11,10 @@ const main = async () => {
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, "./suite/index");

const launchArgs = [path.resolve(__dirname)]

// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath });
await runTests({ extensionDevelopmentPath, extensionTestsPath, launchArgs });
} catch (err) {
console.error("Failed to run tests");
process.exit(1);
Expand Down
17 changes: 7 additions & 10 deletions test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,34 @@ suite("Extension Test Suite", () => {

}).timeout(TIMEOUT);

// TODO: Fix Tests
/*
test("Bad SQL should have the correct diagnostics", async () => {
const documentUri = Helper.getDocumentUri("/test_sql/bad.sql");
const documentUri = Helper.getDocumentUri("/test_sql/diagnostics.sql");
await Helper.activate(documentUri);

const actualDiagnostics = vscode.languages.getDiagnostics(documentUri);

assert.strictEqual(actualDiagnostics.length, 2);
[
{ range: Helper.toRange(1, 11, 1, 10), message: "Keywords must be consistently upper case.", code: "CP01" },
{ range: Helper.toRange(2, 1, 2, 1), message: "Files must end with a single trailing newline.", code: "LT12" },
{ range: Helper.toRange(1, 0, 1, 4), message: "Keywords must be upper case.", code: "CP01" },
{ range: Helper.toRange(1, 5, 1, 12), message: "Files must end with a single trailing newline.", code: "LT12" },
].forEach((expectedDiagnostic, i) => {
assertDiagnosticIsEqual(actualDiagnostics[i], expectedDiagnostic);
});
}).timeout(TIMEOUT);

test("Bad SQL has zero diagnostics after document format", async () => {
const documentUri = Helper.getDocumentUri("/test_sql/format.sql");
// const document = await Helper.activate(documentUri);
// const preFormatDiagnostics = vscode.languages.getDiagnostics(documentUri);
// assert.strictEqual(preFormatDiagnostics.length, 1, "Pre-format diagnostics not expected length");
const document = await Helper.activate(documentUri);
const preFormatDiagnostics = vscode.languages.getDiagnostics(documentUri);
assert.strictEqual(preFormatDiagnostics.length, 1, "Pre-format diagnostics not expected length");

await Helper.format(documentUri);
// await Helper.activate(documentUri);
await Helper.activate(documentUri);

const postFormatDiagnostics = vscode.languages.getDiagnostics(documentUri);
assert.strictEqual(postFormatDiagnostics.length, 0, "Post-format diagnostics not expected length");

}).timeout(TIMEOUT);
*/

const assertDiagnosticIsEqual = (actual: vscode.Diagnostic, expected: { range: any; message: any; code: any; }) => {
assert.deepStrictEqual(actual.range, expected.range);
Expand Down
4 changes: 3 additions & 1 deletion test/suite/helper.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import * as assert from "assert";
import * as vscode from "vscode";

export const SLEEP_TIME = 10000;

export const activate = async (documentUri: vscode.Uri): Promise<vscode.TextDocument | undefined> => {
// The extensionId is `publisher.name` from package.json
const extension = vscode.extensions.getExtension("vscode-sqlfluff");
const extension = vscode.extensions.getExtension("dorzey.vscode-sqlfluff");
assert.notStrictEqual(extension, undefined);
await extension?.activate();
try {
await vscode.commands.executeCommand("workbench.action.closeActiveEditor");
Expand Down
2 changes: 2 additions & 0 deletions test/suite/test_sql/diagnostics.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT a
from a_table;
File renamed without changes.

0 comments on commit 9b159ff

Please sign in to comment.