Skip to content

Commit 7ab3633

Browse files
silverwindlafriks
andauthored
Enable linting of JS inside templates (#13708)
Indentation-related rules are disabled because indent templates with tabs but our lint rules expect spaces. Also had to exclude a few files where using template variables in the JS is causing syntax errors for the JS parser. I don't think there's a way to solve this otherwise. Co-authored-by: Lauris BH <[email protected]>
1 parent 3f13e07 commit 7ab3633

File tree

7 files changed

+81
-9
lines changed

7 files changed

+81
-9
lines changed

.eslintrc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ reportUnusedDisableDirectives: true
33

44
ignorePatterns:
55
- /web_src/js/vendor
6+
- /templates/base/head.tmpl
7+
- /templates/repo/activity.tmpl
8+
- /templates/repo/view_file.tmpl
69

710
parserOptions:
811
sourceType: module
@@ -12,6 +15,7 @@ plugins:
1215
- eslint-plugin-unicorn
1316
- eslint-plugin-import
1417
- eslint-plugin-vue
18+
- eslint-plugin-html
1519

1620
extends:
1721
- plugin:vue/recommended
@@ -27,12 +31,19 @@ globals:
2731
SimpleMDE: false
2832
u2fApi: false
2933

34+
settings:
35+
html/html-extensions: [".tmpl"]
36+
3037
overrides:
31-
- files: ["web_src/**/*.js", "web_src/**/*.vue"]
38+
- files: ["web_src/**/*.js", "web_src/**/*.vue", "templates/**/*.tmpl"]
3239
env:
3340
browser: true
3441
jquery: true
3542
node: false
43+
- files: ["templates/**/*.tmpl"]
44+
rules:
45+
no-tabs: [0]
46+
indent: [2, tab, {SwitchCase: 1}]
3647
- files: ["web_src/**/*worker.js"]
3748
env:
3849
worker: true

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ lint: lint-frontend lint-backend
312312

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

318318
.PHONY: lint-backend

package-lock.json

Lines changed: 60 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
@@ -55,6 +55,7 @@
5555
},
5656
"devDependencies": {
5757
"eslint": "7.13.0",
58+
"eslint-plugin-html": "6.1.1",
5859
"eslint-plugin-import": "2.22.1",
5960
"eslint-plugin-unicorn": "23.0.0",
6061
"eslint-plugin-vue": "7.1.0",

templates/base/footer.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<script src="{{StaticUrlPrefix}}/vendor/plugins/codemirror/addon/mode/loadmode.js"></script>
1717
<script src="{{StaticUrlPrefix}}/vendor/plugins/codemirror/mode/meta.js"></script>
1818
<script>
19-
CodeMirror.modeURL = "{{StaticUrlPrefix}}/vendor/plugins/codemirror/mode/%N/%N.js";
19+
CodeMirror.modeURL = '{{StaticUrlPrefix}}/vendor/plugins/codemirror/mode/%N/%N.js';
2020
</script>
2121
{{end}}
2222

templates/repo/diff/box.tmpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,14 @@
278278

279279
{{if .IsSplitStyle}}
280280
<script>
281-
document.addEventListener('DOMContentLoaded', function() {
281+
document.addEventListener('DOMContentLoaded', () => {
282282
$('tr.add-code').each(function() {
283-
var prev = $(this).prev();
284-
if(prev.is('.del-code') && prev.children().eq(5).text().trim() === '') {
285-
while(prev.prev().is('.del-code') && prev.prev().children().eq(5).text().trim() === '') {
283+
let prev = $(this).prev();
284+
if (prev.is('.del-code') && prev.children().eq(5).text().trim() === '') {
285+
while (prev.prev().is('.del-code') && prev.prev().children().eq(5).text().trim() === '') {
286286
prev = prev.prev();
287287
}
288-
prev.children().eq(3).attr("data-line-num", $(this).children().eq(3).attr("data-line-num"));
288+
prev.children().eq(3).attr('data-line-num', $(this).children().eq(3).attr('data-line-num'));
289289
prev.children().eq(3).html($(this).children().eq(3).html());
290290
prev.children().eq(4).html($(this).children().eq(4).html());
291291
prev.children().eq(5).html($(this).children().eq(5).html());

templates/repo/home.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
if (httpsButton) httpsButton.classList[isSSH ? 'remove' : 'add']('primary');
136136
setTimeout(() => {
137137
if (sshButton) sshButton.classList.remove('no-transition');
138-
if (httpsButto) httpsButton.classList.remove('no-transition');
138+
if (httpsButton) httpsButton.classList.remove('no-transition');
139139
}, 100);
140140
</script>
141141
{{if or (not $.DisableHTTP) (and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH))}}

0 commit comments

Comments
 (0)