Skip to content

Commit f08c561

Browse files
committed
feat: Store app state at localStorage
1 parent dd4f6e2 commit f08c561

File tree

7 files changed

+68
-11
lines changed

7 files changed

+68
-11
lines changed

index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ <h1>ECMAScript Lint</h1>
4848
Use recommended values if available
4949
</label>
5050
</div>
51+
<div class="form-group">
52+
<label>
53+
<input type="checkbox" class="modules-feature">
54+
ECMAScript modules
55+
</label>
56+
</div>
5157
</div>
5258
</fieldset>
5359
</div>

src/environments.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export default class Environments extends MatreshkaArray {
2121

2222
this
2323
.bindNode('sandbox', parent.select('.environments'))
24-
.rerender();
24+
.rerender()
25+
.update(data);
2526
}
2627
toJSON() {
2728
const result = {};
@@ -33,7 +34,16 @@ export default class Environments extends MatreshkaArray {
3334
return result;
3435
}
3536

36-
update() {
37+
update(env) {
38+
if(!env) return this;
39+
40+
for (const item of this) {
41+
const { environment } = item;
42+
if(environment in env) {
43+
item.checked = env[environment]
44+
}
45+
}
46+
3747
return this;
3848
}
3949
}

src/index.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import MatreshkaObject from 'matreshka/object';
2+
import calc from 'matreshka/calc';
23
import lint from './lint';
34
import { setParser } from './lint/parser';
45
import Environments from './environments';
@@ -11,8 +12,18 @@ module.exports = new class Application extends MatreshkaObject {
1112
constructor() {
1213
super({
1314
env: {},
14-
rules: {}
15+
rules: {},
16+
parserOptions: {
17+
ecmaVersion: 2017,
18+
ecmaFeatures: {
19+
experimentalObjectRestSpread: true
20+
}
21+
}
1522
})
23+
.set({
24+
configName: localStorage.eslintio ? '' : 'airbnb'
25+
})
26+
.setData(JSON.parse(localStorage.eslintio || '{}'))
1627
.bindNode({
1728
sandbox: 'form',
1829
configName: {
@@ -40,7 +51,8 @@ module.exports = new class Application extends MatreshkaObject {
4051
})
4152
},
4253
parserName: ':sandbox .parser-name',
43-
useRecommended: ':sandbox .use-recommended'
54+
useRecommended: ':sandbox .use-recommended',
55+
modulesFeature: ':sandbox .modules-feature'
4456
})
4557
.instantiate({
4658
env: Environments,
@@ -70,6 +82,8 @@ module.exports = new class Application extends MatreshkaObject {
7082
const results = lint(this.code, this.toJSON());
7183

7284
this.set({ results });
85+
86+
localStorage.eslintio = JSON.stringify(this);
7387
},
7488
'change:parserName': () => setParser(this.parserName),
7589
'rules@rulechange': () => {
@@ -82,5 +96,17 @@ module.exports = new class Application extends MatreshkaObject {
8296
}
8397
}
8498
});
99+
100+
calc(this, 'modulesFeature', {
101+
object: this.parserOptions,
102+
key: 'sourceType'
103+
}, sourceType => sourceType === 'module');
104+
105+
calc(this.parserOptions, 'sourceType', {
106+
object: this,
107+
key: 'modulesFeature'
108+
}, modulesFeature => modulesFeature ? 'module' : 'script');
109+
110+
85111
}
86112
}();

src/results/index.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ import MatreshkaArray from 'matreshka/array';
22
import ResultsItem from './item';
33

44
export default class Results extends MatreshkaArray {
5-
itemRenderer = `<div class="alert alert-danger">
6-
{{ message }}
7-
(<a href="{{ href }}" target="_blank">{{ ruleId }}</a>)
8-
</div>`;
95
Model = ResultsItem;
106
constructor(data, parent) {
117
super()

src/results/item.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
import MatreshkaObject from 'matreshka/object';
2+
import display from 'matreshka/binders/display';
23
import plugins from '../lint/plugins';
34

45
export default class extends MatreshkaObject {
6+
renderer = `<div class="alert alert-danger">
7+
{{ message }}
8+
<span class="rule-clarification-container">
9+
(<a href="{{ href }}" target="_blank">{{ ruleId }}</a>)
10+
</span>
11+
</div>`;
512
constructor(data) {
613
super(data)
714
.calc({
815
href: {
916
source: 'ruleId',
1017
handler: (ruleId) => {
18+
if(!ruleId) {
19+
return '';
20+
}
21+
1122
const splitted = ruleId.split('/');
1223
let pluginName;
1324
let ruleName;
@@ -26,4 +37,8 @@ export default class extends MatreshkaObject {
2637
}
2738
});
2839
}
40+
41+
onRender() {
42+
this.bindNode('href', ':sandbox .rule-clarification-container', display())
43+
}
2944
}

src/rules/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ export default class Rules extends MatreshkaArray {
1818
this.trigger('rulechange');
1919
}
2020
})
21-
.recreate(plugins);
21+
.recreate(plugins)
22+
.update(data);
2223
}
2324

2425
update(rules) {
26+
if(!rules) return this;
27+
2528
for (const group of this) {
2629
for (const rule of group) {
2730
const fullRuleName = group.getFullRuleName(rule.ruleName, group.name);
@@ -34,6 +37,8 @@ export default class Rules extends MatreshkaArray {
3437
rule.value = rules[fullRuleName] || recommended[fullRuleName] || 'off';
3538
}
3639
}
40+
41+
return this;
3742
}
3843

3944
toJSON() {

src/rules/rule.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import MatreshkaObject from 'matreshka/object';
2-
// import prop from 'matreshka/binders/prop';
32

43
export default class Rule extends MatreshkaObject {
5-
renderer = `<label title="{{ dynamicValueJSON }}" class="col-md-4 col-sm-6 form-check-label">
4+
renderer = `<label title="{{ dynamicValueJSON }}" class="col-md-4 col-sm-6 col-xs-12 form-check-label">
65
<input type="checkbox" checked="{{ isOn }}"> {{ ruleName }}
76
</label>`;
87
constructor(data) {

0 commit comments

Comments
 (0)