Skip to content

Commit de409c3

Browse files
authored
Add formatter to project (#48)
* Add prettier to project * Add a prettierignore file * Add yarn scripts for formatting * Make formatting changes * Add formatting check * Fix issue where prettier moved a comment
1 parent 479eaa6 commit de409c3

File tree

98 files changed

+4406
-4171
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+4406
-4171
lines changed

.github/workflows/lint.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ jobs:
2424
- uses: "bahmutov/npm-install@v1"
2525
- name: "Run Eslint"
2626
run: "yarn run lint"
27+
- name: "Run formatting check"
28+
run: "yarn run format:check"
2729
- name: "Run Typescript type checking"
2830
run: "yarn run tsc -b"

.prettierignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
src/spicedb-common/protodefs
2+
examples
3+
public
4+
5+
# We use yamllint in most places and they disagree
6+
**/*.yaml

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ We use [yarn](https://yarnpkg.com/) to run common tasks in the project.
8383

8484
### Testing
8585

86-
In order to build and test the project, a [modern version of node] and knowledge of [React app architecture] are required.
86+
In order to build and test the project, a [modern version of node] and knowledge of [React app architecture] are required.
8787

8888
[modern version of node]: https://nodejs.org/en/about/previous-releases
8989
[React app architecture]: https://react.dev/

buf.gen.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
2-
version: 'v2'
2+
version: "v2"
33
plugins:
44
- remote: "buf.build/community/timostamm-protobuf-ts:v2.9.1"
5-
out: 'src/spicedb-common/protodefs'
5+
out: "src/spicedb-common/protodefs"
66
opt:
77
- "long_type_string"
88
- "generate_dependencies"

cypress.config.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineConfig } from 'cypress';
1+
import { defineConfig } from "cypress";
22

33
export default defineConfig({
44
retries: 1,
@@ -10,10 +10,10 @@ export default defineConfig({
1010
chromeWebSecurity: false,
1111

1212
e2e: {
13-
baseUrl: 'http://localhost:3000',
13+
baseUrl: "http://localhost:3000",
1414
specPattern: [
15-
'cypress/integration/**/*.spec.{js,ts}',
16-
'cypress/e2e/**/*.cy.{js,jsx,ts,tsx}',
15+
"cypress/integration/**/*.spec.{js,ts}",
16+
"cypress/e2e/**/*.cy.{js,jsx,ts,tsx}",
1717
],
1818
},
1919
});

cypress/integration/basic.spec.js

+20-24
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,37 @@
11
/// <reference types="cypress" />
22

3-
describe('Playground', () => {
3+
describe("Playground", () => {
44
beforeEach(() => {
55
cy.visitPlayground();
6-
})
6+
});
77

8-
it('displays tutorial', () => {
9-
cy.get('.react-joyride__tooltip')
10-
.contains('Welcome!')
11-
.should('have.length', 1)
8+
it("displays tutorial", () => {
9+
cy.get(".react-joyride__tooltip")
10+
.contains("Welcome!")
11+
.should("have.length", 1);
1212
});
1313

14-
it('can dismiss tutorial', () => {
15-
cy.contains('Skip')
16-
.click();
14+
it("can dismiss tutorial", () => {
15+
cy.contains("Skip").click();
1716
cy.reload();
18-
cy.contains('Welcome!').should('not.exist')
17+
cy.contains("Welcome!").should("not.exist");
1918
});
2019

21-
it('displays header buttons', () => {
20+
it("displays header buttons", () => {
2221
cy.dismissTour();
23-
cy.get('a').contains('Discuss on Discord').should('exist');
24-
cy.get('header > button').contains('Select Example Schema').should('exist');
25-
cy.get('header > button').contains('Share').should('exist');
26-
cy.get('header > button').contains('Download').should('exist');
27-
cy.get('header > button').contains('Load From File').should('exist');
28-
cy.contains('Sign In To Import').should('exist');
22+
cy.get("a").contains("Discuss on Discord").should("exist");
23+
cy.get("header > button").contains("Select Example Schema").should("exist");
24+
cy.get("header > button").contains("Share").should("exist");
25+
cy.get("header > button").contains("Download").should("exist");
26+
cy.get("header > button").contains("Load From File").should("exist");
27+
cy.contains("Sign In To Import").should("exist");
2928
});
3029

31-
it('default validation succeeds', () => {
30+
it("default validation succeeds", () => {
3231
cy.dismissTour();
3332
cy.waitForWasm();
34-
cy.tab('Assertions');
35-
cy.get('button')
36-
.contains('Run')
37-
.click();
38-
cy.contains('Validated!')
39-
.should('exist');
33+
cy.tab("Assertions");
34+
cy.get("button").contains("Run").click();
35+
cy.contains("Validated!").should("exist");
4036
});
4137
});

cypress/integration/nav.spec.js

+38-60
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,62 @@
11
/// <reference types="cypress" />
22

3-
describe('Navigation', () => {
3+
describe("Navigation", () => {
44
beforeEach(() => {
55
cy.visitPlayground();
66
cy.dismissTour();
7-
})
7+
});
88

9-
it('displays schema tab', () => {
10-
cy.tab('Schema');
9+
it("displays schema tab", () => {
10+
cy.tab("Schema");
1111
// Default editor content
12-
cy.editorText()
13-
.containsAll([
14-
'definition user {}',
15-
'definition resource {',
16-
'}',
17-
]);
12+
cy.editorText().containsAll([
13+
"definition user {}",
14+
"definition resource {",
15+
"}",
16+
]);
1817
// Sub-menu buttons
19-
cy.get('button')
20-
.contains('Format')
21-
.should('exist');
18+
cy.get("button").contains("Format").should("exist");
2219
});
2320

24-
it('displays relationships tab', () => {
25-
cy.tab('Test Relationships');
21+
it("displays relationships tab", () => {
22+
cy.tab("Test Relationships");
2623
// Editor mode buttons
27-
cy.get('[aria-label="relationship editor view"]')
24+
cy.get('[aria-label="relationship editor view"]');
2825
// Grid view
29-
cy.contains('Highlight same types, objects and relations')
30-
cy.get('[aria-label="code editor"]').click()
26+
cy.contains("Highlight same types, objects and relations");
27+
cy.get('[aria-label="code editor"]').click();
3128
// Text view
32-
cy.editorText()
33-
.contains('resource:anotherresource#writer@user:somegal');
29+
cy.editorText().contains("resource:anotherresource#writer@user:somegal");
3430
});
3531

36-
it('displays assertions tab', () => {
37-
cy.tab('Assertions');
32+
it("displays assertions tab", () => {
33+
cy.tab("Assertions");
3834
// Default editor content
39-
cy.editorText()
40-
.containsAll([
41-
'assertTrue',
42-
'assertFalse',
43-
]);
35+
cy.editorText().containsAll(["assertTrue", "assertFalse"]);
4436
// Sub-menu buttons
45-
cy.contains('Validation not run')
46-
.should('exist');
47-
cy.get('button')
48-
.contains('Run')
49-
.should('exist');
37+
cy.contains("Validation not run").should("exist");
38+
cy.get("button").contains("Run").should("exist");
5039
});
5140

52-
it('displays expected relations tab', () => {
53-
cy.tab('Expected Relations');
41+
it("displays expected relations tab", () => {
42+
cy.tab("Expected Relations");
5443
// No default editor content
55-
// Sub-menu buttons
56-
cy.contains('Validation not run')
57-
.should('exist');
58-
cy.get('button')
59-
.contains('Run')
60-
.should('exist');
61-
cy.get('button')
62-
.contains('Re-Generate')
63-
.should('exist');
64-
cy.get('button')
65-
.contains('Compute and Diff')
66-
.should('exist');
44+
// Sub-menu buttons
45+
cy.contains("Validation not run").should("exist");
46+
cy.get("button").contains("Run").should("exist");
47+
cy.get("button").contains("Re-Generate").should("exist");
48+
cy.get("button").contains("Compute and Diff").should("exist");
6749
});
6850

69-
it('displays panels', () => {
51+
it("displays panels", () => {
7052
cy.waitForWasm();
71-
cy.panel('Problems');
72-
cy.panelText()
73-
.contains('No problems found');
74-
cy.panel('Check Watches');
75-
cy.panelText()
76-
.find('table.MuiTable-root');
77-
cy.panel('System Visualization')
78-
cy.panelText()
79-
.find('div.vis-network');
80-
cy.panel('Last Validation Run');
81-
cy.panelText()
82-
.contains('Validation Not Run');
53+
cy.panel("Problems");
54+
cy.panelText().contains("No problems found");
55+
cy.panel("Check Watches");
56+
cy.panelText().find("table.MuiTable-root");
57+
cy.panel("System Visualization");
58+
cy.panelText().find("div.vis-network");
59+
cy.panel("Last Validation Run");
60+
cy.panelText().contains("Validation Not Run");
8361
});
84-
});
62+
});

cypress/support/commands.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Cypress.Commands.add("waitForWasm", () => {
4444
errorMsg: "WASM development package not loaded",
4545
timeout: 30000,
4646
interval: 500,
47-
}
47+
},
4848
);
4949
return;
5050
});
@@ -58,7 +58,7 @@ Cypress.Commands.add(
5858
list.forEach((line) => {
5959
cy.wrap(subject).contains(line);
6060
});
61-
}
61+
},
6262
);
6363

6464
//

cypress/support/e2e.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
// ***********************************************************
1515

1616
// Import commands.js using ES2015 syntax:
17-
import './commands';
17+
import "./commands";
1818

1919
// Handle uncaught exceptions
20-
Cypress.on('uncaught:exception', (err) => {
20+
Cypress.on("uncaught:exception", (err) => {
2121
// TODO: Ignore transient network errors until either browser caching
2222
// or js fixtures are supported
2323
// https://github.com/cypress-io/cypress/issues/18335
2424
// https://github.com/cypress-io/cypress/issues/1271
25-
if (err.message.includes('Uncaught NetworkError')) {
25+
if (err.message.includes("Uncaught NetworkError")) {
2626
return false;
2727
}
2828
});

eslint.config.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
import js from '@eslint/js'
2-
import globals from 'globals'
3-
import reactHooks from 'eslint-plugin-react-hooks'
4-
import reactRefresh from 'eslint-plugin-react-refresh'
5-
import tseslint from 'typescript-eslint'
1+
import js from "@eslint/js";
2+
import globals from "globals";
3+
import reactHooks from "eslint-plugin-react-hooks";
4+
import reactRefresh from "eslint-plugin-react-refresh";
5+
import tseslint from "typescript-eslint";
66

77
export default tseslint.config(
8-
{ ignores: ['dist', 'src/spicedb-common/protodefs'] },
8+
{ ignores: ["dist", "src/spicedb-common/protodefs"] },
99
{
1010
extends: [js.configs.recommended, ...tseslint.configs.recommended],
11-
files: ['**/*.{ts,tsx}'],
11+
files: ["**/*.{ts,tsx}"],
1212
languageOptions: {
1313
ecmaVersion: 2020,
1414
globals: globals.browser,
1515
},
1616
plugins: {
17-
'react-hooks': reactHooks,
18-
'react-refresh': reactRefresh,
17+
"react-hooks": reactHooks,
18+
"react-refresh": reactRefresh,
1919
},
2020
rules: {
2121
...reactHooks.configs.recommended.rules,
22-
'react-refresh/only-export-components': [
23-
'warn',
22+
"react-refresh/only-export-components": [
23+
"warn",
2424
{ allowConstantExport: true },
2525
],
2626
},
2727
},
28-
)
28+
);

index.html

+29-22
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
3+
<head>
4+
<script src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.min.js"></script>
5+
<link
6+
href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.min.css"
7+
rel="stylesheet"
8+
type="text/css"
9+
/>
310

4-
<head>
5-
<script src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.min.js"></script>
6-
<link href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.21.0/vis.min.css" rel="stylesheet" type="text/css" />
11+
<script src="/wasm_exec.js"></script>
712

8-
<script src="/wasm_exec.js"></script>
9-
10-
<meta charset="utf-8" />
11-
<meta name="robots" content="noindex,nofollow" />
12-
<link rel="icon" href="/favicon.svg" />
13-
<meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width" />
14-
<meta name="theme-color" content="#000000" />
15-
<link rel="apple-touch-icon" href="/logo192.png" />
16-
<link rel="manifest" href="/manifest.json" />
17-
<title>SpiceDB Playground</title>
18-
</head>
19-
20-
<body>
21-
<noscript>JavaScript is required to run this single-page app. Sorry :/</noscript>
22-
<div id="root"></div>
23-
<div id="portal"></div>
24-
<script type="module" src="/src/index.tsx"></script>
25-
</body>
13+
<meta charset="utf-8" />
14+
<meta name="robots" content="noindex,nofollow" />
15+
<link rel="icon" href="/favicon.svg" />
16+
<meta
17+
name="viewport"
18+
content="minimum-scale=1, initial-scale=1, width=device-width"
19+
/>
20+
<meta name="theme-color" content="#000000" />
21+
<link rel="apple-touch-icon" href="/logo192.png" />
22+
<link rel="manifest" href="/manifest.json" />
23+
<title>SpiceDB Playground</title>
24+
</head>
2625

26+
<body>
27+
<noscript
28+
>JavaScript is required to run this single-page app. Sorry :/</noscript
29+
>
30+
<div id="root"></div>
31+
<div id="portal"></div>
32+
<script type="module" src="/src/index.tsx"></script>
33+
</body>
2734
</html>

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"eslint-plugin-react-refresh": "^0.4.18",
8080
"globals": "^15.14.0",
8181
"postcss-safe-parser": "7.0.0",
82+
"prettier": "3.4.2",
8283
"typescript": "~5.7.3",
8384
"typescript-eslint": "^8.20.0",
8485
"vite": "^6.0.7",
@@ -91,6 +92,8 @@
9192
"test": "vitest",
9293
"lint": "eslint .",
9394
"lint-fix": "eslint --fix .",
95+
"format": "prettier . -w",
96+
"format:check": "prettier . -c",
9497
"cy:run": "cypress run --browser chrome",
9598
"cy:open": "cypress open",
9699
"update:spicedb": "./scripts/update-spicedb.sh",

0 commit comments

Comments
 (0)