Skip to content

Commit 67e6674

Browse files
committed
Merge branch 'develop-codemirror-v6' of https://github.com/processing/p5.js-web-editor into develop-codemirror-v6
2 parents 80b2e8e + 3d020a5 commit 67e6674

3 files changed

Lines changed: 21 additions & 48 deletions

File tree

client/modules/IDE/components/Editor/stateUtils.js

Lines changed: 13 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ import { html } from '@codemirror/lang-html';
4949
import { json, jsonParseLinter } from '@codemirror/lang-json';
5050
import { xml } from '@codemirror/lang-xml';
5151
import { linter } from '@codemirror/lint';
52-
import { JSHINT } from 'jshint';
5352
import { HTMLHint } from 'htmlhint';
5453
import { CSSLint } from 'csslint';
5554
import { emmetConfig } from '@emmetio/codemirror6-plugin';
5655
import { color as colorPicker } from '@connieye/codemirror-color-picker';
5756

58-
import p5JavaScript from './p5JavaScript';
57+
import { esLint } from '@codemirror/lang-javascript';
58+
import { Linter as ESLinter } from 'eslint-linter-browserify';
5959
import { tidyCodeWithPrettier } from './tidier';
60+
import p5JavaScript from './p5JavaScript';
6061
import { highlightStyle } from './highlightStyle';
6162
import { errorDecorationStateField } from './consoleErrorDecoration';
6263

@@ -182,53 +183,17 @@ function makeHtmlLinter(callback) {
182183
};
183184
}
184185

185-
const JSHINT_OPTIONS = {
186-
asi: true,
187-
eqeqeq: false,
188-
'-W041': false,
189-
esversion: 11
186+
const ESLINT_CONFIG = {
187+
languageOptions: {
188+
ecmaVersion: 2021
189+
},
190+
rules: {
191+
semi: 'off',
192+
eqeqeq: 'off'
193+
}
190194
};
191195

192-
// TODO: Consider using ESLINT instead
193-
function makeJsLinter(callback) {
194-
return (view) => {
195-
const documentContent = view.state.doc.toString();
196-
197-
// Run JSHINT
198-
JSHINT(documentContent, JSHINT_OPTIONS);
199-
const { errors } = JSHINT;
200-
201-
// Return errors
202-
const diagnostics = [];
203-
errors.forEach((error) => {
204-
if (!error) return;
205-
206-
const { line: errorLine, character: errorCharacter, evidence } = error;
207-
const cmLine = view.state.doc.line(errorLine);
208-
209-
// https://github.com/codemirror/codemirror5/blob/master/addon/lint/javascript-lint.js
210-
const start = errorCharacter - 1;
211-
let end = start + 1;
212-
if (evidence) {
213-
const index = evidence.substring(start).search(/.\b/);
214-
if (index > -1) {
215-
end += index;
216-
}
217-
}
218-
219-
diagnostics.push({
220-
from: cmLine.from + start,
221-
to: cmLine.from + end,
222-
severity: error.code.startsWith('W') ? 'warning' : 'error',
223-
message: error.reason
224-
});
225-
});
226-
227-
if (callback) callback(diagnostics);
228-
229-
return diagnostics;
230-
};
231-
}
196+
const eslint = new ESLinter();
232197

233198
function makeJsonLinter(callback) {
234199
const baseJsonLinter = jsonParseLinter();
@@ -244,7 +209,7 @@ function getFileLinter(fileName, callback) {
244209

245210
switch (fileMode) {
246211
case 'javascript':
247-
return linter(makeJsLinter(callback));
212+
return linter(esLint(eslint, ESLINT_CONFIG));
248213
case 'html':
249214
return linter(makeHtmlLinter(callback));
250215
case 'css':

package-lock.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@
266266
"dotenv": "^2.0.0",
267267
"dropzone": "^4.3.0",
268268
"escape-string-regexp": "^1.0.5",
269+
"eslint-linter-browserify": "^10.0.3",
269270
"eslint-scope": "^8.4.0",
270271
"eslint-webpack-plugin": "^3.1.1",
271272
"express": "^4.22.1",

0 commit comments

Comments
 (0)