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

feat: introduce codespell and example linters #1

Merged
merged 1 commit into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions codespell_to_sarif.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python3

import json
import sys

def to_result_sarif(path: str, line_number: int, column_number: int, rule_id: str, message: str):
return {
"level": "error",
"locations": [{
"physicalLocation": {
"artifactLocation": {
"uri": path,
},
"region": {
"startColumn": column_number,
"startLine": line_number,
}
}
}],
"message": {
"text": message,
},
"ruleId": rule_id,
}

# the engrish langauge is easy to mispell

def main(argv):

results = []

for line in sys.stdin.readlines():
filename, line_number, message = line.split(':')
results.append(to_result_sarif(filename, int(line_number), 0, 'misspelled', message.strip()))


sarif = {
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
"version": "2.1.0",
"runs": [{
"results": results
}],
}

print(json.dumps(sarif, indent=2))




if __name__ == '__main__':
main(sys.argv)
12 changes: 12 additions & 0 deletions example_linter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

LINE_NUMBER=0
COLUMN_NUMBER=0
SEVERITY="error"
MESSAGE="example message"
CODE="example-finding"

for PATH in "${BASH_ARGV[@]}"
do
echo "${PATH}:${LINE_NUMBER}:${COLUMN_NUMBER}: [${SEVERITY}] ${MESSAGE} (${CODE})"
done
20 changes: 19 additions & 1 deletion trunk.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
version: 0.1
lint:
definitions:
- name: example
files: [ALL]
commands:
- output: parsable
run: ${actionroot}/example_linter.sh ${target}
success_codes: [0]
read_output_from: stdout
- name: codespell
files: [ALL]
runtime: python
package: codespell
commands:
- output: sarif
run: codespell ${target}
success_codes: [0, 65]
read_output_from: stdout
parser:
runtime: python
run: ${actionroot}/codespell_to_sarif.py
- name: sqlfluff
files: [sql]
runtime: python
Expand All @@ -13,4 +32,3 @@ lint:
parser:
runtime: python
run: ${actionroot}/sqlfluff_to_sarif.py