Skip to content

Commit 0caa84a

Browse files
authored
support lint fix command in js release tool (#11722)
* support lint fix command in js release tool * Update devToolUtils.ts * update * Revert "update" This reverts commit fdbbd85. * Update devToolUtils.ts * Revert "Update devToolUtils.ts" This reverts commit 1f429d8. * Update devToolUtils.ts * Update devToolUtils.ts * test code * test code * Update devToolUtils.ts * try to use root path * Revert "try to use root path" This reverts commit d4b0161. * Update devToolUtils.ts * Update devToolUtils.ts * bump version
1 parent b389d7e commit 0caa84a

File tree

6 files changed

+34
-6
lines changed

6 files changed

+34
-6
lines changed

tools/js-sdk-release-tools/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/js-sdk-release-tools/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@azure-tools/js-sdk-release-tools",
3-
"version": "2.14.2",
3+
"version": "2.14.3",
44
"description": "",
55
"files": [
66
"dist"

tools/js-sdk-release-tools/src/common/devToolUtils.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11

22
import { logger } from '../utils/logger.js';
3+
import * as path from 'path';
4+
import { exists } from 'fs-extra';
35
import { runCommand, runCommandOptions } from './utils.js';
46

57
export async function formatSdk(packageDirectory: string) {
@@ -29,4 +31,24 @@ export async function updateSnippets(packageDirectory: string) {
2931
} catch (error) {
3032
logger.warn(`Failed to update snippets due to: ${(error as Error)?.stack ?? error}`);
3133
}
34+
}
35+
36+
export async function lintFix(packageDirectory: string) {
37+
const hasSampleFolder = await exists(path.join(packageDirectory, "samples-dev"));
38+
const samplesDev = hasSampleFolder ? ' samples-dev' : '';
39+
const cwd = packageDirectory;
40+
const options = { ...runCommandOptions, cwd };
41+
42+
logger.info("Start to build @azure/eslint-plugin-azure-sdk package to install eslint dependency.");
43+
await runCommand('pnpm', ['build', '--filter', `@azure/eslint-plugin-azure-sdk...`], runCommandOptions);
44+
logger.info("Build @azure/eslint-plugin-azure-sdk package successfully.");
45+
logger.info(`Start to fix lint errors in '${packageDirectory}'.`);
46+
const lintFixCommand = `run vendored eslint package.json api-extractor.json src test${samplesDev} --fix --fix-type [problem,suggestion]`;
47+
48+
try {
49+
await runCommand(`npm`, ['exec', '--', 'dev-tool', lintFixCommand], options, true, 300, true);
50+
logger.info(`Fix the automatically repairable lint errors successfully.`);
51+
} catch (error) {
52+
logger.warn(`Failed to fix lint errors due to: ${(error as Error)?.stack ?? error}`);
53+
}
3254
}

tools/js-sdk-release-tools/src/common/rushUtils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { glob } from 'glob';
1111
import { logger } from '../utils/logger.js';
1212
import unixify from 'unixify';
1313
import { existsSync } from 'fs';
14-
import { formatSdk, updateSnippets } from './devToolUtils.js';
14+
import { formatSdk, lintFix, updateSnippets } from './devToolUtils.js';
1515

1616
interface ProjectItem {
1717
packageName: string;
@@ -134,6 +134,8 @@ export async function buildPackage(
134134
await runCommand(`pnpm`, ['install'], runCommandOptions, false);
135135
logger.info(`Pnpm install successfully.`);
136136

137+
await lintFix(packageDirectory);
138+
137139
logger.info(`Start to build package '${name}'.`);
138140
await runCommand('pnpm', ['build', '--filter', `${name}...`], runCommandOptions);
139141
}

tools/js-sdk-release-tools/src/hlc/generateMgmt.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {getReleaseTool} from "./utils/getReleaseTool.js";
1616
import { addApiViewInfo } from "../utils/addApiViewInfo.js";
1717
import { defaultChildProcessTimeout } from '../common/utils.js'
1818
import { isRushRepo } from "../common/rushUtils.js";
19-
import { updateSnippets } from "../common/devToolUtils.js";
19+
import { lintFix, updateSnippets } from "../common/devToolUtils.js";
2020
import { ChangelogResult } from "../changelog/v2/ChangelogGenerator.js";
2121

2222
export async function generateMgmt(options: {
@@ -131,6 +131,8 @@ export async function generateMgmt(options: {
131131
} else {
132132
logger.info(`Start to run command: 'pnpm install'.`);
133133
execSync('pnpm install', {stdio: 'inherit'});
134+
135+
await lintFix(packagePath);
134136

135137
logger.info(`Start to run command: 'pnpm build --filter ${packageName}...', that builds generated codes, except test and sample, which may be written manually.`);
136138
execSync(`pnpm build --filter ${packageName}...`, {stdio: 'inherit'});

tools/js-sdk-release-tools/src/llc/generateRLCInPipeline/generateRLCInPipeline.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { remove } from 'fs-extra';
2222
import { generateChangelogAndBumpVersion } from "../../common/changelog/automaticGenerateChangeLogAndBumpVersion.js";
2323
import { updateChangelogResult } from "../../common/packageResultUtils.js";
2424
import { isRushRepo } from "../../common/rushUtils.js";
25-
import { formatSdk, updateSnippets } from "../../common/devToolUtils.js";
25+
import { formatSdk, updateSnippets, lintFix } from "../../common/devToolUtils.js";
2626
import { RunMode } from "../../common/types.js";
2727
import { exists } from 'fs-extra';
2828

@@ -272,6 +272,8 @@ export async function generateRLCInPipeline(options: {
272272
} else {
273273
logger.info(`Start to update.`);
274274
execSync('pnpm install', {stdio: 'inherit'});
275+
276+
await lintFix(packagePath);
275277

276278
logger.info(`Start to build '${packageName}', except for tests and samples, which may be written manually.`);
277279
// To build generated codes except test and sample, we need to change tsconfig.json.

0 commit comments

Comments
 (0)