Skip to content

Commit 245ac4c

Browse files
committed
feat: Allow to go to line
1 parent eb35b34 commit 245ac4c

File tree

5 files changed

+75
-51
lines changed

5 files changed

+75
-51
lines changed

packages/frontend/Messages.js

Lines changed: 0 additions & 50 deletions
This file was deleted.

packages/frontend/Messages/Message.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import MatreshkaObject from 'matreshka/object';
2+
import display from 'matreshka/binders/display';
3+
4+
export default class Message extends MatreshkaObject {
5+
renderer = '<pre class="result-item"><span class="position" title="Go to the line">{{ line }}:{{ column }}</span> {{ type }} {{ message }} <span class="result-link">(<a href="{{ link }}" target="_blank">{{ ruleId }}</a>)</span> </pre>';
6+
7+
constructor(data) {
8+
super(data)
9+
.calc('type', 'severity', severity => (severity === 1 ? 'warning' : 'error'))
10+
.calc('link', 'ruleId', (ruleId) => {
11+
if (!ruleId) {
12+
return null;
13+
}
14+
15+
const [groupName, ruleName] = ruleId.split('/');
16+
17+
if (!ruleName) {
18+
return `http://eslint.org/docs/rules/${groupName}`;
19+
}
20+
21+
if (groupName === 'react') {
22+
return `https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/${ruleName}.md`;
23+
}
24+
25+
if (groupName === 'jsx-a11y') {
26+
return `https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/${ruleName}.md`;
27+
}
28+
29+
return null;
30+
});
31+
}
32+
33+
onRender() {
34+
this
35+
.bindNode('type', ':sandbox', {
36+
setValue(type, { node }) {
37+
node.classList.add(`result-${type}`);
38+
}
39+
})
40+
.bindNode('link', ':sandbox .result-link', display());
41+
}
42+
}

packages/frontend/Messages/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import MatreshkaArray from 'matreshka/array';
2+
import display from 'matreshka/binders/display';
3+
import Message from './Message';
4+
5+
export default class Messages extends MatreshkaArray {
6+
Model = Message;
7+
constructor(data, parent) {
8+
super()
9+
.bindNode({
10+
sandbox: parent.select('#result-container'),
11+
container: ':sandbox .result-errors',
12+
noErrors: {
13+
node: ':sandbox .result-success',
14+
binder: display()
15+
}
16+
});
17+
}
18+
}

packages/frontend/css/style.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,12 @@ button[type="reset"]:active {}
986986
white-space: normal;
987987
}
988988

989+
.result-item .position {
990+
text-decoration: underline;
991+
text-decoration-style: dotted;
992+
cursor: pointer;
993+
}
994+
989995
.result-item a {
990996
white-space: nowrap;
991997
}

packages/frontend/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ module.exports = new class App extends MatreshkaObject {
3636
})
3737
}
3838
})
39+
.set({
40+
editor: this.nodes.code.nextElementSibling.CodeMirror
41+
})
3942
.calc('chosenConfig', ['configName', 'configs'], (configName, configs) => {
4043
if (!configName || !configs) {
4144
return {};
@@ -53,6 +56,10 @@ module.exports = new class App extends MatreshkaObject {
5356
},
5457
'change:code': () => {
5558
this.noErrors = false;
59+
},
60+
'messages.*@click::(.position)': ({ self: { line, column } }) => {
61+
this.editor.setCursor({ line: line - 1, ch: column - 1 });
62+
this.editor.focus();
5663
}
5764
})
5865
.instantiate({
@@ -62,7 +69,8 @@ module.exports = new class App extends MatreshkaObject {
6269
})
6370
.init();
6471

65-
this.nodes.code.nextElementSibling.CodeMirror.addKeyMap({
72+
73+
this.editor.addKeyMap({
6674
'Ctrl-Enter': () => this.lint(),
6775
'Cmd-Enter': () => this.lint(),
6876
'Cmd-A': inst => inst.execCommand('selectAll')

0 commit comments

Comments
 (0)