lint addon is not working
See original GitHub issueI’ve been trying to add javascript-lint gutter markers to my code editor and I haven’t been getting anywhere. I am importing the lint.js and javascript-lint.js files from codemirror like I assume I am supposed to do. I have also added the lint and gutter options to my options object like I’ve also seen. I am getting everything to work properly except the lint gutter markers. Below is the code I am using to make the code editor and the result after I have bundled the code and am running it on my website. Am I doing something wrong? Help is much appreciated, thanks!
Javascipt File
import React from 'react';
import CodeMirror from 'react-codemirror';
const isBrowser = typeof window !== 'undefined';
isBrowser ? function(){
require('codemirror/mode/javascript/javascript');
require('codemirror/addon/lint/lint');
require('codemirror/addon/lint/javascript-lint');
}() : undefined;
import _ from 'underscore';
class CodeEditor extends React.Component{
constructor(props){
super(props);
this.state = {
code: this.props.children,
output: "",
theme: 'tomorrow-night-bright',
error: ""
};
}
updateCode(e) {
this.setState({
code: e
});
}
toggleTheme() {
let newTheme = this.state.theme == 'tomorrow-night-bright' ? 'default' : 'tomorrow-night-bright';
this.setState({
theme: newTheme
});
}
evalCode() {
let newOutput = "";
let code = this.state.code.replace(/\/\*[\s\S]*?\*\/|([^\\:]|^)\/\/.*$|(<script>)|eval|XMLHttpRequest|document\.write/gm,"");
try{
newOutput = (() => {return eval(code)})();
} catch(e) {
newOutput = "";
}
let error = "";
if(this.props.test) {
let include = this.props.test.include;
let notInclude = this.props.test.notInclude || [];
let expectedOutput = this.props.test.output;
include = include.map(item => code.indexOf(item).toString());
notInclude = notInclude.map(item => code.indexOf(item).toString());
if(include.indexOf("-1") != -1) {
console.log("You did not use the necessary items in this exercise.");
error = <div className="editorError">You did not use the necessary items in this exercise.</div>;
} else if(notInclude.indexOf("-1") == -1) {
console.log("You still have some of following keywords in your program: " + notInclude);
error = <div className="editorError">You still have some of following keywords in your program: {notInclude}</div>;
} else if(_.isEqual(newOutput,expectedOutput) === false) {
console.log("Oops, it looks like your output does not match expected output.");
error = <div className="editorError">Oops, it looks like your output does not match expected output.</div>;
} else {
error = <div className="editorSuccess">Good Job!</div>;
}
}
this.setState({
output: newOutput,
error: error
});
}
render() {
let outputClass = 'editorOutput';
let buttonsClass = 'editorButtons';
if(this.state.theme == 'default'){
outputClass = 'editorOutput lightEditorOutput';
buttonsClass = 'editorButtons lightEditorButtons';
}
let options = {
lineNumbers: true,
mode: 'javascript',
theme: this.state.theme,
scrollbarStyle: 'null',
lineWrapping: true,
lint: true,
gutters: [
'CodeMirror-lint-markers',
]
};
return (
<div className="editorContainer">
<div className={buttonsClass}>
<button onClick={this.evalCode.bind(this)}>Run</button>
<button onClick={this.toggleTheme.bind(this)}>Toggle Light/Dark</button>
{this.state.error}
</div>
<CodeMirror ref="editor" className="editor" value={this.state.code} onChange={this.updateCode.bind(this)} options={options}/>
<div className={outputClass}>
<small style={{color: "red",fontSize: "10px"}}>Output</small><br/>{JSON.stringify(this.state.output)}
</div>
</div>
);
}
}
export default CodeEditor;
Result
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
React-codemirror 2 linting feature not working - Stack Overflow
The lint addon from CodeMirror requires jshint library. If you add it ( npm i jshint ), the following code should work:
Read more >addons-linter - npm
The Add-ons Linter is being used by web-ext and addons.mozilla.org to lint WebExtensions. It can also be used as a standalone binary and...
Read more >CodeMirror: Lint Fix - GitHub Pages
Lint Fix is a CodeMirror addon that provides UI for quick-fixing lint issues. Demo. You can see an interactive demo on the Demo...
Read more >How To Todo In Ember Template Lint
... ember-template-lint addon provides a new option to the existing states for linting rules. With this new functionality, linting issues ...
Read more >CodeMirror 5 User Manual
And a highlightLines option to add a style to lines that contain problems. Depends on addon/lint/lint.css . A demo can be found here....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
O WOW I fixed it!
My problem was I didn’t load this …
codemirror/addon/lint/lint.css
Boom! God is good 👍
For further clarification here are my imports:
And don’t forget these options:
👍