Skip to content

Commit

Permalink
Use rome for lint/format for ts
Browse files Browse the repository at this point in the history
instead of eslint/prettier

Co-authored-by: Hong Minhee <hong.minhee@planetariumhq.com>
  • Loading branch information
tkiapril and dahlia committed Feb 23, 2023
1 parent 627b328 commit 90ded7e
Show file tree
Hide file tree
Showing 21 changed files with 150 additions and 136 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ indent_style = space
continuation_indent_size = 4
indent_size = 4

[*.{ps1,sh,yaml,yml}]
[*.{json,ps1,sh,yaml,yml}]
indent_size = 2
continuation_indent_size = 2

Expand Down
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/.yarn/releases/* binary
/.yarn/plugins/**/* binary
/.pnp.* binary linguist-generated
/yarn.lock binary linguist-generated
9 changes: 8 additions & 1 deletion .github/bin/dist-npm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ else
dry_run=
fi

version_type="$(cat "$(dirname $0)/../../obj/version_type.txt")"
if [[ "$version_type" = stable ]]; then
tag=latest
else
tag="$version_type"
fi

for npmpkg in "${npm_packages[@]}"; do
for tgz in "./$npmpkg"/*.tgz; do
# shellcheck disable=SC2086
npm publish --access=public $dry_run "$tgz"
npm publish --access=public --tag="$tag" $dry_run "$tgz"
done
done
2 changes: 2 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ jobs:
echo "$VERSION_SUFFIX" > obj/version_suffix.txt
fi
echo "$PACKAGE_VERSION" > obj/package_version.txt
echo "$VERSION_TYPE" > obj/version_type.txt
env:
VERSION_PREFIX: ${{ steps.determine-version.outputs.version-prefix }}
VERSION_SUFFIX: ${{ steps.determine-version.outputs.version-suffix }}
PACKAGE_VERSION: ${{ steps.determine-version.outputs.package-version }}
VERSION_TYPE: ${{ steps.determine-version.outputs.version-type }}
- run: .github/bin/dist-release-note.sh CHANGES.md obj/release_note.txt
- uses: actions/upload-artifact@main
with:
Expand Down
3 changes: 0 additions & 3 deletions .prettierignore

This file was deleted.

3 changes: 1 addition & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"streetsidesoftware.code-spell-checker",
"GitHub.vscode-pull-request-github",
"arcanis.vscode-zipfs",
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint"
"rome.rome"
]
}
5 changes: 2 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"**/.yarn": true,
"**/.pnp.*": true
},
"prettier.prettierPath": ".yarn/sdks/prettier/index.js",
"csharp.semanticHighlighting.enabled": true,
"cSpell.words": [
"Bencodex",
Expand Down Expand Up @@ -52,11 +51,11 @@
"typescript.enablePromptUseWorkspaceTsdk": true,
"eslint.nodePath": ".yarn/sdks",
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.defaultFormatter": "rome.rome",
"editor.formatOnSave": true
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.defaultFormatter": "rome.rome",
"editor.formatOnSave": true
}
}
20 changes: 0 additions & 20 deletions .yarn/sdks/eslint/lib/api.js

This file was deleted.

6 changes: 0 additions & 6 deletions .yarn/sdks/eslint/package.json

This file was deleted.

20 changes: 0 additions & 20 deletions .yarn/sdks/prettier/index.js

This file was deleted.

6 changes: 0 additions & 6 deletions .yarn/sdks/prettier/package.json

This file was deleted.

25 changes: 0 additions & 25 deletions @planetarium/tx/.eslintrc.yaml

This file was deleted.

1 change: 0 additions & 1 deletion @planetarium/tx/.prettierrc.yaml

This file was deleted.

20 changes: 0 additions & 20 deletions @planetarium/tx/hooks/pre-commit

This file was deleted.

2 changes: 1 addition & 1 deletion @planetarium/tx/test/address.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ test("encodeAddressSet", () => {
let prev: ArrayBuffer | null = null;
for (const v of encoded) {
if (!(v instanceof ArrayBuffer)) return false;
if (v.byteLength != 20 || !checks.has(hex(v))) return false;
if (v.byteLength !== 20 || !checks.has(hex(v))) return false;
if (prev != null && compareUint8Array(prev, v) >= 0) return false;
checks.delete(hex(v));
prev = v;
Expand Down
2 changes: 1 addition & 1 deletion Libplanet.Tools/download.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const SUFFIXES = {
};
const PACKAGE_PATH = path.dirname(fileURLToPath(import.meta.url));
const METADATA_PATH = path.join(PACKAGE_PATH, "package.json");
export const BIN_NAME = process.platform == "win32" ? "planet.exe" : "planet";
export const BIN_NAME = process.platform === "win32" ? "planet.exe" : "planet";
export const BIN_PATH = path.join(PACKAGE_PATH, "bin");

export async function download(options = {}) {
Expand Down
21 changes: 15 additions & 6 deletions hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@ set -e
"$(dirname "$0")/check-changelog"
"$(dirname "$0")/check-projects"

for jsproj in "$(dirname "$0")/../@planetarium"/*; do
if [[ -x "$jsproj/hooks/pre-commit" ]]; then
pushd "$jsproj"
hooks/pre-commit
popd
if command -v yarn --help > /dev/null; then
if [[ "$CI" = "true" ]]; then
yarn --immutable
else
yarn --silent
fi
done

# FIXME: The following workaround should be removed when Rome fixes their bug
# which fails to resolve symlinks referring to the parent directory.
rm -f @planetarium/cli
trap "ln -sf ../Libplanet.Tools @planetarium/cli" EXIT
yarn rome check .
else
echo warn: yarn is not available\; not running commands pertaining to node.js. >&2
exit 0
fi

# vim: set filetype=sh ts=2 sw=2 et:
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"devDependencies": {
"@vitest/coverage-c8": "^0.22.1",
"node-fetch": "^3.1.1",
"prettier": "^2.8.4",
"rome": "^11.0.0",
"typescript": "^4.8.4",
"unzipper": "^0.10.11"
},
Expand Down
30 changes: 30 additions & 0 deletions rome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "https://github.com/rome/tools/raw/cli/v11.0.0/npm/rome/configuration_schema.json",
"files": {
"ignore": [
"./Libplanet/",
"./Libplanet.*/",
"./@planetarium/*/dist/",
"./@planetarium/*/coverage/",
"./.pnp.*"
]
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"style": {
"recommended": true,
"useTemplate": "off"
},
"correctness": {
"recommended": true,
"noUnnecessaryContinue": "off"
}
}
},
"formatter": {
"enabled": false,
"indentStyle": "space"
}
}
24 changes: 15 additions & 9 deletions scripts/determine-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ async function getTag() {
}

function getScheduledJobDate() {
if (
process.env.GITHUB_EVENT_NAME &&
process.env.GITHUB_EVENT_NAME.startsWith("schedule")
) {
if (process.env.GITHUB_EVENT_NAME?.startsWith("schedule")) {
// TODO: Read the date from the event payload for determinism.
const now = new Date();
return `${now.getUTCFullYear()}${
Expand All @@ -80,28 +77,31 @@ async function main() {
const csprojPath = path.join(
path.dirname(__dirname),
"Libplanet",
"Libplanet.csproj"
"Libplanet.csproj",
);
const versionPrefix = await readVersionPrefix(csprojPath);
const scheduledJobDate = getScheduledJobDate();
const tag = await getTag();
const commitHash = (await getCommitHash()).substring(0, 7);
let packageVersion;
let versionSuffix;
let versionType;
if (scheduledJobDate != null) {
// Nightly
versionSuffix = `nightly.${scheduledJobDate}`;
packageVersion = `${versionPrefix}-${versionSuffix}`;
versionSuffix += `+${commitHash}`;
versionType = "nightly";
} else if (tag != null) {
// Release
if (tag !== versionPrefix) {
console.error(
`Git tag (${tag}) does not match VersionPrefix (${versionPrefix})`
`Git tag (${tag}) does not match VersionPrefix (${versionPrefix})`,
);
process.exit(1);
}
packageVersion = tag;
versionType = "stable";
} else {
// Dev
const timestamp = await getCommitTimestamp();
Expand All @@ -113,24 +113,30 @@ async function main() {
versionSuffix = `dev.${ts}`;
packageVersion = `${versionPrefix}-${versionSuffix}`;
versionSuffix += `+${commitHash}`;
versionType = "dev";
}
console.error("VersionPrefix:", versionPrefix);
if (versionSuffix) console.error("VersionSuffix:", versionSuffix);
console.error("PackageVersion:", packageVersion);
console.error("VersionType:", versionType);
if (process.env.GITHUB_OUTPUT) {
// https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#environment-files
await fs.appendFile(
process.env.GITHUB_OUTPUT,
`version-prefix=${versionPrefix}`
`version-prefix=${versionPrefix}`,
);
if (versionSuffix)
await fs.appendFile(
process.env.GITHUB_OUTPUT,
`version-suffix=${versionSuffix}`
`version-suffix=${versionSuffix}`,
);
await fs.appendFile(
process.env.GITHUB_OUTPUT,
`package-version=${packageVersion}`
`package-version=${packageVersion}`,
);
await fs.appendFile(
process.env.GITHUB_OUTPUT,
`version-type=${versionType}`,
);
}
}
Expand Down
Loading

0 comments on commit 90ded7e

Please sign in to comment.