Skip to content

Commit e42e197

Browse files
committed
Replace imports check presubmit with a working eslint rule.
1 parent 89f5fbf commit e42e197

File tree

5 files changed

+42
-270
lines changed

5 files changed

+42
-270
lines changed

build/commands/PRESUBMIT.py

Lines changed: 0 additions & 58 deletions
This file was deleted.

build/commands/PRESUBMIT_test.py

Lines changed: 0 additions & 211 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2026 The Brave Authors. All rights reserved.
2+
// This Source Code Form is subject to the terms of the Mozilla Public
3+
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
// You can obtain one at https://mozilla.org/MPL/2.0/.
5+
6+
import { execSync } from 'child_process'
7+
8+
// Run the TypeScript compiler.
9+
run('tsc --project build/commands')
10+
11+
// Run the ESLint linter. This is required to catch possible runtime errors
12+
// that might occur because of broken imports.
13+
run('eslint --quiet build/commands')
14+
15+
// Run the Jest test runner. Pass through any extra arguments to it.
16+
const extraArgs = process.argv.slice(2).join(' ')
17+
run(`jest build/commands${extraArgs ? ` ${extraArgs}` : ''}`)
18+
19+
// Run a command and exit cleanly without exception noise.
20+
function run(cmd: string): void {
21+
console.log(`> ${cmd}`)
22+
try {
23+
execSync(cmd, { stdio: 'inherit' })
24+
} catch (e: any) {
25+
process.exit(e.status ?? 1)
26+
}
27+
}

eslint.config.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { defineConfig, globalIgnores } from 'eslint/config'
77

88
import jest from 'eslint-plugin-jest'
9+
import importPlugin from 'eslint-plugin-import'
910
import licenses from 'eslint-plugin-licenses'
1011
import noUnsanitized from 'eslint-plugin-no-unsanitized'
1112
import reactHooks from 'eslint-plugin-react-hooks'
@@ -287,6 +288,19 @@ export default defineConfig([
287288
'@typescript-eslint/no-require-imports': 'off',
288289
},
289290
},
291+
{
292+
// Enforce import resolution for build/commands scripts. When running
293+
// TypeScript natively via Node.js (no transpilation), imports must use the
294+
// real file extension. For example, if a file is named config.ts, importing
295+
// it as './config.js' is an error.
296+
files: ['build/commands/**/*.{js,cjs,mjs,ts,cts,mts}'],
297+
plugins: {
298+
import: importPlugin,
299+
},
300+
rules: {
301+
'import/no-unresolved': 'error',
302+
},
303+
},
290304
{
291305
// Test data files; skips some non-important rules.
292306
files: ['test/data/**/*.js'],

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"docs": "node ./build/commands/scripts/commands.js docs",
3232
"test": "node ./build/commands/scripts/commands.js test",
3333
"list_affected_tests": "node ./build/commands/scripts/commands.js list_affected_tests",
34-
"test:scripts": "tsc --project build/commands && jest build/commands",
34+
"test:scripts": "node ./build/commands/scripts/testScripts.ts",
3535
"tslint": "npm run eslint",
3636
"eslint": "eslint --quiet .",
3737
"pep8": "pycodestyle --max-line-length 120 -r script",

0 commit comments

Comments
 (0)