Koray08
November 22, 2023, 1:07pm
1
Is there any way of creating a linter for python?
marijn
November 22, 2023, 4:00pm
2
You’d have to find some kind of Python linter that can run in the browser, wrap it to convert the diagnostics it outputs to the format CodeMirror expects, wrap it with linter
, and use it as an extension.
1 Like
vsh
July 13, 2024, 6:14pm
3
I faced this need while working on ViperIDE .
It turned out to be much easier than I anticipated, thanks to WebAssembly and the Ruff Python linter.
const ruffLinter = linter((view) => {
const doc = view.state.doc
const res = ruffWorkspace.check(doc.toString())
const diagnostics = []
for (let d of res) {
diagnostics.push({
from: doc.line(d.location.row).from + d.location.column - 1,
to: doc.line(d.end_location.row).from + d.end_location.column - 1,
severity: (d.message.indexOf('Error:') >= 0) ? 'error' : 'warning',
message: d.code ? d.code + ': ' + d.message : d.message,
})
}
return diagnostics
})
Result:
1 Like