Commit 7e6c8ec6 authored by Jérome Perrin's avatar Jérome Perrin

include ruff as linter

parent ec356fc2
[submodule "ruff"]
path = ruff
url = https://github.com/astral-sh/ruff/
...@@ -4,8 +4,12 @@ This code is based on https://github.com/Microsoft/monaco-editor-samples/tree/a9 ...@@ -4,8 +4,12 @@ This code is based on https://github.com/Microsoft/monaco-editor-samples/tree/a9
To build, after cloning this repository: To build, after cloning this repository:
install https://rustwasm.github.io/wasm-pack/installer/
run:
``` ```
npm install npm install
npm run build:wasm
npm run build npm run build
``` ```
......
import 'core-js/actual'; // BBB firefox 68 // import 'core-js/actual'; // BBB firefox 68
import "./public-path.js" import "./public-path.js"
import * as monaco from 'monaco-editor'; import * as monaco from 'monaco-editor';
import init, { Workspace } from "./ruff/crates/ruff_wasm/src/pkg";
/**
* @param {monaco.editor.IEditor} editor
* @param {object} config the config, following https://raw.githubusercontent.com/charliermarsh/ruff/main/ruff.schema.json
* @returns {Disposable}
*/
self.registerRuffDiagnosticProvider = async (editor, config) => {
await init();
const workspace = new Workspace(config)
const model = editor.getModel()
let codeActionProviderDisposable;
return model.onDidChangeContent(() => {
const diagnostics = workspace.check(model.getValue());
codeActionProviderDisposable?.dispose();
codeActionProviderDisposable = monaco.languages.registerCodeActionProvider("python", {
provideCodeActions: function (model, position) {
const actions = diagnostics
.filter((check) => position.startLineNumber === check.location.row)
.filter(({ fix }) => fix)
.map((check) => ({
title: check.fix
? check.fix.message
? `${check.code}: ${check.fix.message}`
: `Fix ${check.code}`
: "Fix",
id: `fix-${check.code}`,
kind: "quickfix",
edit: check.fix
? {
edits: check.fix.edits.map((edit) => ({
resource: model.uri,
versionId: model.getVersionId(),
textEdit: {
range: {
startLineNumber: edit.location.row,
startColumn: edit.location.column,
endLineNumber: edit.end_location.row,
endColumn: edit.end_location.column,
},
text: edit.content || "",
},
})),
}
: undefined,
}));
return { actions, dispose: () => {} };
},
});
monaco.editor.setModelMarkers(
model,
"owner",
diagnostics.map((diagnostic) => ({
startLineNumber: diagnostic.location.row,
startColumn: diagnostic.location.column,
endLineNumber: diagnostic.end_location.row,
endColumn: diagnostic.end_location.column,
message: `${diagnostic.code}: ${diagnostic.message}`,
severity: monaco.MarkerSeverity.Error,
tags:
diagnostic.code === "F401" || diagnostic.code === "F841"
? [monaco.MarkerTag.Unnecessary]
: [],
})),
);
}
);
}
self.MonacoEnvironment = { self.MonacoEnvironment = {
getWorkerUrl: function (moduleId, label) { getWorkerUrl: function (moduleId, label) {
if (label === 'json') { if (label === 'json') {
......
{ {
"name": "monaco-editor-erp5", "name": "monaco-editor-erp5",
"scripts": { "scripts": {
"build:wasm": "wasm-pack -v build ruff/crates/ruff_wasm --target web",
"build": "webpack --config webpack.config.js", "build": "webpack --config webpack.config.js",
"deploy": "node deploy.js" "deploy": "node deploy.js"
}, },
......
ruff @ 7b4b0045
Subproject commit 7b4b0045067b8eb41d0b03d9c3549ce3595373fa
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment