From 5ab387745b62113a8b8868ab18e1c1cdfd2ea33b Mon Sep 17 00:00:00 2001 From: Jay Harris Date: Tue, 18 Feb 2025 15:02:47 +1300 Subject: [PATCH] Fix presubmit --- .eslintrc.js | 1 + build/commands/scripts/lit_mangler.test.ts | 14 ++++++-------- build/commands/scripts/lit_mangler.ts | 4 ++-- .../extensions/detail_view.mangle.html.ts | 2 +- chromium_src/tools/grit/preprocess_if_expr.py | 3 ++- tools/chromium_src/check_chromium_src.py | 7 ++++++- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 4bd2ab79185c..d364f1ccbabc 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -68,6 +68,7 @@ module.exports = { ], 'object-shorthand': 0, 'n/no-callback-literal': 0, + 'no-template-curly-in-string': 0, '@typescript-eslint/await-thenable': 0, '@typescript-eslint/consistent-generic-constructors': 0, '@typescript-eslint/ban-ts-comment': 0, diff --git a/build/commands/scripts/lit_mangler.test.ts b/build/commands/scripts/lit_mangler.test.ts index a03ac24da69d..c03288b8d47b 100644 --- a/build/commands/scripts/lit_mangler.test.ts +++ b/build/commands/scripts/lit_mangler.test.ts @@ -74,7 +74,6 @@ describe('Attribute handling', () => { expect(div?.getAttribute('?hidden')).toBe('${this.foo || this.bar || "

haha

"}') }, template) }) - }); describe('End to end', () => { @@ -94,7 +93,7 @@ export function getList(this: string[]) { Hi All! Greetings could be: \${["Hi", 'Kiora', 'Gidday'].map(g => html\`\${g}\`).join('\n')} - +
\${this.map(t => getHtml.call({ name: t, data: {} }))}
@@ -120,7 +119,7 @@ export function getList(this: string[]) { Hi All! Greetings could be: \${["Hi", 'Kiora', 'Gidday'].map(g => html\`\${g}\`).join('\n')} - +
\${this.map(t => getHtml.call({ name: t, data: {} }))}
@@ -159,7 +158,7 @@ export function getList(this: string[]) { Hi All! Greetings could be: \${["Hi", 'Kiora', 'Gidday'].map(g => html\`$$lit_mangler_3$$\`).join('\n')} - +
\${this.map(t => getHtml.call({ name: t, data: {} }))}
@@ -218,14 +217,14 @@ export function getList(this: string[]) { utilsForTest.mangle(e => { const root = e.querySelector('div') root?.removeAttribute('?hidden') - root!.childNodes[0].textContent = root!.childNodes[0].textContent!.replace("Hi All!", '') + root!.childNodes[0].textContent = root!.childNodes[0].textContent!.replace(" Hi All!\n", '') root?.prepend(`
Greetings from the Mangler
`) }, t => t.text.includes('Hi All!')) utilsForTest.mangle(e => { e.querySelector('b')?.setAttribute('hidden', '${g === "hi"}') }, t => t.text.startsWith(' { const root = e.querySelector('div') root?.setAttribute('class', '${this.name === "jay" && "best"}') @@ -245,10 +244,9 @@ export function getHtml(this: FakeElement & { name: string }) { export function getList(this: string[]) { const haxor = 'whatevs" onload="javascript:alert(\`pwnd\`)' return html\`
Greetings from the Mangler
- Greetings could be: \${["Hi", 'Kiora', 'Gidday'].map(g => html\`\`).join('\n')} - +
\${this.map(t => getHtml.call({ name: t, data: {} }))}
diff --git a/build/commands/scripts/lit_mangler.ts b/build/commands/scripts/lit_mangler.ts index bc43966bec9b..ce5f9c1b7f69 100644 --- a/build/commands/scripts/lit_mangler.ts +++ b/build/commands/scripts/lit_mangler.ts @@ -105,10 +105,10 @@ const write = (file: string) => { /** * Mangles a given html template using the given mangler function. - * + * * Example usage: * mangle((element) => element.textContent = "foo", t => t.text.includes('allow-incognito')) - * + * * @param mangler The function to use to mangle the template. * @param getTemplate The template to mangle, or a predicate to find a matching template. If undefined, the first html template will be used. */ diff --git a/chromium_src/chrome/browser/resources/extensions/detail_view.mangle.html.ts b/chromium_src/chrome/browser/resources/extensions/detail_view.mangle.html.ts index 499bc9c67abf..093d8f932348 100644 --- a/chromium_src/chrome/browser/resources/extensions/detail_view.mangle.html.ts +++ b/chromium_src/chrome/browser/resources/extensions/detail_view.mangle.html.ts @@ -13,4 +13,4 @@ mangle((element) => { section.textContent = '$i18n{privateInfoWarning}' section.append(' $i18n{spanningInfoWarning}') section.append(' $i18n{privateAndTorInfoWarning}') -}, t => t.text.includes('id="allow-incognito"')) +}, t => t.text.includes('id="allow-incognito"')) diff --git a/chromium_src/tools/grit/preprocess_if_expr.py b/chromium_src/tools/grit/preprocess_if_expr.py index c3b399dac4aa..b69838af2b23 100644 --- a/chromium_src/tools/grit/preprocess_if_expr.py +++ b/chromium_src/tools/grit/preprocess_if_expr.py @@ -58,7 +58,8 @@ def run_mangler(mangler_file, preprocess_file): 'npx', '--no', '--', 'tsx', '--tsconfig', ts_config, lit_mangler, 'mangle', '-m', mangler_file, '-i', preprocess_file, '-o', preprocess_file - ]) + ], + check=True) def get_chromium_src_files(in_folder, in_files): diff --git a/tools/chromium_src/check_chromium_src.py b/tools/chromium_src/check_chromium_src.py index 937346100f95..2d2d056a2266 100755 --- a/tools/chromium_src/check_chromium_src.py +++ b/tools/chromium_src/check_chromium_src.py @@ -349,7 +349,12 @@ def do_check_overrides(self): display_override_filepath = os.path.join('chromium_src', override_filepath) if not os.path.isfile(original_filepath): - if self.gen_buildir is None: + if override_filepath.endswith( + '.mangle.html.ts') and os.path.isfile( + original_filepath.replace('.mangle.html.ts', + '.html.ts')): + original_filepath_found = True + elif self.gen_buildir is None: # When invoked from presubmit there's no gen_dir, so we can # try to at least check that the include in the override is # consistent with overriding a generated file.