-
Notifications
You must be signed in to change notification settings - Fork 85
Code formatter #385
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
Open
franekwitt
wants to merge
7
commits into
sio2project:master
Choose a base branch
from
franekwitt:code_formatter
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+382
−31
Open
Code formatter #385
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9ba9b1e
code_formatter
franekwitt 70d3af0
Add tests
franekwitt eedf1eb
cleanup formatter.js
franekwitt a57010c
remove pygments
franekwitt affbfba
allow formatting C files
franekwitt e3b16a2
add clang-format readme
franekwitt 7beb7f7
Fix review issues.
franekwitt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,279 @@ | ||
[ | ||
{ | ||
"pk": 1, | ||
"model": "contests.submission", | ||
"fields": { | ||
"status": "OK", | ||
"problem_instance": 1, | ||
"kind": "NORMAL", | ||
"comment": "", | ||
"score": "int:0000000000000000034", | ||
"user": 1001, | ||
"date": "2012-06-03T22:07:07.516Z" | ||
} | ||
}, | ||
{ | ||
"pk": 1, | ||
"model": "contests.submissionreport", | ||
"fields": { | ||
"status": "ACTIVE", | ||
"kind": "INITIAL", | ||
"submission": 1, | ||
"creation_date": "2012-08-03T22:07:29.547Z" | ||
} | ||
}, | ||
{ | ||
"pk": 2, | ||
"model": "contests.submissionreport", | ||
"fields": { | ||
"status": "ACTIVE", | ||
"kind": "NORMAL", | ||
"submission": 1, | ||
"creation_date": "2012-08-03T22:07:39.662Z" | ||
} | ||
}, | ||
{ | ||
"pk": 1, | ||
"model": "contests.scorereport", | ||
"fields": { | ||
"status": "OK", | ||
"comment": null, | ||
"score": null, | ||
"submission_report": 1, | ||
"max_score": "int:0000000000000000100" | ||
} | ||
}, | ||
{ | ||
"pk": 2, | ||
"model": "contests.scorereport", | ||
"fields": { | ||
"status": "RE", | ||
"comment": null, | ||
"score": "int:0000000000000000034", | ||
"submission_report": 2, | ||
"max_score": "int:0000000000000000100" | ||
} | ||
}, | ||
{ | ||
"pk": 1, | ||
"model": "contests.userresultforproblem", | ||
"fields": { | ||
"status": "OK", | ||
"problem_instance": 1, | ||
"score": "int:0000000000000000034", | ||
"user": 1001, | ||
"submission_report": 2 | ||
} | ||
}, | ||
{ | ||
"pk": 1, | ||
"model": "contests.userresultforround", | ||
"fields": { | ||
"score": "int:0000000000000000034", | ||
"user": 1001, | ||
"round": 1 | ||
} | ||
}, | ||
{ | ||
"pk": 1, | ||
"model": "contests.userresultforcontest", | ||
"fields": { | ||
"score": "int:0000000000000000034", | ||
"user": 1001, | ||
"contest": "c" | ||
} | ||
}, | ||
{ | ||
"pk": 1, | ||
"model": "programs.programsubmission", | ||
"fields": { | ||
"source_file": "data:submissions/c/1.py:data:submissions/c/2.py:YSwgYiA9IGlucHV0KCkuc3BsaXQoKQoKcHJpbnQoaW50KGEpICsgaW50KGIpKQ==", | ||
"source_length": 46 | ||
} | ||
}, | ||
{ | ||
"pk": 1, | ||
"model": "programs.compilationreport", | ||
"fields": { | ||
"status": "OK", | ||
"compiler_output": "", | ||
"submission_report": 1 | ||
} | ||
}, | ||
{ | ||
"pk": 2, | ||
"model": "programs.compilationreport", | ||
"fields": { | ||
"status": "OK", | ||
"compiler_output": "", | ||
"submission_report": 2 | ||
} | ||
}, | ||
{ | ||
"pk": 1, | ||
"model": "programs.testreport", | ||
"fields": { | ||
"status": "OK", | ||
"comment": "", | ||
"test_time_limit": 10000, | ||
"submission_report": 1, | ||
"time_used": 1, | ||
"test_group": "0", | ||
"score": "int:0000000000000000000", | ||
"test_name": "0", | ||
"test": 1 | ||
} | ||
}, | ||
{ | ||
"pk": 2, | ||
"model": "programs.testreport", | ||
"fields": { | ||
"status": "OK", | ||
"comment": "", | ||
"test_time_limit": 10000, | ||
"submission_report": 1, | ||
"time_used": 1, | ||
"test_group": "1ocen", | ||
"score": "int:0000000000000000000", | ||
"test_name": "1ocen", | ||
"test": 4 | ||
} | ||
}, | ||
{ | ||
"pk": 3, | ||
"model": "programs.testreport", | ||
"fields": { | ||
"status": "OK", | ||
"comment": "", | ||
"test_time_limit": 10000, | ||
"submission_report": 2, | ||
"time_used": 1, | ||
"test_group": "1", | ||
"score": "int:0000000000000000005", | ||
"test_name": "1a", | ||
"test": 2 | ||
} | ||
}, | ||
{ | ||
"pk": 4, | ||
"model": "programs.testreport", | ||
"fields": { | ||
"status": "OK", | ||
"comment": "", | ||
"test_time_limit": 10000, | ||
"submission_report": 2, | ||
"time_used": 1, | ||
"test_group": "3", | ||
"score": "int:0000000000000000034", | ||
"test_name": "3", | ||
"test": 6 | ||
} | ||
}, | ||
{ | ||
"pk": 5, | ||
"model": "programs.testreport", | ||
"fields": { | ||
"status": "WA", | ||
"comment": "", | ||
"test_time_limit": 10000, | ||
"submission_report": 2, | ||
"time_used": 0, | ||
"test_group": "2", | ||
"score": "int:0000000000000000000", | ||
"test_name": "2", | ||
"test": 5 | ||
} | ||
}, | ||
{ | ||
"pk": 6, | ||
"model": "programs.testreport", | ||
"fields": { | ||
"status": "RE", | ||
"comment": "program exited with code 1", | ||
"test_time_limit": 100, | ||
"submission_report": 2, | ||
"time_used": 0, | ||
"test_group": "1", | ||
"score": "int:0000000000000000000", | ||
"test_name": "1b", | ||
"test": 3 | ||
} | ||
}, | ||
{ | ||
"pk": 1, | ||
"model": "programs.groupreport", | ||
"fields": { | ||
"status": "OK", | ||
"group": "0", | ||
"score": "int:0000000000000000000", | ||
"max_score": "int:0000000000000000000", | ||
"submission_report": 1 | ||
} | ||
}, | ||
{ | ||
"pk": 2, | ||
"model": "programs.groupreport", | ||
"fields": { | ||
"status": "OK", | ||
"group": "1ocen", | ||
"score": "int:0000000000000000000", | ||
"max_score": "int:0000000000000000000", | ||
"submission_report": 1 | ||
} | ||
}, | ||
{ | ||
"pk": 3, | ||
"model": "programs.groupreport", | ||
"fields": { | ||
"status": "RE", | ||
"group": "1", | ||
"score": "int:0000000000000000000", | ||
"max_score": "int:0000000000000000033", | ||
"submission_report": 2 | ||
} | ||
}, | ||
{ | ||
"pk": 4, | ||
"model": "programs.groupreport", | ||
"fields": { | ||
"status": "OK", | ||
"group": "0", | ||
"score": "int:0000000000000000000", | ||
"max_score": "int:0000000000000000000", | ||
"submission_report": 2 | ||
} | ||
}, | ||
{ | ||
"pk": 5, | ||
"model": "programs.groupreport", | ||
"fields": { | ||
"status": "OK", | ||
"group": "3", | ||
"score": "int:0000000000000000034", | ||
"max_score": "int:0000000000000000034", | ||
"submission_report": 2 | ||
} | ||
}, | ||
{ | ||
"pk": 6, | ||
"model": "programs.groupreport", | ||
"fields": { | ||
"status": "OK", | ||
"group": "1ocen", | ||
"score": "int:0000000000000000000", | ||
"max_score": "int:0000000000000000000", | ||
"submission_report": 2 | ||
} | ||
}, | ||
{ | ||
"pk": 7, | ||
"model": "programs.groupreport", | ||
"fields": { | ||
"status": "WA", | ||
"group": "2", | ||
"score": "int:0000000000000000000", | ||
"max_score": "int:0000000000000000033", | ||
"submission_report": 2 | ||
} | ||
} | ||
] |
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains hidden or 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,31 @@ | ||
import init, { format, version } from "./clang-format.js"; | ||
|
||
// clang-format | ||
async function cpp_code_formatter(source) { | ||
await init(); | ||
const formatted = format( | ||
source, | ||
"main.cc", | ||
JSON.stringify({ | ||
BasedOnStyle: "Chromium", | ||
IndentWidth: 4, | ||
ColumnLimit: 80, | ||
}) | ||
); | ||
return formatted; | ||
} | ||
|
||
async function format_cpp_code() { | ||
const source = document.getElementById("raw_source").textContent; | ||
const formatted_source = await cpp_code_formatter(source); | ||
const visible_source = document.getElementById("visible_source"); | ||
const coloured_source = Prism.highlight(formatted_source, Prism.languages.cpp, "cpp"); | ||
visible_source.innerHTML = coloured_source; | ||
|
||
const button = document.getElementById("format_btn"); | ||
button.classList.remove("btn-outline-secondary"); | ||
button.classList.add("btn-success"); | ||
button.textContent = gettext("Formatted!"); | ||
} | ||
|
||
globalThis.format_cpp_code = format_cpp_code; |
This file contains hidden or 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,2 @@ | ||
Clang-format WASM build (with source) can be found here: https://github.com/wasm-fmt/clang-format/releases/download/v0.2.8/clang-format.wasm | ||
In order to update just replace the .wasm file. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.