From 67ad82d52ef69caac918aefd5951962baf3051bb Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Tue, 13 Dec 2022 21:27:16 +0100 Subject: [PATCH 1/3] add lint + prettier check before test --- .github/workflows/test.yml | 15 ++++++++------- package.json | 6 ++++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7813cf60..8667da4b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,10 +10,11 @@ jobs: node-version: [18] steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - cache: 'npm' - - run: npm install - - run: npm test + - uses: actions/checkout@v2 + - uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: "npm" + - run: npm install + - run: npm run check + - run: npm test diff --git a/package.json b/package.json index 6921fafc..dff9985c 100644 --- a/package.json +++ b/package.json @@ -18,8 +18,10 @@ "deploy": "NODE_DEBUG=gh-pages gh-pages -d out", "jsdoc": "jsdoc packages/ -c jsdoc.config.json", "jsdoc-json": "jsdoc packages/ --template ./node_modules/jsdoc-json --destination doc.json -c jsdoc.config.json", - "lint": "npx eslint . --ext mjs,js --quiet", - "codeformat": "prettier --write ." + "lint": "eslint . --ext mjs,js --quiet", + "codeformat": "prettier --write .", + "format-check": "prettier --check .", + "check": "npm run format-check && npm run lint" }, "workspaces": [ "packages/*" From bf1ba6efc0a78ce0525b57ba5af1091085d917bf Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Tue, 13 Dec 2022 21:32:03 +0100 Subject: [PATCH 2/3] code format --- .prettierignore | 1 + .prettierrc | 29 +++++++++---------- .../core/examples/vite-vanilla-repl/main.js | 2 +- packages/core/hap.mjs | 16 +++++----- packages/core/pattern.mjs | 19 ++++++------ packages/core/test/pattern.test.mjs | 14 ++++----- packages/core/timespan.mjs | 4 +-- packages/osc/server.js | 2 -- .../react/examples/nano-repl/vite.config.js | 8 ++--- packages/react/index.html | 2 +- packages/react/postcss.config.js | 2 +- packages/react/src/main.jsx | 13 ++++++--- packages/serial/serial.mjs | 23 ++++++++------- packages/soundfonts/list.mjs | 6 ++-- repl/postcss.config.js | 2 +- repl/src/index.css | 8 ++--- tutorial/postcss.config.cjs | 2 +- 17 files changed, 75 insertions(+), 78 deletions(-) diff --git a/.prettierignore b/.prettierignore index b4980cfc..d962cf6b 100644 --- a/.prettierignore +++ b/.prettierignore @@ -5,3 +5,4 @@ **/out **/dist packages/mini/krill-parser.js +packages/xen/tunejs.js diff --git a/.prettierrc b/.prettierrc index 12500f0d..c35a73b5 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,16 +1,15 @@ { - "printWidth": 120, - "useTabs": false, - "tabWidth": 2, - "semi": true, - "singleQuote": true, - "jsxSingleQuote": false, - "trailingComma": "all", - "bracketSpacing": true, - "jsxBracketSameLine": false, - "arrowParens": "always", - "proseWrap": "preserve", - "htmlWhitespaceSensitivity": "css", - "endOfLine": "lf" - } - \ No newline at end of file + "printWidth": 120, + "useTabs": false, + "tabWidth": 2, + "semi": true, + "singleQuote": true, + "jsxSingleQuote": false, + "trailingComma": "all", + "bracketSpacing": true, + "jsxBracketSameLine": false, + "arrowParens": "always", + "proseWrap": "preserve", + "htmlWhitespaceSensitivity": "css", + "endOfLine": "lf" +} diff --git a/packages/core/examples/vite-vanilla-repl/main.js b/packages/core/examples/vite-vanilla-repl/main.js index 72d80b92..3724ef95 100644 --- a/packages/core/examples/vite-vanilla-repl/main.js +++ b/packages/core/examples/vite-vanilla-repl/main.js @@ -16,7 +16,7 @@ evalScope( import('@strudel.cycles/tonal'), ); -setStringParser(mini) +setStringParser(mini); const { evaluate } = repl({ defaultOutput: webaudioOutput, diff --git a/packages/core/hap.mjs b/packages/core/hap.mjs index ae6b2177..30251959 100644 --- a/packages/core/hap.mjs +++ b/packages/core/hap.mjs @@ -80,16 +80,16 @@ export class Hap { } show(compact = false) { - const value = typeof this.value === 'object' - ? compact + const value = + typeof this.value === 'object' + ? compact ? JSON.stringify(this.value).slice(1, -1).replaceAll('"', '').replaceAll(',', ' ') : JSON.stringify(this.value) - : this.value + : this.value; var spans = ''; if (this.whole == undefined) { spans = '~' + this.part.show; - } - else { + } else { var is_whole = this.whole.begin.equals(this.part.begin) && this.whole.end.equals(this.part.end); if (!this.whole.begin.equals(this.part.begin)) { spans = this.whole.begin.show() + ' ⇜ '; @@ -102,12 +102,10 @@ export class Hap { spans += ')'; } if (!this.whole.end.equals(this.part.end)) { - spans += ' ⇝ ' + this.whole.end.show() + spans += ' ⇝ ' + this.whole.end.show(); } } - return ( - '[ ' + spans + ' | ' + value + ' ]' - ); + return '[ ' + spans + ' | ' + value + ' ]'; } showWhole(compact = false) { diff --git a/packages/core/pattern.mjs b/packages/core/pattern.mjs index 4bd55395..98bc23a7 100644 --- a/packages/core/pattern.mjs +++ b/packages/core/pattern.mjs @@ -541,35 +541,34 @@ export class Pattern { defragmentHaps() { // remove continuous haps const pat = this.discreteOnly(); - + return pat.withHaps((haps) => { const result = []; - for (var i=0; i < haps.length; ++i) { + for (var i = 0; i < haps.length; ++i) { var searching = true; var a = haps[i]; while (searching) { const a_value = JSON.stringify(haps[i].value); var found = false; - for(var j=i+1; j { }); describe('defragmentHaps', () => { it('Can merge two touching haps with same whole and value', () => { - expect(stack(pure('a').mask(1,0), pure('a').mask(0,1)).defragmentHaps().firstCycle().length) - .toStrictEqual(1); + expect(stack(pure('a').mask(1, 0), pure('a').mask(0, 1)).defragmentHaps().firstCycle().length).toStrictEqual(1); }); it('Doesnt merge two overlapping haps', () => { - expect(stack(pure('a').mask(1,1,0), pure('a').mask(0,1)).defragmentHaps().firstCycle().length) - .toStrictEqual(2); + expect(stack(pure('a').mask(1, 1, 0), pure('a').mask(0, 1)).defragmentHaps().firstCycle().length).toStrictEqual( + 2, + ); }); it('Doesnt merge two touching haps with different values', () => { - expect(stack(pure('a').mask(1,0), pure('b').mask(0,1)).defragmentHaps().firstCycle().length) - .toStrictEqual(2); + expect(stack(pure('a').mask(1, 0), pure('b').mask(0, 1)).defragmentHaps().firstCycle().length).toStrictEqual(2); }); it('Doesnt merge two touching haps with different wholes', () => { - expect(stack(sequence('a', silence), pure('a').mask(0,1)).defragmentHaps().firstCycle().length) - .toStrictEqual(2); + expect(stack(sequence('a', silence), pure('a').mask(0, 1)).defragmentHaps().firstCycle().length).toStrictEqual(2); }); }); }); diff --git a/packages/core/timespan.mjs b/packages/core/timespan.mjs index c2a1651e..4cbfb999 100644 --- a/packages/core/timespan.mjs +++ b/packages/core/timespan.mjs @@ -20,9 +20,9 @@ export class TimeSpan { // Support zero-width timespans if (begin.equals(end)) { - return([new TimeSpan(begin, end)]); + return [new TimeSpan(begin, end)]; } - + while (end.gt(begin)) { // If begin and end are in the same cycle, we're done. if (begin.sam().equals(end_sam)) { diff --git a/packages/osc/server.js b/packages/osc/server.js index ba6f9f90..42722d28 100644 --- a/packages/osc/server.js +++ b/packages/osc/server.js @@ -25,8 +25,6 @@ const config = { }, }; - - const osc = new OSC({ plugin: new OSC.BridgePlugin(config) }); osc.open(); // start a WebSocket server on port 8080 diff --git a/packages/react/examples/nano-repl/vite.config.js b/packages/react/examples/nano-repl/vite.config.js index b1b5f91e..627a3196 100644 --- a/packages/react/examples/nano-repl/vite.config.js +++ b/packages/react/examples/nano-repl/vite.config.js @@ -1,7 +1,7 @@ -import { defineConfig } from 'vite' -import react from '@vitejs/plugin-react' +import { defineConfig } from 'vite'; +import react from '@vitejs/plugin-react'; // https://vitejs.dev/config/ export default defineConfig({ - plugins: [react()] -}) + plugins: [react()], +}); diff --git a/packages/react/index.html b/packages/react/index.html index 4ec7488d..83d2bd57 100644 --- a/packages/react/index.html +++ b/packages/react/index.html @@ -2,7 +2,7 @@ - + Strudel React Components diff --git a/packages/react/postcss.config.js b/packages/react/postcss.config.js index 8365a461..b77b9fe4 100644 --- a/packages/react/postcss.config.js +++ b/packages/react/postcss.config.js @@ -9,4 +9,4 @@ module.exports = { tailwindcss: {}, autoprefixer: {}, }, -} +}; diff --git a/packages/react/src/main.jsx b/packages/react/src/main.jsx index 57beb943..e9780201 100644 --- a/packages/react/src/main.jsx +++ b/packages/react/src/main.jsx @@ -1,5 +1,10 @@ -import React from 'react' -import ReactDOM from 'react-dom' -import App from './App' +import React from 'react'; +import ReactDOM from 'react-dom'; +import App from './App'; -ReactDOM.render(,document.getElementById('root')) \ No newline at end of file +ReactDOM.render( + + + , + document.getElementById('root'), +); diff --git a/packages/serial/serial.mjs b/packages/serial/serial.mjs index e5e7c188..c4e52d4d 100644 --- a/packages/serial/serial.mjs +++ b/packages/serial/serial.mjs @@ -23,17 +23,16 @@ export async function getWriter(br = 38400) { const encoder = new TextEncoder(); const writer = port.writable.getWriter(); writeMessage = function (message, chk) { - const encoded = encoder.encode(message) + const encoded = encoder.encode(message); if (!chk) { writer.write(encoded); - } - else { + } else { const bytes = new Uint8Array(4); bytes[0] = 124; // | symbol - bytes[1] = (chk >> 8) & 0xFF; - bytes[2] = chk & 0xFF; + bytes[1] = (chk >> 8) & 0xff; + bytes[2] = chk & 0xff; bytes[3] = 59; // semicolon - const withchk = new Uint8Array(encoded.length+4) + const withchk = new Uint8Array(encoded.length + 4); withchk.set(encoded); withchk.set(bytes, encoded.length); writer.write(withchk); @@ -48,12 +47,12 @@ const latency = 0.1; // crc16 (CCITT-FALSE) https://gist.github.com/tijnkooijmans/10981093 function crc16(data) { - const length = data.length + const length = data.length; if (length == 0) { return 0; } - var crc = 0xFFFF; + var crc = 0xffff; for (var i = 0; i < length; ++i) { crc ^= data.charCodeAt(i) << 8; for (var j = 0; j < 8; ++j) { @@ -64,7 +63,7 @@ function crc16(data) { return crc & 0xffff; } -Pattern.prototype.serial = function (br=38400,sendcrc=false,singlecharids=false) { +Pattern.prototype.serial = function (br = 38400, sendcrc = false, singlecharids = false) { return this.withHap((hap) => { if (!writeMessage) { getWriter(br); @@ -96,7 +95,7 @@ Pattern.prototype.serial = function (br=38400,sendcrc=false,singlecharids=false) } message += ')'; if (sendcrc) { - chk = crc16(message) + chk = crc16(message); } } else { for (const [key, val] of Object.entries(hap.value)) { @@ -108,7 +107,9 @@ Pattern.prototype.serial = function (br=38400,sendcrc=false,singlecharids=false) } const offset = (time - currentTime + latency) * 1000; - window.setTimeout(function () {writeMessage(message, chk)}, offset); + window.setTimeout(function () { + writeMessage(message, chk); + }, offset); }; return hap.setContext({ ...hap.context, onTrigger, dominantTrigger: true }); }); diff --git a/packages/soundfonts/list.mjs b/packages/soundfonts/list.mjs index 3d103a96..527ef024 100644 --- a/packages/soundfonts/list.mjs +++ b/packages/soundfonts/list.mjs @@ -42,7 +42,7 @@ export const instruments = [ '0031_FluidR3_GM_sf2_file', '0031_GeneralUserGS_sf2_file', '0031_SoundBlasterOld_sf2', // pianos until here - '0040_Aspirin_sf2_file', + '0040_Aspirin_sf2_file', '0040_Chaos_sf2_file', '0040_FluidR3_GM_sf2_file', // rhodes '0040_GeneralUserGS_sf2_file', // staccato rhodes @@ -59,7 +59,7 @@ export const instruments = [ '0046_GeneralUserGS_sf2_file', // ? '0050_Aspirin_sf2_file', // glass organ '0050_Chaos_sf2_file', // short glass organ - '0050_FluidR3_GM_sf2_file',// long glass organ ! + '0050_FluidR3_GM_sf2_file', // long glass organ ! '0050_GeneralUserGS_sf2_file', // short glass organ '0050_JCLive_sf2_file', // glass organ '0050_SBLive_sf2', // ? @@ -1635,7 +1635,7 @@ export const drums = [ '81_4_Chaos_sf2_file', ]; -// see https://www.midi.org/specifications-old/item/gm-level-1-sound-set +// see https://www.midi.org/specifications-old/item/gm-level-1-sound-set export const instrumentNames = []; instrumentNames[0] = 'Acoustic Grand Piano: Piano'; instrumentNames[1] = 'Bright Acoustic Piano: Piano'; diff --git a/repl/postcss.config.js b/repl/postcss.config.js index 8365a461..b77b9fe4 100644 --- a/repl/postcss.config.js +++ b/repl/postcss.config.js @@ -9,4 +9,4 @@ module.exports = { tailwindcss: {}, autoprefixer: {}, }, -} +}; diff --git a/repl/src/index.css b/repl/src/index.css index ec2585e8..7323ae85 100644 --- a/repl/src/index.css +++ b/repl/src/index.css @@ -1,13 +1,11 @@ body { margin: 0; - font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', - 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', - sans-serif; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', + 'Droid Sans', 'Helvetica Neue', sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } code { - font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', - monospace; + font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace; } diff --git a/tutorial/postcss.config.cjs b/tutorial/postcss.config.cjs index 8365a461..b77b9fe4 100644 --- a/tutorial/postcss.config.cjs +++ b/tutorial/postcss.config.cjs @@ -9,4 +9,4 @@ module.exports = { tailwindcss: {}, autoprefixer: {}, }, -} +}; From 5d3c522da29e3b9da7a08922560991a9d7ffa79b Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Tue, 13 Dec 2022 21:53:45 +0100 Subject: [PATCH 3/3] run prettier + lint separately (improves output) --- .github/workflows/test.yml | 3 ++- package.json | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8667da4b..0f7d0ead 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,5 +16,6 @@ jobs: node-version: ${{ matrix.node-version }} cache: "npm" - run: npm install - - run: npm run check + - run: npm run format-check + - run: npm run lint - run: npm test diff --git a/package.json b/package.json index dff9985c..8c19ab86 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "description": "Port of tidalcycles to javascript", "scripts": { "pretest": "cd tutorial && npm run jsdoc-json", - "test": "npm run lint && vitest run --version", + "test": "vitest run --version", "test-ui": "vitest --ui", "test-coverage": "vitest --coverage", "bootstrap": "lerna bootstrap", @@ -21,7 +21,7 @@ "lint": "eslint . --ext mjs,js --quiet", "codeformat": "prettier --write .", "format-check": "prettier --check .", - "check": "npm run format-check && npm run lint" + "check": "npm run format-check && npm run lint && npm run test" }, "workspaces": [ "packages/*"