Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .dprint.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
},
// NOTE: if extending this list, also update settings.template.json.
"plugins": [
"https://plugins.dprint.dev/typescript-0.93.3.wasm",
"https://plugins.dprint.dev/json-0.19.4.wasm",
"https://plugins.dprint.dev/markdown-0.17.8.wasm",
"https://plugins.dprint.dev/g-plane/pretty_yaml-v0.5.0.wasm"
"npm:@dprint/typescript@0.96.1",
"npm:@dprint/json@0.23.0",
"npm:@dprint/markdown@0.22.1",
"npm:dprint-plugin-yaml@0.6.0"
],
"indentWidth": 4,
"lineWidth": 120,
Expand Down
115 changes: 49 additions & 66 deletions dangerfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,81 +80,64 @@ newPackageJsonFiles.forEach(p => {
}
});

function chunked<T>(arr: T[], size: number): T[][] {
const result: T[][] = [];
for (let i = 0; i < arr.length; i += size) {
result.push(arr.slice(i, i + size));
}
return result;
}

const unformatted = [];
const dprintErrors = [];
const allFiles = [...danger.git.created_files, ...danger.git.modified_files];
// We batch this in chunks to avoid hitting max arg length issues.
for (const files of chunked(allFiles, 50)) {
const result = cp.spawnSync(
process.execPath,
["node_modules/dprint/bin.js", "check", "--list-different", ...files],
{ encoding: "utf8", maxBuffer: 100 * 1024 * 1024 },
);
// https://dprint.dev/cli/#exit-codes
switch (result.status) {
case 0:
case 14:
// No change or no files matched
break;
case 20:
for (const line of result.stdout.split(/\r?\n/)) {
if (line) {
unformatted.push(path.relative(process.cwd(), line));
}
}
break;
default:
dprintErrors.push(result.stderr.trim());
break;
}
}

if (dprintErrors.length > 0) {
fail("dprint failed to execute");
// The file paths are provided over stdin to avoid hitting max arg length issues.
const result = cp.spawnSync(
process.execPath,
["node_modules/dprint/bin.cjs", "check", "--list-different", "--stdin-files"],
{ encoding: "utf8", input: allFiles.join("\n"), maxBuffer: 100 * 1024 * 1024 },
);
// https://dprint.dev/cli/#exit-codes
switch (result.status) {
case 0:
case 14:
// No change or no files matched
break;
case 20: {
const unformatted = result.stdout.split(/\r?\n/)
.filter(line => line)
.map(line => path.relative(process.cwd(), line));
const message = [
"## Formatting",
"",
];

// Try and make sure no reasonable error could ever close the code block.
// You can open a code block with as many backticks as you want, so long as
// you close it with the same string. Inside of the code block, any lower
// number of backticks cannot close the block.
const codeBlock = "``````````";
const message = [
"## Formatting errors",
"",
codeBlock,
dprintErrors.join("\n\n"),
codeBlock,
];

markdown(message.join("\n"));
} else if (unformatted.length > 0) {
const message = [
"## Formatting",
"",
];

message.push(
`The following files are not formatted:
message.push(
`The following files are not formatted:
1. ` + unformatted.slice(0, 5).join("\n1. "),
);
if (unformatted.length > 5) {
const extras = unformatted.slice(5);
message.push(`
);
if (unformatted.length > 5) {
const extras = unformatted.slice(5);
message.push(`
<details>
<summary>as well as these ${extras.length} other files...</summary>
<p>${extras.join(", ")}</p>
</details>
`);
}

message.push("\nConsider running `pnpm dprint fmt` on these files to make review easier.");

markdown(message.join("\n"));
break;
}
default: {
fail("dprint failed to execute");

message.push("\nConsider running `pnpm dprint fmt` on these files to make review easier.");
// Try and make sure no reasonable error could ever close the code block.
// You can open a code block with as many backticks as you want, so long as
// you close it with the same string. Inside of the code block, any lower
// number of backticks cannot close the block.
const codeBlock = "``````````";
const message = [
"## Formatting errors",
"",
codeBlock,
result.stderr.trim(),
codeBlock,
];

markdown(message.join("\n"));
markdown(message.join("\n"));
break;
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@definitelytyped/header-parser": "latest",
"@definitelytyped/typescript-versions": "latest",
"@definitelytyped/utils": "latest",
"dprint": "^0.49.0",
"dprint": "^0.56.1",
"eslint-plugin-jsdoc": "^44.2.7",
"husky": "^9.1.7",
"lint-staged": "^15.2.0",
Expand Down
2 changes: 1 addition & 1 deletion types/hapi/v16/test/response/error-representation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const preResponse: Hapi.ServerExtRequestHandler = function(request, reply) {

const error = response;
const ctx = {
message: (error.output!.statusCode === 404 ? "page not found" : "something went wrong"),
message: error.output!.statusCode === 404 ? "page not found" : "something went wrong",
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ new HardSourceWebpackPlugin.SerializerCacachePlugin();
new HardSourceWebpackPlugin.SerializerJsonPlugin();

new HardSourceWebpackPlugin.ParallelModulePlugin({
fork: ((
fork: (
forkFn: (modulePath: string, args?: readonly string[], options?: ForkOptions) => ChildProcess,
compiler: webpack.Compiler,
webpackBin: string,
) => {
}),
},
numWorkers: () => 3,
minModules: 10,
});
2 changes: 1 addition & 1 deletion types/inboxsdk/inboxsdk-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ InboxSDK.load(1, "1234").then((sdk: InboxSDK.InboxSDKInstance) => {
InboxSDK.load(1, "1234").then((sdk: InboxSDK.InboxSDKInstance) => {
const unregister = sdk.Toolbars.registerThreadButton({
hasDropdown: true,
hideFor: (routeView => routeView.getParams()),
hideFor: routeView => routeView.getParams(),
iconClass: "big",
iconUrl: "http://url.com",
keyboardShortcutHandle: {
Expand Down
2 changes: 1 addition & 1 deletion types/jasminewd2/jasminewd2-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe("jasminewd", () => {
return {
compare(actual: any, expected: void) {
return {
pass: (actual.isDisplayed() as Promise<boolean>),
pass: actual.isDisplayed() as Promise<boolean>,
};
},
};
Expand Down
2 changes: 1 addition & 1 deletion types/lodash-es/scripts/generate-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ import { ${flattenModules.map(val => `${val} as ${val}1`).join(",")}} from 'loda
function findDprint() {
let p = __dirname;
while (true) {
const dprintPath = path.join(p, "node_modules", "dprint", "bin.js");
const dprintPath = path.join(p, "node_modules", "dprint", "bin.cjs");
if (fs.existsSync(dprintPath)) {
return dprintPath;
}
Expand Down
2 changes: 1 addition & 1 deletion types/mongoose-paginate/mongoose-paginate-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ router.get("/users.json", function(req: Request, res: Response) {
let descending: boolean = true;
let options: PaginateOptions = {} as PaginateOptions;
options.select = "email username";
options.sort = { "username": (descending ? -1 : 1) };
options.sort = { "username": descending ? -1 : 1 };
options.populate = "";
options.populate = {
path: "",
Expand Down
2 changes: 1 addition & 1 deletion types/nodal/nodal-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class AccessToken extends Nodal.Model {
new Date().valueOf(),
),
token_type: "bearer",
expires_at: (new Date(new Date().valueOf() + (30 * 24 * 60 * 60 * 1000))),
expires_at: new Date(new Date().valueOf() + (30 * 24 * 60 * 60 * 1000)),
ip_address: params.ip_address,
}).save(callback);
});
Expand Down
2 changes: 1 addition & 1 deletion types/node/scripts/generate-docs/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const ignoreFiles = new Set([
function findDprint() {
let p = __dirname;
while (true) {
const dprintPath = join(p, "node_modules", "dprint", "bin.js");
const dprintPath = join(p, "node_modules", "dprint", "bin.cjs");
if (fs.existsSync(dprintPath)) {
return dprintPath;
}
Expand Down
2 changes: 1 addition & 1 deletion types/nvd3/test/multibarChart2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace nvd3_test_multibarChart2 {
var test_data = [3, 128, .1].map(function(data, i) {
return {
key: (i == 1) ? "Non-stackable Stream" + i : "Stream" + i,
nonStackable: (i == 1),
nonStackable: i == 1,
values: data,
};
});
Expand Down
9 changes: 8 additions & 1 deletion types/react-dom/canary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ export interface BrowserUsable {
}

declare module "." {
function browser(): BrowserUsable;
/**
* Creates an opaque Usable that opts a subtree into browser-only rendering.
* `reason` is diagnostic metadata: an SSR renderer uses it as the `cause` of
* the recoverable error it reports when deferring the subtree to the browser.
* A function is called lazily by that renderer; in the browser the reason is
* never observed.
*/
function browser(reason?: string | (() => unknown)): BrowserUsable;
}

declare module "react" {
Expand Down
10 changes: 10 additions & 0 deletions types/react-dom/test/canary-tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,14 @@ function browserUsableTests() {
// browser() returns an opaque, renderer-specific Usable that React.use accepts
// $ExpectType unknown
React.use(ReactDOM.browser());

// The reason can be a string or a lazy initializer whose return value an
// SSR renderer uses as the cause of the recoverable error.
// $ExpectType BrowserUsable
ReactDOM.browser("Only render this content in a browser");
// $ExpectType BrowserUsable
ReactDOM.browser(() => new Error("Only render this content in a browser"));

// @ts-expect-error -- the reason is a string or a zero-arg initializer, not an arbitrary value
ReactDOM.browser(new Error("Only render this content in a browser"));
}
2 changes: 1 addition & 1 deletion types/rsocket-core/rsocket-core-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ new RSocketClient<Buffer, Buffer>({
},
// Transports default to sending/receiving strings:
// Use BufferEncoders to enable binary
transport: (undefined as any),
transport: undefined as any,
});

const compositeMetadata = decodeCompositeMetadata(encodeCompositeMetadata([
Expand Down
2 changes: 1 addition & 1 deletion types/sitemap2/sitemap2-tests.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Sitemap = require("sitemap2");

const sitemap = new Sitemap({
hostName: ("https://example.com/"),
hostName: "https://example.com/",
fileName: "sitemap.xml",
limit: 50000,
cacheTime: 1000,
Expand Down
2 changes: 1 addition & 1 deletion types/slickgrid/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ for (var i = 0; i < 500; i++) {
percentComplete: Math.round(Math.random() * 100),
start: "01/01/2009",
finish: "01/05/2009",
effortDriven: (i % 5 == 0),
effortDriven: i % 5 == 0,
};
}

Expand Down
4 changes: 2 additions & 2 deletions types/stream-buffers/stream-buffers-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import * as streamBuffers from "stream-buffers";
// https://github.com/samcday/node-stream-buffer

const myWritableStreamBuffer = new streamBuffers.WritableStreamBuffer({
initialSize: (100 * 1024), // start at 100 kilobytes.
incrementAmount: (10 * 1024), // grow by 10 kilobytes each time buffer overflows.
initialSize: 100 * 1024, // start at 100 kilobytes.
incrementAmount: 10 * 1024, // grow by 10 kilobytes each time buffer overflows.
});

const a = streamBuffers.DEFAULT_INITIAL_SIZE; // (8 * 1024)
Expand Down
4 changes: 2 additions & 2 deletions types/vex-js/vex-js-tests.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import vex = require("vex-js");

var vexContent = vex.open({
afterClose: (() => null),
afterOpen: ((vexContent: JQuery) => null),
afterClose: () => null,
afterOpen: (vexContent: JQuery) => null,
content: "<div><p>Modal</p></div>",
showCloseButton: false,
escapeButtonCloses: true,
Expand Down