Skip to content

Commit 8556f10

Browse files
authored
[.github] Update tseslint.configs from recommended to recommendedTypeChecked (#38673)
1 parent 3031e91 commit 8556f10

22 files changed

+153
-120
lines changed

.github/eslint.config.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,19 @@ import tseslint from "typescript-eslint";
88
/** @type {import('eslint').Linter.Config[]} */
99
export default defineConfig(
1010
eslint.configs.recommended,
11-
tseslint.configs.recommended,
11+
tseslint.configs.recommendedTypeChecked,
1212
{
13-
languageOptions: { globals: globals.node },
13+
languageOptions: {
14+
// we only run in node, not browser
15+
globals: globals.node,
16+
// required to use tseslint.configs.recommendedTypeChecked
17+
parserOptions: {
18+
projectService: true,
19+
// ensures the tsconfig path resolves relative to this file
20+
// default is process.cwd() when running eslint, which may be incorrect
21+
tsconfigRootDir: import.meta.dirname,
22+
},
23+
},
1424
},
1525
{
1626
ignores: ["coverage/**", "shared/coverage/**"],

.github/shared/test/examples.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export const fullGitSha = "abc123abc123abc123abc123abc123abc123abc1";
22

3-
export const swaggerHandWritten = JSON.stringify("foo");
3+
export const swaggerHandWritten = JSON.stringify({});
44

55
export const swaggerTypeSpecGenerated = JSON.stringify({
66
info: {

.github/workflows/src/arm-auto-signoff.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { inspect } from "util";
12
import { CommitStatusState, PER_PAGE_MAX } from "../../shared/src/github.js";
23
import { equals } from "../../shared/src/set.js";
34
import { byDate, invert } from "../../shared/src/sort.js";
@@ -69,7 +70,7 @@ export async function getLabelActionImpl({ owner, repo, issue_number, head_sha,
6970
? labelActions[LabelAction.Remove]
7071
: labelActions[LabelAction.None];
7172

72-
core.info(`Labels: ${labelNames}`);
73+
core.info(`Labels: ${inspect(labelNames)}`);
7374

7475
// permissions: { actions: read }
7576
const workflowRuns = await github.paginate(github.rest.actions.listWorkflowRunsForRepo, {
@@ -125,7 +126,9 @@ export async function getLabelActionImpl({ owner, repo, issue_number, head_sha,
125126
// Continue checking other requirements
126127
} else {
127128
// If workflow succeeded, it should have one workflow or the other
128-
throw `Workflow artifacts did not contain 'incremental-typespec': ${JSON.stringify(artifactNames)}`;
129+
throw new Error(
130+
`Workflow artifacts did not contain 'incremental-typespec': ${JSON.stringify(artifactNames)}`,
131+
);
129132
}
130133
} else {
131134
core.info(`Workflow '${wfName}' is still in-progress: status='${run.status}'`);
@@ -181,7 +184,7 @@ export async function getLabelActionImpl({ owner, repo, issue_number, head_sha,
181184
(matchingStatus.state === CommitStatusState.ERROR ||
182185
matchingStatus.state === CommitStatusState.FAILURE)
183186
) {
184-
core.info(`Status '${matchingStatus}' did not succeed`);
187+
core.info(`Status '${matchingStatus.context}' did not succeed`);
185188
return removeAction;
186189
}
187190

.github/workflows/src/arm-incremental-typespec.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
swagger,
1111
} from "../../shared/src/changed-files.js";
1212
import { Readme } from "../../shared/src/readme.js";
13+
import { Swagger } from "../../shared/src/swagger.js";
1314
import { CoreLogger } from "./core-logger.js";
1415

1516
// Enable simple-git debug logging to improve console output
@@ -55,19 +56,17 @@ export default async function incrementalTypeSpec({ core }) {
5556
}
5657
}
5758

58-
let swaggerObj;
5959
try {
60-
swaggerObj = JSON.parse(swaggerText);
60+
const swagger = new Swagger(file, { content: swaggerText });
61+
if (!(await swagger.getTypeSpecGenerated())) {
62+
core.info(`File "${file}" does not contain "info.x-typespec-generated"`);
63+
return false;
64+
}
6165
} catch {
6266
// If swagger cannot be parsed as JSON, it's not "incremental typespec"
6367
core.info(`File "${file}" cannot be parsed as JSON`);
6468
return false;
6569
}
66-
67-
if (!swaggerObj["info"]?.["x-typespec-generated"]) {
68-
core.info(`File "${file}" does not contain "info.x-typespec-generated"`);
69-
return false;
70-
}
7170
}
7271

7372
/** @type Set<string> */
@@ -142,9 +141,9 @@ export default async function incrementalTypeSpec({ core }) {
142141
let containsTypeSpecGeneratedSwagger = false;
143142
// TODO: Add lint rule to prevent using "for...in" instead of "for...of"
144143
for (const file of specRmSwaggerFilesBaseBranch) {
145-
const baseSwagger = await git.show([`HEAD^:${file}`]);
146-
const baseSwaggerObj = JSON.parse(baseSwagger);
147-
if (baseSwaggerObj["info"]?.["x-typespec-generated"]) {
144+
const baseSwaggerContent = await git.show([`HEAD^:${file}`]);
145+
const baseSwagger = new Swagger(file, { content: baseSwaggerContent });
146+
if (await baseSwagger.getTypeSpecGenerated()) {
148147
core.info(
149148
`Spec folder '${changedSpecDir}' in base branch contains typespec-generated swagger: '${file}'`,
150149
);

.github/workflows/src/avocado-code.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { readFile } from "fs/promises";
2+
import { inspect } from "util";
23
import {
34
generateMarkdownTable,
45
MessageLevel,
@@ -29,7 +30,7 @@ export default async function generateJobSummary({ core }) {
2930
} catch (error) {
3031
// If we can't read the file, the previous step must have failed catastrophically.
3132
// generateJobSummary() should never fail, so just log the error and return
32-
core.info(`Error reading '${avocadoOutputFile}': ${error}`);
33+
core.info(`Error reading '${avocadoOutputFile}': ${inspect(error)}`);
3334
return;
3435
}
3536

@@ -51,6 +52,6 @@ export default async function generateJobSummary({ core }) {
5152
core.summary.addRaw(generateMarkdownTable(messages));
5253
}
5354

54-
core.summary.write();
55+
await core.summary.write();
5556
core.setOutput("summary", process.env.GITHUB_STEP_SUMMARY);
5657
}

.github/workflows/src/context.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { inspect } from "util";
12
import { isFullGitSha } from "../../shared/src/git.js";
23
import { PER_PAGE_MAX } from "../../shared/src/github.js";
34
import { CoreLogger } from "./core-logger.js";
@@ -22,7 +23,15 @@ export async function extractInputs(github, context, core) {
2223
core.info("extractInputs()");
2324
core.info(` eventName: ${context.eventName}`);
2425
core.info(` payload.action: ${context.payload.action}`);
25-
core.info(` payload.workflow_run.event: ${context.payload.workflow_run?.event || "undefined"}`);
26+
27+
let workflowRunEvent = "undefined";
28+
if (context.eventName === "workflow_run") {
29+
const payload = /** @type {import("@octokit/webhooks-types").WorkflowRunEvent} */ (
30+
context.payload
31+
);
32+
workflowRunEvent = payload.workflow_run?.event;
33+
}
34+
core.info(` payload.workflow_run.event: ${workflowRunEvent}`);
2635

2736
// Log full context when debug is enabled. Most workflows should be idempotent and can be re-run
2837
// with debug enabled to replay the previous context.
@@ -164,7 +173,7 @@ export async function extractInputs(github, context, core) {
164173
core.info(`Error: ${error instanceof Error ? error.message : "unknown"}`);
165174

166175
// Long message only in debug
167-
core.debug(`Error: ${error}`);
176+
core.debug(`Error: ${inspect(error)}`);
168177
}
169178

170179
if (pullRequests.length === 0) {
@@ -270,10 +279,10 @@ export async function extractInputs(github, context, core) {
270279
run_id: payload.workflow_run.id,
271280
};
272281
} else if (context.eventName === "check_run") {
273-
let checkRun = context.payload.check_run;
274282
const payload = /** @type {import("@octokit/webhooks-types").CheckRunEvent} */ (
275283
context.payload
276284
);
285+
const checkRun = payload.check_run;
277286
const repositoryInfo = getRepositoryInfo(payload.repository);
278287
inputs = {
279288
owner: repositoryInfo.owner,

.github/workflows/src/doc-preview.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { inspect } from "util";
2+
13
const DOCS_NAMESPACE = "_swagger_specs";
24
const SPEC_FILE_REGEX =
35
"(specification/)+(.*)/(resourcemanager|resource-manager|dataplane|data-plane|control-plane)/(.*)/(preview|stable|privatepreview)/(.*?)/(example)?(.*)";
@@ -141,7 +143,7 @@ export function getSwaggersToProcess(swaggerFiles) {
141143
const parsed = parseSwaggerFilePath(file);
142144
swaggerFileObjs.push(parsed);
143145
} catch (error) {
144-
console.log(`Skipping file "${file}" due to parsing error: ${error}`);
146+
console.log(`Skipping file "${file}" due to parsing error: ${inspect(error)}`);
145147
continue;
146148
}
147149
}

.github/workflows/src/github-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default async function importAllModules({ core }) {
3030
const fileUrl = pathToFileURL(fullPath).href;
3131

3232
// if import fails, throws error which causes step to fail
33-
const module = await import(fileUrl);
33+
const module = /** @type {unknown} */ (await import(fileUrl));
3434

3535
core.info(inspect(module));
3636
core.info("");

.github/workflows/src/github.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { inspect } from "util";
12
import { toPercent } from "../../shared/src/math.js";
23
import { Duration, formatDuration, getDuration, subtract } from "../../shared/src/time.js";
34

@@ -18,7 +19,7 @@ export async function writeToActionsSummary(content, core) {
1819
await core.summary.addRaw(content).write();
1920
core.info("Successfully wrote to the GitHub Actions summary");
2021
} catch (error) {
21-
throw new Error(`Failed to write to the GitHub Actions summary: ${error}`);
22+
throw new Error(`Failed to write to the GitHub Actions summary: ${inspect(error)}`);
2223
}
2324
}
2425

@@ -33,8 +34,9 @@ export function createLogHook(endpoint, logger) {
3334
*/
3435
function logHook(options) {
3536
const request = endpoint(options);
36-
const { method, url, body } = request;
37-
logger.info(`[github] ${method.toUpperCase()} ${url} ${body ? JSON.stringify(body) : ""}`);
37+
logger.info(
38+
`[github] ${request.method.toUpperCase()} ${request.url} ${request.body ? JSON.stringify(request.body) : ""}`,
39+
);
3840
}
3941

4042
return logHook;

.github/workflows/src/issues.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { inspect } from "util";
2+
13
/**
24
* Retrieves the PR number associated with a specific commit SHA
35
* @param {import('@actions/github-script').AsyncFunctionArguments["github"]} github - GitHub API client
@@ -38,7 +40,7 @@ export async function getIssueNumber(github, head_sha, logger) {
3840
logger?.info(`No open PRs found for commit ${head_sha}`);
3941
}
4042
} catch (error) {
41-
logger?.error(`Error searching for PRs with commit ${head_sha}: ${error}`);
43+
logger?.error(`Error searching for PRs with commit ${head_sha}: ${inspect(error)}`);
4244
throw error;
4345
}
4446

0 commit comments

Comments
 (0)