Skip to content

Commit

Permalink
chore: style formatting and linting fixes (#366)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
SgtPooki authored Jan 16, 2023
1 parent 0536782 commit a81d48b
Show file tree
Hide file tree
Showing 7 changed files with 391 additions and 108 deletions.
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

0 comments on commit a81d48b

Please sign in to comment.