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
5 changes: 5 additions & 0 deletions apps/oxlint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"type": "module",
"main": "dist/index.js",
"bin": "dist/cli.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "pnpm run build-napi-release && pnpm run build-js",
"build-dev": "pnpm run build-napi && pnpm run build-js",
Expand Down Expand Up @@ -34,9 +35,13 @@
"files": [
"dist"
],
"dependencies": {
"@oxc-project/types": "workspace:^"
},
"devDependencies": {
"eslint": "^9.36.0",
"execa": "^9.6.0",
"jiti": "^2.6.0",
"tsdown": "0.15.1",
"typescript": "catalog:",
"vitest": "catalog:"
Expand Down
5 changes: 5 additions & 0 deletions apps/oxlint/src-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import type { Context } from './plugins/context.ts';
import type { CreateOnceRule, Plugin, Rule } from './plugins/load.ts';
import type { BeforeHook, Visitor, VisitorWithHooks } from './plugins/types.ts';

export type { Context, Diagnostic } from './plugins/context.ts';
export type { Fix, Fixer, FixFn, NodeOrToken, Range } from './plugins/fix.ts';
export type { CreateOnceRule, CreateRule, Plugin, Rule } from './plugins/load.ts';
export type { AfterHook, BeforeHook, RuleMeta, Visitor, VisitorWithHooks } from './plugins/types.ts';

const { defineProperty, getPrototypeOf, hasOwn, setPrototypeOf, create: ObjectCreate } = Object;

const dummyOptions: unknown[] = [],
Expand Down
6 changes: 3 additions & 3 deletions apps/oxlint/src-js/plugins/fix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export type FixFn = (
// Type of a fix, as returned by `fix` function.
export type Fix = { range: Range; text: string };

type Range = [number, number];
export type Range = [number, number];

// Currently we only support `Node`s, but will add support for `Token`s later
interface NodeOrToken {
export interface NodeOrToken {
start: number;
end: number;
}
Expand Down Expand Up @@ -60,7 +60,7 @@ const FIXER = Object.freeze({
},
});

type Fixer = typeof FIXER;
export type Fixer = typeof FIXER;

/**
* Get fixes from a `Diagnostic`.
Expand Down
2 changes: 1 addition & 1 deletion apps/oxlint/src-js/plugins/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface Plugin {
// If `createOnce` method is present, `create` is ignored.
export type Rule = CreateRule | CreateOnceRule;

interface CreateRule {
export interface CreateRule {
meta?: RuleMeta;
create: (context: Context) => Visitor;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/oxlint/test/fixtures/definePlugin/.oxlintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"jsPlugins": ["./plugin.js"],
"jsPlugins": ["./plugin.ts"],
"categories": { "correctness": "off" },
"rules": {
"define-plugin-plugin/create": "error",
Expand Down
2 changes: 1 addition & 1 deletion apps/oxlint/test/fixtures/definePlugin/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import plugin from './plugin.js';
import plugin from './plugin.ts';

export default [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { sep } from 'node:path';
import { definePlugin } from '../../../dist/index.js';
import type { Rule } from '../../../dist/index.js';

// `loc` is required for ESLint
const SPAN = {
Expand All @@ -14,10 +15,10 @@ const SPAN = {
const DIR_PATH_LEN = import.meta.dirname.length + 1;

const relativePath = sep === '/'
? path => path.slice(DIR_PATH_LEN)
: path => path.slice(DIR_PATH_LEN).replace(/\\/g, '/');
? (path: string) => path.slice(DIR_PATH_LEN)
: (path: string) => path.slice(DIR_PATH_LEN).replace(/\\/g, '/');

const createRule = {
const createRule: Rule = {
create(context) {
context.report({ message: `create body:\nthis === rule: ${this === createRule}`, node: SPAN });

Expand All @@ -37,18 +38,19 @@ const createRule = {
// adds to the rule.
let createOnceCallCount = 0;

const createOnceRule = {
const createOnceRule: Rule = {
createOnce(context) {
createOnceCallCount++;

// `fileNum` should be different for each file.
// `identNum` should start at 1 for each file.
let fileNum = 0, identNum;
let fileNum = 0, identNum: number;
// Note: Files are processed in unpredictable order, so `files/1.js` may be `fileNum` 1 or 2.
// Therefore, collect all visits and check them in `after` hook of the 2nd file.
const visits = [];
const visits: { fileNum: number; identNum: number }[] = [];

// `this` should be the rule object
// oxlint-disable-next-line typescript-eslint/no-this-alias
const topLevelThis = this;

return {
Expand Down Expand Up @@ -106,7 +108,7 @@ const createOnceRule = {
};

// Tests that `before` hook returning `false` disables visiting AST for the file.
const createOnceBeforeFalseRule = {
const createOnceBeforeFalseRule: Rule = {
createOnce(context) {
return {
before() {
Expand Down Expand Up @@ -139,7 +141,7 @@ const createOnceBeforeFalseRule = {

// These 3 rules test that `createOnce` without `before` and `after` hooks works correctly.

const createOnceBeforeOnlyRule = {
const createOnceBeforeOnlyRule: Rule = {
createOnce(context) {
return {
before() {
Expand All @@ -160,7 +162,7 @@ const createOnceBeforeOnlyRule = {
},
};

const createOnceAfterOnlyRule = {
const createOnceAfterOnlyRule: Rule = {
createOnce(context) {
return {
Identifier(node) {
Expand All @@ -181,7 +183,7 @@ const createOnceAfterOnlyRule = {
},
};

const createOnceNoHooksRule = {
const createOnceNoHooksRule: Rule = {
createOnce(context) {
return {
Identifier(node) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"jsPlugins": ["./plugin.js"],
"jsPlugins": ["./plugin.ts"],
"categories": { "correctness": "off" },
"rules": {
"define-plugin-and-rule-plugin/create": "error",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import plugin from './plugin.js';
import plugin from './plugin.ts';

export default [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const SPAN = {
const DIR_PATH_LEN = import.meta.dirname.length + 1;

const relativePath = sep === '/'
? path => path.slice(DIR_PATH_LEN)
: path => path.slice(DIR_PATH_LEN).replace(/\\/g, '/');
? (path: string) => path.slice(DIR_PATH_LEN)
: (path: string) => path.slice(DIR_PATH_LEN).replace(/\\/g, '/');

const createRule = defineRule({
create(context) {
Expand All @@ -42,12 +42,13 @@ const createOnceRule = defineRule({

// `fileNum` should be different for each file.
// `identNum` should start at 1 for each file.
let fileNum = 0, identNum;
let fileNum = 0, identNum: number;
// Note: Files are processed in unpredictable order, so `files/1.js` may be `fileNum` 1 or 2.
// Therefore, collect all visits and check them in `after` hook of the 2nd file.
const visits = [];
const visits: { fileNum: number; identNum: number }[] = [];

// `this` should be the rule object returned by `defineRule`
// oxlint-disable-next-line typescript-eslint/no-this-alias
const topLevelThis = this;

return {
Expand Down
2 changes: 1 addition & 1 deletion apps/oxlint/test/fixtures/defineRule/.oxlintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"jsPlugins": ["./plugin.js"],
"jsPlugins": ["./plugin.ts"],
"categories": { "correctness": "off" },
"rules": {
"define-rule-plugin/create": "error",
Expand Down
2 changes: 1 addition & 1 deletion apps/oxlint/test/fixtures/defineRule/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import plugin from './plugin.js';
import plugin from './plugin.ts';

export default [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const SPAN = {
const DIR_PATH_LEN = import.meta.dirname.length + 1;

const relativePath = sep === '/'
? path => path.slice(DIR_PATH_LEN)
: path => path.slice(DIR_PATH_LEN).replace(/\\/g, '/');
? (path: string) => path.slice(DIR_PATH_LEN)
: (path: string) => path.slice(DIR_PATH_LEN).replace(/\\/g, '/');

const createRule = defineRule({
create(context) {
Expand All @@ -42,12 +42,13 @@ const createOnceRule = defineRule({

// `fileNum` should be different for each file.
// `identNum` should start at 1 for each file.
let fileNum = 0, identNum;
let fileNum = 0, identNum: number;
// Note: Files are processed in unpredictable order, so `files/1.js` may be `fileNum` 1 or 2.
// Therefore, collect all visits and check them in `after` hook of the 2nd file.
const visits = [];
const visits: { fileNum: number; identNum: number }[] = [];

// `this` should be the rule object returned by `defineRule`
// oxlint-disable-next-line typescript-eslint/no-this-alias
const topLevelThis = this;

return {
Expand Down
23 changes: 18 additions & 5 deletions apps/oxlint/tsdown.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { defineConfig } from 'tsdown';
import { defineConfig, type UserConfig } from 'tsdown';

export default defineConfig({
entry: ['src-js/index.ts', 'src-js/cli.ts', 'src-js/plugins/index.ts'],
const commonConfig: UserConfig = {
format: ['esm'],
platform: 'node',
target: 'node20',
Expand All @@ -19,5 +18,19 @@ export default defineConfig({
// At present only compress syntax.
// Don't mangle identifiers or remove whitespace, so `dist` code remains somewhat readable.
minify: { compress: true, mangle: false, codegen: { removeWhitespace: false } },
attw: true,
});
};

// Only generate `.d.ts` file for main export, not for CLI
export default defineConfig([
{
entry: ['src-js/cli.ts', 'src-js/plugins/index.ts'],
...commonConfig,
dts: false,
},
{
entry: 'src-js/index.ts',
...commonConfig,
dts: true,
attw: true,
},
]);
Loading
Loading