From f4bcadcd04749b80848bf49e24e4ff79adbe633c Mon Sep 17 00:00:00 2001 From: Caleb Evans Date: Sat, 31 Aug 2024 18:39:40 -0700 Subject: [PATCH] Add 'format' npm script; run Prettier on all files --- .github/workflows/tests.yml | 6 ++-- .prettierignore | 1 + README.md | 4 +-- index.html | 50 ++++++++++++++++-------------- package.json | 3 +- test/app.spec.js | 2 -- test/collection.spec.js | 7 ++--- test/expression-collection.spec.js | 2 -- test/expression.spec.js | 47 +++++++--------------------- test/ui.spec.js | 2 -- test/variable-collection.spec.js | 4 --- test/variable.spec.js | 2 -- 12 files changed, 49 insertions(+), 81 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 36d6f22..9898ec9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,9 +5,9 @@ name: tests on: push: - branches: ["*"] + branches: ['*'] pull_request: - branches: ["*"] + branches: ['*'] jobs: test: @@ -31,7 +31,7 @@ jobs: uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - cache: "pnpm" + cache: 'pnpm' - name: Install dependencies run: pnpm install --frozen-lockfile diff --git a/.prettierignore b/.prettierignore index 5c32cb1..2b7feaf 100644 --- a/.prettierignore +++ b/.prettierignore @@ -4,6 +4,7 @@ node_modules .env .env.* !.env.example +/.aider* # Ignore files for PNPM, NPM and YARN pnpm-lock.yaml diff --git a/README.md b/README.md index 608f8bf..aa0a102 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Truthy -*Copyright 2016-2023 Caleb Evans* -*Released under the MIT License* +_Copyright 2016-2023 Caleb Evans_ +_Released under the MIT License_ [![tests](https://github.com/caleb531/truthy/actions/workflows/tests.yml/badge.svg)](https://github.com/caleb531/truthy/actions/workflows/tests.yml) [![Coverage Status](https://coveralls.io/repos/github/caleb531/truthy/badge.svg?branch=main)](https://coveralls.io/github/caleb531/truthy?branch=main) diff --git a/index.html b/index.html index ea102ce..0d411d0 100644 --- a/index.html +++ b/index.html @@ -1,26 +1,30 @@ - + - - - Truthy | Truth tables made easy | Caleb Evans - - - - - - - - + + + Truthy | Truth tables made easy | Caleb Evans + + + + + + + + +
-
- - - + + diff --git a/package.json b/package.json index 5787b7d..60765b0 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "dev": "vite", "build": "vite build", "preview": "vite preview", - "lint": "eslint", + "lint": "prettier --check . && eslint .", + "format": "prettier --write .", "test": "vitest run", "coverage": "vitest run --coverage" }, diff --git a/test/app.spec.js b/test/app.spec.js index 1f03880..7ddc0e7 100644 --- a/test/app.spec.js +++ b/test/app.spec.js @@ -1,7 +1,6 @@ import App from '../scripts/models/app.js'; describe('app', () => { - it('should initialize with no arguments', () => { let app = new App(); expect(app).toHaveProperty('variables'); @@ -58,5 +57,4 @@ describe('app', () => { expect(restoredApp).toBeTruthy(); expect(restoredApp.serialize()).toEqual(serializedApp); }); - }); diff --git a/test/collection.spec.js b/test/collection.spec.js index 0528096..6f46bc7 100644 --- a/test/collection.spec.js +++ b/test/collection.spec.js @@ -1,11 +1,9 @@ import Collection from '../scripts/models/collection.js'; describe('collection', () => { - class DummyItem { constructor(args) { this.foo = args.foo; - } serialize() { return { foo: this.foo }; @@ -27,8 +25,8 @@ describe('collection', () => { it('should serialize to a JSON object', () => { let serializedCollection = { items: [{ foo: 'abc' }, { foo: 'xyz' }] }; let collection = new Collection({ - SubCollectionItem: DummyItem, - items: serializedCollection.items + SubCollectionItem: DummyItem, + items: serializedCollection.items }); expect(collection.serialize()).toEqual(serializedCollection); }); @@ -117,5 +115,4 @@ describe('collection', () => { expect(collection.length).toEqual(0); expect(collection.items.length).toEqual(0); }); - }); diff --git a/test/expression-collection.spec.js b/test/expression-collection.spec.js index e7b1ab7..6f8903f 100644 --- a/test/expression-collection.spec.js +++ b/test/expression-collection.spec.js @@ -2,7 +2,6 @@ import ExpressionCollection from '../scripts/models/expression-collection.js'; import Expression from '../scripts/models/expression.js'; describe('expression collection', () => { - it('should initialize with list of expressions', () => { let expressions = new ExpressionCollection({ items: [{ string: 'a xor b' }, { string: 's nand t' }] @@ -13,5 +12,4 @@ describe('expression collection', () => { expect(expression).toBeInstanceOf(Expression); }); }); - }); diff --git a/test/expression.spec.js b/test/expression.spec.js index a57f650..9ffb4b5 100644 --- a/test/expression.spec.js +++ b/test/expression.spec.js @@ -1,7 +1,6 @@ import Expression from '../scripts/models/expression.js'; describe('expression', () => { - it('should initialize with unmodified input string', () => { let expression = new Expression({ string: ' p and q ' @@ -25,10 +24,13 @@ describe('expression', () => { const testResults = testCases.map((testCase) => { let actualOutput = expression.evaluate(testCase.varValues); // String of current variable values for display in fail message - let varValuesStr = Object.entries(testCase.varValues).map(([varName, varValue]) => { - return varName + ' is ' + varValue; - }).join(' and '); - const message = () => `expected '${expressionStr}' to evaluate to ${testCase.output} but got ${actualOutput} (when ${varValuesStr})`; + let varValuesStr = Object.entries(testCase.varValues) + .map(([varName, varValue]) => { + return varName + ' is ' + varValue; + }) + .join(' and '); + const message = () => + `expected '${expressionStr}' to evaluate to ${testCase.output} but got ${actualOutput} (when ${varValuesStr})`; if (actualOutput === testCase.output) { return { message, pass: true }; } else { @@ -36,14 +38,15 @@ describe('expression', () => { } }); - return testResults.find((result) => { - return !result.pass; - }) || testResults[testResults.length - 1]; + return ( + testResults.find((result) => { + return !result.pass; + }) || testResults[testResults.length - 1] + ); } }); describe('variable name', () => { - it('should evaluate', () => { expect('p').toEvaluateTo([ { varValues: { p: false }, output: false }, @@ -79,13 +82,10 @@ describe('expression', () => { { varValues: { p: true }, output: null } ]); }); - }); describe('boolean value', () => { - describe('false', () => { - let testCases = [ { varValues: { p: false }, output: false }, { varValues: { p: true }, output: false } @@ -98,11 +98,9 @@ describe('expression', () => { it('should be case-insensitive', () => { expect('FaLsE').toEvaluateTo(testCases); }); - }); describe('true', () => { - let testCases = [ { varValues: { p: false }, output: true }, { varValues: { p: true }, output: true } @@ -115,13 +113,10 @@ describe('expression', () => { it('should be case-insensitive', () => { expect('tRuE').toEvaluateTo(testCases); }); - }); - }); describe('NOT operation', () => { - let testCases = [ { varValues: { p: false }, output: true }, { varValues: { p: true }, output: false } @@ -153,11 +148,9 @@ describe('expression', () => { { varValues: { p: true }, output: null } ]); }); - }); describe('AND operation', () => { - let testCases = [ { varValues: { p: false, q: false }, output: false }, { varValues: { p: false, q: true }, output: false }, @@ -200,11 +193,9 @@ describe('expression', () => { it('should ignore whitespace around arithmetic operator', () => { expect('p * q').toEvaluateTo(testCases); }); - }); describe('NAND operation', () => { - let testCases = [ { varValues: { p: false, q: false }, output: true }, { varValues: { p: false, q: true }, output: true }, @@ -223,11 +214,9 @@ describe('expression', () => { it('should ignore operator case', () => { expect('p NanD q').toEvaluateTo(testCases); }); - }); describe('OR operation', () => { - let testCases = [ { varValues: { p: false, q: false }, output: false }, { varValues: { p: false, q: true }, output: true }, @@ -270,11 +259,9 @@ describe('expression', () => { it('should ignore whitespace around arithmetic operator', () => { expect('p + q').toEvaluateTo(testCases); }); - }); describe('NOR operation', () => { - let testCases = [ { varValues: { p: false, q: false }, output: true }, { varValues: { p: false, q: true }, output: false }, @@ -293,11 +280,9 @@ describe('expression', () => { it('should ignore operator case', () => { expect('p NoR q').toEvaluateTo(testCases); }); - }); describe('XOR operation', () => { - let testCases = [ { varValues: { p: false, q: false }, output: false }, { varValues: { p: false, q: true }, output: true }, @@ -324,11 +309,9 @@ describe('expression', () => { it('should ignore whitespace around shorthand operator', () => { expect('p ^ q').toEvaluateTo(testCases); }); - }); describe('implication operation', () => { - let testCases = [ { varValues: { p: false, q: false }, output: true }, { varValues: { p: false, q: true }, output: true }, @@ -343,11 +326,9 @@ describe('expression', () => { it('should ignore whitespace around operator', () => { expect('p -> q').toEvaluateTo(testCases); }); - }); describe('double-implication (XNOR) operation', () => { - let testCases = [ { varValues: { p: false, q: false }, output: true }, { varValues: { p: false, q: true }, output: false }, @@ -374,7 +355,6 @@ describe('expression', () => { it('should ignore named operator case', () => { expect('p xNoR q').toEvaluateTo(testCases); }); - }); it('should respect parentheses', () => { @@ -405,7 +385,6 @@ describe('expression', () => { }); describe('more than two variables', () => { - let testCases = [ { varValues: { p: false, q: false, r: false }, output: false }, { varValues: { p: false, q: false, r: true }, output: true }, @@ -420,7 +399,5 @@ describe('expression', () => { it('should evaluate named operator', () => { expect('p xor q xor r').toEvaluateTo(testCases); }); - }); - }); diff --git a/test/ui.spec.js b/test/ui.spec.js index b8e6a09..4ba263a 100644 --- a/test/ui.spec.js +++ b/test/ui.spec.js @@ -3,7 +3,6 @@ import m from 'mithril'; import AppComponent from '../scripts/components/app.jsx'; describe('app UI', () => { - beforeEach(() => { localStorage.clear(); document.body.appendChild(document.createElement('main')); @@ -227,5 +226,4 @@ describe('app UI', () => { let expression = document.querySelector('.expression:last-child input'); expect(expression).toHaveValue('a ^ b'); }); - }); diff --git a/test/variable-collection.spec.js b/test/variable-collection.spec.js index 4a23a46..3054ae4 100644 --- a/test/variable-collection.spec.js +++ b/test/variable-collection.spec.js @@ -2,7 +2,6 @@ import VariableCollection from '../scripts/models/variable-collection.js'; import Variable from '../scripts/models/variable.js'; describe('variable collection', () => { - it('should initialize with list of variables', () => { let variables = new VariableCollection({ items: [{ name: 'u' }, { name: 'v' }] @@ -34,7 +33,6 @@ describe('variable collection', () => { }); describe('getNextVariableName', () => { - let variables = new VariableCollection({ items: [{ name: 'q' }, { name: 's' }, { name: 'z' }, { name: 'a' }] }); @@ -48,7 +46,5 @@ describe('variable collection', () => { it('should wrap around to next available name as needed', () => { expect(variables.getNextVariableName(variables.items[2])).toEqual('b'); }); - }); - }); diff --git a/test/variable.spec.js b/test/variable.spec.js index 496c8a6..0e28d01 100644 --- a/test/variable.spec.js +++ b/test/variable.spec.js @@ -1,7 +1,6 @@ import Variable from '../scripts/models/variable.js'; describe('variable', () => { - it('should initialize with unmodified name', () => { let variable = new Variable({ name: 'g' @@ -14,5 +13,4 @@ describe('variable', () => { let variable = new Variable(serializedVariable); expect(variable.serialize()).toEqual(serializedVariable); }); - });