@@ -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
@@ -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
233198function 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' :
0 commit comments