@plumeria/eslint-plugin 19.10.0 → 19.10.2

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
@@ -39,7 +39,8 @@ prop carries styles. It is `classStyle` unless you changed it, so most projects
39
39
  configure nothing.
40
40
 
41
41
  If you did rename it — via `styleProp` on `withPlumeria` or on the unplugin
42
- options — tell the plugin the same name. ESLint cannot read it from your bundler
42
+ options — tell the plugin the same name. The lint the bundler plugins run in the
43
+ build is given that name already. ESLint cannot read it from your bundler
43
44
  config, so set it once in `settings` and every rule picks it up:
44
45
 
45
46
  ```js
@@ -257,6 +258,16 @@ plumerialint
257
258
  The process exits with a non-zero status code if any errors or warnings are found,
258
259
  making it suitable for use in CI and build pipelines.
259
260
 
261
+ ### Styling prop
262
+
263
+ If the styling prop is renamed, pass the name with `--style-prop`. Without the
264
+ flag, `plumerialint` asks ESLint for `settings.plumeria.styleProp` when ESLint
265
+ and a flat config are installed, and uses `classStyle` otherwise:
266
+
267
+ ```bash
268
+ plumerialint --style-prop sx
269
+ ```
270
+
260
271
  ### Aborting Builds on Lint Errors (Parallel Pipeline)
261
272
 
262
273
  You can run `plumerialint` in parallel with your build command (e.g. `next build` or `vite build`) using the `--` separator:
package/bin/oxlint.js CHANGED
@@ -3,6 +3,7 @@
3
3
  const { spawn } = require('child_process');
4
4
  const process = require('process');
5
5
  const path = require('path');
6
+ const fs = require('fs');
6
7
  const oxlintConfig = path.join(__dirname, '..', 'oxlint.json');
7
8
  const oxlintBin = path.join(
8
9
  path.dirname(require.resolve('oxlint/package.json')),
@@ -10,49 +11,69 @@ const oxlintBin = path.join(
10
11
  'oxlint',
11
12
  );
12
13
 
14
+ const { cliOverrides } = require('../dist/cli.js');
15
+ const { lintConfig } = require('../dist/guard.js');
16
+
13
17
  const doubleDashIndex = process.argv.indexOf('--');
14
- let oxlintExtraArgs = [];
18
+ let cliArgs = [];
15
19
  let buildCommand = null;
16
20
  let buildArgs = [];
17
21
 
18
22
  if (doubleDashIndex !== -1) {
19
- oxlintExtraArgs = process.argv.slice(2, doubleDashIndex);
23
+ cliArgs = process.argv.slice(2, doubleDashIndex);
20
24
  if (doubleDashIndex + 1 < process.argv.length) {
21
25
  buildCommand = process.argv[doubleDashIndex + 1];
22
26
  buildArgs = process.argv.slice(doubleDashIndex + 2);
23
27
  }
24
28
  } else {
25
- oxlintExtraArgs = process.argv.slice(2);
29
+ cliArgs = process.argv.slice(2);
26
30
  }
27
31
 
28
- const oxlintArgs = [
29
- oxlintBin,
30
- '-c',
31
- oxlintConfig,
32
- '--deny-warnings',
33
- '--no-error-on-unmatched-pattern',
34
- ...oxlintExtraArgs,
35
- ];
32
+ async function startOxlint() {
33
+ const { overrides, rest } = await cliOverrides(cliArgs, process.cwd());
34
+ const config = lintConfig(overrides);
35
+ const child = spawn(
36
+ process.execPath,
37
+ [
38
+ oxlintBin,
39
+ '-c',
40
+ config,
41
+ '--deny-warnings',
42
+ '--no-error-on-unmatched-pattern',
43
+ ...rest,
44
+ ],
45
+ { stdio: 'inherit' },
46
+ );
47
+ if (config !== oxlintConfig) {
48
+ child.on('close', () => fs.rmSync(config, { force: true }));
49
+ }
50
+ return child;
51
+ }
36
52
 
37
53
  function handleOxlintError(err) {
38
54
  console.error('Error running oxlint:', err.message);
39
55
  process.exit(1);
40
56
  }
41
57
 
58
+ function fail(err) {
59
+ console.error(`✖ [plumerialint] ${err.message}`);
60
+ process.exit(1);
61
+ }
62
+
42
63
  if (!buildCommand) {
43
- const child = spawn(process.execPath, oxlintArgs, { stdio: 'inherit' });
44
- child.on('error', handleOxlintError);
45
- child.on('close', (code) => {
46
- process.exit(code || 0);
47
- });
64
+ startOxlint().then((child) => {
65
+ child.on('error', handleOxlintError);
66
+ child.on('close', (code) => {
67
+ process.exit(code || 0);
68
+ });
69
+ }, fail);
48
70
  } else {
49
71
  let oxlintExited = false;
50
72
  let oxlintCode = null;
51
73
  let buildExited = false;
52
74
  let buildCode = null;
53
75
  let aborted = false;
54
-
55
- const oxlintChild = spawn(process.execPath, oxlintArgs, { stdio: 'inherit' });
76
+ let oxlintChild = null;
56
77
 
57
78
  const fullBuildCommand =
58
79
  buildArgs.length > 0
@@ -78,16 +99,12 @@ if (!buildCommand) {
78
99
  } else if (failedSource === 'build') {
79
100
  console.error(`\n✖ [plumerialint] Build failed. Aborting lint...`);
80
101
  try {
81
- oxlintChild.kill();
102
+ if (oxlintChild) oxlintChild.kill();
82
103
  } catch (e) {}
83
104
  process.exit(exitCode || 1);
84
105
  }
85
106
  }
86
107
 
87
- oxlintChild.on('error', (err) => {
88
- handleOxlintError(err);
89
- });
90
-
91
108
  buildChild.on('error', (err) => {
92
109
  console.error(
93
110
  `Error running build command "${buildCommand}":`,
@@ -96,16 +113,6 @@ if (!buildCommand) {
96
113
  abort(1, 'build');
97
114
  });
98
115
 
99
- oxlintChild.on('close', (code) => {
100
- oxlintExited = true;
101
- oxlintCode = code;
102
- if (code !== 0) {
103
- abort(code, 'lint');
104
- } else if (buildExited) {
105
- process.exit(buildCode || 0);
106
- }
107
- });
108
-
109
116
  buildChild.on('close', (code) => {
110
117
  buildExited = true;
111
118
  buildCode = code;
@@ -115,4 +122,22 @@ if (!buildCommand) {
115
122
  process.exit(oxlintCode || 0);
116
123
  }
117
124
  });
125
+
126
+ startOxlint().then((child) => {
127
+ if (aborted) {
128
+ child.kill();
129
+ return;
130
+ }
131
+ oxlintChild = child;
132
+ child.on('error', handleOxlintError);
133
+ child.on('close', (code) => {
134
+ oxlintExited = true;
135
+ oxlintCode = code;
136
+ if (code !== 0) {
137
+ abort(code, 'lint');
138
+ } else if (buildExited) {
139
+ process.exit(buildCode || 0);
140
+ }
141
+ });
142
+ }, fail);
118
143
  }
package/dist/cli.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { type LintOverrides } from './guard';
2
+ export declare function takeStyleProp(args: string[]): {
3
+ styleProp?: string;
4
+ rest: string[];
5
+ };
6
+ export declare function stylePropFromESLint(cwd: string): Promise<string | undefined>;
7
+ export declare function cliOverrides(args: string[], cwd: string): Promise<{
8
+ overrides: LintOverrides;
9
+ rest: string[];
10
+ }>;
package/dist/cli.js ADDED
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.takeStyleProp = takeStyleProp;
37
+ exports.stylePropFromESLint = stylePropFromESLint;
38
+ exports.cliOverrides = cliOverrides;
39
+ const path = __importStar(require("path"));
40
+ const guard_1 = require("./guard");
41
+ const STYLE_PROP_FLAG = '--style-prop';
42
+ const PROBED_FILES = ['src/index.tsx', 'app/page.tsx', 'index.tsx', 'index.js'];
43
+ function takeStyleProp(args) {
44
+ const rest = [];
45
+ let styleProp;
46
+ for (let i = 0; i < args.length; i++) {
47
+ const arg = args[i];
48
+ if (arg === STYLE_PROP_FLAG) {
49
+ styleProp = args[++i];
50
+ if (!styleProp)
51
+ throw new Error(`${STYLE_PROP_FLAG} needs a prop name`);
52
+ }
53
+ else if (arg.startsWith(`${STYLE_PROP_FLAG}=`)) {
54
+ styleProp = arg.slice(STYLE_PROP_FLAG.length + 1);
55
+ if (!styleProp)
56
+ throw new Error(`${STYLE_PROP_FLAG} needs a prop name`);
57
+ }
58
+ else {
59
+ rest.push(arg);
60
+ }
61
+ }
62
+ return { styleProp, rest };
63
+ }
64
+ async function stylePropFromESLint(cwd) {
65
+ let eslint;
66
+ try {
67
+ eslint = require(require.resolve('eslint', { paths: [cwd] }));
68
+ }
69
+ catch {
70
+ return undefined;
71
+ }
72
+ try {
73
+ const ESLint = eslint.loadESLint
74
+ ? await eslint.loadESLint({ useFlatConfig: true })
75
+ : eslint.ESLint;
76
+ const instance = new ESLint({ cwd });
77
+ for (const file of PROBED_FILES) {
78
+ const config = (await instance.calculateConfigForFile(path.join(cwd, file)));
79
+ const styleProp = config?.settings?.plumeria?.styleProp;
80
+ if (typeof styleProp === 'string')
81
+ return styleProp;
82
+ }
83
+ }
84
+ catch {
85
+ return undefined;
86
+ }
87
+ return undefined;
88
+ }
89
+ async function cliOverrides(args, cwd) {
90
+ const { styleProp, rest } = takeStyleProp(args);
91
+ return {
92
+ overrides: (0, guard_1.lintOverrides)({
93
+ styleProp: styleProp ?? (await stylePropFromESLint(cwd)),
94
+ }),
95
+ rest,
96
+ };
97
+ }
package/dist/guard.d.ts CHANGED
@@ -1,11 +1,20 @@
1
- export declare const GUARD_ENV = "PLUMERIA_LINT_GUARD";
2
1
  type Spelling = boolean | {
3
2
  sizes?: boolean;
4
3
  } | undefined;
5
- export interface SpellingOptions {
4
+ interface LintOptions {
6
5
  withoutLogicalProperties?: Spelling;
7
6
  withoutPhysicalProperties?: Spelling;
7
+ styleProp?: string;
8
8
  }
9
- export declare function spellingRules(options: SpellingOptions): Record<string, unknown>;
10
- export declare function startLintGuard(rules?: Record<string, unknown>): boolean;
9
+ export interface LintOverrides {
10
+ rules?: Record<string, unknown>;
11
+ settings?: {
12
+ plumeria: {
13
+ styleProp: string;
14
+ };
15
+ };
16
+ }
17
+ export declare function lintOverrides(options: LintOptions): LintOverrides;
18
+ export declare function lintConfig(overrides: LintOverrides): string;
19
+ export declare function startLintGuard(overrides?: LintOverrides): boolean;
11
20
  export {};
package/dist/guard.js CHANGED
@@ -33,14 +33,14 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.GUARD_ENV = void 0;
37
- exports.spellingRules = spellingRules;
36
+ exports.lintOverrides = lintOverrides;
37
+ exports.lintConfig = lintConfig;
38
38
  exports.startLintGuard = startLintGuard;
39
39
  const child_process_1 = require("child_process");
40
40
  const fs = __importStar(require("fs"));
41
41
  const os = __importStar(require("os"));
42
42
  const path = __importStar(require("path"));
43
- exports.GUARD_ENV = 'PLUMERIA_LINT_GUARD';
43
+ const GUARD_ENV = 'PLUMERIA_LINT_GUARD';
44
44
  const BASE_CONFIG = path.join(__dirname, '..', 'oxlint.json');
45
45
  function spellingRule(spelling) {
46
46
  if (!spelling)
@@ -49,7 +49,8 @@ function spellingRule(spelling) {
49
49
  ? ['error', { sizes: true }]
50
50
  : 'error';
51
51
  }
52
- function spellingRules(options) {
52
+ function lintOverrides(options) {
53
+ const overrides = {};
53
54
  const rules = {};
54
55
  const logical = spellingRule(options.withoutLogicalProperties);
55
56
  const physical = spellingRule(options.withoutPhysicalProperties);
@@ -57,20 +58,25 @@ function spellingRules(options) {
57
58
  rules['@plumeria/no-logical-properties'] = logical;
58
59
  if (physical)
59
60
  rules['@plumeria/no-physical-properties'] = physical;
60
- return rules;
61
+ if (logical || physical)
62
+ overrides.rules = rules;
63
+ if (options.styleProp) {
64
+ overrides.settings = { plumeria: { styleProp: options.styleProp } };
65
+ }
66
+ return overrides;
61
67
  }
62
- function lintConfig(rules) {
63
- if (Object.keys(rules).length === 0)
68
+ function lintConfig(overrides) {
69
+ if (!overrides.rules && !overrides.settings)
64
70
  return BASE_CONFIG;
65
71
  const file = path.join(os.tmpdir(), `plumeria-oxlint-${process.pid}.json`);
66
- fs.writeFileSync(file, JSON.stringify({ extends: [BASE_CONFIG], rules }));
72
+ fs.writeFileSync(file, JSON.stringify({ extends: [BASE_CONFIG], ...overrides }));
67
73
  return file;
68
74
  }
69
- function startLintGuard(rules = {}) {
70
- if (process.env[exports.GUARD_ENV])
75
+ function startLintGuard(overrides = {}) {
76
+ if (process.env[GUARD_ENV])
71
77
  return false;
72
- process.env[exports.GUARD_ENV] = '1';
73
- const config = lintConfig(rules);
78
+ process.env[GUARD_ENV] = '1';
79
+ const config = lintConfig(overrides);
74
80
  const child = (0, child_process_1.spawn)(process.execPath, [
75
81
  path.join(path.dirname(require.resolve('oxlint/package.json')), 'bin', 'oxlint'),
76
82
  '-c',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/eslint-plugin",
3
- "version": "19.10.0",
3
+ "version": "19.10.2",
4
4
  "description": "Plumeria ESLint plugin",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -59,7 +59,7 @@
59
59
  "known-css-properties": "^0.37.0",
60
60
  "oxlint": "1.87.0",
61
61
  "zss-engine": "2.9.1",
62
- "@plumeria/compiler": "19.10.0"
62
+ "@plumeria/compiler": "19.10.2"
63
63
  },
64
64
  "scripts": {
65
65
  "build": "rimraf dist && pnpm cjs",