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
15 changes: 15 additions & 0 deletions apps/oxlint/src-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,18 @@ export const defineRule = _defineRule;
* @deprecated Import from `oxlint/plugins-dev` instead
*/
export const RuleTester = _RuleTester;

export { defineConfig } from "./package/config.ts";

export type {
AllowWarnDeny,
OxlintEnv,
DummyRule,
DummyRuleMap,
ExternalPluginEntry,
OxlintGlobals,
RuleCategories,
ExternalPluginsConfig,
OxlintConfig,
OxlintOverride,
} from "./package/config.ts";
54 changes: 54 additions & 0 deletions apps/oxlint/src-js/package/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* `defineConfig` helper and config types.
*/

import type { JsonObject, JsonValue } from "../plugins/json.ts";

export type AllowWarnDeny = "off" | "warn" | "error" | 0 | 1 | 2;

export type DummyRule = AllowWarnDeny | [AllowWarnDeny, ...JsonValue[]];

export type DummyRuleMap = Record<string, DummyRule>;

export type RuleCategories = Record<string, AllowWarnDeny>;
export type OxlintGlobals = Record<
string,
"readonly" | "writable" | "off" | "readable" | "writeable" | boolean
>;

export type OxlintEnv = Record<string, boolean>;

export type ExternalPluginEntry = string | { name: string; specifier: string };

export type ExternalPluginsConfig = ExternalPluginEntry[] | null;

export interface OxlintOverride {
files: string[];
env?: OxlintEnv;
globals?: OxlintGlobals;
plugins?: string[];
jsPlugins?: ExternalPluginsConfig;
rules?: DummyRuleMap;
}

export interface OxlintConfig {
plugins?: string[];
jsPlugins?: ExternalPluginsConfig;
categories?: RuleCategories;
rules?: DummyRuleMap;
settings?: JsonObject;
env?: OxlintEnv;
globals?: OxlintGlobals;
overrides?: OxlintOverride[];
ignorePatterns?: string[];
}

/**
* Define an Oxlint configuration with type inference.
*
* @param config - Oxlint configuration
* @returns Config unchanged
*/
export function defineConfig<T extends OxlintConfig>(config: T): T {
return config;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
debugger;
if (x == 1) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Exit code
1

# stdout
```
x eslint(no-debugger): `debugger` statement is not allowed
,-[files/test.js:1:1]
1 | debugger;
: ^^^^^^^^^
2 | if (x == 1) {
`----
help: Remove the debugger statement

! eslint(eqeqeq): Expected === and instead saw ==
,-[files/test.js:2:7]
1 | debugger;
2 | if (x == 1) {
: ^^
3 | }
`----
help: Prefer === operator

Found 1 warning and 1 error.
Finished in Xms on 1 file with 92 rules using X threads.
```

# stderr
```
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from "#oxlint";

export default defineConfig({
rules: {
"no-debugger": "error",
eqeqeq: "warn",
},
});
Loading