Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: style formatting and linting fixes #366

Merged
merged 4 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
{
"editor.tabSize": 2,
"typescript.format.semicolons": "remove",
"javascript.format.semicolons": "remove",
"typescript.suggest.includeAutomaticOptionalChainCompletions": true,
"editor.formatOnSave": true,
"eslint.codeActionsOnSave.rules": [],
"files.exclude": {
"package-lock.json": true
}
"editor.tabSize": 2,
"typescript.format.semicolons": "remove",
"javascript.format.semicolons": "remove",
"typescript.suggest.includeAutomaticOptionalChainCompletions": true,
"editor.formatOnSave": false,
"eslint.codeActionsOnSave.rules": [],
"files.exclude": {
"package-lock.json": true
},
"standard.enable": true,
"standard.enableGlobally": false,
"standard.run": "onSave",
"standard.autoFixOnSave": true,
"editor.defaultFormatter": "standard.vscode-standard",
"[html]": {
"editor.defaultFormatter": "standard.vscode-standard",
},
"[json]": {
"editor.defaultFormatter": "standard.vscode-standard",
},
"[javascript]": {
"editor.defaultFormatter": "standard.vscode-standard",
}
}
218 changes: 218 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@
"scripts": {
"start": "npm run build && npx -y serve -l 3000 dist",
"copy-assets": "cp-cli src/index.html dist/index.html && cp-cli src/styles.css dist/styles.css",
"lint": "aegir lint",
"lint": "aegir lint && npx -y standard && node scripts/beautify.mjs",
"lint:fix": "aegir lint --fix && npx -y standard --fix && node scripts/beautify.mjs --fix",
"release": "aegir release",
"sw": "node scripts/build-sw.mjs",
"build": "aegir build && npm run copy-assets && npm run sw",
Expand All @@ -133,6 +134,7 @@
"fetch-ponyfill": "^7.1.0",
"ipfs": "^0.65.0",
"ipfs-geoip": "^9.0.0",
"js-beautify": "^1.14.7",
"typescript": "^4.8.4",
"workbox-build": "6.5.4",
"workbox-window": "6.5.4"
Expand Down
43 changes: 43 additions & 0 deletions scripts/beautify.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import jsBeautify from 'js-beautify'
import { promises as fs } from 'fs'

const saveFile = process.argv.slice(2).includes('--fix')

const files = {
'src/index.html': jsBeautify.html,
'src/styles.css': jsBeautify.css
}

async function beautificationFn (filePath, fn) {
console.log(`Checking ${filePath} formatting...`)
const sourceCode = await fs.readFile(filePath, 'utf8')

console.log(`Beautifying ${filePath}...`)
const beautifiedCode = fn(sourceCode, {
indent_size: 2,
space_in_empty_paren: true,
indent_char: ' ',
indent_with_tabs: false,
editorconfig: false,
eol: '\n',
end_with_newline: true,
indent_level: 0
})

// lint mode.. fail if not beautified
if (sourceCode === beautifiedCode) {
console.log(`${filePath} is already beautified`)
return
} else if (!saveFile) {
throw new Error(`${filePath} is not beautified`)
}

if (saveFile) {
console.log(`Saving beautified ${filePath}`)
await fs.writeFile(filePath, beautifiedCode, 'utf8')
}
}

for (const [filePath, fn] of Object.entries(files)) {
await beautificationFn(filePath, fn)
}
6 changes: 3 additions & 3 deletions scripts/build-sw.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {generateSW} from 'workbox-build';
import { generateSW } from 'workbox-build'

generateSW({
globDirectory: 'dist/',
Expand All @@ -11,8 +11,8 @@ generateSW({
runtimeCaching: [
{
urlPattern: /\.(?:png|jpg|jpeg|svg)$/,
handler: 'NetworkFirst',
handler: 'NetworkFirst'
}
],
swDest: 'dist/sw.js'
});
})
Loading