Skip to content

Commit 7c47e24

Browse files
silverwindlafrikslunny
authored
Add Vue linting (#13447)
* Add Vue linting Turns out the .vue files were not linted at all, so I added that as well as re-indented the file to 2-space and fixed all reasonable issues that cam up except one case of a unintended side effect for which I have no idea how to fix it, so the rule was disabled. * misc tweaks * update lockfile * use overrides to include .vue files * treat warnings as errors on lint-frontend * also treat stylelint warnings as errors * use equal sign syntax Co-authored-by: Lauris BH <[email protected]> Co-authored-by: Lunny Xiao <[email protected]>
1 parent ed47da2 commit 7c47e24

File tree

7 files changed

+294
-242
lines changed

7 files changed

+294
-242
lines changed

.eslintrc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ parserOptions:
1111
plugins:
1212
- eslint-plugin-unicorn
1313
- eslint-plugin-import
14+
- eslint-plugin-vue
15+
16+
extends:
17+
- plugin:vue/recommended
1418

1519
env:
1620
es2021: true
@@ -24,7 +28,7 @@ globals:
2428
u2fApi: false
2529

2630
overrides:
27-
- files: ["web_src/**/*.js"]
31+
- files: ["web_src/**/*.js", "web_src/**/*.vue"]
2832
env:
2933
browser: true
3034
jquery: true
@@ -387,6 +391,11 @@ rules:
387391
use-isnan: [2]
388392
valid-typeof: [2, {requireStringLiterals: true}]
389393
vars-on-top: [0]
394+
vue/attributes-order: [0]
395+
vue/component-definition-name-casing: [0]
396+
vue/html-closing-bracket-spacing: [0]
397+
vue/max-attributes-per-line: [0]
398+
vue/one-component-per-file: [0]
390399
wrap-iife: [2, inside]
391400
wrap-regex: [0]
392401
yield-star-spacing: [2, after]

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ lint: lint-frontend lint-backend
312312

313313
.PHONY: lint-frontend
314314
lint-frontend: node_modules
315-
npx eslint web_src/js build webpack.config.js
316-
npx stylelint web_src/less
315+
npx eslint --max-warnings=0 web_src/js build webpack.config.js
316+
npx stylelint --max-warnings=0 web_src/less
317317

318318
.PHONY: lint-backend
319319
lint-backend: golangci-lint revive vet

package-lock.json

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"eslint": "7.11.0",
5555
"eslint-plugin-import": "2.22.1",
5656
"eslint-plugin-unicorn": "23.0.0",
57+
"eslint-plugin-vue": "7.1.0",
5758
"stylelint": "13.7.2",
5859
"stylelint-config-standard": "20.0.0",
5960
"svgo": "1.3.2",
Lines changed: 60 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,71 @@
11
<template>
2-
<div>
3-
<div v-show="isLoading">
4-
<slot name="loading"></slot>
5-
</div>
6-
<h4 class="total-contributions" v-if="!isLoading">
7-
{{ totalContributions }} total contributions in the last 12 months
8-
</h4>
9-
<calendar-heatmap v-show="!isLoading" :locale="locale" :no-data-text="locale.no_contributions" :tooltip-unit="locale.contributions" :end-date="endDate" :values="values" :range-color="colorRange"/>
2+
<div>
3+
<div v-show="isLoading">
4+
<slot name="loading"/>
105
</div>
6+
<h4 v-if="!isLoading" class="total-contributions">
7+
{{ values.length }} total contributions in the last 12 months
8+
</h4>
9+
<calendar-heatmap
10+
v-show="!isLoading"
11+
:locale="locale"
12+
:no-data-text="locale.no_contributions"
13+
:tooltip-unit="locale.contributions"
14+
:end-date="endDate"
15+
:values="values"
16+
:range-color="colorRange"
17+
/>
18+
</div>
1119
</template>
12-
1320
<script>
1421
import {CalendarHeatmap} from 'vue-calendar-heatmap';
1522
const {AppSubUrl, heatmapUser} = window.config;
1623
1724
export default {
18-
name: "ActivityHeatmap",
19-
components: {
20-
CalendarHeatmap
21-
},
22-
data() {
23-
return {
24-
isLoading: true,
25-
colorRange: [],
26-
endDate: null,
27-
values: [],
28-
totalContributions: 0,
29-
suburl: AppSubUrl,
30-
user: heatmapUser,
31-
locale: {
32-
contributions: 'contributions',
33-
no_contributions: 'No contributions',
34-
},
35-
};
25+
name: 'ActivityHeatmap',
26+
components: {CalendarHeatmap},
27+
data: () => ({
28+
isLoading: true,
29+
colorRange: [],
30+
endDate: null,
31+
values: [],
32+
suburl: AppSubUrl,
33+
user: heatmapUser,
34+
locale: {
35+
contributions: 'contributions',
36+
no_contributions: 'No contributions',
3637
},
37-
mounted() {
38-
this.colorRange = [
39-
this.getColor(0),
40-
this.getColor(1),
41-
this.getColor(2),
42-
this.getColor(3),
43-
this.getColor(4),
44-
this.getColor(5)
45-
];
46-
this.endDate = new Date();
47-
this.loadHeatmap(this.user);
48-
},
49-
methods: {
50-
loadHeatmap(userName) {
51-
const self = this;
52-
$.get(`${this.suburl}/api/v1/users/${userName}/heatmap`, (chartRawData) => {
53-
const chartData = [];
54-
for (let i = 0; i < chartRawData.length; i++) {
55-
self.totalContributions += chartRawData[i].contributions;
56-
chartData[i] = {date: new Date(chartRawData[i].timestamp * 1000), count: chartRawData[i].contributions};
57-
}
58-
self.values = chartData;
59-
self.isLoading = false;
60-
});
61-
},
62-
getColor(idx) {
63-
const el = document.createElement('div');
64-
el.className = `heatmap-color-${idx}`;
65-
document.body.appendChild(el);
66-
67-
const color = getComputedStyle(el).backgroundColor;
68-
69-
document.body.removeChild(el);
70-
71-
return color;
72-
}
38+
}),
39+
mounted() {
40+
this.colorRange = [
41+
this.getColor(0),
42+
this.getColor(1),
43+
this.getColor(2),
44+
this.getColor(3),
45+
this.getColor(4),
46+
this.getColor(5)
47+
];
48+
this.endDate = new Date();
49+
this.loadHeatmap(this.user);
50+
},
51+
methods: {
52+
async loadHeatmap(userName) {
53+
const res = await fetch(`${this.suburl}/api/v1/users/${userName}/heatmap`);
54+
const data = await res.json();
55+
this.values = data.map(({contributions, timestamp}) => {
56+
return {date: new Date(timestamp * 1000), count: contributions};
57+
});
58+
this.isLoading = false;
7359
},
74-
}
60+
getColor(idx) {
61+
const el = document.createElement('div');
62+
el.className = `heatmap-color-${idx}`;
63+
document.body.appendChild(el);
64+
const color = getComputedStyle(el).backgroundColor;
65+
document.body.removeChild(el);
66+
return color;
67+
}
68+
},
69+
};
7570
</script>
76-
77-
<style scoped>
78-
79-
</style>
71+
<style scoped/>

0 commit comments

Comments
 (0)