devops: validate js code snippets in flint (#34580)

This commit is contained in:
Yury Semikhatsky 2025-01-31 16:52:55 -08:00 committed by GitHub
parent a1451c75f8
commit cd7f3b6e65
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View File

@ -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": "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-packages": "node utils/workspace.js --ensure-consistent",
"lint-tests": "node utils/lint_tests.js", "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", "clean": "node utils/build/clean.js",
"build": "node utils/build/build.js", "build": "node utils/build/build.js",
"watch": "node utils/build/build.js --watch --lint", "watch": "node utils/build/build.js --watch --lint",

View File

@ -44,8 +44,9 @@ function getAllMarkdownFiles(dirPath, filePaths = []) {
} }
const run = async () => { const run = async () => {
const jsOnly = process.argv.includes('--js-only');
const lintingServiceFactory = new LintingServiceFactory(jsOnly);
const documentationRoot = path.join(PROJECT_DIR, 'docs', 'src'); const documentationRoot = path.join(PROJECT_DIR, 'docs', 'src');
const lintingServiceFactory = new LintingServiceFactory();
let documentation = parseApi(path.join(documentationRoot, 'api')); let documentation = parseApi(path.join(documentationRoot, 'api'));
/** @type {CodeSnippet[]} */ /** @type {CodeSnippet[]} */
@ -69,6 +70,8 @@ const run = async () => {
}); });
} }
await lintingServiceFactory.lintAndReport(codeSnippets); await lintingServiceFactory.lintAndReport(codeSnippets);
if (jsOnly)
return;
const { hasErrors } = lintingServiceFactory.reportMetrics(); const { hasErrors } = lintingServiceFactory.reportMetrics();
if (hasErrors) if (hasErrors)
process.exit(1); process.exit(1);
@ -222,12 +225,12 @@ class JavaLintingService extends LintingService {
} }
class LintingServiceFactory { class LintingServiceFactory {
constructor() { constructor(jsOnly) {
/** @type {LintingService[]} */ /** @type {LintingService[]} */
this.services = [ this.services = [
new JSLintingService(), new JSLintingService(),
] ]
if (!process.env.NO_EXTERNAL_DEPS) { if (!jsOnly) {
this.services.push( this.services.push(
new PythonLintingService(), new PythonLintingService(),
new CSharpLintingService(), new CSharpLintingService(),