Skip to content

Commit

Permalink
chore: correct .gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaKGoldberg committed Jul 17, 2024
1 parent 32686e6 commit 45f77c0
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
cases/
cases/files-*
node_modules/
package-lock.json
5 changes: 0 additions & 5 deletions knip.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{
"$schema": "https://unpkg.com/knip@latest/schema.json",
"entry": ["./src/*.ts"],
"ignore": [
"src/creators/files/createESLintConfigFile.ts",
"src/creators/files/createStandardTSConfigFile.ts",
"src/creators/utils.ts"
],
"ignoreExportsUsedInFile": { "interface": true, "type": true },
"ignoreWorkspaces": ["cases/**"]
}
84 changes: 84 additions & 0 deletions src/creators/cases/createEvenCaseFiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { CaseData } from "../../data.js";
import { Structure } from "../../writing/writeStructure.js";
import { createESLintConfigFile } from "../files/createESLintConfigFile.js";
import { createStandardTSConfigFile } from "../files/createStandardTSConfigFile.js";
import { range } from "../utils.js";

function createExampleFile(index: number) {
return [
index > 1 &&
range(1, index)
.map((i) => `export * as nested${i} from "./nested${i}/index.js";`)
.join("\n\t\t"),
`
export async function example${index}(prefix: string) {
await Promise.resolve();
return prefix + "" + ${index};
}
`,
]
.filter(Boolean)
.join("\n\n");
}

function createExampleDirectory(index: number): Structure {
return {
"index.ts": [createExampleFile(index), "typescript"],
...(index > 2 &&
Object.fromEntries(
range(1, index).map((i) => [
`nested${i}`,
createExampleDirectory(i - 1),
]),
)),
};
}

function createIndexFile(count: number) {
const indices = range(0, count);

return `
import { example0 } from "./example0/index.js";
export async function root() {
// Lint report: no-floating-promises
example0("");
// No lint report
await example0("");
}
${indices.map((index) => `export { example${index} } from "./example${index}/index.js";`).join("\n\t\t")}
`;
}

export function writeEvenCaseFiles(data: CaseData): Structure {
const topLevelWidth = Math.floor(Math.log(data.files) * 1.7);

return {
"eslint.config.js": [
createESLintConfigFile({
singleRun: data.singleRun,
types:
data.types === "service"
? "projectService"
: data.layout === "references"
? "tsconfig.eslint.json"
: true,
}),
"typescript",
],
src: {
"index.ts": [createIndexFile(topLevelWidth), "typescript"],
...Object.fromEntries(
new Array(topLevelWidth)
.fill(undefined)
.map((_, index) => [
`example${index}`,
createExampleDirectory(index),
]),
),
},
"tsconfig.json": [createStandardTSConfigFile(), "json"],
};
}
125 changes: 125 additions & 0 deletions src/creators/cases/createReferencesCaseFiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { CaseData } from "../../data.js";
import { Structure } from "../../writing/writeStructure.js";
import { createESLintConfigFile } from "../files/createESLintConfigFile.js";
import { createStandardTSConfigFile } from "../files/createStandardTSConfigFile.js";
import { range } from "../utils.js";

function createExampleFile(index: number) {
return [
index > 2 &&
range(1, index)
.map((i) => `export * as nested${i} from "./nested${i}/index.js";`)
.join("\n\t\t"),
`
export async function example${index}(prefix: string) {
await Promise.resolve();
return prefix + "" + ${index};
}
`,
]
.filter(Boolean)
.join("\n\n");
}

function createIndexFile(count: number) {
const indices = count > 1 ? range(0, count - 1) : [];

return `
import { example0 } from "./nested0/index.js";
export async function root() {
// Lint report: no-floating-promises
example0("");
// No lint report
await example0("");
}
${indices.map((index) => `export * as nested${index} from "./nested${index}/index.js";`).join("\n\t\t")}
`;
}

function createNestedDirectory(index: number): Structure {
return {
"index.ts": [createExampleFile(index), "typescript"],
...(index > 2 &&
Object.fromEntries(
range(1, index).map((i) => [
`nested${i}`,
createNestedDirectory(i - 1),
]),
)),
};
}

function createProjectDirectory(index: number): Structure {
return {
src: {
"index.ts": [createIndexFile(index), "typescript"],
...(index > 2 &&
Object.fromEntries(
range(0, index - 1).map((i) => [
`nested${i}`,
createNestedDirectory(i),
]),
)),
},
"tsconfig.json": [
{
extends: "../../tsconfig.build.json",
include: ["src"],
},
"json",
],
};
}

export function createReferencesCaseFiles(data: CaseData): Structure {
const topLevelWidth = Math.ceil(
Math.log(data.files) * (data.files > 1000 ? 1.6 : 1.7),
);
const projectNames = range(0, topLevelWidth).map((i) => `project-${i}`);

return {
"eslint.config.js": [
createESLintConfigFile({
singleRun: data.singleRun,
types:
data.types === "service"
? "projectService"
: data.layout === "references"
? "tsconfig.eslint.json"
: true,
}),
"typescript",
],
"tsconfig.build.json": [
{ ...createStandardTSConfigFile(), include: undefined },
"json",
],
...(data.types === "service"
? {
"tsconfig.json": [
{
include: [],
references: projectNames.map((projectName) => ({
path: `./src/${projectName}`,
})),
},
"json",
],
}
: {
"tsconfig.eslint.json": [createStandardTSConfigFile(), "json"],
"tsconfig.json": [createStandardTSConfigFile(), "json"],
}),
src: {
...Object.fromEntries(
projectNames.map((projectName, index) => [
projectName,
createProjectDirectory(index),
]),
),
},
};
}
58 changes: 58 additions & 0 deletions src/creators/cases/createWideCaseFiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { CaseData } from "../../data.js";
import { Structure } from "../../writing/writeStructure.js";
import { createESLintConfigFile } from "../files/createESLintConfigFile.js";
import { createStandardTSConfigFile } from "../files/createStandardTSConfigFile.js";

function createExampleFile(index: number) {
return `
export async function example${index}(prefix: string) {
await Promise.resolve();
return prefix + "" + ${index};
}
`;
}

function createIndexFile(count: number) {
const indices = new Array(count - 1).fill(undefined).map((_, index) => index);

return `
${indices.map((index) => `import { example${index} } from "./example${index}.js";`).join("\n\t\t")}
export async function root() {
// Lint report: no-floating-promises
example0("");
// No lint reports
${indices.map((index) => `await example${index}("");`).join("\n\t\t\t")}
}
`;
}

export function writeWideCaseFiles(data: CaseData): Structure {
return {
"eslint.config.js": [
createESLintConfigFile({
singleRun: data.singleRun,
types:
data.types === "service"
? "projectService"
: data.layout === "references"
? "tsconfig.eslint.json"
: true,
}),
"typescript",
],
src: {
"index.ts": [createIndexFile(data.files), "typescript"],
...Object.fromEntries(
new Array(data.files - 1)
.fill(undefined)
.map((_, index) => [
`example${index}.ts`,
[createExampleFile(index), "typescript"],
]),
),
},
"tsconfig.json": [createStandardTSConfigFile(), "json"],
};
}

0 comments on commit 45f77c0

Please sign in to comment.