Skip to content

Commit 3d020a5

Browse files
authored
Merge pull request #3836 from Nishthajain7/migarte-to-eslint
Migrated from JSHint to ESLint
2 parents 0b40206 + bac3fbe commit 3d020a5

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

@@ -184,53 +185,17 @@ function makeHtmlLinter(callback) {
184185
};
185186
}
186187

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

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

235200
function makeJsonLinter(callback) {
236201
const baseJsonLinter = jsonParseLinter();
@@ -246,7 +211,7 @@ function getFileLinter(fileName, callback) {
246211

247212
switch (fileMode) {
248213
case 'javascript':
249-
return linter(makeJsLinter(callback));
214+
return linter(esLint(eslint, ESLINT_CONFIG));
250215
case 'html':
251216
return linter(makeHtmlLinter(callback));
252217
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)