Skip to content

Commit 87a6bcc

Browse files
committed
prettier tooling
co-authored by Duane Barlow <[email protected]> and Mike Bostock <[email protected]>
1 parent 9d9ba91 commit 87a6bcc

File tree

12 files changed

+90
-42
lines changed

12 files changed

+90
-42
lines changed

.eslintrc.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
2+
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"],
33
"plugins": ["@typescript-eslint"],
44
"parser": "@typescript-eslint/parser",
55
"env": {
@@ -12,8 +12,6 @@
1212
"no-constant-condition": 0,
1313
"no-sparse-arrays": 0,
1414
"no-unexpected-multiline": 0,
15-
"comma-dangle": ["error", "never"],
16-
"semi": [2, "always"],
1715
"@typescript-eslint/no-empty-function": 0,
1816
"@typescript-eslint/no-this-alias": 0,
1917
"@typescript-eslint/no-unused-vars": ["error", {"ignoreRestSiblings": true}]

.git-blame-ignore-revs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# When making commits that are strictly formatting/style changes, add the
2+
# commit hash here, so git blame can ignore the change. See docs for more
3+
# details:
4+
# https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view
5+
#
6+
# Github will use this file to ignore these commits for blame.
7+
#
8+
# Run this to configure git locally to also ignore these commits:
9+
# git config blame.ignoreRevsFile .git-blame-ignore-revs
10+
11+
# Ran prettier on the entire codebase
12+
7dd26612601bbbcfccb81fdf939b7b1a301f1366
13+
# Ran pretier again after resolving merge conflicts
14+
d15ed2364536eebf74217f6cc073c19a734d8c2c

.github/workflows/node.js.yml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,26 @@ name: Node.js CI
44

55
on:
66
push:
7-
branches: [ main ]
7+
branches: [main]
88
pull_request:
9-
branches: [ main ]
9+
branches: [main]
1010

1111
jobs:
1212
build:
13-
1413
runs-on: ubuntu-latest
1514

1615
strategy:
1716
matrix:
1817
node-version: [16.x]
1918

2019
steps:
21-
- uses: actions/checkout@v2
22-
- name: Use Node.js ${{ matrix.node-version }}
23-
uses: actions/setup-node@v1
24-
with:
25-
node-version: ${{ matrix.node-version }}
26-
- run: yarn --frozen-lockfile
27-
- run: |
28-
echo ::add-matcher::.github/eslint.json
29-
yarn run eslint . --format=compact
30-
- run: yarn test
20+
- uses: actions/checkout@v2
21+
- name: Use Node.js ${{ matrix.node-version }}
22+
uses: actions/setup-node@v1
23+
with:
24+
node-version: ${{ matrix.node-version }}
25+
- run: yarn --frozen-lockfile
26+
- run: |
27+
echo ::add-matcher::.github/eslint.json
28+
yarn run eslint . --format=compact
29+
- run: yarn test

.github/workflows/prettier.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Formatting
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
jobs:
8+
prettier:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v2
14+
with:
15+
# Make sure the actual branch is checked out when running on pull requests
16+
ref: ${{ github.head_ref }}
17+
# This is important to fetch the changes to the previous commit
18+
fetch-depth: 0
19+
20+
- name: Check prettier
21+
uses: creyD/[email protected]
22+
with:
23+
prettier_options: --check .

.prettierignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
test/output
2+
test/data
3+
.rollup.cache
4+
dist
5+
*.md

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"bracketSpacing": false,
3+
"printWidth": 120,
4+
"trailingComma": "none"
5+
}

CONTRIBUTING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ yarn test
3636

3737
This will also run ESLint on Plot’s source to help catch simple mistakes, such as unused imports.
3838

39+
Please run Prettier before submitting any pull request. Check “format on save” in your code editor, or run:
40+
41+
```bash
42+
yarn prettier --write .
43+
```
44+
3945
### Unit tests
4046

4147
Unit tests live in `test` and have the `-test.js` file extension; see [`test/marks/area-test.js`](./test/marks/area-test.js) for example. Generally speaking, unit tests make specific, low-level assertions about the behavior of Plot’s API, including internals and helper methods. If you add a new feature, or change the behavior of an existing feature, please update the unit tests so that we can more easily maintain your contribution into the future. For example, here’s a unit test that tests how Plot formats months:

loader.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
transform,
3-
applySourceMap,
4-
installSourceMapSupport,
5-
resolveTsPath
6-
} from "@esbuild-kit/core-utils";
1+
import {transform, applySourceMap, installSourceMapSupport, resolveTsPath} from "@esbuild-kit/core-utils";
72
import {getTsconfig} from "get-tsconfig";
83

94
const sourcemaps = installSourceMapSupport();
@@ -23,9 +18,7 @@ export async function resolve(specifier, context, defaultResolve) {
2318
}
2419
}
2520
const resolved = await defaultResolve(specifier, context, defaultResolve);
26-
return resolved.format === undefined
27-
? {...resolved, format: "module"}
28-
: resolved;
21+
return resolved.format === undefined ? {...resolved, format: "module"} : resolved;
2922
}
3023

3124
export async function load(url, context, defaultLoad) {

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,15 @@
5252
"@typescript-eslint/parser": "^5.25.0",
5353
"canvas": "2",
5454
"eslint": "^8.16.0",
55+
"eslint-config-prettier": "^8.5.0",
5556
"get-tsconfig": "^4.1.0",
5657
"glob": "^8.0.3",
5758
"htl": "0.3",
5859
"js-beautify": "1",
5960
"jsdom": "19",
6061
"mocha": "10",
6162
"module-alias": "2",
63+
"prettier": "^2.7.1",
6264
"rollup": "2",
6365
"rollup-plugin-terser": "7",
6466
"tslib": "^2.4.0",

rollup.config.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ if (typeof d3.jsdelivr === "undefined") throw new Error("unable to resolve d3");
1414
const d3Path = `d3@${d3.version}/${d3.jsdelivr}`;
1515

1616
// Extract copyrights from the LICENSE.
17-
const copyrights = fs.readFileSync("./LICENSE", "utf-8")
17+
const copyrights = fs
18+
.readFileSync("./LICENSE", "utf-8")
1819
.split(/\n/g)
19-
.filter(line => /^copyright\s+/i.test(line))
20-
.map(line => line.replace(/^copyright\s+/i, ""));
20+
.filter((line) => /^copyright\s+/i.test(line))
21+
.map((line) => line.replace(/^copyright\s+/i, ""));
2122

2223
const config = {
2324
input: "bundle.js",
@@ -26,12 +27,7 @@ const config = {
2627
indent: false,
2728
banner: `// ${meta.name} v${meta.version} Copyright ${copyrights.join(", ")}`
2829
},
29-
plugins: [
30-
typescript(),
31-
commonjs(),
32-
json(),
33-
node()
34-
]
30+
plugins: [typescript(), commonjs(), json(), node()]
3531
};
3632

3733
export default [
@@ -43,8 +39,8 @@ export default [
4339
format: "umd",
4440
extend: true,
4541
file: `dist/${filename}.umd.js`,
46-
globals: {"d3": "d3"},
47-
paths: {"d3": d3Path}
42+
globals: {d3: "d3"},
43+
paths: {d3: d3Path}
4844
}
4945
},
5046
{
@@ -55,8 +51,8 @@ export default [
5551
format: "umd",
5652
extend: true,
5753
file: `dist/${filename}.umd.min.js`,
58-
globals: {"d3": "d3"},
59-
paths: {"d3": d3Path}
54+
globals: {d3: "d3"},
55+
paths: {d3: d3Path}
6056
},
6157
plugins: [
6258
...config.plugins,

0 commit comments

Comments
 (0)