| 
									
										
										
										
											2018-02-20 23:24:55 -05:00
										 |  |  | // CodeMirror, copyright (c) by Marijn Haverbeke and others
 | 
					
						
							|  |  |  | // Distributed under an MIT license: http://codemirror.net/LICENSE
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | (function(mod) { | 
					
						
							|  |  |  |   if (typeof exports == "object" && typeof module == "object") // CommonJS
 | 
					
						
							|  |  |  |     mod(require("../../lib/codemirror")); | 
					
						
							|  |  |  |   else if (typeof define == "function" && define.amd) // AMD
 | 
					
						
							|  |  |  |     define(["../../lib/codemirror"], mod); | 
					
						
							|  |  |  |   else // Plain browser env
 | 
					
						
							|  |  |  |     mod(CodeMirror); | 
					
						
							|  |  |  | })(function(CodeMirror) { | 
					
						
							|  |  |  |   "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-23 20:10:29 -05:00
										 |  |  |   async function validator(text, options) { | 
					
						
							| 
									
										
										
										
											2018-02-21 20:30:15 -05:00
										 |  |  |     await requireLibrary(ESLINT); | 
					
						
							| 
									
										
										
										
											2018-02-20 23:24:55 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-23 20:10:29 -05:00
										 |  |  |     if (text.length > 20000) { | 
					
						
							|  |  |  |         console.log("Skipping linting because of large size: ", text.length); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return []; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-20 23:24:55 -05:00
										 |  |  |     var errors = new eslint().verify(text, { | 
					
						
							|  |  |  |         root: true, | 
					
						
							|  |  |  |         parserOptions: { | 
					
						
							|  |  |  |             ecmaVersion: 2017, | 
					
						
							|  |  |  |             sourceType: 'module' | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         extends: ['eslint:recommended', 'airbnb-base'], | 
					
						
							|  |  |  |         env: { | 
					
						
							|  |  |  |             'node': true | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         rules: { | 
					
						
							|  |  |  |             'import/no-unresolved': 'off', | 
					
						
							|  |  |  |             'import/no-extraneous-dependencies': 'off', | 
					
						
							|  |  |  |             'func-names': 'off', | 
					
						
							|  |  |  |             'no-multi-spaces': 'off', | 
					
						
							|  |  |  |             'comma-dangle': ['error'], | 
					
						
							|  |  |  |             'padded-blocks': 'off', | 
					
						
							|  |  |  |             'linebreak-style': 'off', | 
					
						
							|  |  |  |             'class-methods-use-this': 'off', | 
					
						
							|  |  |  |             'no-unused-vars': ['error', { vars: 'local', args: 'after-used' }], | 
					
						
							|  |  |  |             'no-multiple-empty-lines': ['error', { max: 2, maxEOF: 1 }], | 
					
						
							|  |  |  |             'no-nested-ternary': 'off', | 
					
						
							|  |  |  |             'no-underscore-dangle': ['error', {'allow': ['_super', '_lookupFactory']}], | 
					
						
							|  |  |  |             'object-shorthand': ['error', 'methods'], | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     var result = []; | 
					
						
							|  |  |  |     if (errors) parseErrors(errors, result); | 
					
						
							|  |  |  |     return result; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   CodeMirror.registerHelper("lint", "javascript", validator); | 
					
						
							| 
									
										
										
										
											2018-02-22 19:52:08 -05:00
										 |  |  |   // CodeMirror.registerHelper("lint", "htmlmixed", validator);
 | 
					
						
							|  |  |  |   // CodeMirror.registerHelper("lint", "html", validator);
 | 
					
						
							| 
									
										
										
										
											2018-02-20 23:24:55 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   function parseErrors(errors, output) { | 
					
						
							|  |  |  |     for (const error of errors) { | 
					
						
							|  |  |  |       var startLine = error.line - 1; | 
					
						
							|  |  |  |       var endLine = error.endLine !== undefined ? error.endLine - 1 : startLine; | 
					
						
							|  |  |  |       var startCol = error.column - 1; | 
					
						
							|  |  |  |       var endCol = error.endColumn !== undefined ? error.endColumn - 1 : startCol + 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       output.push({ | 
					
						
							|  |  |  |           message: error.message, | 
					
						
							|  |  |  |           severity: error.severity === 1 ? "warning" : "error", | 
					
						
							|  |  |  |           from: CodeMirror.Pos(startLine, startCol), | 
					
						
							|  |  |  |           to: CodeMirror.Pos(endLine, endCol) | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     console.log(output); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }); |