Skip to content

Commit 84d1f4f

Browse files
committed
perf(linter/plugins): downgrade some checks to debug-only (#15922)
These checks are "sanity checks" only. The inputs to these functions comes from Rust code which we control, and would be `debug_assert!` if this was Rust. So only run these assertions in debug build.
1 parent 325af32 commit 84d1f4f

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

apps/oxlint/src-js/plugins/lint.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,13 @@ function lintFileImpl(
9898
}
9999
assertIs<BufferWithArrays>(buffer);
100100

101-
if (typeof filePath !== 'string' || filePath.length === 0) {
102-
throw new Error('expected filePath to be a non-zero length string');
103-
}
104-
if (!Array.isArray(ruleIds) || ruleIds.length === 0) {
105-
throw new Error('Expected `ruleIds` to be a non-zero len array');
101+
if (DEBUG) {
102+
if (typeof filePath !== 'string' || filePath.length === 0) {
103+
throw new Error('Expected filePath to be a non-zero length string');
104+
}
105+
if (!Array.isArray(ruleIds) || ruleIds.length === 0) {
106+
throw new Error('Expected `ruleIds` to be a non-zero length array');
107+
}
106108
}
107109

108110
// Pass file path to context module, so `Context`s know what file is being linted

apps/oxlint/src-js/plugins/load.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,13 @@ export async function loadPlugin(path: string, packageName: string | null): Prom
135135
* @throws {*} If plugin throws an error during import
136136
*/
137137
async function loadPluginImpl(path: string, packageName: string | null): Promise<PluginDetails> {
138-
if (registeredPluginPaths.has(path)) {
139-
throw new Error('This plugin has already been registered. This is a bug in Oxlint. Please report it.');
138+
if (DEBUG) {
139+
if (registeredPluginPaths.has(path)) throw new Error('This plugin has already been registered');
140+
registeredPluginPaths.add(path);
140141
}
141142

142143
const { default: plugin } = (await import(pathToFileURL(path).href)) as { default: Plugin };
143144

144-
registeredPluginPaths.add(path);
145-
146145
// TODO: Use a validation library to assert the shape of the plugin, and of rules
147146

148147
const pluginName = getPluginName(plugin, packageName);

0 commit comments

Comments
 (0)