@metamask-previews/oxlint-config 0.0.0-preview-60e73da

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/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ [Unreleased]: https://github.com/MetaMask/oxlint-config/
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 MetaMask
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # `@metamask/oxlint-config`
2
+
3
+ MetaMask's base Oxlint configuration.
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ yarn add --dev \
9
+ @metamask/oxlint-config@^0.0.0 \
10
+ oxlint@^1.82.0
11
+ ```
12
+
13
+ The order in which you extend ESLint rules matters.
14
+ The `@metamask/*` Oxlint configs should be added to the config array _last_,
15
+ with `@metamask/oxlint-config` first, and `@metamask/oxlint-config-*` in any
16
+ order thereafter.
17
+
18
+ ```js
19
+ import base, { createConfig } from '@metamask/oxlint-config';
20
+
21
+ const config = createConfig({
22
+ extends: [
23
+ // Any custom shared config should be added here.
24
+ // ...
25
+
26
+ // This should be added last unless you know what you're doing.
27
+ base,
28
+ ],
29
+ });
30
+ ```
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@metamask-previews/oxlint-config",
3
+ "version": "0.0.0-preview-60e73da",
4
+ "description": "Shareable MetaMask Oxlint config",
5
+ "homepage": "https://github.com/MetaMask/oxlint-config#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/MetaMask/oxlint-config/issues"
8
+ },
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/MetaMask/oxlint-config.git"
13
+ },
14
+ "files": [
15
+ "src/",
16
+ "!src/**/*.test.js"
17
+ ],
18
+ "type": "module",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./src/index.d.ts",
22
+ "default": "./src/index.js"
23
+ }
24
+ },
25
+ "publishConfig": {
26
+ "access": "public",
27
+ "registry": "https://registry.npmjs.org/"
28
+ },
29
+ "scripts": {
30
+ "changelog:update": "../../scripts/update-changelog.sh @metamask/oxlint-config",
31
+ "changelog:validate": "../../scripts/validate-changelog.sh @metamask/oxlint-config",
32
+ "test": "oxlint ."
33
+ },
34
+ "dependencies": {
35
+ "deepmerge": "^4.3.1"
36
+ },
37
+ "devDependencies": {
38
+ "@metamask/auto-changelog": "^3.4.4",
39
+ "oxlint": "^1.82.0"
40
+ },
41
+ "peerDependencies": {
42
+ "oxlint": "^1.82.0"
43
+ },
44
+ "engines": {
45
+ "node": "^18.18 || >=20"
46
+ }
47
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import type { OxlintConfig } from 'oxlint';
2
+
3
+ /**
4
+ * Create a new Oxlint configuration object by merging extended configurations
5
+ * with the main configuration.
6
+ *
7
+ * @param options - An object containing custom configuration options to
8
+ * override or extend the base configuration.
9
+ * @returns A new Oxlint configuration object that combines the base
10
+ * configuration with the provided extensions.
11
+ */
12
+ export function createConfig(options: Partial<OxlintConfig>): OxlintConfig;
13
+
14
+ declare const config: OxlintConfig;
15
+ export default config;
package/src/index.js ADDED
@@ -0,0 +1,272 @@
1
+ // @ts-check
2
+
3
+ import { defineConfig } from 'oxlint';
4
+
5
+ export default defineConfig({
6
+ plugins: ['eslint', 'import', 'jsdoc', 'promise'],
7
+
8
+ categories: {
9
+ correctness: 'allow',
10
+ },
11
+
12
+ env: {
13
+ 'shared-node-browser': true,
14
+ },
15
+
16
+ rules: {
17
+ // Default ESLint rules, all set to "error" since Oxlint sets them to "warn"
18
+ // by default.
19
+ 'eslint/constructor-super': 'error',
20
+ 'eslint/for-direction': 'error',
21
+ 'eslint/no-async-promise-executor': 'error',
22
+ 'eslint/no-caller': 'error',
23
+ 'eslint/no-class-assign': 'error',
24
+ 'eslint/no-compare-neg-zero': 'error',
25
+ 'eslint/no-cond-assign': 'error',
26
+ 'eslint/no-const-assign': 'error',
27
+ 'eslint/no-constant-binary-expression': 'error',
28
+ 'eslint/no-constant-condition': 'error',
29
+ 'eslint/no-control-regex': 'error',
30
+ 'eslint/no-debugger': 'error',
31
+ 'eslint/no-delete-var': 'error',
32
+ 'eslint/no-dupe-class-members': 'error',
33
+ 'eslint/no-dupe-else-if': 'error',
34
+ 'eslint/no-dupe-keys': 'error',
35
+ 'eslint/no-duplicate-case': 'error',
36
+ 'eslint/no-empty-character-class': 'error',
37
+ 'eslint/no-empty-pattern': 'error',
38
+ 'eslint/no-empty-static-block': 'error',
39
+ 'eslint/no-eval': 'error',
40
+ 'eslint/no-ex-assign': 'error',
41
+ 'eslint/no-extra-boolean-cast': 'error',
42
+ 'eslint/no-func-assign': 'error',
43
+ 'eslint/no-global-assign': 'error',
44
+ 'eslint/no-import-assign': 'error',
45
+ 'eslint/no-invalid-regexp': 'error',
46
+ 'eslint/no-irregular-whitespace': 'error',
47
+ 'eslint/no-iterator': 'error',
48
+ 'eslint/no-loss-of-precision': 'error',
49
+ 'eslint/no-misleading-character-class': 'error',
50
+ 'eslint/no-new-native-nonconstructor': 'error',
51
+ 'eslint/no-nonoctal-decimal-escape': 'error',
52
+ 'eslint/no-obj-calls': 'error',
53
+ 'eslint/no-self-assign': 'error',
54
+ 'eslint/no-setter-return': 'error',
55
+ 'eslint/no-shadow-restricted-names': 'error',
56
+ 'eslint/no-sparse-arrays': 'error',
57
+ 'eslint/no-this-before-super': 'error',
58
+ 'eslint/no-unassigned-vars': 'error',
59
+ 'eslint/no-unsafe-finally': 'error',
60
+ 'eslint/no-unsafe-negation': 'error',
61
+ 'eslint/no-unsafe-optional-chaining': 'error',
62
+ 'eslint/no-unused-labels': 'error',
63
+ 'eslint/no-useless-backreference': 'error',
64
+ 'eslint/no-useless-catch': 'error',
65
+ 'eslint/no-useless-escape': 'error',
66
+ 'eslint/no-useless-rename': 'error',
67
+ 'eslint/no-with': 'error',
68
+ 'eslint/require-yield': 'error',
69
+ 'eslint/use-isnan': 'error',
70
+ 'eslint/valid-typeof': 'error',
71
+
72
+ // Extra ESLint rules that are not enabled by default, but we want to
73
+ // enable.
74
+ 'eslint/accessor-pairs': 'error',
75
+ 'eslint/array-callback-return': 'error',
76
+ 'eslint/block-scoped-var': 'error',
77
+ 'eslint/curly': ['error', 'all'],
78
+ 'eslint/default-case': 'error',
79
+ 'eslint/default-param-last': 'error',
80
+ 'eslint/eqeqeq': ['error', 'smart'],
81
+ 'eslint/grouped-accessor-pairs': 'error',
82
+ 'eslint/guard-for-in': 'error',
83
+ 'eslint/id-length': [
84
+ 'error',
85
+ {
86
+ min: 2,
87
+ properties: 'never',
88
+ exceptionPatterns: ['_', 'a', 'b', 'i', 'j', 'k'],
89
+ },
90
+ ],
91
+ 'eslint/new-cap': [
92
+ 'error',
93
+ {
94
+ newIsCap: true,
95
+ capIsNew: false,
96
+ },
97
+ ],
98
+ 'eslint/no-alert': 'error',
99
+ 'eslint/no-array-constructor': 'error',
100
+ 'eslint/no-bitwise': 'error',
101
+ 'eslint/no-constructor-return': 'error',
102
+ 'eslint/no-div-regex': 'error',
103
+ 'eslint/no-else-return': 'error',
104
+ 'eslint/no-empty-function': 'error',
105
+ 'eslint/no-eq-null': 'error',
106
+ 'eslint/no-extend-native': 'error',
107
+ 'eslint/no-extra-bind': 'error',
108
+ 'eslint/no-extra-label': 'error',
109
+ 'eslint/no-implicit-coercion': 'error',
110
+ 'eslint/no-inner-declarations': ['error', 'functions'],
111
+ 'eslint/no-labels': [
112
+ 'error',
113
+ {
114
+ allowLoop: false,
115
+ allowSwitch: false,
116
+ },
117
+ ],
118
+ 'eslint/no-lone-blocks': 'error',
119
+ 'eslint/no-lonely-if': 'error',
120
+ 'eslint/no-loop-func': 'error',
121
+ 'eslint/no-multi-assign': 'error',
122
+ 'eslint/no-multi-str': 'error',
123
+ 'eslint/no-negated-condition': 'error',
124
+ 'eslint/no-nested-ternary': 'error',
125
+ 'eslint/no-new': 'error',
126
+ 'eslint/no-new-func': 'error',
127
+ 'eslint/no-new-wrappers': 'error',
128
+ 'eslint/no-param-reassign': 'error',
129
+ 'eslint/no-plusplus': [
130
+ 'error',
131
+ {
132
+ allowForLoopAfterthoughts: true,
133
+ },
134
+ ],
135
+ 'eslint/no-proto': 'error',
136
+ 'eslint/no-return-assign': ['error', 'except-parens'],
137
+ 'eslint/no-script-url': 'error',
138
+ 'eslint/no-self-compare': 'error',
139
+ 'eslint/no-shadow': ['error', { builtinGlobals: true }],
140
+ 'eslint/no-template-curly-in-string': 'error',
141
+ 'eslint/no-throw-literal': 'error',
142
+ 'eslint/no-unmodified-loop-condition': 'error',
143
+ 'eslint/no-unneeded-ternary': [
144
+ 'error',
145
+ {
146
+ defaultAssignment: false,
147
+ },
148
+ ],
149
+ 'eslint/no-unused-expressions': [
150
+ 'error',
151
+ {
152
+ allowShortCircuit: true,
153
+ allowTernary: true,
154
+ },
155
+ ],
156
+ 'eslint/no-unused-vars': [
157
+ 'error',
158
+ {
159
+ vars: 'all',
160
+ args: 'all',
161
+ argsIgnorePattern: '[_]+',
162
+ ignoreRestSiblings: true,
163
+ },
164
+ ],
165
+ 'eslint/no-use-before-define': [
166
+ 'error',
167
+ {
168
+ functions: false,
169
+ },
170
+ ],
171
+ 'eslint/no-useless-call': 'error',
172
+ 'eslint/no-useless-computed-key': 'error',
173
+ 'eslint/no-useless-concat': 'error',
174
+ 'eslint/no-useless-constructor': 'error',
175
+ 'eslint/no-useless-return': 'error',
176
+ 'eslint/no-var': 'error',
177
+ 'eslint/no-void': 'error',
178
+ // 'eslint/object-shorthand': 'error',
179
+ 'eslint/operator-assignment': 'error',
180
+ 'eslint/prefer-const': 'error',
181
+ 'eslint/prefer-destructuring': [
182
+ 'error',
183
+ {
184
+ VariableDeclarator: {
185
+ array: false,
186
+ object: true,
187
+ },
188
+ AssignmentExpression: {
189
+ array: false,
190
+ object: false,
191
+ },
192
+ },
193
+ {
194
+ enforceForRenamedProperties: false,
195
+ },
196
+ ],
197
+ 'eslint/prefer-numeric-literals': 'error',
198
+ 'eslint/prefer-promise-reject-errors': 'error',
199
+ 'eslint/prefer-rest-params': 'error',
200
+ 'eslint/prefer-spread': 'error',
201
+ 'eslint/prefer-template': 'error',
202
+ 'eslint/radix': 'error',
203
+ 'eslint/symbol-description': 'error',
204
+ 'eslint/yoda': ['error', 'never'],
205
+
206
+ // Import rules.
207
+ 'import/extensions': [
208
+ 'error',
209
+ 'ignorePackages',
210
+ {
211
+ json: 'always',
212
+ },
213
+ ],
214
+ 'import/first': 'error',
215
+ 'import/no-absolute-path': 'error',
216
+ 'import/no-amd': 'error',
217
+ 'import/no-anonymous-default-export': 'error',
218
+ 'import/no-duplicates': 'error',
219
+ 'import/no-dynamic-require': 'error',
220
+ 'import/no-mutable-exports': 'error',
221
+ 'import/no-named-as-default': 'error',
222
+ 'import/no-named-as-default-member': 'error',
223
+ 'import/no-named-default': 'error',
224
+ 'import/no-nodejs-modules': 'error',
225
+ 'import/no-self-import': 'error',
226
+ 'import/no-unassigned-import': 'error',
227
+ 'import/no-webpack-loader-syntax': 'error',
228
+ 'import/unambiguous': 'error',
229
+
230
+ // JSDoc rules.
231
+ 'jsdoc/check-access': 'error',
232
+ 'jsdoc/check-property-names': 'error',
233
+ 'jsdoc/check-tag-names': 'error',
234
+ 'jsdoc/empty-tags': 'error',
235
+ 'jsdoc/implements-on-classes': 'error',
236
+ 'jsdoc/no-defaults': 'error',
237
+ 'jsdoc/require-param-name': 'error',
238
+ 'jsdoc/require-param': 'error',
239
+ 'jsdoc/require-param-description': 'error',
240
+ 'jsdoc/require-param-type': 'error',
241
+ 'jsdoc/require-property': 'error',
242
+ 'jsdoc/require-property-description': 'error',
243
+ 'jsdoc/require-property-name': 'error',
244
+ 'jsdoc/require-property-type': 'error',
245
+ 'jsdoc/require-returns': 'error',
246
+ 'jsdoc/require-returns-description': 'error',
247
+ 'jsdoc/require-returns-type': 'error',
248
+ 'jsdoc/require-yields': 'error',
249
+
250
+ // Promise rules.
251
+ 'promise/catch-or-return': [
252
+ 'error',
253
+ {
254
+ allowFinally: true,
255
+ },
256
+ ],
257
+ 'promise/no-callback-in-promise': 'error',
258
+ 'promise/no-nesting': 'error',
259
+ 'promise/no-promise-in-callback': 'error',
260
+ 'promise/no-return-in-finally': 'error',
261
+ 'promise/param-names': [
262
+ 'error',
263
+ {
264
+ resolvePattern: '^_?resolve',
265
+ rejectPattern: '^_?reject',
266
+ },
267
+ ],
268
+ 'promise/valid-params': 'error',
269
+ },
270
+ });
271
+
272
+ export { createConfig } from './utils.js';
package/src/utils.js ADDED
@@ -0,0 +1,89 @@
1
+ import deepmerge from 'deepmerge';
2
+
3
+ /**
4
+ * @typedef {import('oxlint').OxlintConfig} OxlintConfig
5
+ */
6
+
7
+ /**
8
+ * @typedef {import('eslint').Linter.Config} Config
9
+ *
10
+ * @typedef {Config & { extends?: Config | Config[] | Config[][] }} ConfigWithExtends
11
+ */
12
+
13
+ /**
14
+ * Get an array from a value. If the value is already an array, it is returned
15
+ * as is. Otherwise, the value is wrapped in an array.
16
+ *
17
+ * @template Type
18
+ * @param {Type | Type[]} value - The value to convert to an array.
19
+ * @returns {Type[]} The value as an array.
20
+ */
21
+ export function getArray(value) {
22
+ if (value === undefined) {
23
+ return [];
24
+ }
25
+
26
+ return Array.isArray(value) ? value : [value];
27
+ }
28
+
29
+ /**
30
+ * Create a config object that extends other configs.
31
+ *
32
+ * This function handles merging multiple configs together specified in the
33
+ * `extends` property of the input config. It recursively resolves any nested
34
+ * `extends` properties in the base configs as well. Oxlint by default only
35
+ * merges the `rules` and `plugins` properties of the configs, but this function
36
+ * can be used to merge any properties of the configs.
37
+ *
38
+ * @example <caption>Extending a single config</caption>
39
+ * import { createConfig } from '@metamask/oxlint-config';
40
+ * import typescript from '@metamask/oxlint-config-typescript';
41
+ *
42
+ * const configs = createConfig({
43
+ * extends: typescript,
44
+ * });
45
+ *
46
+ * export default configs;
47
+ *
48
+ * @example <caption>Extending multiple configs</caption>
49
+ * import { createConfig } from '@metamask/oxlint-config';
50
+ * import typescript from '@metamask/oxlint-config-typescript';
51
+ * import nodejs from '@metamask/oxlint-config-nodejs';
52
+ *
53
+ * const configs = createConfig({
54
+ * extends: [typescript, nodejs],
55
+ * });
56
+ *
57
+ * export default configs;
58
+ *
59
+ * @param {OxlintConfig} config - The config object to create, which may include
60
+ * an `extends` property that specifies one or more base configs to extend.
61
+ * @returns {Omit<OxlintConfig, "extends">} A single config object with all the
62
+ * extended configs merged in.
63
+ */
64
+ export function createConfig(config) {
65
+ const { extends: baseConfig, ...extension } = config;
66
+ const baseConfigs = getArray(baseConfig);
67
+
68
+ if (baseConfigs.length === 0) {
69
+ return extension;
70
+ }
71
+
72
+ const mergedBaseConfig = baseConfigs.reduce((mergedConfig, currentConfig) => {
73
+ const parsedConfig = currentConfig.extends
74
+ ? createConfig(currentConfig)
75
+ : currentConfig;
76
+
77
+ return deepmerge(mergedConfig, parsedConfig, {
78
+ arrayMerge(target, source, options) {
79
+ if (options?.isMergeableObject) {
80
+ return [...new Set([...target, ...source])];
81
+ }
82
+
83
+ return source;
84
+ },
85
+ });
86
+ }, {});
87
+
88
+ return deepmerge(mergedBaseConfig, extension);
89
+ }