Skip to content

Commit

Permalink
Merge pull request #647 from code-dot-org/hoc2023-prettier-src
Browse files Browse the repository at this point in the history
hoc2023: prettier JS files
  • Loading branch information
breville authored Sep 19, 2023
2 parents 6672bdb + 832dd46 commit a3b32a1
Show file tree
Hide file tree
Showing 51 changed files with 3,553 additions and 2,623 deletions.
104 changes: 52 additions & 52 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,59 @@
// or overridden for a particular subset of the project. See
// other .eslintrc.js files for those rules.
module.exports = {
"globals": {
"Phaser": true,
"PIXI": true
globals: {
Phaser: true,
PIXI: true,
},
"plugins": [
],
"extends": [
"eslint:recommended",
],
"env": {
"browser": true,
"node": true,
"es6": true
plugins: [],
extends: ['eslint:recommended'],
env: {
browser: true,
node: true,
es6: true,
},
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2017,
"ecmaFeatures": {
"jsx": true,
"modules": true,
"ecmaVersion": 6,
"experimentalObjectRestSpread": true
}
parserOptions: {
sourceType: 'module',
ecmaVersion: 2017,
ecmaFeatures: {
jsx: true,
modules: true,
ecmaVersion: 6,
experimentalObjectRestSpread: true,
},
},
rules: {
'array-bracket-spacing': ['error', 'never'],
'brace-style': ['error', '1tbs', {allowSingleLine: true}],
'comma-dangle': 'off',
curly: 'error',
'dot-location': ['error', 'property'],
'eol-last': 'error',
eqeqeq: 'error',
'jsx-quotes': 'error', // autofixable
'keyword-spacing': 'error',
indent: ['error', 2, {SwitchCase: 1}],
'no-array-constructor': 'error',
'no-console': 'off',
'no-duplicate-imports': 'error',
'no-empty': 'off',
'no-eval': 'error',
'no-extra-boolean-cast': 'off',
'no-implicit-globals': 'error',
'no-new-object': 'error',
'no-trailing-spaces': 'error',
'no-undef': 'error',
'no-unused-vars': 'error',
'no-with': 'error',
'object-curly-spacing': 'off',
semi: 'error',
'space-before-function-paren': [
'error',
{
anonymous: 'always',
named: 'never',
},
],
strict: 'error',
},
"rules": {
"array-bracket-spacing": ["error", "never"],
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
"comma-dangle": "off",
"curly": "error",
"dot-location": ["error", "property"],
"eol-last": "error",
"eqeqeq": "error",
"jsx-quotes": "error", // autofixable
"keyword-spacing": "error",
"indent": ["error", 2, {"SwitchCase": 1}],
"no-array-constructor": "error",
"no-console": "off",
"no-duplicate-imports": "error",
"no-empty": "off",
"no-eval": "error",
"no-extra-boolean-cast": "off",
"no-implicit-globals": "error",
"no-new-object": "error",
"no-trailing-spaces": "error",
"no-undef": "error",
"no-unused-vars": "error",
"no-with": "error",
"object-curly-spacing": "off",
"semi": "error",
"space-before-function-paren": ["error", {
"anonymous": "always",
"named": "never"
}],
"strict": "error",
}
};
5 changes: 5 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
singleQuote: true,
bracketSpacing: false,
arrowParens: 'avoid',
};
36 changes: 20 additions & 16 deletions demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ import injectInterpreted from './test/helpers/injectInterpreted';
const textareaCode = document.querySelector('#code');
const buttonRun = document.querySelector('#run');

const nativeAPI = window.nativeAPI = new DanceParty({
const nativeAPI = (window.nativeAPI = new DanceParty({
onPuzzleComplete: () => {},
playSound: (url, callback, onEnded) => setTimeout(() => {
callback && callback();
}, 0),
playSound: (url, callback, onEnded) =>
setTimeout(() => {
callback && callback();
}, 0),
onInit: () => {
document.querySelector('#run').style.display = 'inline';
runCode();
},
container: 'dance',
});
}));

// Note: We don't just declare
// async function runCode() {
Expand All @@ -27,22 +28,25 @@ const nativeAPI = window.nativeAPI = new DanceParty({
const runCode = async function () {
await nativeAPI.ensureSpritesAreLoaded();

const {
runUserSetup,
runUserEvents,
getCueList,
} = injectInterpreted(nativeAPI, interpreted, textareaCode.value);
const {runUserSetup, runUserEvents, getCueList} = injectInterpreted(
nativeAPI,
interpreted,
textareaCode.value
);

// Setup event tracking.
nativeAPI.addCues(getCueList());
nativeAPI.onHandleEvents = currentFrameEvents => runUserEvents(currentFrameEvents);
nativeAPI.onHandleEvents = currentFrameEvents =>
runUserEvents(currentFrameEvents);

runUserSetup();

nativeAPI.play(jazzy_beats);
}
};

textareaCode.value = textareaCode.value || `var cat = makeNewDanceSprite("CAT", null, {x: 200, y: 200});
textareaCode.value =
textareaCode.value ||
`var cat = makeNewDanceSprite("CAT", null, {x: 200, y: 200});
setBackgroundEffectWithPalette("disco_ball", "rand");
atTimestamp(2, "measures", function () {
Expand All @@ -51,11 +55,11 @@ atTimestamp(2, "measures", function () {
`;

document.querySelector('#run').addEventListener('click', () => {
if (buttonRun.innerText === "Reset") {
buttonRun.innerText = "Run!";
if (buttonRun.innerText === 'Reset') {
buttonRun.innerText = 'Run!';
nativeAPI.reset();
} else {
buttonRun.innerText = "Reset";
buttonRun.innerText = 'Reset';
runCode();
}
});
30 changes: 16 additions & 14 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ module.exports = config => {
frameworks: ['tap'],
files: [
{pattern: 'test/integration/index.js'},
{pattern: 'test/assets/sprite_sheets/**/*.*', watched: false, included: false, served: true},
{
pattern: 'test/assets/sprite_sheets/**/*.*',
watched: false,
included: false,
served: true,
},
],
preprocessors: {
'test/integration/*.js': ['webpack', 'sourcemap'],
Expand All @@ -15,16 +20,15 @@ module.exports = config => {
fs: 'empty',
},
module: {
rules: [{
enforce: 'post',
test: /\.js$/,
exclude: [
/(test|node_modules)\//,
'src/p5.dance.interpreted.js',
],
loader: 'istanbul-instrumenter-loader'
}]
}
rules: [
{
enforce: 'post',
test: /\.js$/,
exclude: [/(test|node_modules)\//, 'src/p5.dance.interpreted.js'],
loader: 'istanbul-instrumenter-loader',
},
],
},
},
reporters: ['tap-pretty', 'coverage'],

Expand All @@ -40,9 +44,7 @@ module.exports = config => {
// Code coverage.
coverageReporter: {
dir: 'coverage/integration',
reporters: [
{type: 'lcovonly'},
],
reporters: [{type: 'lcovonly'}],
},
});
};
3 changes: 1 addition & 2 deletions levels/effectsLevels.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = {
changeBackgroundAtTimestamp: {
solutions:
`
solutions: `
var lead_dancer;
whenSetup(function () {
Expand Down
104 changes: 52 additions & 52 deletions levels/spriteDance.js
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
module.exports = {
collisionEveryNMeasure: {
solutions: [
`
var lead_dancer;
whenSetup(function () {
makeNewDanceSprite("CAT", "lead_dancer", {x: 200, y: 200});
});
everySeconds(2, "measures", function () {
changeMoveLR("lead_dancer", 3, -1);
});
everySeconds(4, "measures", function () {
changeMoveLR("lead_dancer", 1, -1);
setProp("lead_dancer", "scale", 50);
});
`
var lead_dancer;
whenSetup(function () {
makeNewDanceSprite("CAT", "lead_dancer", {x: 200, y: 200});
});
everySeconds(2, "measures", function () {
changeMoveLR("lead_dancer", 3, -1);
});
everySeconds(4, "measures", function () {
changeMoveLR("lead_dancer", 1, -1);
setProp("lead_dancer", "scale", 50);
});
`,
`
var lead_dancer;
whenSetup(function () {
makeNewDanceSprite("CAT", "lead_dancer", {x: 200, y: 200});
});
everySeconds(4, "measures", function () {
changeMoveLR("lead_dancer", 1, -1);
});
everySeconds(2, "measures", function () {
changeMoveLR("lead_dancer", 3, -1);
});
`
var lead_dancer;
whenSetup(function () {
makeNewDanceSprite("CAT", "lead_dancer", {x: 200, y: 200});
});
everySeconds(4, "measures", function () {
changeMoveLR("lead_dancer", 1, -1);
});
everySeconds(2, "measures", function () {
changeMoveLR("lead_dancer", 3, -1);
});
`,
],
validationCode: `
if (nativeAPI.getTime("measures") === 5) {
let cats = nativeAPI.getGroupByName_('CAT');
for(let i = 0; i < cats.length; i++){
if(cats[i].current_move !== 1){
nativeAPI.fail("Cat sprite not dancing 1.");
}
}
}
if (nativeAPI.getTime("measures") > 8 && nativeAPI.getTime("measures") < 9) {
let cats = nativeAPI.getGroupByName_('CAT');
for(let i = 0; i < cats.length; i++){
if(cats[i].current_move !== 3){
nativeAPI.fail("Cat sprite not dancing 3.");
}
}
}
if (nativeAPI.getTime("measures") > 1 && nativeAPI.getTime("measures") < 2) {
let cats = nativeAPI.getGroupByName_('CAT');
for(let i = 0; i < cats.length; i++){
if(nativeAPI.getProp(cats[i], "scale") === 50) {
nativeAPI.fail("Cat sprite event happened too early.");
}
}
}
if (nativeAPI.getTime("measures") > 9) {
nativeAPI.pass();
}
validationCode: `
if (nativeAPI.getTime("measures") === 5) {
let cats = nativeAPI.getGroupByName_('CAT');
for(let i = 0; i < cats.length; i++){
if(cats[i].current_move !== 1){
nativeAPI.fail("Cat sprite not dancing 1.");
}
}
}
if (nativeAPI.getTime("measures") > 8 && nativeAPI.getTime("measures") < 9) {
let cats = nativeAPI.getGroupByName_('CAT');
for(let i = 0; i < cats.length; i++){
if(cats[i].current_move !== 3){
nativeAPI.fail("Cat sprite not dancing 3.");
}
}
}
if (nativeAPI.getTime("measures") > 1 && nativeAPI.getTime("measures") < 2) {
let cats = nativeAPI.getGroupByName_('CAT');
for(let i = 0; i < cats.length; i++){
if(nativeAPI.getProp(cats[i], "scale") === 50) {
nativeAPI.fail("Cat sprite event happened too early.");
}
}
}
if (nativeAPI.getTime("measures") > 9) {
nativeAPI.pass();
}
`,
},
};
};
Loading

0 comments on commit a3b32a1

Please sign in to comment.