Skip to content

Commit 0a55371

Browse files
Copilotpelikhangithub-actions[bot]
authored
Enforce syntax-aware linting for bundled CommonJS action scripts (#43470)
* Initial plan * Plan compiler validation fix Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> * Enforce setup JS lint in lint-cjs Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 19d59cd commit 0a55371

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,8 +837,9 @@ validate-cjs-syntax:
837837

838838
# Lint JavaScript (.cjs and .js) and JSON files in actions/setup/js directory
839839
.PHONY: lint-cjs
840-
lint-cjs: fmt-check-cjs validate-cjs-syntax
841-
@echo "✓ JavaScript formatting validated"
840+
lint-cjs: fmt-check-cjs validate-cjs-syntax check-node-version
841+
@cd eslint-factory && { [ -d node_modules ] || npm ci; } && npm run lint:setup-js
842+
@echo "✓ JavaScript formatting, syntax, and lint validated"
842843

843844
# Lint JSON files in pkg directory (excluding actions/setup/js, which is handled by npm script)
844845
.PHONY: lint-json
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Linter } from "eslint";
2+
import { describe, expect, it } from "vitest";
3+
4+
const cjsConfig = {
5+
languageOptions: {
6+
ecmaVersion: "latest" as const,
7+
sourceType: "commonjs" as const,
8+
},
9+
};
10+
11+
describe("CommonJS syntax validation", () => {
12+
it("rejects await inside non-async functions", () => {
13+
const linter = new Linter();
14+
const messages = linter.verify(`function writeStepSummaryWithTokenUsage(coreObj) { await coreObj.summary.write(); }`, cjsConfig, "parse_mcp_gateway_log.cjs");
15+
16+
expect(messages).toContainEqual(
17+
expect.objectContaining({
18+
fatal: true,
19+
ruleId: null,
20+
severity: 2,
21+
})
22+
);
23+
});
24+
25+
it("allows await inside async functions", () => {
26+
const linter = new Linter();
27+
const messages = linter.verify(`async function writeStepSummaryWithTokenUsage(coreObj) { await coreObj.summary.write(); }`, cjsConfig, "parse_mcp_gateway_log.cjs");
28+
29+
expect(messages).toEqual([]);
30+
});
31+
});

0 commit comments

Comments
 (0)