Skip to content

Commit

Permalink
prettier tooling
Browse files Browse the repository at this point in the history
co-authored by Duane Barlow <[email protected]> and Mike Bostock <[email protected]>
  • Loading branch information
Fil committed Jul 22, 2022
1 parent 9d9ba91 commit 87a6bcc
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 42 deletions.
4 changes: 1 addition & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"],
"plugins": ["@typescript-eslint"],
"parser": "@typescript-eslint/parser",
"env": {
Expand All @@ -12,8 +12,6 @@
"no-constant-condition": 0,
"no-sparse-arrays": 0,
"no-unexpected-multiline": 0,
"comma-dangle": ["error", "never"],
"semi": [2, "always"],
"@typescript-eslint/no-empty-function": 0,
"@typescript-eslint/no-this-alias": 0,
"@typescript-eslint/no-unused-vars": ["error", {"ignoreRestSiblings": true}]
Expand Down
14 changes: 14 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# When making commits that are strictly formatting/style changes, add the
# commit hash here, so git blame can ignore the change. See docs for more
# details:
# https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view
#
# Github will use this file to ignore these commits for blame.
#
# Run this to configure git locally to also ignore these commits:
# git config blame.ignoreRevsFile .git-blame-ignore-revs

# Ran prettier on the entire codebase
7dd26612601bbbcfccb81fdf939b7b1a301f1366
# Ran pretier again after resolving merge conflicts
d15ed2364536eebf74217f6cc073c19a734d8c2c
25 changes: 12 additions & 13 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,26 @@ name: Node.js CI

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: yarn --frozen-lockfile
- run: |
echo ::add-matcher::.github/eslint.json
yarn run eslint . --format=compact
- run: yarn test
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: yarn --frozen-lockfile
- run: |
echo ::add-matcher::.github/eslint.json
yarn run eslint . --format=compact
- run: yarn test
23 changes: 23 additions & 0 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Formatting

on:
pull_request:
branches: [main]

jobs:
prettier:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
with:
# Make sure the actual branch is checked out when running on pull requests
ref: ${{ github.head_ref }}
# This is important to fetch the changes to the previous commit
fetch-depth: 0

- name: Check prettier
uses: creyD/[email protected]
with:
prettier_options: --check .
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test/output
test/data
.rollup.cache
dist
*.md
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"bracketSpacing": false,
"printWidth": 120,
"trailingComma": "none"
}
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ yarn test

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

Please run Prettier before submitting any pull request. Check “format on save” in your code editor, or run:

```bash
yarn prettier --write .
```

### Unit tests

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:
Expand Down
11 changes: 2 additions & 9 deletions loader.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
transform,
applySourceMap,
installSourceMapSupport,
resolveTsPath
} from "@esbuild-kit/core-utils";
import {transform, applySourceMap, installSourceMapSupport, resolveTsPath} from "@esbuild-kit/core-utils";
import {getTsconfig} from "get-tsconfig";

const sourcemaps = installSourceMapSupport();
Expand All @@ -23,9 +18,7 @@ export async function resolve(specifier, context, defaultResolve) {
}
}
const resolved = await defaultResolve(specifier, context, defaultResolve);
return resolved.format === undefined
? {...resolved, format: "module"}
: resolved;
return resolved.format === undefined ? {...resolved, format: "module"} : resolved;
}

export async function load(url, context, defaultLoad) {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@
"@typescript-eslint/parser": "^5.25.0",
"canvas": "2",
"eslint": "^8.16.0",
"eslint-config-prettier": "^8.5.0",
"get-tsconfig": "^4.1.0",
"glob": "^8.0.3",
"htl": "0.3",
"js-beautify": "1",
"jsdom": "19",
"mocha": "10",
"module-alias": "2",
"prettier": "^2.7.1",
"rollup": "2",
"rollup-plugin-terser": "7",
"tslib": "^2.4.0",
Expand Down
22 changes: 9 additions & 13 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ if (typeof d3.jsdelivr === "undefined") throw new Error("unable to resolve d3");
const d3Path = `d3@${d3.version}/${d3.jsdelivr}`;

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

const config = {
input: "bundle.js",
Expand All @@ -26,12 +27,7 @@ const config = {
indent: false,
banner: `// ${meta.name} v${meta.version} Copyright ${copyrights.join(", ")}`
},
plugins: [
typescript(),
commonjs(),
json(),
node()
]
plugins: [typescript(), commonjs(), json(), node()]
};

export default [
Expand All @@ -43,8 +39,8 @@ export default [
format: "umd",
extend: true,
file: `dist/${filename}.umd.js`,
globals: {"d3": "d3"},
paths: {"d3": d3Path}
globals: {d3: "d3"},
paths: {d3: d3Path}
}
},
{
Expand All @@ -55,8 +51,8 @@ export default [
format: "umd",
extend: true,
file: `dist/${filename}.umd.min.js`,
globals: {"d3": "d3"},
paths: {"d3": d3Path}
globals: {d3: "d3"},
paths: {d3: d3Path}
},
plugins: [
...config.plugins,
Expand Down
5 changes: 1 addition & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"lib": [
"esnext",
"dom"
],
"lib": ["esnext", "dom"],
"strict": true,
"stripInternal": true,
"outDir": "dist",
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,11 @@ escodegen@^2.0.0:
optionalDependencies:
source-map "~0.6.1"

eslint-config-prettier@^8.5.0:
version "8.5.0"
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-8.5.0.tgz#5a81680ec934beca02c7b1a61cf8ca34b66feab1"
integrity sha512-obmWKLUNCnhtQRKc+tmnYuQl0pFU1ibYJQ5BGhTVB08bHe9wC8qUeG7c08dj9XX+AuPj1YSGSQIHl1pnDHZR0Q==

eslint-scope@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.1.tgz#e786e59a66cb92b3f6c1fb0d508aab174848f48c"
Expand Down Expand Up @@ -2482,6 +2487,11 @@ prelude-ls@~1.1.2:
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
integrity sha512-ESF23V4SKG6lVSGZgYNpbsiaAkdab6ZgOxe52p7+Kid3W3u3bxR4Vfd/o21dmN7jSt0IwgZ4v5MUd26FEtXE9w==

prettier@^2.7.1:
version "2.7.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.7.1.tgz#e235806850d057f97bb08368a4f7d899f7760c64"
integrity sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==

pretty-format@^28.1.3:
version "28.1.3"
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-28.1.3.tgz#c9fba8cedf99ce50963a11b27d982a9ae90970d5"
Expand Down

0 comments on commit 87a6bcc

Please sign in to comment.