From cd7f3b6e65d25defdbf27da5d133cff586ef7d17 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Fri, 31 Jan 2025 16:52:55 -0800 Subject: [PATCH] devops: validate js code snippets in flint (#34580) --- package.json | 2 +- utils/doclint/linting-code-snippets/cli.js | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 2b138262eb..04795972f3 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "lint": "npm run eslint && npm run tsc && npm run doc && npm run check-deps && node utils/generate_channels.js && node utils/generate_types/ && npm run lint-tests && npm run test-types && npm run lint-packages", "lint-packages": "node utils/workspace.js --ensure-consistent", "lint-tests": "node utils/lint_tests.js", - "flint": "concurrently \"npm run eslint\" \"npm run tsc\" \"npm run doc\" \"npm run check-deps\" \"node utils/generate_channels.js\" \"node utils/generate_types/\" \"npm run lint-tests\" \"npm run test-types\" \"npm run lint-packages\"", + "flint": "concurrently \"npm run eslint\" \"npm run tsc\" \"npm run doc\" \"npm run check-deps\" \"node utils/generate_channels.js\" \"node utils/generate_types/\" \"npm run lint-tests\" \"npm run test-types\" \"npm run lint-packages\" \"node utils/doclint/linting-code-snippets/cli.js --js-only\"", "clean": "node utils/build/clean.js", "build": "node utils/build/build.js", "watch": "node utils/build/build.js --watch --lint", diff --git a/utils/doclint/linting-code-snippets/cli.js b/utils/doclint/linting-code-snippets/cli.js index 7139bb105a..f704087032 100644 --- a/utils/doclint/linting-code-snippets/cli.js +++ b/utils/doclint/linting-code-snippets/cli.js @@ -44,8 +44,9 @@ function getAllMarkdownFiles(dirPath, filePaths = []) { } const run = async () => { + const jsOnly = process.argv.includes('--js-only'); + const lintingServiceFactory = new LintingServiceFactory(jsOnly); const documentationRoot = path.join(PROJECT_DIR, 'docs', 'src'); - const lintingServiceFactory = new LintingServiceFactory(); let documentation = parseApi(path.join(documentationRoot, 'api')); /** @type {CodeSnippet[]} */ @@ -69,6 +70,8 @@ const run = async () => { }); } await lintingServiceFactory.lintAndReport(codeSnippets); + if (jsOnly) + return; const { hasErrors } = lintingServiceFactory.reportMetrics(); if (hasErrors) process.exit(1); @@ -222,12 +225,12 @@ class JavaLintingService extends LintingService { } class LintingServiceFactory { - constructor() { + constructor(jsOnly) { /** @type {LintingService[]} */ this.services = [ new JSLintingService(), ] - if (!process.env.NO_EXTERNAL_DEPS) { + if (!jsOnly) { this.services.push( new PythonLintingService(), new CSharpLintingService(),