Skip to content
Open
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
61 changes: 15 additions & 46 deletions client/modules/IDE/components/Editor/stateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ import { html } from '@codemirror/lang-html';
import { json } from '@codemirror/lang-json';
import { xml } from '@codemirror/lang-xml';
import { linter } from '@codemirror/lint';
import { JSHINT } from 'jshint';
import { HTMLHint } from 'htmlhint';
import { CSSLint } from 'csslint';
import { emmetConfig } from '@emmetio/codemirror6-plugin';

import p5JavaScript from './p5JavaScript';
import { esLint } from '@codemirror/lang-javascript';
import { Linter } from 'eslint-linter-browserify';
import { tidyCodeWithPrettier } from './tidier';
import p5JavaScript from './p5JavaScript';
import { highlightStyle } from './highlightStyle';
import { errorDecorationStateField } from './consoleErrorDecoration';

Expand Down Expand Up @@ -182,60 +183,28 @@ function makeHtmlLinter(callback) {
};
}

const JSHINT_OPTIONS = {
asi: true,
eqeqeq: false,
'-W041': false,
esversion: 11
const ESLINT_CONFIG = {
languageOptions: {
ecmaVersion: 2021
},
rules: {
semi: 'off',
eqeqeq: 'off'
}
};

// TODO: Consider using ESLINT instead
function makeJsLinter(callback) {
return (view) => {
const documentContent = view.state.doc.toString();

// Run JSHINT
JSHINT(documentContent, JSHINT_OPTIONS);
const { errors } = JSHINT;

// Return errors
const diagnostics = [];
errors.forEach((error) => {
if (!error) return;

const { line: errorLine, character: errorCharacter, evidence } = error;
const cmLine = view.state.doc.line(errorLine);

// https://github.com/codemirror/codemirror5/blob/master/addon/lint/javascript-lint.js
const start = errorCharacter - 1;
let end = start + 1;
if (evidence) {
const index = evidence.substring(start).search(/.\b/);
if (index > -1) {
end += index;
}
}

diagnostics.push({
from: cmLine.from + start,
to: cmLine.from + end,
severity: error.code.startsWith('W') ? 'warning' : 'error',
message: error.reason
});
});
const eslint = new Linter();

if (callback) callback(diagnostics);

return diagnostics;
};
function makeJsLinter(callback) {
return linter(esLint(eslint, ESLINT_CONFIG));
}

function getFileLinter(fileName, callback) {
const fileMode = getFileMode(fileName);

switch (fileMode) {
case 'javascript':
return linter(makeJsLinter(callback));
return makeJsLinter(callback);
case 'html':
return linter(makeHtmlLinter(callback));
case 'css':
Expand Down
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@
"dotenv": "^2.0.0",
"dropzone": "^4.3.0",
"escape-string-regexp": "^1.0.5",
"eslint-linter-browserify": "^10.0.3",
"eslint-scope": "^8.4.0",
"eslint-webpack-plugin": "^3.1.1",
"express": "^4.21.2",
Expand Down