diff --git a/linters/detekt/detekt.test.ts b/linters/detekt/detekt.test.ts index bf7711ea0..7f492b426 100644 --- a/linters/detekt/detekt.test.ts +++ b/linters/detekt/detekt.test.ts @@ -51,6 +51,8 @@ const gradlePreCheck: TestCallback = (driver) => { - name: JAVA_HOME value: ${javaPath} optional: false + - name: PATH + list: ["\${env.PATH}"] `); driver.writeFile(trunkYamlPath, finalContents); // trunk-ignore-end(semgrep) diff --git a/linters/sqlfluff/plugin.yaml b/linters/sqlfluff/plugin.yaml index bbb3a4f54..f4a7a12d3 100644 --- a/linters/sqlfluff/plugin.yaml +++ b/linters/sqlfluff/plugin.yaml @@ -14,6 +14,8 @@ lint: known_good_version: 1.4.5 direct_configs: - .sqlfluff + affects_cache: + - pyproject.toml suggest_if: config_present commands: - name: lint diff --git a/linters/sqlfluff/sqlfluff_to_sarif.py b/linters/sqlfluff/sqlfluff_to_sarif.py index 5f76f74be..39346337f 100755 --- a/linters/sqlfluff/sqlfluff_to_sarif.py +++ b/linters/sqlfluff/sqlfluff_to_sarif.py @@ -2,11 +2,26 @@ import json import sys +from typing import Optional def to_result_sarif( - path: str, line_number: int, column_number: int, rule_id: str, message: str + path: str, + start_line_number: int, + start_column_number: int, + end_line_number: Optional[int], + end_column_number: Optional[int], + rule_id: str, + message: str, ): + region = { + "startLine": start_line_number, + "startColumn": start_column_number, + } + if end_line_number is not None and end_column_number is not None: + region["endLine"] = end_line_number + region["endColumn"] = end_column_number + return { "level": "error", "locations": [ @@ -15,10 +30,7 @@ def to_result_sarif( "artifactLocation": { "uri": path, }, - "region": { - "startColumn": column_number, - "startLine": line_number, - }, + "region": region, } } ], @@ -36,13 +48,27 @@ def main(argv): for result in sqlfluff_json: filepath = result["filepath"] for violation in result["violations"]: - line_number = violation["line_no"] - column_number = violation["line_pos"] + # In sqlfluff 3.0.0, line_no/line_pos replaced with start_*/end_* + start_line_number = violation.get("start_line_no", violation.get("line_no")) + start_column_number = violation.get( + "start_line_pos", violation.get("line_pos") + ) + end_line_number = violation.get("end_line_no") + end_column_number = violation.get("end_line_pos") + rule_id = violation["code"] message = violation["description"] results.append( - to_result_sarif(filepath, line_number, column_number, rule_id, message) + to_result_sarif( + filepath, + start_line_number, + start_column_number, + end_line_number, + end_column_number, + rule_id, + message, + ) ) sarif = { diff --git a/linters/sqlfluff/test_data/sqlfluff_v3.0.0_basic_check.check.shot b/linters/sqlfluff/test_data/sqlfluff_v3.0.0_basic_check.check.shot new file mode 100644 index 000000000..7e9228016 --- /dev/null +++ b/linters/sqlfluff/test_data/sqlfluff_v3.0.0_basic_check.check.shot @@ -0,0 +1,244 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Testing linter sqlfluff test basic_check 1`] = ` +{ + "issues": [ + { + "code": "AM04", + "column": "1", + "file": "test_data/basic_check.in.sql", + "issueClass": "ISSUE_CLASS_EXISTING", + "level": "LEVEL_HIGH", + "line": "1", + "linter": "sqlfluff", + "message": "Query produces an unknown number of result columns.", + "ranges": [ + { + "filePath": "test_data/basic_check.in.sql", + "length": "49", + }, + ], + "targetType": "sql", + }, + { + "code": "CP01", + "column": "1", + "file": "test_data/basic_check.in.sql", + "issueClass": "ISSUE_CLASS_EXISTING", + "level": "LEVEL_HIGH", + "line": "1", + "linter": "sqlfluff", + "message": "Keywords must be consistently upper case.", + "ranges": [ + { + "filePath": "test_data/basic_check.in.sql", + "length": "6", + }, + ], + "targetType": "sql", + }, + { + "code": "LT09", + "column": "1", + "file": "test_data/basic_check.in.sql", + "issueClass": "ISSUE_CLASS_EXISTING", + "level": "LEVEL_HIGH", + "line": "1", + "linter": "sqlfluff", + "message": "Select targets should be on a new line unless there is only one select target.", + "ranges": [ + { + "filePath": "test_data/basic_check.in.sql", + "length": "26", + }, + ], + "targetType": "sql", + }, + { + "code": "AL03", + "column": "12", + "file": "test_data/basic_check.in.sql", + "issueClass": "ISSUE_CLASS_EXISTING", + "level": "LEVEL_HIGH", + "line": "1", + "linter": "sqlfluff", + "message": "Column expression without alias. Use explicit \`AS\` clause.", + "ranges": [ + { + "filePath": "test_data/basic_check.in.sql", + "length": "1", + "offset": "11", + }, + ], + "targetType": "sql", + }, + { + "code": "CP01", + "column": "20", + "file": "test_data/basic_check.in.sql", + "issueClass": "ISSUE_CLASS_EXISTING", + "level": "LEVEL_HIGH", + "line": "1", + "linter": "sqlfluff", + "message": "Keywords must be consistently upper case.", + "ranges": [ + { + "filePath": "test_data/basic_check.in.sql", + "length": "2", + "offset": "19", + }, + ], + "targetType": "sql", + }, + { + "code": "LT01", + "column": "22", + "file": "test_data/basic_check.in.sql", + "issueClass": "ISSUE_CLASS_EXISTING", + "level": "LEVEL_HIGH", + "line": "1", + "linter": "sqlfluff", + "message": "Expected only single space before naked identifier. Found ' '.", + "ranges": [ + { + "filePath": "test_data/basic_check.in.sql", + "length": "2", + "offset": "21", + }, + ], + "targetType": "sql", + }, + { + "code": "CP02", + "column": "24", + "file": "test_data/basic_check.in.sql", + "issueClass": "ISSUE_CLASS_EXISTING", + "level": "LEVEL_HIGH", + "line": "1", + "linter": "sqlfluff", + "message": "Unquoted identifiers must be consistently lower case.", + "ranges": [ + { + "filePath": "test_data/basic_check.in.sql", + "length": "3", + "offset": "23", + }, + ], + "targetType": "sql", + }, + { + "code": "LT01", + "column": "27", + "file": "test_data/basic_check.in.sql", + "issueClass": "ISSUE_CLASS_EXISTING", + "level": "LEVEL_HIGH", + "line": "1", + "linter": "sqlfluff", + "message": "Expected only single space before 'from' keyword. Found ' '.", + "ranges": [ + { + "filePath": "test_data/basic_check.in.sql", + "length": "2", + "offset": "26", + }, + ], + "targetType": "sql", + }, + { + "code": "CP01", + "column": "29", + "file": "test_data/basic_check.in.sql", + "issueClass": "ISSUE_CLASS_EXISTING", + "level": "LEVEL_HIGH", + "line": "1", + "linter": "sqlfluff", + "message": "Keywords must be consistently upper case.", + "ranges": [ + { + "filePath": "test_data/basic_check.in.sql", + "length": "4", + "offset": "28", + }, + ], + "targetType": "sql", + }, + { + "code": "CP02", + "column": "34", + "file": "test_data/basic_check.in.sql", + "issueClass": "ISSUE_CLASS_EXISTING", + "level": "LEVEL_HIGH", + "line": "1", + "linter": "sqlfluff", + "message": "Unquoted identifiers must be consistently lower case.", + "ranges": [ + { + "filePath": "test_data/basic_check.in.sql", + "length": "8", + "offset": "33", + }, + ], + "targetType": "sql", + }, + { + "code": "CP02", + "column": "43", + "file": "test_data/basic_check.in.sql", + "issueClass": "ISSUE_CLASS_EXISTING", + "level": "LEVEL_HIGH", + "line": "1", + "linter": "sqlfluff", + "message": "Unquoted identifiers must be consistently lower case.", + "ranges": [ + { + "filePath": "test_data/basic_check.in.sql", + "length": "7", + "offset": "42", + }, + ], + "targetType": "sql", + }, + { + "code": "LT01", + "column": "7", + "file": "test_data/basic_check.in.sql", + "issueClass": "ISSUE_CLASS_EXISTING", + "level": "LEVEL_HIGH", + "line": "1", + "linter": "sqlfluff", + "message": "Expected only single space before star '*'. Found ' '.", + "ranges": [ + { + "filePath": "test_data/basic_check.in.sql", + "length": "2", + "offset": "6", + }, + ], + "targetType": "sql", + }, + ], + "lintActions": [ + { + "command": "lint", + "fileGroupName": "sql", + "linter": "sqlfluff", + "paths": [ + "test_data/basic_check.in.sql", + ], + "verb": "TRUNK_VERB_CHECK", + }, + { + "command": "lint", + "fileGroupName": "sql", + "linter": "sqlfluff", + "paths": [ + "test_data/basic_check.in.sql", + ], + "upstream": true, + "verb": "TRUNK_VERB_CHECK", + }, + ], + "taskFailures": [], + "unformattedFiles": [], +} +`; diff --git a/linters/sqlfluff/test_data/sqlfluff_v3.0.0_basic_fmt.fmt.shot b/linters/sqlfluff/test_data/sqlfluff_v3.0.0_basic_fmt.fmt.shot new file mode 100644 index 000000000..c29cb0da2 --- /dev/null +++ b/linters/sqlfluff/test_data/sqlfluff_v3.0.0_basic_fmt.fmt.shot @@ -0,0 +1,15 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Testing formatter sqlfluff test basic_fmt 1`] = ` +"SELECT + col_a, + col_b, + COUNT(*) AS num, + SUM(num) OVER ( + PARTITION BY col_a + ORDER BY col_b + ) AS an_aggregate_function +FROM tbl_a +GROUP BY 1, 2 +" +`; diff --git a/runtimes/node/plugin.yaml b/runtimes/node/plugin.yaml index 0c1e72d59..09657f4b5 100644 --- a/runtimes/node/plugin.yaml +++ b/runtimes/node/plugin.yaml @@ -44,6 +44,9 @@ runtimes: - name: NODE_OPTIONS value: ${env.NODE_OPTIONS} optional: true + - name: NPM_CONFIG_USERCONFIG + value: ${env.NPM_CONFIG_USERCONFIG} + optional: true linter_environment: - name: PATH list: ["${linter}/node_modules/.bin"]