Skip to content

Commit db3359f

Browse files
committed
tidy js with js-beautify
1 parent 0fc48e6 commit db3359f

17 files changed

+387
-223
lines changed

build-assets.mjs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
#!/usr/bin/env node
2+
23
import * as esbuild from 'esbuild'
3-
import { lessLoader } from 'esbuild-plugin-less';
4-
import { sassPlugin } from 'esbuild-sass-plugin';
5-
import { writeFile, opendir, unlink } from 'node:fs/promises';
4+
import {
5+
lessLoader
6+
}
7+
from 'esbuild-plugin-less';
8+
import {
9+
sassPlugin
10+
}
11+
from 'esbuild-sass-plugin';
12+
import {
13+
writeFile,
14+
opendir,
15+
unlink
16+
}
17+
from 'node:fs/promises';
618
import path from 'node:path';
719
import parseArgs from 'minimist';
820

@@ -33,9 +45,12 @@ const config = {
3345
name = 'metacpan-build';
3446

3547
setup(build) {
36-
build.onResolve(
37-
{ filter: /^\// },
38-
args => ({ external: true }),
48+
build.onResolve({
49+
filter: /^\//
50+
},
51+
args => ({
52+
external: true
53+
}),
3954
);
4055

4156
build.initialOptions.metafile = true;
@@ -76,7 +91,9 @@ if (args.minify) {
7691
config.minify = true;
7792
}
7893
if (args.clean) {
79-
for await (const file of await opendir(config.outdir, { withFileTypes: true })) {
94+
for await (const file of await opendir(config.outdir, {
95+
withFileTypes: true
96+
})) {
8097
const filePath = path.join(file.parentPath, file.name);
8198
if (file.name.match(/^\./)) {
8299
// ignore these

precious.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,15 @@ tidy-flags = "--write"
5353
ok-exit-codes = 0
5454
lint-failure-exit-codes = 1
5555
ignore-stderr = [ "Code style issues" ]
56+
57+
[commands.js-beautify]
58+
type = "tidy"
59+
include = [ "**/*.js", "**/*.mjs" ]
60+
cmd = [
61+
"npx", "-s", "js-beautify",
62+
"--editorconfig",
63+
"--brace-style", "end-expand",
64+
"--replace"
65+
]
66+
ok-exit-codes = 0
67+
lint-failure-exit-codes = 1

root/static/js/autocomplete.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ jQuery(search_input).autocomplete({
3131
onSelect: function(suggestion) {
3232
if (suggestion.data.type == 'module') {
3333
document.location.href = '/pod/' + suggestion.data.module;
34-
} else if (suggestion.data.type == 'author') {
34+
}
35+
else if (suggestion.data.type == 'author') {
3536
document.location.href = '/author/' + suggestion.data.id;
3637
}
3738
}

root/static/js/bootstrap-slidepanel.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,24 @@ for (const toggle of document.querySelectorAll('[data-toggle="slidepanel"]')) {
66
continue;
77
}
88

9-
const showAnim = new Animation( new KeyframeEffect(
10-
panel,
11-
{ transform: [ 'translateX(-100%)', 'translateX(0)' ] },
9+
const showAnim = new Animation(new KeyframeEffect(
10+
panel, {
11+
transform: ['translateX(-100%)', 'translateX(0)']
12+
},
1213
200
1314
));
1415

1516
const hideAnim = new Animation(new KeyframeEffect(
16-
panel,
17-
{ transform: [ 'translateX(0)', 'translateX(-100%)' ] },
17+
panel, {
18+
transform: ['translateX(0)', 'translateX(-100%)']
19+
},
1820
200
1921
));
2022
hideAnim.addEventListener('finish', () => {
2123
panel.style.removeProperty('visibility');
2224
});
2325

24-
toggle.addEventListener('click', function (e) {
26+
toggle.addEventListener('click', function(e) {
2527
e.preventDefault();
2628

2729
toggle.classList.toggle('slidepanel-visible');

root/static/js/brush-cpan-changes.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,27 @@ const regexLib = require('syntaxhighlighter-regex').commonRegExp;
33

44
function Brush() {
55
this.regexList = [
6-
// these classes/colors are totally arbitrary
7-
{ regex: /^\{\{\$NEXT\}\}$/gm, css: 'color3' }, // placeholder (oops)
8-
{ regex: /^v?([0-9._]+)(-TRIAL)?([ \t]+.+)?/gm, css: 'constants' }, // version/date
9-
{ regex: /^\s+\[.+?\]/gm, css: 'value' }, // group
10-
{ regex: /^\s+[-*]/gm, css: 'functions' }, // item marker
11-
{ regex: /^[^v0-9].+\n(?=\nv?[0-9_.])/g, css: 'preprocessor' } // preamble
6+
// these classes/colors are totally arbitrary
7+
{
8+
regex: /^\{\{\$NEXT\}\}$/gm,
9+
css: 'color3'
10+
}, // placeholder (oops)
11+
{
12+
regex: /^v?([0-9._]+)(-TRIAL)?([ \t]+.+)?/gm,
13+
css: 'constants'
14+
}, // version/date
15+
{
16+
regex: /^\s+\[.+?\]/gm,
17+
css: 'value'
18+
}, // group
19+
{
20+
regex: /^\s+[-*]/gm,
21+
css: 'functions'
22+
}, // item marker
23+
{
24+
regex: /^[^v0-9].+\n(?=\nv?[0-9_.])/g,
25+
css: 'preprocessor'
26+
} // preamble
1227
];
1328
};
1429

root/static/js/brush-perl.js

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,77 @@ function Brush() {
3636
// Moose
3737
'has extends with before after around override augment';
3838

39-
this.regexList = [
40-
{ regex: /(<<|&lt;&lt;)((\w+)|(['"])(.+?)\4)[\s\S]+?\n\3\5\n/g, css: 'string' }, // here doc (maybe html encoded)
41-
{ regex: /#.*$/gm, css: 'comments' },
42-
{ regex: /^#!.*\n/g, css: 'preprocessor' }, // shebang
43-
{ regex: /-?\w+(?=\s*=(>|&gt;))/g, css: 'string' }, // fat comma
39+
this.regexList = [{
40+
regex: /(<<|&lt;&lt;)((\w+)|(['"])(.+?)\4)[\s\S]+?\n\3\5\n/g,
41+
css: 'string'
42+
}, // here doc (maybe html encoded)
43+
{
44+
regex: /#.*$/gm,
45+
css: 'comments'
46+
},
47+
{
48+
regex: /^#!.*\n/g,
49+
css: 'preprocessor'
50+
}, // shebang
51+
{
52+
regex: /-?\w+(?=\s*=(>|&gt;))/g,
53+
css: 'string'
54+
}, // fat comma
4455

4556
// is this too much?
46-
{ regex: /\bq[qwxr]?\([\s\S]*?\)/g, css: 'string' }, // quote-like operators ()
47-
{ regex: /\bq[qwxr]?\{[\s\S]*?\}/g, css: 'string' }, // quote-like operators {}
48-
{ regex: /\bq[qwxr]?\[[\s\S]*?\]/g, css: 'string' }, // quote-like operators []
49-
{ regex: /\bq[qwxr]?(<|&lt;)[\s\S]*?(>|&gt;)/g, css: 'string' }, // quote-like operators <>
50-
{ regex: /\bq[qwxr]?([^\w({<[])[\s\S]*?\1/g, css: 'string' }, // quote-like operators non-paired
57+
{
58+
regex: /\bq[qwxr]?\([\s\S]*?\)/g,
59+
css: 'string'
60+
}, // quote-like operators ()
61+
{
62+
regex: /\bq[qwxr]?\{[\s\S]*?\}/g,
63+
css: 'string'
64+
}, // quote-like operators {}
65+
{
66+
regex: /\bq[qwxr]?\[[\s\S]*?\]/g,
67+
css: 'string'
68+
}, // quote-like operators []
69+
{
70+
regex: /\bq[qwxr]?(<|&lt;)[\s\S]*?(>|&gt;)/g,
71+
css: 'string'
72+
}, // quote-like operators <>
73+
{
74+
regex: /\bq[qwxr]?([^\w({<[])[\s\S]*?\1/g,
75+
css: 'string'
76+
}, // quote-like operators non-paired
5177

52-
{ regex: regexLib.doubleQuotedString, css: 'string' },
53-
{ regex: regexLib.singleQuotedString, css: 'string' },
78+
{
79+
regex: regexLib.doubleQuotedString,
80+
css: 'string'
81+
},
82+
{
83+
regex: regexLib.singleQuotedString,
84+
css: 'string'
85+
},
5486
// currently ignoring single quote package separator and utf8 names
55-
{ regex: /(?:&amp;|[$@%*]|\$#)\$?[a-zA-Z_](\w+|::)*/g, css: 'variable' },
56-
{ regex: /(^|\n)\s*__(?:END|DATA)__\b[\s\S]*$/g, css: 'comments' },
87+
{
88+
regex: /(?:&amp;|[$@%*]|\$#)\$?[a-zA-Z_](\w+|::)*/g,
89+
css: 'variable'
90+
},
91+
{
92+
regex: /(^|\n)\s*__(?:END|DATA)__\b[\s\S]*$/g,
93+
css: 'comments'
94+
},
5795

5896
// don't capture the newline after =cut so that =cut\n\n=head1 will start a new pod section
59-
{ regex: /(^|\n)=\w[\s\S]*?(\n=cut\s*(?=\n)|$)/g, css: 'comments' }, // pod
97+
{
98+
regex: /(^|\n)=\w[\s\S]*?(\n=cut\s*(?=\n)|$)/g,
99+
css: 'comments'
100+
}, // pod
60101

61-
{ regex: new RegExp(this.getKeywords(funcs), 'gm'), css: 'functions' },
62-
{ regex: new RegExp(this.getKeywords(keywords), 'gm'), css: 'keyword' }
102+
{
103+
regex: new RegExp(this.getKeywords(funcs), 'gm'),
104+
css: 'functions'
105+
},
106+
{
107+
regex: new RegExp(this.getKeywords(keywords), 'gm'),
108+
css: 'keyword'
109+
}
63110
];
64111

65112
this.forHtmlScript(regexLib.phpScriptTags);

root/static/js/cpan.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ async function processUserData() {
2121
let user_data;
2222
try {
2323
user_data = await fetch('/account/login_status').then(res => res.json());
24-
} catch (e) {
24+
}
25+
catch (e) {
2526
document.body.classList.remove('logged-in');
2627
document.body.classList.add('logged-out');
2728
return;
@@ -237,7 +238,8 @@ for (const favForm of document.querySelectorAll('form[action="/account/favorite/
237238
},
238239
body: formData,
239240
});
240-
} catch (e) {
241+
}
242+
catch (e) {
241243
if (confirm("You have to complete a Captcha in order to ++.")) {
242244
document.location.href = "/account/turing";
243245
}
@@ -254,7 +256,8 @@ for (const favForm of document.querySelectorAll('form[action="/account/favorite/
254256
favForm.querySelector('input[name="remove"]').value = 1;
255257
if (!count)
256258
button.classList.toggle('highlight');
257-
} else {
259+
}
260+
else {
258261
// can't delete what's already deleted
259262
favForm.querySelector('input[name="remove"]').value = 0;
260263

root/static/js/document-ui.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import storage from './storage.js';
22

33
export const createAnchors = (topList) => {
4-
const it = typeof (topList)[Symbol.iterator] === 'function' ? topList : [topList];
4+
const it = typeof(topList)[Symbol.iterator] === 'function' ? topList : [topList];
55
for (const top of it) {
66
for (const heading of top.querySelectorAll(':scope h1,h2,h3,h4,h5,h6,dt')) {
77
const id = heading.id;
@@ -53,7 +53,8 @@ export const formatTOC = (toc) => {
5353
toc_body.style.height = null;
5454
});
5555
});
56-
} else {
56+
}
57+
else {
5758
const finish = e => {
5859
toc_body.removeEventListener('transitionend', finish);
5960
toc_body.style.height = null;

0 commit comments

Comments
 (0)