Skip to content

Commit 49f33d2

Browse files
authored
Merge branch 'main' into repo-sync
2 parents 68b280a + 2de66f3 commit 49f33d2

2 files changed

Lines changed: 28 additions & 8 deletions

File tree

script/i18n/lint-translation-files.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import { execSync } from 'child_process'
1111
import program from 'commander'
12+
import fs from 'fs'
1213

1314
// Set up supported linting check types and their corresponding commands.
1415
const CHECK_COMMANDS = {
@@ -48,7 +49,7 @@ if (SUPPORTED_CHECK_TYPES.includes(specifiedCheckType)) {
4849
function lintAndResetFiles(checkType) {
4950
console.log(`Running ${checkType} check...`)
5051

51-
const log = `~/docs-translation-${checkType}-error.txt`
52+
const log = `${process.env.HOME}/docs-translation-${checkType}-error.txt`
5253
const cmd = `${CHECK_COMMANDS[checkType]} > ${log}`
5354

5455
// Lint the files based on the check type and output the errors to a log file.
@@ -58,10 +59,28 @@ function lintAndResetFiles(checkType) {
5859
console.log(`There were new ${checkType} errors! Check ${log} for more details.`)
5960
}
6061

61-
// Reset the files
62-
execSync(
63-
`cat ${log} | egrep "^translations/.*/(.+.md|.+.yml)$" | uniq | xargs -L1 script/i18n/reset-translated-file.js --prefer-main`
64-
)
62+
// return if file does not exist
63+
if (!fs.existsSync(log)) {
64+
console.log(`${log}: no such file`)
65+
return
66+
}
67+
68+
const filesToReset = fs
69+
.readFileSync(log)
70+
.toString()
71+
.split('\n')
72+
.filter((p) => p.startsWith('translations') && (p.endsWith('.md') || p.endsWith('.yml')))
73+
74+
if (filesToReset.length === 0) {
75+
console.log('There are no violations')
76+
return
77+
}
78+
79+
// We are not passing --prefer-main because we want to remove the file so we
80+
// reset it directly to the English source
81+
filesToReset.forEach((file) => {
82+
execSync(`script/i18n/reset-translated-file.js ${file}`)
83+
})
6584

6685
// Print a message with next steps
6786
console.log(`Success!

tests/linting/lint-files.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,15 @@ if (!process.env.TEST_TRANSLATION) {
277277
} else {
278278
// get all translated markdown or yaml files by comparing files changed to main branch
279279
const changedFilesRelPaths = execSync(
280-
'git -c diff.renameLimit=10000 diff --name-only origin/main | egrep "^translations/.*/.+.(yml|md)$"',
280+
'git -c diff.renameLimit=10000 diff --name-only origin/main',
281281
{ maxBuffer: 1024 * 1024 * 100 }
282282
)
283283
.toString()
284284
.split('\n')
285-
if (changedFilesRelPaths === '') process.exit(0)
285+
.filter((p) => p.startsWith('translations') && (p.endsWith('.md') || p.endsWith('.yml')))
286286

287-
console.log('testing translations.')
287+
// If there are no changed files, there's nothing to lint: signal a successful termination.
288+
if (changedFilesRelPaths.length === 0) process.exit(0)
288289

289290
console.log(`Found ${changedFilesRelPaths.length} translated files.`)
290291

0 commit comments

Comments
 (0)