Skip to content

Commit a81d48b

Browse files
authored
chore: style formatting and linting fixes (#366)
* chore(formatting-settings): ensure formatting is handled properly * chore(lint): fix lint errors * chore(lint): lint css files too * chore(lint): fix style of src/styles.css
1 parent 0536782 commit a81d48b

File tree

7 files changed

+391
-108
lines changed

7 files changed

+391
-108
lines changed

Diff for: .vscode/settings.json

+23-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
{
2-
"editor.tabSize": 2,
3-
"typescript.format.semicolons": "remove",
4-
"javascript.format.semicolons": "remove",
5-
"typescript.suggest.includeAutomaticOptionalChainCompletions": true,
6-
"editor.formatOnSave": true,
7-
"eslint.codeActionsOnSave.rules": [],
8-
"files.exclude": {
9-
"package-lock.json": true
10-
}
2+
"editor.tabSize": 2,
3+
"typescript.format.semicolons": "remove",
4+
"javascript.format.semicolons": "remove",
5+
"typescript.suggest.includeAutomaticOptionalChainCompletions": true,
6+
"editor.formatOnSave": false,
7+
"eslint.codeActionsOnSave.rules": [],
8+
"files.exclude": {
9+
"package-lock.json": true
10+
},
11+
"standard.enable": true,
12+
"standard.enableGlobally": false,
13+
"standard.run": "onSave",
14+
"standard.autoFixOnSave": true,
15+
"editor.defaultFormatter": "standard.vscode-standard",
16+
"[html]": {
17+
"editor.defaultFormatter": "standard.vscode-standard",
18+
},
19+
"[json]": {
20+
"editor.defaultFormatter": "standard.vscode-standard",
21+
},
22+
"[javascript]": {
23+
"editor.defaultFormatter": "standard.vscode-standard",
24+
}
1125
}

Diff for: package-lock.json

+218
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@
109109
"scripts": {
110110
"start": "npm run build && npx -y serve -l 3000 dist",
111111
"copy-assets": "cp-cli src/index.html dist/index.html && cp-cli src/styles.css dist/styles.css",
112-
"lint": "aegir lint",
112+
"lint": "aegir lint && npx -y standard && node scripts/beautify.mjs",
113+
"lint:fix": "aegir lint --fix && npx -y standard --fix && node scripts/beautify.mjs --fix",
113114
"release": "aegir release",
114115
"sw": "node scripts/build-sw.mjs",
115116
"build": "aegir build && npm run copy-assets && npm run sw",
@@ -133,6 +134,7 @@
133134
"fetch-ponyfill": "^7.1.0",
134135
"ipfs": "^0.65.0",
135136
"ipfs-geoip": "^9.0.0",
137+
"js-beautify": "^1.14.7",
136138
"typescript": "^4.8.4",
137139
"workbox-build": "6.5.4",
138140
"workbox-window": "6.5.4"

Diff for: scripts/beautify.mjs

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import jsBeautify from 'js-beautify'
2+
import { promises as fs } from 'fs'
3+
4+
const saveFile = process.argv.slice(2).includes('--fix')
5+
6+
const files = {
7+
'src/index.html': jsBeautify.html,
8+
'src/styles.css': jsBeautify.css
9+
}
10+
11+
async function beautificationFn (filePath, fn) {
12+
console.log(`Checking ${filePath} formatting...`)
13+
const sourceCode = await fs.readFile(filePath, 'utf8')
14+
15+
console.log(`Beautifying ${filePath}...`)
16+
const beautifiedCode = fn(sourceCode, {
17+
indent_size: 2,
18+
space_in_empty_paren: true,
19+
indent_char: ' ',
20+
indent_with_tabs: false,
21+
editorconfig: false,
22+
eol: '\n',
23+
end_with_newline: true,
24+
indent_level: 0
25+
})
26+
27+
// lint mode.. fail if not beautified
28+
if (sourceCode === beautifiedCode) {
29+
console.log(`${filePath} is already beautified`)
30+
return
31+
} else if (!saveFile) {
32+
throw new Error(`${filePath} is not beautified`)
33+
}
34+
35+
if (saveFile) {
36+
console.log(`Saving beautified ${filePath}`)
37+
await fs.writeFile(filePath, beautifiedCode, 'utf8')
38+
}
39+
}
40+
41+
for (const [filePath, fn] of Object.entries(files)) {
42+
await beautificationFn(filePath, fn)
43+
}

Diff for: scripts/build-sw.mjs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {generateSW} from 'workbox-build';
1+
import { generateSW } from 'workbox-build'
22

33
generateSW({
44
globDirectory: 'dist/',
@@ -11,8 +11,8 @@ generateSW({
1111
runtimeCaching: [
1212
{
1313
urlPattern: /\.(?:png|jpg|jpeg|svg)$/,
14-
handler: 'NetworkFirst',
14+
handler: 'NetworkFirst'
1515
}
1616
],
1717
swDest: 'dist/sw.js'
18-
});
18+
})

0 commit comments

Comments
 (0)