eslint-plugin-oxfmt 0.0.10 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -135,7 +135,7 @@ All options are optional and default to sensible values.
135
135
  | Option | Type | Default | Description |
136
136
  | ------------ | --------- | ------- | ------------------------------------------------------------------------------------------------------ |
137
137
  | `useConfig` | `boolean` | `true` | Load `.oxfmtrc` / config files via `load-oxfmt-config`. Set to `false` to rely only on inline options. |
138
- | `configPath` | `string` | — | Custom path to an oxfmt config file. Resolved from ESLint `cwd` when set. |
138
+ | `configPath` | `string` | — | Custom path to an oxfmt config file. Resolved from ESLint `cwd` when set. |
139
139
 
140
140
  > Note: `cwd` is taken from ESLint automatically; you usually do not need to set it manually.
141
141
 
package/dist/index.mjs CHANGED
@@ -7,9 +7,9 @@ import { DIFFERENCE, generateDifferences } from "generate-differences";
7
7
  var __defProp = Object.defineProperty;
8
8
  var __exportAll = (all, symbols) => {
9
9
  let target = {};
10
- for (var name$2 in all) {
11
- __defProp(target, name$2, {
12
- get: all[name$2],
10
+ for (var name in all) {
11
+ __defProp(target, name, {
12
+ get: all[name],
13
13
  enumerable: true
14
14
  });
15
15
  }
@@ -67,7 +67,7 @@ const configs = { recommended };
67
67
  //#endregion
68
68
  //#region package.json
69
69
  var name = "eslint-plugin-oxfmt";
70
- var version = "0.0.10";
70
+ var version = "0.0.12";
71
71
 
72
72
  //#endregion
73
73
  //#region src/meta.ts
@@ -152,7 +152,7 @@ function _reportDifference(context, difference, rangeOffset = 0) {
152
152
 
153
153
  //#endregion
154
154
  //#region src/schema.ts
155
- const sharedSchema = {
155
+ const oxfmtOptionsSchema = {
156
156
  additionalProperties: false,
157
157
  type: "object",
158
158
  properties: {
@@ -379,6 +379,55 @@ const sharedSchema = {
379
379
  }
380
380
  }
381
381
  };
382
+ const oxfmtConfigSchema = {
383
+ additionalProperties: false,
384
+ type: "object",
385
+ properties: {
386
+ configPath: {
387
+ description: `Path to Oxfmt configuration file.\nIf you provide an absolute path, Oxfmt will use it directly.\n If not provided, Oxfmt will search for configuration files starting from the current working directory upwards.\n\n- (Default: undefined)`,
388
+ type: "string"
389
+ },
390
+ useConfig: {
391
+ description: `Whether to load Oxfmt configuration file.\n\n- (Default: true)`,
392
+ type: "boolean"
393
+ }
394
+ }
395
+ };
396
+ const oxfmtRuleSchema = {
397
+ additionalProperties: false,
398
+ type: "object",
399
+ properties: {
400
+ ...oxfmtOptionsSchema.properties,
401
+ ...oxfmtConfigSchema.properties,
402
+ overrides: {
403
+ description: `File-specific overrides.\nWhen a file matches multiple overrides, the later override takes precedence (array order matters).\n\n- (Default: [])`,
404
+ type: "array",
405
+ items: {
406
+ additionalProperties: false,
407
+ required: ["files"],
408
+ type: "object",
409
+ properties: {
410
+ excludeFiles: {
411
+ description: `Glob patterns to exclude from this override.`,
412
+ type: "array",
413
+ items: { type: "string" }
414
+ },
415
+ files: {
416
+ description: `Glob patterns to match files for this override.\nAll patterns are relative to the Oxfmt configuration file.`,
417
+ type: "array",
418
+ items: { type: "string" }
419
+ },
420
+ options: {
421
+ additionalProperties: false,
422
+ description: `Format options to apply for matched files.`,
423
+ type: "object",
424
+ properties: { ...oxfmtOptionsSchema.properties }
425
+ }
426
+ }
427
+ }
428
+ }
429
+ }
430
+ };
382
431
 
383
432
  //#endregion
384
433
  //#region src/rules/oxfmt.ts
@@ -388,54 +437,13 @@ const oxfmt = {
388
437
  defaultOptions: [],
389
438
  fixable: "code",
390
439
  messages,
440
+ schema: [oxfmtRuleSchema],
391
441
  type: "layout",
392
442
  docs: {
393
443
  description: "Format code via oxfmt",
394
444
  recommended: true,
395
445
  url: "https://github.com/ntnyq/eslint-plugin-oxfmt"
396
- },
397
- schema: [{
398
- additionalProperties: false,
399
- type: "object",
400
- properties: {
401
- ...sharedSchema.properties,
402
- configPath: {
403
- description: `Path to Oxfmt configuration file.\nIf you provide an absolute path, Oxfmt will use it directly.\n If not provided, Oxfmt will search for configuration files starting from the current working directory upwards.\n\n- (Default: undefined)`,
404
- type: "string"
405
- },
406
- overrides: {
407
- description: `File-specific overrides.\nWhen a file matches multiple overrides, the later override takes precedence (array order matters).\n\n- (Default: [])`,
408
- type: "array",
409
- items: {
410
- additionalProperties: false,
411
- required: ["files"],
412
- type: "object",
413
- properties: {
414
- excludeFiles: {
415
- description: `Glob patterns to exclude from this override.`,
416
- type: "array",
417
- items: { type: "string" }
418
- },
419
- files: {
420
- description: `Glob patterns to match files for this override.\nAll patterns are relative to the Oxfmt configuration file.`,
421
- type: "array",
422
- items: { type: "string" }
423
- },
424
- options: {
425
- additionalProperties: false,
426
- description: `Format options to apply for matched files.`,
427
- type: "object",
428
- properties: { ...sharedSchema.properties }
429
- }
430
- }
431
- }
432
- },
433
- useConfig: {
434
- description: `Whether to load Oxfmt configuration file.\n\n- (Default: true)`,
435
- type: "boolean"
436
- }
437
- }
438
- }]
446
+ }
439
447
  },
440
448
  create(context) {
441
449
  if (!formatViaOxfmt) formatViaOxfmt = createSyncFn(join(dirWorkers, "oxfmt.mjs"));
@@ -102,6 +102,8 @@ export type OxfmtOxfmt = []|[{
102
102
 
103
103
  configPath?: string
104
104
 
105
+ useConfig?: boolean
106
+
105
107
  overrides?: {
106
108
 
107
109
  excludeFiles?: string[]
@@ -197,6 +199,4 @@ export type OxfmtOxfmt = []|[{
197
199
  vueIndentScriptAndStyle?: boolean
198
200
  }
199
201
  }[]
200
-
201
- useConfig?: boolean
202
202
  }]
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "eslint-plugin-oxfmt",
3
3
  "type": "module",
4
- "version": "0.0.10",
4
+ "version": "0.0.12",
5
5
  "description": "An ESLint plugin for formatting code with oxfmt.",
6
6
  "keywords": [
7
7
  "eslint",
@@ -44,18 +44,19 @@
44
44
  "sideEffects": false,
45
45
  "peerDependencies": {
46
46
  "eslint": "^9.5.0",
47
- "oxfmt": "^0.26.0"
47
+ "oxfmt": "^0.28.0"
48
48
  },
49
49
  "dependencies": {
50
50
  "generate-differences": "^0.1.1",
51
- "load-oxfmt-config": "^0.0.7",
51
+ "load-oxfmt-config": "^0.1.0",
52
+ "picomatch": "^4.0.3",
52
53
  "synckit": "^0.11.12"
53
54
  },
54
55
  "devDependencies": {
55
- "@ntnyq/eslint-config": "^6.0.0-beta.2",
56
+ "@ntnyq/eslint-config": "^6.0.0-beta.6",
56
57
  "@types/json-schema": "^7.0.15",
57
- "@types/node": "^25.0.10",
58
- "@typescript/native-preview": "^7.0.0-dev.20260120.1",
58
+ "@types/node": "^25.2.0",
59
+ "@typescript/native-preview": "^7.0.0-dev.20260202.1",
59
60
  "bumpp": "^10.4.0",
60
61
  "eslint": "^9.39.2",
61
62
  "eslint-parser-plain": "^0.1.1",
@@ -64,20 +65,21 @@
64
65
  "husky": "^9.1.7",
65
66
  "nano-staged": "^0.9.0",
66
67
  "npm-run-all2": "^8.0.4",
67
- "oxfmt": "^0.26.0",
68
+ "oxfmt": "^0.28.0",
68
69
  "show-invisibles": "^0.0.2",
69
70
  "tinyglobby": "^0.2.15",
70
- "tsdown": "^0.20.0-beta.4",
71
+ "tsdown": "^0.20.1",
71
72
  "tsx": "^4.21.0",
72
73
  "typescript": "^5.9.3",
73
- "vitest": "^4.0.17",
74
- "eslint-plugin-oxfmt": "0.0.10"
74
+ "vitest": "^4.0.18",
75
+ "eslint-plugin-oxfmt": "0.0.12"
75
76
  },
76
77
  "engines": {
77
78
  "node": "^20.19.0 || >=22.12.0"
78
79
  },
79
80
  "nano-staged": {
80
- "*.{js,ts,mjs,cjs,md,vue,yml,yaml,toml,json}": "eslint --fix"
81
+ "*.{js,ts,mjs,cjs,md,vue,yml,yaml,toml,json}": "eslint --fix",
82
+ "*": "oxfmt --no-error-on-unmatched-pattern"
81
83
  },
82
84
  "scripts": {
83
85
  "build": "pnpm run update:rule-options && tsdown",
@@ -86,7 +88,7 @@
86
88
  "format:check": "oxfmt --check",
87
89
  "lint": "eslint",
88
90
  "release": "run-s release:check release:version",
89
- "release:check": "run-s lint typecheck test build",
91
+ "release:check": "run-s format:check lint typecheck test build",
90
92
  "release:version": "bumpp",
91
93
  "test": "vitest",
92
94
  "typecheck": "tsgo --noEmit",
package/workers/oxfmt.mjs CHANGED
@@ -1,7 +1,9 @@
1
1
  // @ts-check
2
2
 
3
+ import { relative } from 'node:path'
3
4
  import { loadOxfmtConfig } from 'load-oxfmt-config'
4
5
  import { format } from 'oxfmt'
6
+ import picomatch from 'picomatch'
5
7
  import { runAsWorker } from 'synckit'
6
8
 
7
9
  /**
@@ -12,9 +14,66 @@ import { runAsWorker } from 'synckit'
12
14
  */
13
15
 
14
16
  /**
15
- * @typedef {import('oxfmt').FormatOptions & PluginOptions} Options
17
+ * @typedef {object} Override
18
+ * @property {string[]} files - Glob patterns to match files
19
+ * @property {string[]} [excludeFiles] - Glob patterns to exclude files
20
+ * @property {import('oxfmt').FormatOptions} [options] - Format options to apply
16
21
  */
17
22
 
23
+ /**
24
+ * @typedef {import('oxfmt').FormatOptions & PluginOptions & {overrides?: Override[]}} Options
25
+ */
26
+
27
+ /**
28
+ * Apply overrides to the base options based on the filename
29
+ * @param filename - The file path
30
+ * @param cwd - Current working directory
31
+ * @param baseOptions - Base format options
32
+ * @param [overrides] - Override configurations
33
+ * @returns - Merged options
34
+ */
35
+ function applyOverrides(
36
+ /** @type {string} */
37
+ filename,
38
+ /** @type {string} */
39
+ cwd,
40
+ /** @type {import('oxfmt').FormatOptions} */
41
+ baseOptions,
42
+ /** @type {Override[] | undefined} */
43
+ overrides,
44
+ ) {
45
+ if (!overrides || overrides.length === 0) {
46
+ return baseOptions
47
+ }
48
+
49
+ // Get relative path from cwd and normalize to forward slashes for cross-platform compatibility
50
+ const relativePath = relative(cwd, filename).replace(/\\/g, '/')
51
+
52
+ let mergedOptions = { ...baseOptions }
53
+
54
+ // Apply overrides in order (later overrides take precedence)
55
+ for (const override of overrides) {
56
+ const { excludeFiles, files, options: overrideOptions } = override
57
+
58
+ // Check if file matches the files patterns
59
+ const isMatchFiles = picomatch(files)
60
+ const matches = isMatchFiles(relativePath)
61
+
62
+ // Check if file is excluded
63
+ let excluded = false
64
+ if (excludeFiles && excludeFiles.length > 0) {
65
+ const isMatchExclude = picomatch(excludeFiles)
66
+ excluded = isMatchExclude(relativePath)
67
+ }
68
+
69
+ if (matches && !excluded && overrideOptions) {
70
+ mergedOptions = { ...mergedOptions, ...overrideOptions }
71
+ }
72
+ }
73
+
74
+ return mergedOptions
75
+ }
76
+
18
77
  runAsWorker(
19
78
  async (
20
79
  /**
@@ -30,8 +89,16 @@ runAsWorker(
30
89
  */
31
90
  options,
32
91
  ) => {
33
- const { configPath, cwd, useConfig = true, ...formatOptions } = options
34
- const mergedOptions = {
92
+ const {
93
+ configPath,
94
+ cwd,
95
+ overrides,
96
+ useConfig = true,
97
+ ...formatOptions
98
+ } = options
99
+
100
+ // Load base options from config or use provided options
101
+ const baseOptions = {
35
102
  ...(useConfig
36
103
  ? await loadOxfmtConfig({
37
104
  configPath,
@@ -41,6 +108,9 @@ runAsWorker(
41
108
  ...formatOptions,
42
109
  }
43
110
 
111
+ // Apply overrides based on filename
112
+ const mergedOptions = applyOverrides(filename, cwd, baseOptions, overrides)
113
+
44
114
  const formatResult = await format(filename, sourceText, mergedOptions)
45
115
  return formatResult
46
116
  },