@@ -49,14 +49,15 @@ import { html } from '@codemirror/lang-html';
4949import { json , jsonParseLinter } from '@codemirror/lang-json' ;
5050import { xml } from '@codemirror/lang-xml' ;
5151import { linter } from '@codemirror/lint' ;
52- import { JSHINT } from 'jshint' ;
5352import { HTMLHint } from 'htmlhint' ;
5453import { CSSLint } from 'csslint' ;
5554import { emmetConfig } from '@emmetio/codemirror6-plugin' ;
5655import { 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' ;
5959import { tidyCodeWithPrettier } from './tidier' ;
60+ import p5JavaScript from './p5JavaScript' ;
6061import { highlightStyle } from './highlightStyle' ;
6162import { 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
235200function 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' :
0 commit comments