Skip to content
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
2 changes: 1 addition & 1 deletion content/alarm-clock/Clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
since this number is out of the range for `int`
(-32,768 ... 32,767), we'll get an unexpected result:
-5536 instead of 60000.
*/
*/
#define MINUTE 60 * 1000L /* ms */
#define TIMESPAN_DAY TimeSpan(1, 0, 0, 0)
/* gac:end */
Expand Down
4 changes: 2 additions & 2 deletions content/dice-roller/dice-roller.ino
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ void loop() {
✅ Give `digitalRead(...)` a meaningful name by storing the result
it into a variable */
bool buttonPressed = digitalRead(BUTTON_PIN) == LOW;
/* gac:
Check if this is the first time the button is pressed. */
/* gac:
Check if this is the first time the button is pressed. */
if (!randomReady && buttonPressed) {
/* Initialize the random number generator with the number of
microseconds between program start and the first button press */
Expand Down
4 changes: 2 additions & 2 deletions content/simon/pitches.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**************************************************
* This file defines constants with the frequency
* of different musical notes.
This file defines constants with the frequency
of different musical notes.
*************************************************/

#define NOTE_B0 31
Expand Down
6 changes: 6 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: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@types/react-test-renderer": "^16.9.2",
"@typescript-eslint/eslint-plugin": "^3.7.0",
"@typescript-eslint/parser": "^3.7.0",
"astyle": "^2.0.0",
"eslint": "^7.5.0",
"eslint-config-prettier": "^6.11.0",
"eslint-config-standard": "^14.1.1",
Expand Down Expand Up @@ -63,6 +64,9 @@
],
"*.md": [
"prettier --write"
],
"*.{h,ino,cpp}": [
"node utils/format-arduino-code"
]
}
}
36 changes: 36 additions & 0 deletions utils/format-arduino-code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* A small command-line utility used by the git pre-commit hook
* to automatically format the code.
*/

const { format } = require('astyle');
const { promises: fs } = require('fs');

// Source: https://github.com/arduino/Arduino/blob/ide-1.5.x/build/shared/lib/formatter.conf
const ARDUINO_FORMAT_RULES = [
'mode=c',
'indent=spaces=2',
'indent-preprocessor',
'indent-classes',
'indent-switches',
'indent-cases',
'indent-col1-comments',
'pad-oper',
'pad-header',
'keep-one-line-statements',
'remove-comment-prefix',
].join(' ');

async function main() {
for (const file of process.argv.slice(2)) {
const source = await fs.readFile(file, 'utf-8');
console.log(file);
const formatted = await format(source, ARDUINO_FORMAT_RULES);
if (source !== formatted) {
console.log(`* Formating ${file}`);
await fs.writeFile(file, formatted);
}
}
}

main();