eslint-plugin-oxfmt 0.0.11 → 0.0.13

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/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import * as eslint0 from "eslint";
1
+ import * as eslint from "eslint";
2
2
  import { Linter, Rule } from "eslint";
3
3
 
4
4
  //#region src/types.d.ts
@@ -23,7 +23,7 @@ declare const meta: {
23
23
  //#endregion
24
24
  //#region src/rules/index.d.ts
25
25
  declare const rules: {
26
- oxfmt: eslint0.Rule.RuleModule;
26
+ oxfmt: eslint.Rule.RuleModule;
27
27
  };
28
28
  //#endregion
29
29
  //#region src/parser.d.ts
package/dist/index.mjs CHANGED
@@ -3,9 +3,9 @@ import { createSyncFn } from "synckit";
3
3
  import { URL, fileURLToPath } from "node:url";
4
4
  import { DIFFERENCE, generateDifferences } from "generate-differences";
5
5
 
6
- //#region rolldown:runtime
6
+ //#region \0rolldown/runtime.js
7
7
  var __defProp = Object.defineProperty;
8
- var __exportAll = (all, symbols) => {
8
+ var __exportAll = (all, no_symbols) => {
9
9
  let target = {};
10
10
  for (var name in all) {
11
11
  __defProp(target, name, {
@@ -13,7 +13,7 @@ var __exportAll = (all, symbols) => {
13
13
  enumerable: true
14
14
  });
15
15
  }
16
- if (symbols) {
16
+ if (!no_symbols) {
17
17
  __defProp(target, Symbol.toStringTag, { value: "Module" });
18
18
  }
19
19
  return target;
@@ -58,7 +58,7 @@ const recommended = {
58
58
  name: "oxfmt/recommended",
59
59
  languageOptions: { parser: parserPlain },
60
60
  plugins: { get oxfmt() {
61
- return src_default;
61
+ return plugin;
62
62
  } },
63
63
  rules: { "oxfmt/oxfmt": "error" }
64
64
  };
@@ -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.11";
70
+ var version = "0.0.13";
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,59 +437,18 @@ 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"));
450
+ const sourceText = context.sourceCode.text;
442
451
  return { Program() {
443
- const sourceText = context.sourceCode.text;
444
452
  try {
445
453
  const formatResult = formatViaOxfmt(context.filename, sourceText, {
446
454
  ...context.options?.[0],
@@ -503,7 +511,6 @@ const plugin = {
503
511
  meta,
504
512
  rules
505
513
  };
506
- var src_default = plugin;
507
514
 
508
515
  //#endregion
509
- export { configs, src_default as default, meta, parserPlain, plugin, recommended, rules };
516
+ export { configs, plugin as default, plugin, meta, parserPlain, recommended, rules };
@@ -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.11",
4
+ "version": "0.0.13",
5
5
  "description": "An ESLint plugin for formatting code with oxfmt.",
6
6
  "keywords": [
7
7
  "eslint",
@@ -44,34 +44,35 @@
44
44
  "sideEffects": false,
45
45
  "peerDependencies": {
46
46
  "eslint": "^9.5.0",
47
- "oxfmt": "^0.27.0"
47
+ "oxfmt": "^0.28.0"
48
48
  },
49
49
  "dependencies": {
50
50
  "generate-differences": "^0.1.1",
51
- "load-oxfmt-config": "^0.0.8",
51
+ "load-oxfmt-config": "^0.1.1",
52
+ "picomatch": "^4.0.3",
52
53
  "synckit": "^0.11.12"
53
54
  },
54
55
  "devDependencies": {
55
- "@ntnyq/eslint-config": "^6.0.0-beta.4",
56
+ "@ntnyq/eslint-config": "^6.0.0-beta.7",
56
57
  "@types/json-schema": "^7.0.15",
57
- "@types/node": "^25.0.10",
58
- "@typescript/native-preview": "^7.0.0-dev.20260126.1",
59
- "bumpp": "^10.4.0",
58
+ "@types/node": "^25.2.2",
59
+ "@typescript/native-preview": "^7.0.0-dev.20260208.1",
60
+ "bumpp": "^10.4.1",
60
61
  "eslint": "^9.39.2",
61
62
  "eslint-parser-plain": "^0.1.1",
62
63
  "eslint-typegen": "^2.3.0",
63
- "eslint-vitest-rule-tester": "^3.0.1",
64
+ "eslint-vitest-rule-tester": "^3.1.0",
64
65
  "husky": "^9.1.7",
65
66
  "nano-staged": "^0.9.0",
66
67
  "npm-run-all2": "^8.0.4",
67
- "oxfmt": "^0.27.0",
68
+ "oxfmt": "^0.28.0",
68
69
  "show-invisibles": "^0.0.2",
69
70
  "tinyglobby": "^0.2.15",
70
- "tsdown": "^0.20.1",
71
+ "tsdown": "^0.20.3",
71
72
  "tsx": "^4.21.0",
72
73
  "typescript": "^5.9.3",
73
74
  "vitest": "^4.0.18",
74
- "eslint-plugin-oxfmt": "0.0.11"
75
+ "eslint-plugin-oxfmt": "0.0.13"
75
76
  },
76
77
  "engines": {
77
78
  "node": "^20.19.0 || >=22.12.0"
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
  /**
@@ -10,10 +12,62 @@ import { runAsWorker } from 'synckit'
10
12
  * @property {string} cwd - Current working directory for resolving configuration
11
13
  * @property {string} [configPath] - Custom path to oxfmt configuration file
12
14
  */
15
+ /**
16
+ * @typedef {import('load-oxfmt-config').FormatOptionOverride} Override
17
+ */
18
+ /**
19
+ * @typedef {import('load-oxfmt-config').OxfmtOptions & PluginOptions} Options
20
+ */
13
21
 
14
22
  /**
15
- * @typedef {import('oxfmt').FormatOptions & PluginOptions} Options
23
+ * Apply overrides to the base options based on the filename
24
+ * @param filename - The file path
25
+ * @param cwd - Current working directory
26
+ * @param baseOptions - Base format options
27
+ * @param [overrides] - Override configurations
28
+ * @returns - Merged options
16
29
  */
30
+ function applyOverrides(
31
+ /** @type {string} */
32
+ filename,
33
+ /** @type {string} */
34
+ cwd,
35
+ /** @type {import('oxfmt').FormatOptions} */
36
+ baseOptions,
37
+ /** @type {Override[] | undefined} */
38
+ overrides,
39
+ ) {
40
+ if (!overrides || overrides.length === 0) {
41
+ return baseOptions
42
+ }
43
+
44
+ // Get relative path from cwd and normalize to forward slashes for cross-platform compatibility
45
+ const relativePath = relative(cwd, filename).replace(/\\/g, '/')
46
+
47
+ let mergedOptions = { ...baseOptions }
48
+
49
+ // Apply overrides in order (later overrides take precedence)
50
+ for (const override of overrides) {
51
+ const { excludeFiles, files, options: overrideOptions } = override
52
+
53
+ // Check if file matches the files patterns
54
+ const isMatchFiles = picomatch(files)
55
+ const matches = isMatchFiles(relativePath)
56
+
57
+ // Check if file is excluded
58
+ let excluded = false
59
+ if (excludeFiles && excludeFiles.length > 0) {
60
+ const isMatchExclude = picomatch(excludeFiles)
61
+ excluded = isMatchExclude(relativePath)
62
+ }
63
+
64
+ if (matches && !excluded && overrideOptions) {
65
+ mergedOptions = { ...mergedOptions, ...overrideOptions }
66
+ }
67
+ }
68
+
69
+ return mergedOptions
70
+ }
17
71
 
18
72
  runAsWorker(
19
73
  async (
@@ -30,8 +84,16 @@ runAsWorker(
30
84
  */
31
85
  options,
32
86
  ) => {
33
- const { configPath, cwd, useConfig = true, ...formatOptions } = options
34
- const mergedOptions = {
87
+ const {
88
+ configPath,
89
+ cwd,
90
+ overrides,
91
+ useConfig = true,
92
+ ...formatOptions
93
+ } = options
94
+
95
+ // Load base options from config or use provided options
96
+ const baseOptions = {
35
97
  ...(useConfig
36
98
  ? await loadOxfmtConfig({
37
99
  configPath,
@@ -41,6 +103,14 @@ runAsWorker(
41
103
  ...formatOptions,
42
104
  }
43
105
 
106
+ // Apply overrides based on filename
107
+ const mergedOptions = applyOverrides(
108
+ filename,
109
+ cwd,
110
+ baseOptions,
111
+ useConfig ? baseOptions.overrides : overrides,
112
+ )
113
+
44
114
  const formatResult = await format(filename, sourceText, mergedOptions)
45
115
  return formatResult
46
116
  },