-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
7 changed files
with
391 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.