@appium/oxc-config 1.1.0

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.
Files changed (4) hide show
  1. package/README.md +78 -0
  2. package/oxfmt.mjs +168 -0
  3. package/oxlint.mjs +210 -0
  4. package/package.json +47 -0
package/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # @appium/oxc-config
2
+
3
+ > Shared [Oxlint](https://oxc.rs/docs/guide/usage/linter) and [Oxfmt](https://oxc.rs/docs/guide/usage/formatter) configuration for [Appium](https://github.com/appium/appium) and Appium-adjacent projects.
4
+
5
+ [![NPM version](https://img.shields.io/npm/v/@appium/oxc-config.svg)](https://npmjs.org/package/@appium/oxc-config)
6
+ [![Downloads](https://img.shields.io/npm/dm/@appium/oxc-config.svg)](https://npmjs.org/package/@appium/oxc-config)
7
+
8
+ This package pins compatible `oxlint`, `oxlint-tsgolint`, and `oxfmt` versions. Import lint and format settings from their respective subpaths:
9
+
10
+ - `@appium/oxc-config/oxlint`
11
+ - `@appium/oxc-config/oxfmt`
12
+
13
+ ## Usage
14
+
15
+ Install the package:
16
+
17
+ ```bash
18
+ npm install @appium/oxc-config --save-dev
19
+ ```
20
+
21
+ ### Oxlint
22
+
23
+ Create `oxlint.config.mjs` in your project root:
24
+
25
+ ```js
26
+ import appiumConfig, {defineConfig, ignorePatterns} from '@appium/oxc-config/oxlint';
27
+
28
+ export default defineConfig({
29
+ extends: [appiumConfig],
30
+ ignorePatterns: [...ignorePatterns],
31
+ });
32
+ ```
33
+
34
+ Run Oxlint:
35
+
36
+ ```bash
37
+ npx oxlint -c oxlint.config.mjs .
38
+ ```
39
+
40
+ ### Oxfmt
41
+
42
+ Create `oxfmt.config.mjs` in your project root:
43
+
44
+ ```js
45
+ import appiumConfig, {defineConfig, ignorePatterns as appiumIgnorePatterns} from '@appium/oxc-config/oxfmt';
46
+
47
+ export default defineConfig({
48
+ ...appiumConfig,
49
+ ignorePatterns: [...appiumIgnorePatterns],
50
+ });
51
+ ```
52
+
53
+ Run Oxfmt:
54
+
55
+ ```bash
56
+ npx oxfmt -c oxfmt.config.mjs .
57
+ ```
58
+
59
+ ## Notes
60
+
61
+ - **Type-aware linting**: Oxlint config enables `options.typeAware` via the bundled `oxlint-tsgolint` dependency.
62
+ - **`.editorconfig`**: Oxfmt reads `.editorconfig` for unset formatting options (`printWidth`, `tabWidth`, `useTabs`, `endOfLine`, `insertFinalNewline`). The shared Oxfmt config applies Appium fallbacks only for options not defined in the nearest `.editorconfig`; defined options stay unset so Oxfmt can still apply section-specific values at format time.
63
+ - **`.gitignore`**: Oxlint and Oxfmt respect `.gitignore` automatically.
64
+ - **`ignorePatterns`**: Oxlint does not inherit `ignorePatterns` via `extends` — import and spread the exported arrays in your root config.
65
+
66
+ ### Rules without Oxlint equivalents
67
+
68
+ | Legacy rule | Notes |
69
+ | --- | --- |
70
+ | `@typescript-eslint/member-ordering` | Class member ordering |
71
+ | `n/no-deprecated-api` | Node.js deprecated API usage |
72
+ | `jsdoc/require-jsdoc` | JSDoc on exported functions |
73
+ | `perfectionist/sort-modules` | Export-before-non-export module ordering |
74
+ | `@stylistic/*` | Replaced by Oxfmt |
75
+
76
+ ## License
77
+
78
+ Licensed Apache-2.0
package/oxfmt.mjs ADDED
@@ -0,0 +1,168 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+
4
+ /**
5
+ * Default ignore patterns for Appium Oxfmt projects.
6
+ */
7
+ export {defineConfig} from 'oxfmt';
8
+
9
+ export const ignorePatterns = [
10
+ '**/.*',
11
+ '**/build/**',
12
+ '**/fixtures/**',
13
+ '**/*.min.*',
14
+ '**/*.md',
15
+ '**/*.html',
16
+ '**/generated/**',
17
+ '**/*.hbs',
18
+ '**/*mkdocs.{yml,yaml}',
19
+ ];
20
+
21
+ /**
22
+ * Appium fallback values for Oxfmt options that can also be supplied by
23
+ * `.editorconfig`. These mirror the monorepo `.editorconfig`.
24
+ *
25
+ * @see https://oxc.rs/docs/guide/usage/formatter/config#editorconfig
26
+ */
27
+ export const editorConfigFallbacks = {
28
+ printWidth: 120,
29
+ tabWidth: 2,
30
+ useTabs: false,
31
+ endOfLine: 'lf',
32
+ insertFinalNewline: true,
33
+ };
34
+
35
+ /** @type {Record<keyof typeof editorConfigFallbacks, string>} */
36
+ const editorConfigOptionKeys = {
37
+ printWidth: 'max_line_length',
38
+ tabWidth: 'indent_size',
39
+ useTabs: 'indent_style',
40
+ endOfLine: 'end_of_line',
41
+ insertFinalNewline: 'insert_final_newline',
42
+ };
43
+
44
+ /**
45
+ * @param {string} cwd
46
+ * @returns {string | null}
47
+ */
48
+ function findEditorConfig(cwd) {
49
+ let dir = path.resolve(cwd);
50
+
51
+ while (true) {
52
+ const file = path.join(dir, '.editorconfig');
53
+ if (fs.existsSync(file)) {
54
+ return file;
55
+ }
56
+
57
+ const parent = path.dirname(dir);
58
+ if (parent === dir) {
59
+ return null;
60
+ }
61
+
62
+ dir = parent;
63
+ }
64
+ }
65
+
66
+ /**
67
+ * @param {string} filePath
68
+ * @returns {Set<string>}
69
+ */
70
+ function parseEditorConfigDefinedKeys(filePath) {
71
+ /** @type {Set<string>} */
72
+ const definedKeys = new Set();
73
+
74
+ for (const line of fs.readFileSync(filePath, 'utf8').split(/\r?\n/u)) {
75
+ const trimmed = line.trim();
76
+ if (!trimmed || trimmed.startsWith('#') || trimmed.startsWith(';')) {
77
+ continue;
78
+ }
79
+
80
+ if (trimmed.startsWith('[') && trimmed.endsWith(']')) {
81
+ continue;
82
+ }
83
+
84
+ const separatorIndex = trimmed.indexOf('=');
85
+ if (separatorIndex === -1) {
86
+ continue;
87
+ }
88
+
89
+ definedKeys.add(trimmed.slice(0, separatorIndex).trim().toLowerCase());
90
+ }
91
+
92
+ return definedKeys;
93
+ }
94
+
95
+ /**
96
+ * Returns Appium fallbacks only for Oxfmt options not defined anywhere in the
97
+ * nearest ancestor `.editorconfig`.
98
+ *
99
+ * Options that are defined in `.editorconfig` are left unset so Oxfmt can
100
+ * still apply section-specific values (including glob overrides) at format time.
101
+ *
102
+ * @param {string} [cwd]
103
+ * @returns {Partial<typeof editorConfigFallbacks>}
104
+ */
105
+ export function resolveEditorConfigFallbacks(cwd = process.cwd()) {
106
+ const filePath = findEditorConfig(cwd);
107
+ if (!filePath) {
108
+ return {...editorConfigFallbacks};
109
+ }
110
+
111
+ const definedKeys = parseEditorConfigDefinedKeys(filePath);
112
+ /** @type {Partial<typeof editorConfigFallbacks>} */
113
+ const fallbacks = {};
114
+
115
+ for (const [oxfmtKey, ecKey] of Object.entries(editorConfigOptionKeys)) {
116
+ if (!definedKeys.has(ecKey)) {
117
+ fallbacks[/** @type {keyof typeof editorConfigFallbacks} */ (oxfmtKey)] =
118
+ editorConfigFallbacks[/** @type {keyof typeof editorConfigFallbacks} */ (oxfmtKey)];
119
+ }
120
+ }
121
+
122
+ return fallbacks;
123
+ }
124
+
125
+ /**
126
+ * Returns whether an `.editorconfig` file exists in `cwd` or any parent
127
+ * directory.
128
+ *
129
+ * @param {string} [cwd]
130
+ * @returns {boolean}
131
+ */
132
+ export function hasEditorConfig(cwd = process.cwd()) {
133
+ return findEditorConfig(cwd) !== null;
134
+ }
135
+
136
+ /**
137
+ * Build shared Oxfmt format options for Appium projects.
138
+ *
139
+ * Non-`.editorconfig` options are always set here. Options that Oxfmt can read
140
+ * from `.editorconfig` use {@link editorConfigFallbacks} only when that file
141
+ * does not define the corresponding property; otherwise they stay unset so
142
+ * Oxfmt can apply the file's values (including glob overrides) at format time.
143
+ *
144
+ * @param {string} [cwd]
145
+ * @returns {Record<string, unknown>}
146
+ */
147
+ export function createFormatOptions(cwd = process.cwd()) {
148
+ return {
149
+ semi: true,
150
+ singleQuote: true,
151
+ quoteProps: 'as-needed',
152
+ trailingComma: 'all',
153
+ bracketSpacing: false,
154
+ sortImports: true,
155
+ ...resolveEditorConfigFallbacks(cwd),
156
+ };
157
+ }
158
+
159
+ /**
160
+ * Shared Oxfmt configuration for Appium projects.
161
+ */
162
+ /** @type {Record<string, unknown>} */
163
+ const config = {
164
+ ...createFormatOptions(),
165
+ ignorePatterns,
166
+ };
167
+
168
+ export default config;
package/oxlint.mjs ADDED
@@ -0,0 +1,210 @@
1
+ export {defineConfig} from 'oxlint';
2
+
3
+ /**
4
+ * Default ignore patterns for Appium Oxlint projects.
5
+ *
6
+ * Oxlint does not inherit `ignorePatterns` via `extends`, so import and spread
7
+ * this array in your root config. Oxlint also respects `.gitignore` automatically.
8
+ */
9
+ export const ignorePatterns = ['**/.*', '**/*-d.ts', '**/build/**', '**/coverage/**', '**/build-fixtures/**'];
10
+
11
+ /**
12
+ * Shared Oxlint configuration for Appium projects.
13
+ *
14
+ * Migrated from @appium/eslint-config-appium-ts via @oxlint/migrate.
15
+ * Stylistic rules are intentionally omitted; use `@appium/oxc-config/oxfmt` instead.
16
+ *
17
+ * Rules not available in Oxlint (no equivalent yet):
18
+ * - @typescript-eslint/member-ordering
19
+ * - n/no-deprecated-api
20
+ * - jsdoc/require-jsdoc
21
+ * - perfectionist/sort-modules
22
+ */
23
+ /** @type {import('oxlint').OxlintConfig} */
24
+ const config = {
25
+ plugins: [],
26
+ categories: {
27
+ correctness: 'off',
28
+ },
29
+ options: {
30
+ typeAware: true,
31
+ },
32
+ env: {
33
+ builtin: true,
34
+ },
35
+ rules: {
36
+ // --- ESLint recommended (js/recommended) ---
37
+ 'constructor-super': 'error',
38
+ 'for-direction': 'error',
39
+ 'getter-return': 'error',
40
+ 'no-async-promise-executor': 'error',
41
+ 'no-case-declarations': 'error',
42
+ 'no-class-assign': 'error',
43
+ 'no-compare-neg-zero': 'error',
44
+ 'no-cond-assign': 'error',
45
+ 'no-const-assign': 'error',
46
+ 'no-constant-binary-expression': 'error',
47
+ 'no-constant-condition': 'error',
48
+ 'no-control-regex': 'error',
49
+ 'no-debugger': 'error',
50
+ 'no-delete-var': 'error',
51
+ 'no-dupe-class-members': 'error',
52
+ 'no-dupe-else-if': 'error',
53
+ 'no-dupe-keys': 'error',
54
+ 'no-duplicate-case': 'error',
55
+ 'no-empty': 'off',
56
+ 'no-empty-character-class': 'error',
57
+ 'no-empty-pattern': 'error',
58
+ 'no-empty-static-block': 'error',
59
+ 'no-ex-assign': 'error',
60
+ 'no-extra-boolean-cast': 'error',
61
+ 'no-fallthrough': 'error',
62
+ 'no-func-assign': 'error',
63
+ 'no-global-assign': 'error',
64
+ 'no-import-assign': 'error',
65
+ 'no-invalid-regexp': 'error',
66
+ 'no-irregular-whitespace': 'error',
67
+ 'no-loss-of-precision': 'error',
68
+ 'no-misleading-character-class': 'error',
69
+ 'no-new-native-nonconstructor': 'error',
70
+ 'no-nonoctal-decimal-escape': 'error',
71
+ 'no-obj-calls': 'error',
72
+ 'no-prototype-builtins': 'warn',
73
+ 'no-redeclare': 'error',
74
+ 'no-regex-spaces': 'error',
75
+ 'no-self-assign': 'error',
76
+ 'no-setter-return': 'error',
77
+ 'no-shadow-restricted-names': 'error',
78
+ 'no-sparse-arrays': 'error',
79
+ 'no-this-before-super': 'error',
80
+ 'no-unassigned-vars': 'warn',
81
+ 'no-undef': 'error',
82
+ 'no-unexpected-multiline': 'off',
83
+ 'no-unreachable': 'error',
84
+ 'no-unsafe-finally': 'error',
85
+ 'no-unsafe-negation': 'error',
86
+ 'no-unsafe-optional-chaining': 'error',
87
+ 'no-unused-labels': 'error',
88
+ 'no-unused-private-class-members': 'error',
89
+ 'no-unused-vars': 'warn',
90
+ 'no-useless-assignment': 'warn',
91
+ 'no-useless-backreference': 'error',
92
+ 'no-useless-catch': 'error',
93
+ 'no-useless-escape': 'error',
94
+ 'no-with': 'error',
95
+ 'preserve-caught-error': 'warn',
96
+ 'require-yield': 'error',
97
+ 'use-isnan': 'error',
98
+ 'valid-typeof': 'error',
99
+
100
+ // --- eslint-plugin-promise (flat/recommended) ---
101
+ 'promise/always-return': 'error',
102
+ 'promise/no-return-wrap': 'warn',
103
+ 'promise/param-names': 'warn',
104
+ 'promise/catch-or-return': 'warn',
105
+ 'promise/no-nesting': 'warn',
106
+ 'promise/no-promise-in-callback': 'warn',
107
+ 'promise/no-callback-in-promise': 'warn',
108
+ 'promise/avoid-new': 'off',
109
+ 'promise/no-new-statics': 'error',
110
+ 'promise/no-return-in-finally': 'warn',
111
+ 'promise/valid-params': 'warn',
112
+ 'promise/prefer-await-to-callbacks': 'warn',
113
+ 'promise/prefer-await-to-then': 'warn',
114
+
115
+ // --- eslint-plugin-import-x (flat/recommended) ---
116
+ 'import/named': 'warn',
117
+ 'import/namespace': 'error',
118
+ 'import/default': 'error',
119
+ 'import/export': 'error',
120
+ 'import/no-named-as-default': 'warn',
121
+ 'import/no-named-as-default-member': 'warn',
122
+ 'import/no-duplicates': 'error',
123
+
124
+ // --- typescript-eslint recommended ---
125
+ 'no-array-constructor': 'error',
126
+ 'no-unused-expressions': 'error',
127
+ 'typescript/ban-ts-comment': [
128
+ 'warn',
129
+ {
130
+ 'ts-expect-error': 'allow-with-description',
131
+ 'ts-ignore': 'allow-with-description',
132
+ },
133
+ ],
134
+ 'typescript/no-duplicate-enum-values': 'error',
135
+ 'typescript/no-empty-object-type': 'off',
136
+ 'typescript/no-explicit-any': 'off',
137
+ 'typescript/no-extra-non-null-assertion': 'error',
138
+ 'typescript/no-misused-new': 'error',
139
+ 'typescript/no-namespace': 'error',
140
+ 'typescript/no-non-null-asserted-optional-chain': 'error',
141
+ 'typescript/no-require-imports': 'off',
142
+ 'typescript/no-this-alias': 'error',
143
+ 'typescript/no-unnecessary-type-constraint': 'error',
144
+ 'typescript/no-unsafe-declaration-merging': 'error',
145
+ 'typescript/no-unsafe-function-type': 'error',
146
+ 'typescript/no-wrapper-object-types': 'error',
147
+ 'typescript/prefer-as-const': 'error',
148
+ 'typescript/prefer-namespace-keyword': 'error',
149
+ 'typescript/triple-slash-reference': 'error',
150
+ 'typescript/consistent-type-imports': [
151
+ 'error',
152
+ {
153
+ prefer: 'type-imports',
154
+ fixStyle: 'separate-type-imports',
155
+ },
156
+ ],
157
+ 'typescript/no-non-null-assertion': 'warn',
158
+ 'typescript/dot-notation': 'error',
159
+
160
+ // --- Appium custom rules ---
161
+ curly: 'error',
162
+ 'arrow-body-style': 'warn',
163
+ eqeqeq: ['error', 'smart'],
164
+ 'no-console': 'error',
165
+ 'object-shorthand': 'error',
166
+ radix: 'error',
167
+ 'require-await': 'off',
168
+ 'no-empty-function': 'off',
169
+ 'unicorn/prefer-node-protocol': 'warn',
170
+
171
+ // eslint-config-prettier disables (kept for parity with legacy config)
172
+ 'unicorn/empty-brace-spaces': 'off',
173
+ 'unicorn/no-nested-ternary': 'off',
174
+ 'unicorn/number-literal-case': 'off',
175
+ },
176
+ overrides: [
177
+ {
178
+ files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
179
+ plugins: ['promise', 'import', 'typescript', 'unicorn'],
180
+ env: {
181
+ es2022: true,
182
+ node: true,
183
+ },
184
+ globals: {
185
+ NodeJS: 'readonly',
186
+ BufferEncoding: 'readonly',
187
+ },
188
+ },
189
+ {
190
+ files: ['**/*.{ts,tsx,mtsx}'],
191
+ plugins: ['typescript'],
192
+ rules: {
193
+ 'typescript/no-floating-promises': 'warn',
194
+ },
195
+ },
196
+ {
197
+ files: ['**/test/**'],
198
+ plugins: ['typescript', 'import'],
199
+ rules: {
200
+ 'no-unused-expressions': 'off',
201
+ 'import/no-named-as-default-member': 'off',
202
+ 'typescript/ban-ts-comment': 'off',
203
+ 'typescript/no-non-null-assertion': 'off',
204
+ 'typescript/no-floating-promises': 'off',
205
+ },
206
+ },
207
+ ],
208
+ };
209
+
210
+ export default config;
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@appium/oxc-config",
3
+ "version": "1.1.0",
4
+ "description": "Shared Oxlint and Oxfmt config for Appium projects",
5
+ "keywords": [
6
+ "appium",
7
+ "oxc",
8
+ "oxfmt",
9
+ "oxlint",
10
+ "typescript"
11
+ ],
12
+ "homepage": "https://appium.io",
13
+ "bugs": {
14
+ "url": "https://github.com/appium/appium/issues"
15
+ },
16
+ "license": "Apache-2.0",
17
+ "author": "https://github.com/appium",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/appium/appium.git",
21
+ "directory": "packages/oxc-config"
22
+ },
23
+ "files": [
24
+ "oxlint.mjs",
25
+ "oxfmt.mjs"
26
+ ],
27
+ "type": "module",
28
+ "exports": {
29
+ "./oxlint": "./oxlint.mjs",
30
+ "./oxfmt": "./oxfmt.mjs"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "scripts": {
36
+ "test:smoke": "node scripts/test-smoke.mjs"
37
+ },
38
+ "dependencies": {
39
+ "oxfmt": "0.59.0",
40
+ "oxlint": "1.74.0",
41
+ "oxlint-tsgolint": "0.25.0"
42
+ },
43
+ "engines": {
44
+ "node": "^20.19.0 || ^22.12.0 || >=24.0.0",
45
+ "npm": ">=10"
46
+ }
47
+ }