Skip to content

Commit

Permalink
chore: format most files using dprint instead of Prettier (zwave-js…
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone authored Aug 23, 2023
1 parent 69b27b4 commit 13ab114
Show file tree
Hide file tree
Showing 530 changed files with 16,180 additions and 14,365 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"customizations": {
"vscode": {
"extensions": [
"dprint.dprint",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"EditorConfig.EditorConfig",
"amodio.toggle-excluded-files",
"zwave-js.config-editor"
Expand Down
69 changes: 69 additions & 0 deletions .dprint.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"lineWidth": 80,
"useTabs": true,
"indentWidth": 4,
"newLineKind": "lf",

"typescript": {
"semiColons": "prefer",
"quoteStyle": "alwaysDouble",
"module.sortImportDeclarations": "caseSensitive",
"importDeclaration.sortNamedImports": "caseSensitive",
"module.sortExportDeclarations": "caseSensitive",
"exportDeclaration.sortNamedExports": "caseSensitive",
"arrowFunction.useParentheses": "force",
// Preserve maximum overlap with the current formatter,
// then consider turning these off one by one.
// "operatorPosition": "sameLine",
"conditionalExpression.operatorPosition": "nextLine",
"conditionalType.operatorPosition": "nextLine",
"constructorType.spaceAfterNewKeyword": true,
"constructSignature.spaceAfterNewKeyword": true,
"binaryExpression.linePerExpression": true,
"quoteProps": "asNeeded"
},

"json": {},

"markdown": {},

"prettier": {
"associations": [
// Prettier formats those better
"packages/nvmedit/test/fixtures/**/*.json",
"**/*.yml",
"**/*.yaml"
],

"semi": true,
"trailingComma": "all",
"singleQuote": false,
"printWidth": 80,
"endOfLine": "lf",

"yml.useTabs": false,
"yml.tabWidth": 2,
"yml.singleQuote": true
},

"excludes": [
"**/build",
"**/node_modules",
"**/package.json",
"**/*-lock.json",
".github/workflows",
".yarn/plugins",
".yarn/releases",
".tmp/",
"cache/",
"packages/*/api.md",
"CHANGELOG*.md",
".yarnrc.yml"
],
"plugins": [
"https://github.com/AlCalzone/dprint-plugin-typescript/releases/download/loop-label/dprint_plugin_typescript.wasm",
"https://plugins.dprint.dev/json-0.17.4.wasm",
"https://plugins.dprint.dev/markdown-0.15.3.wasm",
"https://plugins.dprint.dev/prettier-0.27.0.json@3557a62b4507c55a47d8cde0683195b14d13c41dda66d0f0b0e111aed107e2fe"
]
}
8 changes: 4 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Note to future self:
If ESLint is ever extremely slow again, check if there are .js and/or .map files in the source directories
and delete them:
Expand All @@ -24,10 +24,8 @@ module.exports = {
// Use the recommended rules from the @typescript-eslint/eslint-plugin
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
// Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
"plugin:prettier/recommended",
],
plugins: ["deprecation"],
plugins: ["deprecation", "unused-imports"],
reportUnusedDisableDirectives: true,
rules: {
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
Expand Down Expand Up @@ -123,6 +121,8 @@ module.exports = {
],
"quote-props": ["error", "as-needed"],
"deprecation/deprecation": "error",
"unused-imports/no-unused-imports-ts": "error",
"unused-imports/no-unused-imports": "error",
},
overrides: [
{
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/build-cache-download/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: 'Downloads the previously stored turborepo cache'
author: 'AlCalzone'

runs:
using: "composite"
using: 'composite'
steps:
- name: Download turbo cache artifact
uses: actions/download-artifact@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/build-cache-upload/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: 'Uploads the turborepo cache to be used in later jobs'
author: 'AlCalzone'

runs:
using: "composite"
using: 'composite'
steps:
- name: Compress turbo cache # Uploading or downloading many files takes ages
shell: bash
Expand Down
3 changes: 2 additions & 1 deletion .github/actions/generateTypedDocs/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ const checkPaths = ["docs/", "packages/*/api.md"];
head: branchName,
base: "master",
title: "docs: update typed documentation and API report 🤖",
body: `The auto-generated documentation and/or API reports have changed. Please review the changes and merge them if desired.`,
body:
`The auto-generated documentation and/or API reports have changed. Please review the changes and merge them if desired.`,
maintainer_can_modify: true,
});
prNumber = pr.data.number;
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/prepare-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ inputs:
required: true

runs:
using: "composite"
using: 'composite'
steps:
- name: Use Node.js ${{ inputs.node-version }}
uses: actions/setup-node@v3
Expand Down
18 changes: 9 additions & 9 deletions .github/actions/zwave-js-bot/action.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
name: "Z-Wave JS Bot"
description: "Contains the actions the Bot can execute"
author: "AlCalzone"
name: 'Z-Wave JS Bot'
description: 'Contains the actions the Bot can execute'
author: 'AlCalzone'
inputs:
githubToken:
description: "The github token to use for authentication"
description: 'The github token to use for authentication'
required: true
npmToken:
description: "The token used to publish to npm"
description: 'The token used to publish to npm'
required: true
task:
description: "What the bot is supposed to do"
description: 'What the bot is supposed to do'
required: true
pr:
description: "(publish-pr task only) The PR that should be published"
description: '(publish-pr task only) The PR that should be published'
required: false
runs:
using: "node16"
main: "main.js"
using: 'node16'
main: 'main.js'
20 changes: 12 additions & 8 deletions .github/actions/zwave-js-bot/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ async function publishPr() {
await exec.exec("yarn", ["config", "set", "npmAuthToken", npmToken]);

// Figure out the next version
newVersion = `${semver.inc(
require(`${process.env.GITHUB_WORKSPACE}/package.json`).version,
"prerelease",
)}-pr-${pr}-${pull.merge_commit_sha.slice(0, 7)}`;
newVersion = `${
semver.inc(
require(`${process.env.GITHUB_WORKSPACE}/package.json`).version,
"prerelease",
)
}-pr-${pr}-${pull.merge_commit_sha.slice(0, 7)}`;

// Bump versions
await exec.exec(
Expand All @@ -55,9 +57,10 @@ async function publishPr() {
// and release changed packages
await exec.exec(
"yarn",
`workspaces foreach -vti --no-private npm publish --tolerate-republish --tag next`.split(
" ",
),
`workspaces foreach -vti --no-private npm publish --tolerate-republish --tag next`
.split(
" ",
),
);
success = true;
} catch (e) {
Expand All @@ -78,7 +81,8 @@ yarn add zwave-js@${newVersion}
octokit.issues.createComment({
...options,
issue_number: pr,
body: `😥 Unfortunately I could not publish the new packages. Check out the logs to see what went wrong.`,
body:
`😥 Unfortunately I could not publish the new packages. Check out the logs to see what went wrong.`,
});
}
}
8 changes: 4 additions & 4 deletions .github/bot-scripts/addCompatFlag.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
const { ConfigManager } = require("@zwave-js/config");
const JSONC = require("comment-json");
const fs = require("fs-extra");
const { formatWithPrettier } = require("./utils");
const { formatWithDprint } = require("./utils");

/**
* @param {{github: Github, context: Context}} param
Expand All @@ -23,9 +23,9 @@ async function main(param) {
const firmwareVersion = idParts[3];

// Parse the given flags while preserving comments
// We need to format the flags with Prettier because someone might have forgotten quotes
// We need to format the flags because someone might have forgotten quotes
const flags = JSONC.parse(
formatWithPrettier("file.json", `{${process.env.flag}}`),
formatWithDprint("file.json", `{${process.env.flag}}`),
);

const device = await cm.lookupDevice(
Expand All @@ -46,7 +46,7 @@ async function main(param) {

// And save it again
content = JSONC.stringify(json, undefined, "\t");
content = formatWithPrettier("file.json", content);
content = formatWithDprint(filename, content);
await fs.writeFile(filename, content, "utf8");
}
}
Expand Down
4 changes: 2 additions & 2 deletions .github/bot-scripts/addFingerprint.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { ConfigManager } = require("@zwave-js/config");
const { formatId } = require("@zwave-js/shared");
const JSONC = require("comment-json");
const fs = require("fs-extra");
const { formatWithPrettier } = require("./utils");
const { formatWithDprint } = require("./utils");

/**
* @param {{github: Github, context: Context}} param
Expand Down Expand Up @@ -48,7 +48,7 @@ async function main(param) {

// And save it again
content = JSONC.stringify(json, undefined, "\t");
content = formatWithPrettier("file.json", content);
content = formatWithDprint(filename, content);
await fs.writeFile(filename, content, "utf8");

// Return the device label so it can be used in the PR title
Expand Down
10 changes: 6 additions & 4 deletions .github/bot-scripts/approveWorkflows.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async function main(param) {
status: "action_required",
});
const pendingRuns = workflow_runs.filter((run) =>
workflowIDs.includes(run.workflow_id),
workflowIDs.includes(run.workflow_id)
);

/** @type {number[]} */
Expand Down Expand Up @@ -77,9 +77,11 @@ async function main(param) {
}

console.log(
`Changed files in PR #${pulls[0].number}: ${[...filenames]
.map((f) => `\n· ${f}`)
.join("")}`,
`Changed files in PR #${pulls[0].number}: ${
[...filenames]
.map((f) => `\n· ${f}`)
.join("")
}`,
);

console.log(`Check okay... workflow run will be approved`);
Expand Down
12 changes: 7 additions & 5 deletions .github/bot-scripts/ensureLogfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ async function main(param) {
console.log(`hasLink: ${hasLink}`);
console.log(`hasZjsLog: ${hasZjsLog}`);
console.log(
`codeBlockContent (matches = ${codeBlockRegex.test(
codeBlockContent,
)}): ${codeBlockContent}`,
`codeBlockContent (matches = ${
codeBlockRegex.test(
codeBlockContent,
)
}): ${codeBlockContent}`,
);

let message = "";
Expand Down Expand Up @@ -80,8 +82,8 @@ Please consider uploading a logfile that captures your problem.`;
});
const existing = comments.find(
(c) =>
c.user.login === "zwave-js-bot" &&
c.body.includes(LOGFILE_COMMENT_TAG),
c.user.login === "zwave-js-bot"
&& c.body.includes(LOGFILE_COMMENT_TAG),
);
if (existing) {
if (message) {
Expand Down
3 changes: 2 additions & 1 deletion .github/bot-scripts/fixLintFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ async function main(param) {

let feedbackText;
if (process.env.PENDING) {
feedbackText = `🐌 Please wait for the lint check to complete, then try again.`;
feedbackText =
`🐌 Please wait for the lint check to complete, then try again.`;
} else if (process.env.FEEDBACK === "error") {
feedbackText = `❌ I tried my best, but something went wrong.`;
} else if (process.env.FEEDBACK === "unchanged") {
Expand Down
3 changes: 2 additions & 1 deletion .github/bot-scripts/importConfigCreatePR.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ async function main(param) {
await github.rest.issues.createComment({
...options,
issue_number: context.payload.issue.number,
body: `🔨 I created a PR at #${prNumber} - check it out! Usually, I'm going to need some help from a human to make sure the configuration matches the [style guide](${urls.styleGuide}).
body:
`🔨 I created a PR at #${prNumber} - check it out! Usually, I'm going to need some help from a human to make sure the configuration matches the [style guide](${urls.styleGuide}).
If anyone feels compelled to help out, please follow these steps:
Expand Down
3 changes: 2 additions & 1 deletion .github/bot-scripts/rebaseFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ async function main(param) {

let feedbackText;
if (process.env.FEEDBACK === "error") {
feedbackText = `❌ I tried my best, but unfortunately this branch cannot be rebased automatically.`;
feedbackText =
`❌ I tried my best, but unfortunately this branch cannot be rebased automatically.`;
} else {
return;
}
Expand Down
24 changes: 12 additions & 12 deletions .github/bot-scripts/shouldAutomerge.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@
function shouldAutomerge(update) {
return (
// devDependencies: patch and minor
(update.dependencyType === "direct:development" &&
(update.updateType === "version-update:semver-patch" ||
update.updateType === "version-update:semver-minor")) ||
(update.dependencyType === "direct:development"
&& (update.updateType === "version-update:semver-patch"
|| update.updateType === "version-update:semver-minor"))
// production dependencies: patch
(update.dependencyType === "direct:production" &&
update.updateType === "version-update:semver-patch") ||
|| (update.dependencyType === "direct:production"
&& update.updateType === "version-update:semver-patch")
// production dependencies: minor if security alert
(update.dependencyType === "direct:production" &&
update.updateType === "version-update:semver-minor" &&
update.alertState === "OPEN") ||
|| (update.dependencyType === "direct:production"
&& update.updateType === "version-update:semver-minor"
&& update.alertState === "OPEN")
// indirect dependencies: minor if security alert
(update.dependencyType === "indirect" &&
(update.updateType === "version-update:semver-patch" ||
update.updateType === "version-update:semver-minor") &&
update.alertState === "OPEN")
|| (update.dependencyType === "indirect"
&& (update.updateType === "version-update:semver-patch"
|| update.updateType === "version-update:semver-minor")
&& update.alertState === "OPEN")
);
}

Expand Down
Loading

0 comments on commit 13ab114

Please sign in to comment.