Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion apps/oxlint/test/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ interface TestOptions {
snapshotName?: string;
// Function to get extra data to include in the snapshot
getExtraSnapshotData?: (dirPath: string) => Promise<{ [key: string]: string }>;

overrideFiles?: string;
}

/**
Expand All @@ -29,7 +31,7 @@ async function testFixture(fixtureName: string, options?: TestOptions): Promise<
// Use current NodeJS executable, rather than `node`, to avoid problems with a Node version manager
// installed on system resulting in using wrong NodeJS version
command: process.execPath,
args: [CLI_PATH, ...args, 'files'],
args: [CLI_PATH, ...args, options?.overrideFiles ?? 'files'],
fixtureName,
snapshotName: options?.snapshotName ?? 'output',
getExtraSnapshotData: options?.getExtraSnapshotData,
Expand Down Expand Up @@ -73,6 +75,12 @@ describe('oxlint CLI', () => {
await testFixture('basic_custom_plugin_many_files');
});

it('should load a custom plugin correctly when extending in a nested config', async () => {
await testFixture('custom_plugin_nested_config', {
overrideFiles: '.',
});
});

it('should load a custom plugin when configured in overrides', async () => {
await testFixture('custom_plugin_via_overrides');
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"jsPlugins": ["./plugin.ts"],
"rules": {
"basic-custom-plugin/no-debugger": "error"
},
"categories": { "correctness": "off" }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["../.oxlintrc.json"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
debugger;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Exit code
1

# stdout
```
x basic-custom-plugin(no-debugger): Unexpected Debugger Statement
,-[nested/index.ts:1:1]
1 | debugger;
: ^^^^^^^^^
`----

Found 0 warnings and 1 error.
Finished in Xms on 2 files using X threads.
```

# stderr
```
WARNING: JS plugins are experimental and not subject to semver.
Breaking changes are possible while JS plugins support is under development.
```
23 changes: 23 additions & 0 deletions apps/oxlint/test/fixtures/custom_plugin_nested_config/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { Plugin } from '../../../dist/index.js';

const plugin: Plugin = {
meta: {
name: 'basic-custom-plugin',
},
rules: {
'no-debugger': {
create(context) {
return {
DebuggerStatement(debuggerStatement) {
context.report({
message: 'Unexpected Debugger Statement',
node: debuggerStatement,
});
},
};
},
},
},
};

export default plugin;
24 changes: 24 additions & 0 deletions crates/oxc_linter/src/config/oxlintrc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,30 @@ impl Oxlintrc {

config.path = path.to_path_buf();

// resolve relative paths
if let Some(external_plugins) = &mut config.external_plugins
&& let Some(config_dir) = config.path.parent()
{
*external_plugins = std::mem::take(external_plugins)
.into_iter()
.map(|specifier| {
let is_relative = specifier.starts_with("./") || specifier.starts_with("../");
if is_relative {
config_dir
.join(&specifier)
.into_os_string()
.into_string()
// there is a corner case where this can fail
// for non-utf8 paths, this relative plugin specifier
// may be resolved relative to the wrong config file
// when two are merged.
.unwrap_or(specifier)
} else {
specifier
}
})
.collect();
}
Ok(config)
}

Expand Down
Loading