editor icon indicating copy to clipboard operation
editor copied to clipboard

Code Linting

Open hugomarfani opened this issue 3 years ago • 5 comments

Add Code Lining

Expected Behaviour

DECLARE num1 AS STRINGOFTEXT STRINGOFTEXT should be underlined to show that this is not a correct datatype

Actual Behavior

Not yet implemented

hugomarfani avatar Mar 29 '22 10:03 hugomarfani

Will be useful → https://github.com/codemirror/lint

Coding-Cactus avatar Mar 31 '22 20:03 Coding-Cactus

An example of linting cm6 https://codemirror.net/6/screenreaderdemo/

const {EditorState, EditorView, basicSetup} = CM["@codemirror/basic-setup"];
const {html} = CM["@codemirror/lang-html"];
const {linter} = CM["@codemirror/lint"];

const replace = ["cardamom", "hummingbird", "granfalloon", "galleass", "capybara", "lemur", "topology"];

function lintFoo(view) {
  let words = /\b(foo|bar|baz|quux)\b/g, m, doc = view.state.doc.toString();
  let diagnostics = [];
  while (m = words.exec(doc)) {
    diagnostics.push({
      from: m.index, to: m.index + m[0].length,
      severity: "warning",
      message: `The word "${m[0]}" is deprecated.`,
      actions: [{name: "fix", apply(view, from, to) {
        view.dispatch({changes: {from, to, insert: replace[Math.floor(Math.random() * replace.length)]}});
      }}]
    });
  }
  return diagnostics
}
(window ).view = new EditorView({
  state: EditorState.create({
    doc: `<!doctype html>
<body>
  <p>This is the editable example document.</p>
  <p>The linter highlights words like foo, bar, and baz.</p>
</body>
`,
    extensions: [basicSetup, html(), linter(lintFoo)]
  }),
  parent: document.querySelector("#editor")
});

Coding-Cactus avatar Apr 03 '22 11:04 Coding-Cactus

🛑 (On hold until the interpreter is implemented)

Coding-Cactus avatar May 12 '22 07:05 Coding-Cactus

:green_circle: back in action

Coding-Cactus avatar Nov 22 '22 20:11 Coding-Cactus

:red_circle: nvm

Coding-Cactus avatar Nov 22 '22 20:11 Coding-Cactus